:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #fbfaf8;
  --soft: #f2f0ec;
  --text: #1b1b1b;
  --muted: #636363;
  --light: #8a8a8a;
  --line: #e5e2dd;
  --line-strong: #d7d2ca;
  --gold: #9a7b56;
  --red: #b84e42;
  --red-soft: #f8e9e6;
  --green: #2f7456;
  --green-soft: #eaf4ef;
  --amber-soft: #fff4dc;
  --blue-soft: #e8f1f5;
  --radius: 8px;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 247, 245, 0.96) 220px),
    var(--bg);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(229, 226, 221, 0.86);
  background: rgba(247, 247, 245, 0.92);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 2.4vw, 38px);
  line-height: 1.12;
  font-weight: 760;
}

.subtitle {
  margin: 8px 0 0;
  max-width: 560px;
  color: var(--muted);
  font-size: 14px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
}

.nav button, .button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 8px 13px;
}

.nav button {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 7px 13px;
}

.nav button.active, .button.primary {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.button.ghost { background: transparent; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.panel-head h2 { margin: 0; font-size: 16px; font-weight: 760; }
.panel-head span { color: var(--light); font-size: 12px; }
.panel-body { padding: 14px; }

.login-card {
  max-width: 430px;
  margin: 86px auto 0;
}

.login-card .panel {
  border-color: var(--line-strong);
  box-shadow: 0 18px 42px rgba(30, 27, 22, 0.08);
}

.login-card .panel-head {
  padding: 18px 18px 14px;
  background: var(--surface);
}

.login-card .panel-head h2 { font-size: 20px; }
.login-body { display: grid; gap: 12px; padding: 18px; }

input, select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid rgba(154, 123, 86, 0.18);
  border-color: var(--gold);
}

.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.error { min-height: 20px; margin: 0; color: var(--red); }

.identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.view {
  display: none;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.view.active { display: grid; }
.side { position: sticky; top: 108px; }
.stack { display: grid; gap: 11px; }

label, .label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.work { min-width: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 7px; }

.segmented button {
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.segmented button.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 12px;
}

.stat {
  min-height: 76px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-value { font-size: 26px; font-weight: 860; line-height: 1.05; }
.stat-label { margin-top: 5px; color: var(--muted); font-size: 12px; }

.student-grid, .score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 8px;
}

.student-card, .score-card, .rank-item, .log-item, .question-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.student-card {
  display: grid;
  gap: 8px;
  min-height: 90px;
  padding: 10px;
  text-align: left;
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.student-card:hover:not(:disabled) {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.student-card:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.student-card.good { background: var(--green-soft); }
.student-card.warn { background: var(--amber-soft); }
.student-card.bad { background: var(--red-soft); }
.student-card.blue { background: var(--blue-soft); }

.student-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.student-id, .rank-no { color: var(--gold); font-size: 12px; font-weight: 860; }
.student-name { font-size: 16px; font-weight: 800; }

.badge {
  display: inline-flex;
  min-width: 32px;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 860;
}

.summary-lists {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.list-box {
  min-height: 106px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.list-box h3 { margin: 0 0 7px; font-size: 14px; }
.list-box p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.rank-list, .drawer {
  display: grid;
  gap: 7px;
  max-height: 560px;
  overflow: auto;
}

.rank-item, .log-item, .question-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  text-align: left;
}

.rank-score { font-size: 20px; font-weight: 860; }
.rank-title, .log-meta { color: var(--muted); font-size: 12px; }
.score-card { padding: 10px; }

.score-actions {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.round-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
}

.round-btn.minus { background: var(--red); }
.score-now { text-align: center; font-size: 24px; font-weight: 860; }

.quiz-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 420px;
  gap: 14px;
}

.quiz-card {
  display: grid;
  gap: 16px;
  place-items: center;
  min-height: 330px;
  margin-top: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  text-align: center;
}

.quiz-id { color: var(--gold); font-weight: 860; }
.quiz-title { font-size: 32px; font-weight: 860; }
.quiz-meta { color: var(--muted); }

.type-manager {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.type-manager summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
}

.type-create {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.type-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.type-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

@media (max-width: 980px) {
  .topbar { position: static; flex-direction: column; align-items: stretch; }
  .nav { justify-content: flex-start; border-radius: var(--radius); }
  .view.active, .quiz-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .stats, .summary-lists { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .app { width: min(100vw - 20px, 1500px); padding-top: 14px; }
  h1 { font-size: 28px; }
  .login-card { margin-top: 48px; }
  .student-grid, .score-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats, .summary-lists { grid-template-columns: 1fr; }
}
