/* ── Design Tokens (OKLCH) ── */
:root {
  /* Brand: Light + cyan accent (TikTok vibe) */
  --bg: oklch(0.985 0.003 260);         /* near-white */
  --surface: oklch(1 0 0);               /* pure white */
  --surface-raised: oklch(0.97 0.005 260);
  --ink: oklch(0.14 0.015 260);          /* near-black */
  --muted: oklch(0.52 0.02 260);         /* secondary text */
  --line: oklch(0.9 0.01 260);           /* light border */
  --accent: oklch(0.62 0.2 175);         /* cyan – TikTok vibe */
  --accent-hover: oklch(0.55 0.22 175);
  --accent-dim: oklch(0.62 0.2 175 / 0.08);
  --success: oklch(0.62 0.18 145);
  --warn: oklch(0.7 0.16 75);
  --danger: oklch(0.58 0.22 25);

  /* Typography */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Spacing */
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3, p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: oklch(1 0 0 / 0.92);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-link {
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.logo-link:hover { opacity: 0.8; }
.logo-link img { display: block; height: 32px; width: auto; }

.brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

/* Timer */
.timer {
  flex-shrink: 0;
  min-width: 110px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: right;
}

.timer span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.timer strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--accent);
  font-family: var(--font-mono);
}

.timer.is-low strong {
  color: var(--danger);
  animation: pulse-warn 1.2s ease-in-out infinite;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Mode Screen ── */
.mode-screen {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 64px);
  padding: 32px 20px;
}

.mode-panel {
  width: min(720px, 100%);
  text-align: center;
}

.mode-panel h2 {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  text-wrap: balance;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--ink), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.mode-panel > p {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 36px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 200px;
  padding: 28px 24px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.mode-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, oklch(0.62 0.2 175 / 0.04), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px oklch(0.62 0.2 175 / 0.1);
}

.mode-card:hover::before { opacity: 1; }

.mode-card strong {
  position: relative;
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  color: var(--ink);
}

.mode-card span {
  position: relative;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.mode-card.primary-mode {
  background: linear-gradient(145deg, oklch(0.62 0.2 175), oklch(0.55 0.22 175));
  border-color: oklch(0.62 0.2 175 / 0.4);
}

.mode-card.primary-mode strong { color: #fff; }
.mode-card.primary-mode span { color: oklch(1 0 0 / 0.85); }

.mode-card.primary-mode:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 40px oklch(0.62 0.2 175 / 0.2);
}

/* ── Layout (Exam View) ── */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 24px;
}

.is-hidden { display: none !important; }

/* ── Sidebar ── */
.sidebar {
  position: sticky;
  top: 76px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.student-panel {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.student-panel label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.student-panel label + label { margin-top: 14px; }

.student-panel input {
  width: 100%;
  height: 38px;
  margin-top: 6px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.2s;
}

.student-panel input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.student-panel input::placeholder { color: oklch(0.65 0.01 260); }

.score-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.score-preview span {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.score-preview strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Question Nav */
.question-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.question-nav a {
  display: grid;
  place-items: center;
  height: 34px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.15s;
  font-variant-numeric: tabular-nums;
}

.question-nav a:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.question-nav a.done {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: oklch(0.78 0.18 175 / 0.25);
}

/* ── Paper (Exam Content) ── */
.paper { min-width: 0; }

/* Notice box */
.notice {
  padding: 18px 20px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);}

.notice h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
}

.notice ol {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  color: var(--muted);
}

.notice li + li { margin-top: 4px; }

/* Section headers */
.section-header {
  margin: 28px 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Questions ── */
.question {
  padding: 20px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}

.question:hover { border-color: oklch(0.35 0.02 260); }

.question-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.question h3 {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.5;
  flex: 1;
}

.question h3 .meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 6px;
}

.points {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* Options */
.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 14px;
  line-height: 1.5;
}

.option:hover {
  border-color: oklch(0.62 0.2 175 / 0.3);
  background: oklch(0.62 0.2 175 / 0.04);
}

.option input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.option strong {
  font-weight: 600;
  color: var(--muted);
  margin-right: 2px;
}

/* Case table */
.case-table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  font-size: 13px;
}

.case-table th,
.case-table td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.case-table th {
  background: oklch(0.96 0.005 260);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.case-table td {
  font-variant-numeric: tabular-nums;
}

/* Subquestions */
.subquestions {
  margin: 14px 0;
  padding-left: 20px;
  font-size: 14px;
}

.subquestions li {
  margin-bottom: 6px;
  line-height: 1.55;
}

/* Essay textarea */
.question textarea {
  width: 100%;
  min-height: 160px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s;
}

.question textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.question textarea::placeholder { color: oklch(0.6 0.01 260); }

/* ── Submit Panel ── */
.submit-panel {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 0;
  margin-top: 24px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

/* ── Buttons ── */
button {
  min-height: 42px;
  padding: 0 20px;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
}

button:hover {
  border-color: oklch(0.62 0.2 175 / 0.4);
  background: var(--accent-dim);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 16px oklch(0.78 0.18 175 / 0.25);
}

/* ── Dialog (Results) ── */
dialog {
  width: min(860px, calc(100vw - 32px));
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--ink);
  overflow: hidden;
}

dialog::backdrop {
  background: oklch(0.08 0.02 260 / 0.8);
  backdrop-filter: blur(8px);
}

dialog h2 {
  padding: 24px 28px 0;
  font-size: 20px;
  font-weight: 800;
}

.result-hero {
  margin: 20px 28px 0;
  padding: 40px 24px;
  text-align: center;
  background: linear-gradient(145deg, oklch(0.62 0.2 175 / 0.08), oklch(0.62 0.2 175 / 0.03));
  border: 1px solid oklch(0.62 0.2 175 / 0.15);
  border-radius: var(--radius);
}

.result-hero p {
  font-size: 18px;
  font-weight: 600;
  color: var(--muted);
}

.result-hero strong {
  display: block;
  margin: 10px 0 14px;
  font-size: clamp(56px, 12vw, 88px);
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: -0.04em;
}

.result-hero span {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
}

#answerSheet {
  max-height: 380px;
  margin: 20px 28px 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  background: oklch(0.97 0.005 260);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
}

.credit, .dialog-credit {
  padding: 14px 28px;
  font-size: 12px;
  color: var(--muted);
}

.dialog-credit { background: transparent; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 28px 24px;
}

/* ── Footer ── */
.credit {
  margin-top: 20px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: oklch(0.8 0.015 260); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: oklch(0.7 0.02 260); }

/* ── Responsive ── */
@media (max-width: 860px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }

  .timer { width: 100%; text-align: left; }
  .timer strong { font-size: 20px; }

  .layout {
    display: block;
    padding: 14px 16px;
  }

  .sidebar {
    position: static;
    margin-bottom: 16px;
  }

  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 160px; }

  .submit-panel { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .brand h1 { font-size: 15px; }

  .question-head {
    flex-direction: column;
    gap: 8px;
  }

  .points { align-self: flex-start; }

  .submit-panel { display: flex; flex-direction: column; }
  button { width: 100%; }

  .option {
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
