@media screen {
  :root {
    color-scheme: dark;
    --ink: #f6f8f1;
    --muted: #bfc7bd;
    --paper: #141714;
    --white: #1d221e;
    --teal: #c8fb56;
    --pale: #293528;
    --line: #374138;
    --gold: #f4ca7a;
    --red: #ffa99d;
    --shadow: 0 12px 35px #0609064a;
    --sidebar-width: clamp(208px, 17vw, 268px);
    --gutter: clamp(20px, 4.5vw, 76px);
    font-family: 'DM Sans', 'Microsoft JhengHei', system-ui, sans-serif;
  }

  html { scroll-padding-top: 18px; }
  button:focus-visible, a:focus-visible, input:focus-visible,
  select:focus-visible, summary:focus-visible {
    outline-color: var(--teal);
    outline-offset: 3px;
  }

  .topbar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: var(--sidebar-width);
    align-items: stretch;
    justify-content: flex-start;
    flex-flow: column nowrap;
    gap: clamp(16px, 4.5vh, 42px);
    padding: clamp(18px, 3vw, 34px) clamp(15px, 1.8vw, 26px);
    overflow-y: auto;
    background: #191d19;
    border: 0;
    border-right: 1px solid var(--line);
  }

  .brand {
    gap: 10px;
    white-space: normal;
    font-size: 17px;
    line-height: 1.25;
  }

  .brand-icon {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 1px solid #53653a;
    border-radius: 9px;
    background: #22291e;
    color: var(--teal);
    font: 23px/1 system-ui, sans-serif;
  }

  .brand small { letter-spacing: .06em; font-size: 8px; }
  .topbar > nav { display: grid; gap: 5px; }
  .topbar > nav button {
    min-height: 44px;
    width: 100%;
    padding: 8px 10px;
    text-align: start;
    border: 1px solid transparent;
    font-size: 13px;
  }
  .topbar > nav button:hover, .topbar > nav button[aria-current] {
    background: #262e22;
    border-color: #435233;
    color: var(--teal);
  }

  .language-bar {
    margin-top: auto;
    background: none;
    border: 0;
    border-top: 1px solid var(--line);
    padding: 13px 0 0;
  }
  .language-switch { justify-content: flex-start; gap: 5px; }
  .language-switch > span { flex-basis: 100%; }
  .language-switch a { padding: 7px; }
  .language-switch a:hover, .language-switch a[aria-current] {
    background: #262e22;
    color: var(--teal);
  }
  [data-portal-return] {
    display: block;
    line-height: 1.55;
    text-decoration: none;
    font-size: 12px;
  }
  [data-portal-return]:hover { text-decoration: underline; }
  .assessment-menu-toggle { display: none; }

  main {
    width: min(calc(100% - var(--sidebar-width)), 1435px);
    max-width: none;
    margin-left: max(var(--sidebar-width), calc((100% + var(--sidebar-width) - 1435px) / 2));
    padding: clamp(30px, 5vw, 72px) var(--gutter) 70px;
    min-height: calc(100svh - 62px);
  }

  footer {
    margin-left: var(--sidebar-width);
    padding-inline: var(--gutter);
  }

  main, .course-card, .panel, .sidebar { min-width: 0; }
  h1, h2, h3, .test-label { overflow-wrap: anywhere; }
  .hero { gap: clamp(16px, 4vw, 54px); }
  .hero:has(+ .language-note) { margin-bottom: 22px; }
  .hero + .language-note {
    max-width: 70ch;
    padding: 0;
    border: 0;
    background: none;
  }
  .hero h1 { font-weight: 680; }
  .hero h1:lang(en) {
    font-size: clamp(38px, 4.7vw, 69px);
    letter-spacing: -.065em;
    line-height: 1.07;
  }
  .hero h1 em { color: var(--teal); }
  .hero-visual, .score-panel {
    background: radial-gradient(ellipse at 100% 0, #3b5026, #212a20 66%);
    border: 1px solid #566645;
  }
  .circle:after { border-top-color: var(--teal); border-right-color: var(--teal); }
  .course-card, .btn, .resume, .question-card, .option, .sidebar,
  .panel, details, .level-path span, select, input[type="search"], .bank-row,
  table, .empty, .paused, dialog, .language-note {
    background: var(--white);
  }
  .course-card:hover, .course-card:focus-within, .btn:hover, .option:hover {
    background: #283127;
    border-color: #758760;
  }
  .btn.primary, .btn.dark, .tab.active {
    background: var(--teal);
    color: #19210f;
    border-color: var(--teal);
  }
  .btn.primary:hover, .btn.dark:hover { background: #ddff95; }
  .btn.danger { border-color: #87554c; }
  .btn.subtle:hover { background: var(--pale); }
  .tab:hover:not(.active) { background: var(--pale); }
  .btn, .tab, .option { min-height: 44px; }
  .tag.gold { background: #3b311f; color: var(--gold); }
  .tag.red { background: #3e2623; color: var(--red); }
  .course-meta, .q-bottom, .skill-tags span, .audio-box { border-color: var(--line); }
  .course-card { display: flex; flex-direction: column; }
  .course-card .card-actions { margin-top: auto; flex-wrap: wrap; }
  .notice, .passage, .audio-box {
    background: #252e25;
    color: var(--muted);
    border-color: #526550;
  }
  .notice.warn { background: #362c1f; border-color: #6f5832; color: var(--gold); }
  .option.selected { background: #303e23; }
  .option-key, .progress-track, .metric-bar { background: #394437; }
  .selected .option-key, #toast { background: var(--teal); color: #19210f; }
  .q-grid button {
    border-color: var(--line);
    background: #242d23;
    min-height: 38px;
  }
  .q-grid button.answered { border-color: #6b8649; background: #374b2b; }
  .q-grid button:hover { border-color: var(--teal); }
  .q-grid button.flagged:after { background: var(--gold); }
  .score-ring {
    border-color: var(--teal);
    background: #1b231a;
  }
  .metric-bar i { background: var(--teal); }
  .prose p, .prose li, .skill-tags span, .pinyin { color: var(--muted); }
  dialog::backdrop { background: #0b0d0bbf; }
  .skip { background: var(--teal); color: #19210f; }
  .question-figure { background: #f4f7ee; }
  .question-figure-media { cursor: zoom-in; }
  .question-figure figcaption { color: #3d5148; }
  .review-tools { margin: 14px 0 4px; display: flex; align-items: center; gap: 10px; }
  .review-tools > label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
  .review-tools input { accent-color: var(--teal); }
  .review-tools .review-count { color: var(--muted); font-size: 12px; }
  .review-list summary { padding-block: 2px; }
  .review-list details:hover { border-color: #718360; }
  .review-list details[open] { border-color: #687c4d; }
  .review-list details[hidden], .question-list-jump { display: none; }

  @media (min-width: 901px) and (max-width: 1240px) {
    .cards { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .hero { grid-template-columns: minmax(0, 1fr) minmax(215px, .8fr); }
    .hero-visual { flex-wrap: wrap; }
  }

  @media (max-width: 900px) {
    :root { --sidebar-width: 0px; }
    .topbar {
      position: relative;
      inset: auto;
      width: auto;
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      gap: 9px 12px;
      padding: 10px var(--gutter);
      border: 0;
      border-bottom: 1px solid var(--line);
      overflow: visible;
    }
    .topbar .brand { margin: 0; }
    .assessment-menu-toggle {
      display: grid;
      place-items: center;
      justify-self: end;
      width: 44px;
      height: 44px;
      border: 1px solid var(--line);
      border-radius: 8px;
      color: var(--ink);
      background: var(--white);
      font: 20px/1 system-ui, sans-serif;
    }
    .has-assessment-ui .topbar > nav {
      display: none;
      position: absolute;
      inset: 100% var(--gutter) auto;
      max-height: 65dvh;
      overflow: auto;
      padding: 9px;
      border: 1px solid var(--line);
      border-radius: 0 0 12px 12px;
      background: #191d19;
      box-shadow: var(--shadow);
    }
    .has-assessment-ui .topbar > nav[data-open="true"] { display: grid; }
    .language-bar { padding: 0; border: 0; }
    .language-switch > span { display: none; }
    [data-portal-return] { text-align: right; }
    .sidebar { top: 16px; }
  }
  @media (max-width: 680px) {
    :root { --gutter: 18px; }
    .hero h1:lang(en) { font-size: clamp(34px, 9.6vw, 56px); }
    .hero-visual { min-height: 0; }
    .hero-visual .circle { width: 108px; height: 108px; }
    .hero-visual .circle strong { font-size: 32px; }
    .hero-visual .circle span { padding-inline: 8px; text-align: center; }
    .test-header > div:last-child { flex-shrink: 0; max-width: 42%; }
    .test-layout { display: flex; }
    .q-grid button { min-height: 42px; }
    .question-list-jump { display: inline-flex; margin-bottom: 14px; }
    .test-label:lang(en) { overflow-wrap: normal; }
    .option { overflow-wrap: anywhere; }
    .action-row { gap: 8px; }
    .stats-row { flex-wrap: wrap; }
  }
  @media (prefers-reduced-motion: no-preference) {
    .choice-changed { animation: switch-subject .25s ease-out both; }
    @keyframes switch-subject {
      from { opacity: .62; transform: translateY(5px); }
      to { opacity: 1; transform: translateY(0); }
    }
  }
}

@media print {
  .review-tools, .question-list-jump { display: none; }
}
