:root {
  --ink: #102036;
  --ink-soft: #526174;
  --muted: #718093;
  --line: #dce3e9;
  --line-strong: #cbd5de;
  --surface: #ffffff;
  --surface-soft: #f6f8f9;
  --green: #087b52;
  --green-dark: #056641;
  --green-soft: #eaf5f0;
  --amber: #d67a00;
  --amber-soft: #fff6e6;
  --red: #c74747;
  --red-soft: #fff0f0;
  --shadow: 0 18px 50px rgba(16, 32, 54, 0.12);
  --header-height: 92px;
  --footer-height: 84px;
  --sidebar-width: 276px;
  --context-width: 300px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; min-width: 320px; background: var(--surface); }
button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 3px solid rgba(8, 123, 82, 0.25); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--context-width);
  grid-template-rows: var(--header-height) minmax(0, 1fr) var(--footer-height);
  grid-template-areas: "header header header" "sidebar main context" "sidebar footer context";
  background: #fff;
}

.topbar {
  grid-area: header;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto minmax(220px, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  z-index: 10;
}

.brand, .progress-summary, .nav-item, .mobile-menu { border: 0; background: transparent; cursor: pointer; }
.brand { display: flex; align-items: center; gap: 18px; padding: 0 28px; text-align: left; }
.brand-mark { display: grid; place-items: center; width: 50px; height: 50px; color: #fff; background: var(--green); border-radius: 4px; font-size: 21px; font-weight: 750; letter-spacing: -0.04em; box-shadow: 0 4px 10px rgba(8, 123, 82, 0.18); }
.brand-title { font-size: 20px; font-weight: 720; letter-spacing: -0.02em; white-space: nowrap; }
.brand-title b { font-weight: 520; }

.mode-nav { display: flex; align-items: stretch; gap: 20px; }
.nav-item { position: relative; display: flex; align-items: center; justify-content: center; gap: 9px; min-width: 126px; padding: 0 14px; font-size: 16px; font-weight: 590; }
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 4px; transform: scaleX(0); background: var(--green); transition: transform 180ms ease; }
.nav-item:hover, .nav-item.is-active { color: var(--green); }
.nav-item.is-active::after { transform: scaleX(1); }
.nav-count { min-width: 22px; padding: 2px 6px; border-radius: 999px; color: var(--ink-soft); background: var(--surface-soft); font-size: 11px; font-weight: 720; }

.progress-summary { justify-self: end; display: flex; align-items: center; gap: 20px; padding: 0 28px; font-size: 15px; }
.progress-summary strong { color: var(--green); font-size: 18px; }
.progress-ring { --progress: 0deg; display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; background: conic-gradient(var(--green) var(--progress), #e7ebee 0); position: relative; }
.progress-ring::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #fff; }
.progress-ring b { position: relative; z-index: 1; font-size: 12px; }
.mobile-menu { display: none; align-items: center; justify-content: center; }
.mobile-menu svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.section-sidebar { grid-area: sidebar; position: relative; display: flex; flex-direction: column; min-height: 0; padding: 30px 20px 28px 42px; border-right: 1px solid var(--line); background: #fbfcfc; }
.progress-rail { position: absolute; top: 31px; bottom: 171px; left: 20px; width: 3px; background: #d9dee3; overflow: hidden; }
.progress-rail span { position: absolute; top: 0; left: 0; width: 100%; height: 0%; background: var(--green); transition: height 240ms ease; }
.section-list { display: grid; gap: 8px; }
.section-button { width: 100%; display: grid; grid-template-columns: 27px 1fr auto; align-items: center; gap: 10px; min-height: 62px; padding: 0 15px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; font-size: 15px; transition: background 160ms ease, color 160ms ease; }
.section-button:hover { background: #f0f4f3; }
.section-button.is-active { color: var(--green-dark); background: var(--green-soft); }
.section-dot { display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid #b9c4ce; border-radius: 50%; }
.section-button.is-active .section-dot { border-color: #73b59a; }
.section-button.is-active .section-dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.section-name { font-weight: 610; }
.section-count { font-size: 14px; font-variant-numeric: tabular-nums; }
.section-progress { margin-top: auto; padding: 0 3px; color: var(--ink-soft); font-size: 13px; }
.mini-progress { height: 8px; margin: 16px 0 10px; border-radius: 99px; overflow: hidden; background: #e5e9ed; }
.mini-progress span { display: block; width: 0; height: 100%; background: var(--green); border-radius: inherit; transition: width 240ms ease; }
.section-progress strong { color: var(--green-dark); font-size: 15px; font-variant-numeric: tabular-nums; }
.section-progress i { margin: 0 4px; color: var(--muted); font-style: normal; font-weight: 400; }

.question-stage { grid-area: main; min-width: 0; min-height: 0; overflow: hidden; background: #fff; }
.question-scroll { height: 100%; overflow: auto; padding: 34px clamp(32px, 4.2vw, 68px) 38px; scroll-behavior: smooth; }
.question-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 21px; color: var(--ink-soft); font-size: 14px; }
.question-meta > span:first-child { color: var(--ink); font-weight: 680; }
.question-meta strong { color: var(--green); font-size: 16px; }
.meta-divider { color: #aab4bd; }
.question-stage h1 { max-width: 900px; margin: 0; color: var(--ink); font-size: clamp(23px, 2vw, 30px); line-height: 1.45; letter-spacing: -0.025em; font-weight: 730; }
.question-hint { min-height: 22px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.question-hint:empty { display: none; }
.answers { display: grid; gap: 15px; max-width: 940px; margin-top: 25px; }
.answer-option { position: relative; width: 100%; display: grid; grid-template-columns: 40px 1fr 24px; align-items: center; gap: 18px; min-height: 76px; padding: 14px 18px; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; text-align: left; transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, transform 140ms ease; }
.answer-option:hover { border-color: #91bbaa; box-shadow: 0 5px 18px rgba(16, 32, 54, 0.055); transform: translateY(-1px); }
.option-key { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #cdd6de; border-radius: 50%; color: var(--ink); background: #fff; font-size: 18px; font-weight: 600; }
.option-text { color: #1b293d; font-size: 17px; line-height: 1.55; }
.option-check { width: 20px; height: 20px; border: 1.5px solid #b9c4ce; border-radius: 4px; }
.answer-option.is-selected { border-color: var(--green); background: #f7fcf9; box-shadow: 0 0 0 1px rgba(8, 123, 82, 0.04); }
.answer-option.is-selected .option-key { color: #fff; border-color: var(--green); background: var(--green); }
.answer-option.is-selected .option-check { border-color: var(--green); background: var(--green); box-shadow: inset 0 0 0 4px #fff; }
.answer-option[data-type="single"] .option-check, .answer-option[data-type="judge"] .option-check { border-radius: 50%; }
.answer-option.is-correct { border-color: var(--green); background: var(--green-soft); }
.answer-option.is-wrong { border-color: var(--red); background: var(--red-soft); }
.answer-option.is-disabled { cursor: default; transform: none; box-shadow: none; }
.option-result { color: var(--green); font-size: 19px; font-weight: 750; }
.answer-option.is-wrong .option-result { color: var(--red); }

.short-answer { max-width: 940px; }
.short-answer textarea { width: 100%; min-height: 260px; resize: vertical; padding: 20px; border: 1px solid var(--line-strong); border-radius: 7px; color: var(--ink); background: #fff; font-size: 16px; line-height: 1.75; transition: border-color 160ms ease, box-shadow 160ms ease; }
.short-answer textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8, 123, 82, 0.08); outline: none; }
.short-tools { display: flex; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 13px; }

.explanation { max-width: 940px; margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--line); animation: reveal 220ms ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
.explanation-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.explanation-heading h2 { display: flex; align-items: center; gap: 11px; margin: 0; font-size: 17px; }
.explanation-heading h2 span { width: 3px; height: 20px; background: var(--green); border-radius: 3px; }
.explanation-heading button { display: flex; align-items: center; gap: 5px; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 13px; }
.explanation-heading svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }
.answer-result { margin: 0 0 10px; font-size: 15px; }
.answer-result strong { color: var(--green); }
.answer-result.is-error strong { color: var(--red); }
.explanation-copy { color: var(--ink-soft); font-size: 14px; line-height: 1.8; }
.reference-answer { white-space: pre-line; color: var(--ink-soft); font-size: 14px; line-height: 1.85; }

.context-panel { grid-area: context; min-height: 0; overflow: auto; padding: 28px 28px 24px; border-left: 1px solid var(--line); background: #fbfcfc; }
.context-panel h2 { margin: 0 0 16px; font-size: 17px; }
.status-box { display: flex; align-items: center; gap: 13px; min-height: 62px; padding: 0 18px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; }
.status-box span { width: 13px; height: 13px; border-radius: 50%; background: var(--amber); }
.status-box strong { color: var(--amber); font-size: 15px; }
.status-box.is-correct span { background: var(--green); }
.status-box.is-correct strong { color: var(--green); }
.status-box.is-wrong span { background: var(--red); }
.status-box.is-wrong strong { color: var(--red); }
.panel-action { width: 100%; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 11px; min-height: 56px; padding: 0 5px; border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left; font-size: 15px; }
.panel-action > svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.panel-action .chevron { width: 17px; height: 17px; color: var(--muted); }
.switch { width: 42px; height: 24px; padding: 3px; border-radius: 99px; background: #dfe5e9; transition: background 160ms ease; }
.switch::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); transition: transform 160ms ease; }
.panel-action.is-active .switch { background: var(--amber); }
.panel-action.is-active .switch::after { transform: translateX(18px); }
.panel-action.is-active { color: #8c5700; }
.panel-section { margin-top: 24px; }
.panel-section h3 { margin: 0 0 16px; font-size: 15px; }
.keyboard-help > div, .stats-section > div { display: grid; grid-template-columns: 64px 1fr; align-items: center; min-height: 38px; color: var(--ink-soft); font-size: 13px; }
kbd { justify-self: start; min-width: 38px; padding: 5px 7px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: #fff; color: var(--ink); font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }
.stats-section { padding-top: 22px; border-top: 1px solid var(--line); }
.stats-section > div { grid-template-columns: 1fr auto; min-height: 42px; }
.stats-section strong { color: var(--green-dark); font-size: 15px; }
.stats-section small { font-weight: 500; font-size: 11px; }

.answer-actions { grid-area: footer; display: grid; grid-template-columns: minmax(150px, 250px) minmax(220px, 320px) minmax(150px, 250px); align-items: center; justify-content: space-around; gap: 24px; padding: 12px 44px; border-top: 1px solid var(--line); background: rgba(255, 255, 255, 0.98); }
.answer-actions button, .drawer-footer .primary-button { min-height: 52px; border-radius: 5px; cursor: pointer; font-size: 16px; font-weight: 640; transition: background 150ms ease, border-color 150ms ease, transform 150ms ease; }
.answer-actions button:active, .drawer-footer button:active { transform: translateY(1px); }
.secondary-button { display: flex; align-items: center; justify-content: center; gap: 14px; border: 1px solid var(--line-strong); background: #fff; }
.secondary-button:hover { border-color: #8da398; background: #f8faf9; }
.secondary-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.primary-button { border: 1px solid var(--green); color: #fff; background: var(--green); }
.primary-button:hover { border-color: var(--green-dark); background: var(--green-dark); }
.answer-actions button:disabled { opacity: 0.42; cursor: not-allowed; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(16, 32, 54, 0.24); backdrop-filter: blur(2px); }
.answer-drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; display: flex; flex-direction: column; width: min(540px, 100vw); background: #fff; box-shadow: var(--shadow); transform: translateX(104%); transition: transform 220ms ease; }
.answer-drawer.is-open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 26px 30px 20px; border-bottom: 1px solid var(--line); }
.drawer-header p { margin: 0 0 5px; color: var(--green); font-size: 12px; font-weight: 650; }
.drawer-header h2 { margin: 0; font-size: 24px; }
.drawer-header button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--surface-soft); cursor: pointer; }
.drawer-header svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.drawer-legend { display: flex; flex-wrap: wrap; gap: 18px; padding: 16px 30px; border-bottom: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; }
.drawer-legend span { display: flex; align-items: center; gap: 7px; }
.drawer-legend i { width: 10px; height: 10px; border-radius: 2px; background: #eef1f3; }
.drawer-legend i.done { background: var(--green); }
.drawer-legend i.current { box-shadow: 0 0 0 2px var(--green); background: #fff; }
.drawer-legend i.marked { background: var(--amber); }
.drawer-legend i.wrong { background: var(--red); }
.drawer-content { flex: 1; overflow: auto; padding: 25px 30px; }
.sheet-section { margin-bottom: 28px; }
.sheet-section h3 { display: flex; justify-content: space-between; margin: 0 0 14px; font-size: 14px; }
.sheet-section h3 span { color: var(--muted); font-size: 12px; font-weight: 500; }
.question-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; }
.question-cell { aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: pointer; color: var(--ink-soft); font-size: 12px; }
.question-cell:hover { border-color: var(--green); }
.question-cell.is-done { color: #fff; border-color: var(--green); background: var(--green); }
.question-cell.is-current { color: var(--green); border-color: var(--green); background: #fff; box-shadow: 0 0 0 2px rgba(8, 123, 82, .18); }
.question-cell.is-marked { box-shadow: inset 0 -4px 0 var(--amber); }
.question-cell.is-wrong { color: #fff; border-color: var(--red); background: var(--red); }
.drawer-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 18px 30px 24px; border-top: 1px solid var(--line); }
.drawer-footer button { min-height: 48px; border-radius: 5px; cursor: pointer; font-weight: 620; }
.drawer-footer > button:first-child { border: 1px solid var(--line-strong); background: #fff; color: var(--red); }

.toast { position: fixed; left: 50%; bottom: 105px; z-index: 70; padding: 11px 18px; border-radius: 5px; color: #fff; background: var(--ink); box-shadow: 0 8px 30px rgba(16,32,54,.18); font-size: 13px; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.empty-state { display: grid; place-items: center; min-height: 360px; text-align: center; }
.empty-state h1 { margin-bottom: 10px; }
.empty-state p { max-width: 400px; color: var(--muted); line-height: 1.7; }
.empty-state button { margin-top: 20px; min-height: 46px; padding: 0 28px; border-radius: 5px; }

@media (max-width: 1180px) {
  :root { --sidebar-width: 230px; --context-width: 255px; }
  .topbar { grid-template-columns: 1fr auto auto; }
  .brand { padding: 0 20px; }
  .brand-title { font-size: 17px; }
  .mode-nav { gap: 0; }
  .nav-item { min-width: 108px; }
  .progress-summary { padding: 0 18px; }
  .progress-summary > span:first-child { display: none; }
  .question-scroll { padding-left: 34px; padding-right: 34px; }
  .context-panel { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 900px) {
  :root { --header-height: 72px; --footer-height: 74px; }
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "header" "main" "footer"; }
  .topbar { grid-template-columns: 1fr auto auto; }
  .brand { gap: 12px; padding: 0 16px; }
  .brand-mark { width: 42px; height: 42px; font-size: 18px; }
  .brand-title b { display: none; }
  .mode-nav, .context-panel { display: none; }
  .progress-summary { gap: 10px; padding: 0 10px; }
  .progress-ring { width: 45px; height: 45px; }
  .mobile-menu { display: flex; width: 50px; }
  .section-sidebar { position: fixed; top: var(--header-height); left: 0; bottom: 0; z-index: 45; display: flex; width: min(300px, 88vw); transform: translateX(-104%); box-shadow: var(--shadow); transition: transform 220ms ease; }
  .section-sidebar.is-open { transform: translateX(0); }
  .question-scroll { padding: 26px 22px 34px; }
  .answer-actions { padding: 10px 16px; grid-template-columns: 54px 1fr 54px; gap: 10px; }
  .secondary-button span { display: none; }
  .answer-actions button { min-height: 50px; }
}

@media (max-width: 560px) {
  .brand-title { max-width: 150px; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
  .progress-summary > span:first-child { display: none; }
  .question-stage h1 { font-size: 21px; }
  .answer-option { grid-template-columns: 34px 1fr 20px; gap: 12px; min-height: 68px; padding: 12px 13px; }
  .option-key { width: 32px; height: 32px; font-size: 16px; }
  .option-text { font-size: 15px; }
  .question-grid { grid-template-columns: repeat(8, 1fr); }
  .drawer-header, .drawer-content { padding-left: 20px; padding-right: 20px; }
  .drawer-footer { grid-template-columns: 1fr; padding-left: 20px; padding-right: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
