/* 知序 Design System v4.5 — Crisp Editorial Instrument
   Linear × Stripe × Apple Health sweet spot:
   pure gallery-alabaster neutrals + WCAG AA charcoal ink + jewel indigo (#3b5bdb) + refined jade/terracotta. */
:root {
  /* Surfaces & elevation strata (clean neutral gallery frame -> pure alabaster canvas -> crisp white cards) */
  --bg: #f7f7f6;
  --rail-bg: #efefed;
  --surface: #ffffff;
  --surface-2: #f4f4f3;
  --sunken: #e7e7e5;
  --line: rgba(17, 19, 24, 0.085);
  --line-strong: rgba(17, 19, 24, 0.15);
  --line-hover: rgba(17, 19, 24, 0.25);
  --line-solid: #e2e3e5;

  /* Ink (WCAG AA+ crisp charcoal scale — effortless scanning even at 10-11px labels) */
  --ink: #111318;
  --ink-2: #343840;
  --ink-3: #52565e;
  --ink-4: #6b707a;

  /* Primary action spine (crisp obsidian graphite) */
  --action: #16181d;
  --action-top: #262930;
  --action-hover: #0c0d10;
  --action-hover-top: #1d2026;

  /* Primary brand accent (Linear / OpenColor jewel sapphire-indigo — vivid yet refined) */
  --brand: #3b5bdb;
  --brand-top: #4c6ef5;
  --brand-hover: #2f49b5;
  --brand-hover-top: #3b5bdb;
  --brand-ink: #2b44ad;
  --brand-soft: rgba(59, 91, 219, 0.085);
  --brand-line: rgba(59, 91, 219, 0.24);

  /* Editorial terracotta seal (harmonized with logo monogram 序) */
  --seal: #c94a38;
  --seal-top: #d65846;
  --seal-soft: rgba(201, 74, 56, 0.085);
  --seal-line: rgba(201, 74, 56, 0.24);

  /* Status (crisp jewel semantics — instant scanning without neon glare) */
  --ok: #0f8a5f;
  --ok-soft: rgba(15, 138, 95, 0.09);
  --ok-line: rgba(15, 138, 95, 0.24);
  --bad: #c94a38;
  --bad-soft: rgba(201, 74, 56, 0.085);
  --bad-line: rgba(201, 74, 56, 0.24);
  --warn: #c77d14;
  --warn-soft: rgba(199, 125, 20, 0.09);
  --warn-line: rgba(199, 125, 20, 0.24);
  --unsure: #6741d9;
  --unsure-soft: rgba(103, 65, 217, 0.08);
  --unsure-line: rgba(103, 65, 217, 0.22);

  /* Type scale (7 restrained steps) */
  --t-xs: 12px;
  --t-sm: 13px;
  --t-base: 14px;
  --t-md: 15px;
  --t-lg: 17px;
  --t-xl: 22px;
  --t-2xl: 28px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* Concentric radius scale (sharper, caliper-cut geometry) */
  --r-xs: 5px;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 14px;

  /* Multi-layered optical shadows (crisp contact + quiet ambient) */
  --shadow-sm:
    0 1px 1px rgba(17, 19, 24, 0.028),
    0 1px 3px rgba(17, 19, 24, 0.036);
  --shadow-md:
    0 1px 1px -0.5px rgba(17, 19, 24, 0.045),
    0 3px 8px -2px rgba(17, 19, 24, 0.04),
    0 10px 22px -12px rgba(17, 19, 24, 0.06);
  --shadow-lg:
    0 0 0 1px rgba(17, 19, 24, 0.06),
    0 4px 12px rgba(17, 19, 24, 0.08),
    0 22px 48px -12px rgba(17, 19, 24, 0.16);
  --shadow-btn-primary:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.38),
    0 1px 2px rgba(12, 13, 16, 0.26),
    0 4px 10px -3px rgba(12, 13, 16, 0.2);
  --shadow-btn-secondary:
    inset 0 1px 0 rgba(255, 255, 255, 0.96),
    0 1px 1.5px rgba(17, 19, 24, 0.045);
  --ring: 0 0 0 3px rgba(59, 91, 219, 0.2);

  /* Layout */
  --rail: 216px;
  --content: 1080px;
  --content-focus: 860px;
  --gutter: clamp(18px, 2.8vw, 36px);
  --tabbar: 0px;
  --ease: cubic-bezier(0.2, 0.72, 0.2, 1);

  /* Legacy aliases kept for page modules that still read them */
  --muted: var(--ink-3);
  --paper: var(--surface);
  --canvas: var(--bg);
  --forest: var(--brand);
  --green: var(--brand);
  --purple: var(--brand);
  --accent: var(--seal);

  /* Modern progressive enhancement: opt in to intrinsic-size transitions */
  interpolate-size: allow-keywords;
  color-scheme: light;
  font: 15px/1.55 var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  scroll-padding-top: 16px;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  overscroll-behavior-x: none;
  touch-action: pan-y;
  overflow-wrap: break-word;
}
:where(a, code) { overflow-wrap: anywhere; }
/* Keep horizontal scroll gesture alive inside formula/table/tab-strip scrollers */
:where(.library-tracks-wrap, .study-stem, .adp-q-stem, .grade-stem, .task-stem, .buddy-stem, .md-math-block, .md-table-wrap, .teacher-workflow, .katex-display, .paper-preview-stage, .study-option-content, .grade-opt-text) {
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
}
body:has(> .app-rail) {
  background-color: var(--rail-bg);
}
h1, h2, h3, h4, p, ol, ul, figure { margin: 0; }
ol, ul { padding-left: 1.3em; }
a { color: inherit; }
img, svg, canvas { max-width: 100%; }
svg { flex: none; vertical-align: middle; }
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.46; }
button, a, input, summary, select { -webkit-tap-highlight-color: transparent; }
summary { cursor: pointer; }
summary::-webkit-details-marker { display: none; }
:where(button, a, summary, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
::selection {
  background: rgba(37, 70, 162, 0.16);
  color: var(--ink);
}
code, .mono { font-family: var(--font-mono); font-size: 0.9em; font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }

/* Keyboard shortcut keycap (desktop hover devices only) */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.07);
  flex: none;
}
.primary .kbd, .btn-primary .kbd, .study-primary .kbd {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
}
.primary:disabled, .btn-primary:disabled, .study-primary:disabled {
  opacity: 0.62;
}
.primary:disabled .kbd, .btn-primary:disabled .kbd, .study-primary:disabled .kbd {
  color: rgba(255, 255, 255, 0.96);
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.44);
}
@media (hover: none), (max-width: 700px) {
  .kbd { display: none; }
}

/* Status dot indicator (replaces heavy 4px left accent bars) */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-4);
  flex: none;
}
.status-dot.is-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.is-bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.status-dot.is-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.status-dot.is-unsure { background: var(--unsure); box-shadow: 0 0 0 3px var(--unsure-soft); }
.status-dot.is-brand { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.status-dot.is-seal { background: var(--seal); box-shadow: 0 0 0 3px var(--seal-soft); }

/* Inline numeric counter chip inside buttons */
.btn-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: var(--sunken);
  color: var(--ink-2);
}
.primary .btn-count, .btn-primary .btn-count, .study-primary .btn-count {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.96);
}

/* Math / KaTeX harmony */
math { font-family: "STIX Two Math", "Cambria Math", "Times New Roman", math; font-size: 1.07em; }
.katex { font-size: 1.06em; text-rendering: geometricPrecision; }
.katex .mfrac .frac-line { border-bottom-width: 0.055em; }
:where(h1, h2, h3, strong, b) .katex {
  font-size: 1.02em;
  font-weight: 500;
}
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-main {
  position: fixed; top: 8px; left: 8px; z-index: 100; padding: 8px 14px;
  background: var(--surface); color: var(--brand-ink); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); box-shadow: var(--shadow-md); transform: translateY(-220%);
  text-decoration: none; font-size: var(--t-sm); font-weight: 600;
}
.skip-main:focus { transform: none; }

/* Progressive native disclosure animation */
details:not([data-no-anim])::details-content {
  overflow: clip;
}
details:not([data-no-anim]):not([open])::details-content {
  block-size: 0;
  opacity: 0;
}
details:not([data-no-anim])[open]::details-content {
  block-size: auto;
  opacity: 1;
}
@media (prefers-reduced-motion: no-preference) {
  details:not([data-no-anim])::details-content {
    transition-property: block-size, opacity, content-visibility;
    transition-duration: 0.2s, 0.16s, 0.2s;
    transition-timing-function: var(--ease);
    transition-behavior: allow-discrete;
  }
}

/* ---------- Buttons (tactile, orthogonal hover/press/focus states) ---------- */
.btn, .primary, .secondary, .ghost, .link-btn, .study-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 15px; border-radius: var(--r-sm);
  font-size: var(--t-base); font-weight: 600; line-height: 1.2; letter-spacing: -0.005em;
  text-decoration: none; white-space: nowrap;
  border: 1px solid transparent;
  transition:
    background 0.14s var(--ease),
    background-color 0.14s var(--ease),
    border-color 0.14s var(--ease),
    color 0.14s var(--ease),
    box-shadow 0.14s var(--ease),
    scale 0.1s var(--ease);
}
@media (prefers-reduced-motion: no-preference) {
  .btn:active:not(:disabled),
  .primary:active:not(:disabled),
  .secondary:active:not(:disabled),
  .ghost:active:not(:disabled),
  .study-btn:active:not(:disabled) {
    scale: 0.982;
  }
}
.primary, .btn-primary, .study-primary, .study-btn.study-primary, .secondary.primary {
  background: linear-gradient(180deg, var(--action-top) 0%, var(--action) 100%);
  color: #fff;
  border-color: rgba(8, 12, 20, 0.9);
  box-shadow: var(--shadow-btn-primary);
}
.primary:hover:not(:disabled),
.btn-primary:hover:not(:disabled),
.study-primary:hover:not(:disabled),
.study-btn.study-primary:hover:not(:disabled),
.secondary.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--action-hover-top) 0%, var(--action-hover) 100%);
  border-color: #05080d;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -1px 0 rgba(0, 0, 0, 0.48),
    0 2px 5px rgba(10, 14, 22, 0.3),
    0 8px 16px -6px rgba(10, 14, 22, 0.28);
}
.primary:active:not(:disabled),
.btn-primary:active:not(:disabled),
.study-primary:active:not(:disabled) {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
}
.secondary, .btn-secondary, .study-btn {
  background: linear-gradient(180deg, #ffffff 0%, #f9fafb 100%);
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-btn-secondary);
}
.secondary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.study-btn:hover:not(:disabled):not(.study-primary) {
  background: linear-gradient(180deg, #ffffff 0%, #f3f5f8 100%);
  border-color: var(--line-hover);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 1px 3px rgba(15, 23, 42, 0.08);
}
.ghost, .btn-ghost, .study-btn-ghost, .study-btn-quiet,
.study-btn.study-btn-ghost, .study-btn.study-btn-quiet {
  background: transparent;
  color: var(--ink-2);
  border-color: transparent;
  box-shadow: none;
}
.ghost:hover:not(:disabled),
.btn-ghost:hover:not(:disabled),
.study-btn-ghost:hover:not(:disabled),
.study-btn-quiet:hover:not(:disabled),
.study-btn.study-btn-ghost:hover:not(:disabled),
.study-btn.study-btn-quiet:hover:not(:disabled) {
  background: rgba(15, 23, 42, 0.055);
  border-color: transparent;
  color: var(--ink);
  box-shadow: none;
}
.link-btn {
  min-height: 34px; padding: 0 9px; color: var(--brand-ink);
  background: transparent; border-color: transparent; box-shadow: none;
  font-size: var(--t-sm); font-weight: 600;
}
.link-btn:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand-ink); }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: var(--t-sm); border-radius: var(--r-xs); gap: 6px; }
.btn-lg { min-height: 44px; padding: 0 18px; font-size: var(--t-md); border-radius: var(--r-sm); }
.btn-danger { color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border-radius: var(--r-sm); color: var(--ink-3);
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease), scale 0.1s var(--ease);
}
.icon-btn:hover { background: rgba(15, 23, 42, 0.06); color: var(--ink); }

/* ---------- Form controls ---------- */
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input:not([type]), select, textarea {
  min-height: 38px; padding: 7px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background-color: var(--surface); color: var(--ink); font-size: var(--t-base); line-height: 1.4;
  box-shadow: inset 0 1px 1.5px rgba(15, 23, 42, 0.03);
  transition: border-color 0.14s var(--ease), box-shadow 0.14s var(--ease), background-color 0.14s var(--ease);
}
select {
  padding-right: 32px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16' fill='none' stroke='%23687387' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.5 6.25 3.5 3.5 3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px 14px;
  cursor: pointer;
}
select::-ms-expand { display: none; }
/* Desktop customizable select (keeps native scroll-wheel pickers on touch/iOS) */
@media (hover: hover) and (pointer: fine) {
  @supports (appearance: base-select) {
    select,
    select::picker(select) {
      appearance: base-select;
    }
    select {
      display: inline-flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding-right: 10px;
      background-image: none;
    }
    select::picker-icon {
      color: var(--ink-3);
      font-size: 11px;
      line-height: 1;
      flex: none;
      margin-inline-start: auto;
      transition: rotate 0.15s var(--ease), color 0.15s var(--ease);
    }
    select:hover::picker-icon { color: var(--ink-2); }
    select:open::picker-icon { rotate: 180deg; }
    select::picker(select) {
      margin-block: 4px;
      padding: 4px;
      border-radius: var(--r-md);
      border: 1px solid var(--line-strong);
      background-color: var(--surface);
      color: var(--ink);
      box-shadow: var(--shadow-lg);
      font-size: var(--t-sm);
    }
    select option {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 7px 10px;
      border-radius: var(--r-xs);
      color: var(--ink);
      cursor: pointer;
    }
    select option:hover,
    select option:focus-visible {
      background-color: var(--surface-2);
    }
    select option:checked {
      background-color: var(--brand-soft);
      color: var(--brand-ink);
      font-weight: 600;
    }
    select option::checkmark {
      color: var(--brand);
      font-size: 12px;
    }
  }
}
textarea { resize: vertical; line-height: 1.6; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--line-hover); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring), inset 0 1px 1px rgba(15, 23, 42, 0.02);
}
::placeholder { color: var(--ink-4); }
label { font-size: var(--t-base); }

/* ---------- Surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: clamp(18px, 2.2vw, 24px); }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* ---------- Chips, badges, pills ---------- */
.chip, .topic-pick {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface);
  font-size: var(--t-sm); font-weight: 500; color: var(--ink-2); white-space: nowrap;
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.025);
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease), scale 0.1s var(--ease);
}
.chip:hover, .topic-pick:hover { border-color: var(--line-hover); color: var(--ink); background: var(--surface-2); }
.chip.on, .chip[aria-pressed="true"], .topic-pick.on, .topic-pick[aria-pressed="true"] {
  background: var(--brand-soft);
  border-color: var(--brand-line);
  color: var(--brand-ink);
  font-weight: 600;
  box-shadow: none;
}
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 7px;
  border-radius: var(--r-xs); font-size: var(--t-xs); font-weight: 600; line-height: 1;
  white-space: nowrap; background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge-brand { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-unsure { background: var(--unsure-soft); color: var(--unsure); border-color: transparent; }
.badge-seal { background: var(--seal-soft); color: var(--seal); border-color: transparent; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Segmented control (macOS / Linear tactile switch) ---------- */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunken);
  border: 1px solid rgba(15, 23, 42, 0.045);
  border-radius: var(--r-sm);
  box-shadow: inset 0 1px 1.5px rgba(15, 23, 42, 0.045);
}
.segmented > :not(.seg-thumb) {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 13px;
  border-radius: var(--r-xs); font-size: var(--t-sm); font-weight: 600; color: var(--ink-2);
  text-decoration: none; white-space: nowrap;
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.segmented > :not(.seg-thumb):hover { color: var(--ink); }
.segmented > [aria-current="page"], .segmented > [aria-selected="true"], .segmented > .on {
  background: var(--surface);
  color: var(--ink);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.08),
    0 0 0 1px rgba(15, 23, 42, 0.04);
}
.segmented .count {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.segmented [aria-current="page"] .count,
.segmented [aria-selected="true"] .count,
.segmented .on .count { color: var(--brand-ink); }

/* ---------- Page header ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px 24px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-head h1, .study-head h1 {
  font-size: clamp(22px, 2.2vw, 26px); line-height: 1.24; font-weight: 700;
  letter-spacing: -0.025em; color: var(--ink);
}
.page-head p, .page-sub {
  margin-top: 5px; font-size: var(--t-base); color: var(--ink-3); max-width: 62ch;
}
.page-eyebrow, .study-kicker {
  font-size: var(--t-xs); font-weight: 600; color: var(--ink-3);
  margin-bottom: 4px; letter-spacing: 0.03em; text-transform: uppercase;
}
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 10px; }
.section-title h2 { font-size: var(--t-md); font-weight: 700; letter-spacing: -0.015em; color: var(--ink); }
.section-title a, .section-title button { font-size: var(--t-sm); font-weight: 600; color: var(--brand-ink); text-decoration: none; display: inline-flex; align-items: center; gap: 2px; }

/* ---------- Empty state ---------- */
.empty-state, .study-empty {
  display: grid; justify-items: center; text-align: center; gap: 8px;
  padding: clamp(28px, 5vw, 48px) 24px;
  background: var(--surface); border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg); color: var(--ink-2); font-size: var(--t-base);
}
.empty-state .empty-icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); margin-bottom: 4px;
}
.empty-state h2, .empty-state h3 { font-size: var(--t-lg); font-weight: 700; letter-spacing: -0.015em; color: var(--ink); }
.empty-state p { max-width: 42ch; color: var(--ink-3); }
.empty-state .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.empty-note { color: var(--ink-3); font-size: var(--t-sm); }
.subtle { color: var(--ink-3); font-size: var(--t-sm); }

/* ---------- Progress ---------- */
.progress { position: relative; height: 5px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.progress > i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--brand); transition: width 0.4s var(--ease); }
.progress.is-ok > i { background: var(--ok); }

/* ---------- Toast ---------- */
#notice {
  position: fixed; left: 50%; bottom: calc(22px + var(--tabbar) + env(safe-area-inset-bottom)); z-index: 90;
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px)); padding: 10px 16px; border-radius: var(--r-md);
  background: #161c28; color: #f8fafc; font-size: var(--t-sm); font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s var(--ease);
}
#notice:empty { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Top-layer dialogs & popovers (@starting-style + allow-discrete) ---------- */
dialog.sheet {
  border: 1px solid var(--line);
  padding: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.2s;
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
}
@media (prefers-reduced-motion: no-preference) {
  dialog.sheet { transform: translateY(8px) scale(0.975); }
}
dialog.sheet[open]:where(:not([data-closing])) {
  opacity: 1;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) {
    transform: translateY(0) scale(1);
    @starting-style { transform: translateY(8px) scale(0.975); }
  }
}
dialog.sheet::backdrop {
  background-color: rgba(15, 23, 42, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition-property: background-color, backdrop-filter, display, overlay;
  transition-duration: 0.2s;
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
}
dialog.sheet[open]:where(:not([data-closing]))::backdrop {
  background-color: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  @starting-style {
    background-color: rgba(15, 23, 42, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
  }
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: var(--t-lg); font-weight: 700; letter-spacing: -0.015em; }
.sheet-body { padding: 14px 18px 20px; display: grid; gap: 14px; }
.sheet-list { display: grid; gap: 2px; }
.sheet-list a, .sheet-list button {
  display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 8px 10px;
  border-radius: var(--r-md); text-decoration: none; text-align: left; width: 100%;
  transition: background-color 0.14s var(--ease);
}
.sheet-list a:hover, .sheet-list button:hover { background: var(--surface-2); }
.sheet-list .tile-icon {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--brand-ink); flex: none;
}
.sheet-list strong { display: block; font-size: var(--t-base); font-weight: 600; color: var(--ink); }
.sheet-list small { display: block; font-size: var(--t-xs); color: var(--ink-3); }
.field { display: grid; gap: 6px; }
.field > span { font-size: var(--t-sm); font-weight: 600; color: var(--ink); }
.field > small { font-size: var(--t-xs); color: var(--ink-3); line-height: 1.5; }
.settings-segmented { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); }
.settings-segmented > button { justify-content: center; min-height: 34px; }
.ts-density-toggle { padding: 2px; }
.ts-density-toggle > button { min-height: 28px; padding: 0 9px; font-size: 12px; }

/* ---------- App shell (Linear-style Inset window: seamless rail + recessed light canvas) ---------- */
.app-rail {
  position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--rail);
  display: flex; flex-direction: column; gap: 2px; padding: 16px 10px 14px;
  background: var(--rail-bg);
  border-right: 0;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px;
  text-decoration: none; color: var(--ink);
}
.brand-symbol, .mobile-monogram {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(180deg, var(--seal-top) 0%, var(--seal) 100%);
  color: #fff; font-size: 17px; font-weight: 700; letter-spacing: 0;
  border: 1px solid rgba(110, 32, 22, 0.36);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 1px 2px rgba(120, 35, 24, 0.24);
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
}
.brand-name { display: grid; line-height: 1.15; }
.brand-name b { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.brand-name small { font-size: 11.5px; color: var(--ink-3); font-weight: 500; margin-top: 2px; }

.rail-label {
  padding: 16px 10px 5px; font-size: 11px; font-weight: 600;
  color: var(--ink-4); letter-spacing: 0.05em; text-transform: uppercase;
}
.rail-nav { display: grid; gap: 2px; }
.rail-nav a, .rail-action {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px;
  border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none;
  font-size: var(--t-base); font-weight: 500; letter-spacing: -0.005em;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease), box-shadow 0.14s var(--ease);
  width: 100%; text-align: left;
}
.rail-nav a > i, .rail-action > i, .mobile-tabs a > i, .mobile-tabs button > i {
  display: inline-grid; place-items: center; font-style: normal; color: var(--ink-3);
  transition: color 0.14s var(--ease);
}
.rail-nav a > i svg, .rail-action > i svg { width: 16px; height: 16px; stroke-width: 1.85; }
.rail-nav a:hover, .rail-action:hover {
  background: rgba(15, 23, 42, 0.052);
  color: var(--ink);
}
.rail-nav a:hover > i, .rail-action:hover > i { color: var(--ink-2); }
.rail-nav a.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.075),
    0 0 0 1px rgba(15, 23, 42, 0.06);
}
.rail-nav a.active > i { color: var(--ink); }
.rail-nav a small, .tab-badge {
  margin-left: auto; min-width: 20px; height: 18px; padding: 0 5px; border-radius: 5px;
  display: inline-grid; place-items: center;
  background: rgba(182, 59, 45, 0.12); color: var(--bad);
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.rail-nav a.active small {
  background: var(--bad-soft);
  color: var(--bad);
}

/* Consolidated rail footer (single account/target trigger + popover menu) */
.rail-bottom {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.rail-action .ext { margin-left: auto; color: var(--ink-4); }
.rail-teacher-link {
  min-height: 34px;
  font-size: var(--t-sm);
  color: var(--ink-3);
}
.rail-teacher-link:hover { color: var(--ink); }

.student-profile.rail-account-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
  text-align: left;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.student-profile.rail-account-btn:hover,
.student-profile.rail-account-btn[aria-expanded="true"] {
  background: var(--surface);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.profile-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(180deg, #252f42 0%, #151c29 100%);
  color: #f8fafc; font-size: 12px; font-weight: 700; flex: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.profile-mark svg { width: 15px; height: 15px; }
.rail-account-text { min-width: 0; flex: 1; display: grid; gap: 1px; }
.student-profile strong {
  display: block; font-size: var(--t-sm); font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.student-profile small {
  display: block; font-size: 11.5px; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-account-chevron {
  display: inline-grid; place-items: center; color: var(--ink-4); flex: none;
}
.rail-account-chevron svg { width: 14px; height: 14px; }

/* Native popover account menu anchored above rail footer */
.account-popover {
  position: fixed;
  margin: 0;
  padding: 5px;
  min-width: 214px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  transform-origin: bottom left;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.16s;
  transition-timing-function: var(--ease);
  transition-behavior: allow-discrete;
}
@supports (position-area: top span-right) {
  .account-popover[popover] {
    inset: auto;
    position-area: top span-right;
    margin-bottom: 8px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .account-popover { transform: translateY(4px) scale(0.96); }
}
.account-popover:is(:popover-open, .\:popover-open, .is-open) {
  display: grid;
  gap: 2px;
  opacity: 1;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) {
    transform: translateY(0) scale(1);
    @starting-style { transform: translateY(4px) scale(0.96); }
  }
}
@supports not selector(:popover-open) {
  .account-popover:not(.\:popover-open):not(.is-open) { display: none; }
}
.account-pop-head {
  padding: 7px 9px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
  display: grid;
  gap: 1px;
}
.account-pop-head strong { font-size: var(--t-sm); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.account-pop-head small { font-size: 11.5px; color: var(--ink-3); }
.account-pop-item {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 34px; padding: 0 9px;
  border-radius: var(--r-xs); font-size: var(--t-sm); font-weight: 500; color: var(--ink-2);
  text-decoration: none; text-align: left;
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}
.account-pop-item:hover { background: var(--surface-2); color: var(--ink); }
.account-pop-item > i { display: inline-grid; place-items: center; color: var(--ink-3); }
.account-pop-item > i svg { width: 15px; height: 15px; }
.account-pop-item .ext { margin-left: auto; color: var(--ink-4); }
.account-pop-sep { height: 1px; background: var(--line); margin: 3px 4px; border: 0; }

.mobile-brand, .mobile-tabs { display: none; }
#main {
  min-width: 0;
  min-height: calc(100vh - 16px);
  outline: 0;
  margin: 8px 8px 8px var(--rail);
  border-radius: 14px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(15, 23, 42, 0.02) 0.75px, transparent 0.75px);
  background-size: 20px 20px;
  border: 1px solid rgba(15, 23, 42, 0.072);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.03),
    0 10px 28px -18px rgba(15, 23, 42, 0.09);
  padding: clamp(16px, 2vw, 24px) var(--gutter) 40px;
}
#main > * { width: 100%; max-width: var(--content); margin-left: auto; margin-right: auto; }
body[data-page="home"] #main > *,
body[data-page="plan"] #main > *,
body[data-page="mistakes"] #main > *,
body[data-page="grade"] #main > *,
body[data-page="diagnosis"] #main > * {
  max-width: var(--content-focus);
}

/* Subtle route entry polish when View Transitions aren't active */
@media (prefers-reduced-motion: no-preference) {
  .view-enter {
    animation: view-fade-in 0.18s var(--ease) both;
  }
  @keyframes view-fade-in {
    from { opacity: 0; translate: 0 4px; }
    to { opacity: 1; translate: 0 0; }
  }
  ::view-transition-old(main-view) {
    animation: vt-out 0.12s ease-out both;
  }
  ::view-transition-new(main-view) {
    animation: vt-in 0.18s var(--ease) both;
  }
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in { from { opacity: 0; translate: 0 4px; } }
}

.contextbar {
  display: flex; align-items: center; gap: 8px; min-height: 36px; margin-bottom: 12px;
  font-size: var(--t-sm); color: var(--ink-3);
}
.contextbar a {
  display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 10px 0 6px;
  margin-left: -6px; border-radius: var(--r-sm); color: var(--ink-2); font-weight: 600; text-decoration: none;
}
.contextbar a:hover { background: rgba(15, 23, 42, 0.055); color: var(--ink); }
.context-page { color: var(--ink-3); }

/* Compact rail (narrow iPad portrait only — keep full sidebar down to 860px) */
@media (max-width: 860px) and (min-width: 701px) {
  :root { --rail: 74px; }
  .app-rail { padding: 14px 8px 14px; align-items: stretch; }
  .brand { justify-content: center; padding: 4px 0 14px; }
  .brand-name, .rail-account-text, .rail-account-chevron, .rail-action .ext, .rail-teacher-link span { display: none; }
  .rail-nav a, .rail-action {
    flex-direction: column; justify-content: center; gap: 4px;
    min-height: 48px; padding: 6px 2px; font-size: 10.5px; text-align: center;
  }
  .rail-nav a small {
    position: absolute; top: 2px; right: 5px; margin: 0;
    min-width: 16px; height: 15px; padding: 0 4px; border-radius: 999px;
    font-size: 9.5px; line-height: 1;
    background: var(--bad); color: #fff;
    border: 1.5px solid var(--rail-bg);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.16);
  }
  .rail-nav a.active small {
    background: var(--bad); color: #fff;
    border-color: var(--surface);
  }
  .rail-label { display: block; height: 1px; padding: 0; margin: 8px 12px; background: var(--line); font-size: 0; }
  .rail-bottom { padding-bottom: 4px; justify-items: center; }
  .rail-teacher-link { min-height: 38px; width: 42px; }
  .student-profile.rail-account-btn { justify-content: center; padding: 5px; width: 42px; height: 42px; border-radius: 10px; }
}

/* Phone */
@media (max-width: 700px) {
  :root { --rail: 0px; --tabbar: 62px; --gutter: 14px; }
  .app-rail { display: none; }
  .mobile-brand {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: calc(50px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0;
    background: rgba(243, 244, 246, 0.86); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-logo { display: flex; align-items: center; gap: 9px; text-decoration: none; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
  .mobile-monogram { width: 27px; height: 27px; font-size: 14px; border-radius: 7px; }
  .mobile-brand .icon-btn { width: 38px; height: 38px; }
  .mobile-tabs {
    position: fixed; inset: auto 0 0 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 4px 4px env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.9); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-top: 1px solid var(--line);
  }
  .mobile-tabs a, .mobile-tabs button {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 11px; font-weight: 500; color: var(--ink-3); text-decoration: none; border-radius: var(--r-sm);
  }
  .mobile-tabs a > i svg, .mobile-tabs button > i svg { width: 19px; height: 19px; stroke-width: 1.85; }
  .mobile-tabs a.active { color: var(--brand); font-weight: 600; }
  .mobile-tabs a.active > i { color: var(--brand); }
  .mobile-tabs .tab-badge {
    position: absolute; top: 3px; left: calc(50% + 6px); margin: 0; min-width: 17px; height: 16px; font-size: 10px;
    background: var(--bad); color: #fff;
  }
  #main {
    margin: 0; min-height: 0; border-radius: 0; border: 0; box-shadow: none;
    padding: 14px var(--gutter) calc(var(--tabbar) + 28px + env(safe-area-inset-bottom));
  }
  .page-head { margin-bottom: 16px; }
  .contextbar { margin-bottom: 4px; }
  dialog.sheet {
    width: 100vw; max-width: 100vw; margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  @media (prefers-reduced-motion: no-preference) {
    dialog.sheet { transform: translateY(28px); }
    dialog.sheet[open]:where(:not([data-closing])) {
      transform: translateY(0);
      @starting-style { transform: translateY(28px); }
    }
  }
}

@media (max-width: 700px) {
  html {
    scroll-padding-top: calc(56px + env(safe-area-inset-top));
    scroll-padding-bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
  }
  input[type="text"], input[type="search"], input[type="number"], input[type="date"], input:not([type]), select, textarea {
    font-size: 16px;
  }
}

@media (pointer: coarse) {
  .btn, .primary, .secondary, .ghost, .study-btn { min-height: 44px; }
  .link-btn { min-height: 40px; }
  .chip, .topic-pick { min-height: 38px; }
  input[type="text"], input[type="search"], input[type="number"], input[type="date"], input:not([type]), select, textarea {
    min-height: 44px;
    font-size: 16px;
  }
}

/* ---------- Compact layout density (html[data-density="compact"]) ---------- */
html[data-density="compact"] {
  --t-xs: 11px;
  --t-sm: 12px;
  --t-base: 13px;
  --t-md: 14px;
  --t-lg: 15.5px;
  --t-xl: 19px;
  --t-2xl: 23px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --rail: 194px;
  --gutter: clamp(12px, 2vw, 24px);
  font-size: 14px;
  line-height: 1.42;
}
html[data-density="compact"] .app-rail { padding: 12px 8px 10px; gap: 1px; }
html[data-density="compact"] .brand { padding: 2px 6px 12px; gap: 8px; }
html[data-density="compact"] .brand-symbol { width: 28px; height: 28px; font-size: 15px; border-radius: 7px; }
html[data-density="compact"] .brand-name b { font-size: 15px; }
html[data-density="compact"] .rail-label { padding: 10px 8px 3px; font-size: 10.5px; }
html[data-density="compact"] .rail-nav a,
html[data-density="compact"] .rail-action { min-height: 31px; padding: 0 8px; gap: 8px; font-size: 13px; }
html[data-density="compact"] .student-profile.rail-account-btn { padding: 6px 7px; gap: 7px; }
html[data-density="compact"] .profile-mark { width: 26px; height: 26px; border-radius: 6px; }
html[data-density="compact"] #main {
  margin: 5px 5px 5px var(--rail);
  min-height: calc(100vh - 10px);
  border-radius: 11px;
  padding: 12px var(--gutter) 28px;
}
html[data-density="compact"] .page-head { margin-bottom: 12px; gap: 8px 16px; }
html[data-density="compact"] .page-head h1,
html[data-density="compact"] .study-head h1 { font-size: clamp(19px, 1.9vw, 22px); }
html[data-density="compact"] .page-head p,
html[data-density="compact"] .page-sub { margin-top: 2px; font-size: 12.5px; }
html[data-density="compact"] .section-title { margin: 16px 0 6px; }
html[data-density="compact"] .card-pad { padding: 12px 14px; }
html[data-density="compact"] .btn,
html[data-density="compact"] .primary,
html[data-density="compact"] .secondary,
html[data-density="compact"] .ghost,
html[data-density="compact"] .study-btn { min-height: 34px; padding: 0 12px; font-size: 13px; gap: 5px; }
html[data-density="compact"] .btn-lg { min-height: 38px; padding: 0 14px; font-size: 13.5px; }
html[data-density="compact"] .btn-sm { min-height: 28px; padding: 0 9px; font-size: 12px; }
html[data-density="compact"] .chip,
html[data-density="compact"] .topic-pick { min-height: 27px; padding: 0 9px; font-size: 12px; }
html[data-density="compact"] .badge { height: 19px; padding: 0 6px; font-size: 11px; }
html[data-density="compact"] .segmented { padding: 2px; }
html[data-density="compact"] .segmented > :not(.seg-thumb) { min-height: 28px; padding: 0 10px; font-size: 12px; }
html[data-density="compact"] input[type="text"],
html[data-density="compact"] input[type="search"],
html[data-density="compact"] input[type="number"],
html[data-density="compact"] input[type="date"],
html[data-density="compact"] input:not([type]),
html[data-density="compact"] select { min-height: 33px; padding: 5px 9px; }

/* Home & Adaptive compact density */
html[data-density="compact"] .adp-home { gap: 10px; }
html[data-density="compact"] .adp-focus-card { padding: 14px 18px; gap: 10px; }
html[data-density="compact"] .adp-focus-grid { grid-template-columns: minmax(0, 1fr) 216px; gap: 12px 18px; }
html[data-density="compact"] .adp-focus-copy { gap: 6px; }
html[data-density="compact"] .adp-focus-card h1 { font-size: clamp(18px, 1.9vw, 20px); line-height: 1.25; }
html[data-density="compact"] .adp-focus-sub { font-size: 13px; line-height: 1.48; }
html[data-density="compact"] .adp-focus-actions { margin-top: 2px; gap: 6px 8px; }
html[data-density="compact"] .adp-score-panel { padding: 11px 13px 10px; gap: 5px; }
html[data-density="compact"] .adp-score-num-row strong { font-size: 30px; }
html[data-density="compact"] .adp-score-track { margin-top: 3px; height: 6px; }
html[data-density="compact"] .adp-daily-line { padding-top: 8px; gap: 4px; }
html[data-density="compact"] .adp-section { gap: 6px; }
html[data-density="compact"] .adp-section-head h2 { font-size: 13.5px; }
html[data-density="compact"] .adp-sprint-strip { gap: 8px; }
html[data-density="compact"] .adp-sprint-btn { padding: 9px 12px; gap: 2px; }
html[data-density="compact"] .adp-sprint-ico { width: 24px; height: 24px; border-radius: 6px; }
html[data-density="compact"] .adp-sprint-btn strong { font-size: 13px; }
html[data-density="compact"] .adp-sprint-btn small { font-size: 11px; }
html[data-density="compact"] .adp-mod-row { padding: 7px 13px; gap: 5px 10px; }
html[data-density="compact"] .adp-mod-row strong { font-size: 13px; }
html[data-density="compact"] .adp-mod-bar-wrap progress.adp-progress.is-thin { height: 5px; }
html[data-density="compact"] .adp-stage-wrap { margin-top: 14px; gap: 10px; }
html[data-density="compact"] .adp-q-card { padding: 16px 20px; gap: 13px; }
html[data-density="compact"] .adp-q-stem { font-size: 15.5px; line-height: 1.65; }
html[data-density="compact"] .adp-options { gap: 7px; }
html[data-density="compact"] .adp-opt { min-height: 44px; padding: 8px 12px; font-size: 14.5px; }

/* Plan compact density */
html[data-density="compact"] .adp-plan-wrap { gap: 10px; margin-bottom: 12px; }
html[data-density="compact"] .adp-plan-card { padding: 12px 15px; gap: 9px; }
html[data-density="compact"] .adp-step-item { padding: 9px 10px; gap: 4px; }
html[data-density="compact"] .adp-step-item.is-active { margin: 2px -4px; padding: 9px 14px; }
html[data-density="compact"] .adp-step-item p { font-size: 12px; line-height: 1.4; }
html[data-density="compact"] .adp-stage-chip { min-height: 24px; padding: 0 7px; font-size: 11px; }
html[data-density="compact"] .adp-recent-notes { padding-top: 8px; gap: 4px; }
html[data-density="compact"] .adp-recent-notes li { line-height: 1.38; }
html[data-density="compact"] .plan-calendar { padding: 9px 12px 10px; }
html[data-density="compact"] .plan-date-nav { margin-bottom: 7px; }
html[data-density="compact"] .day { min-height: 44px; width: min(100%, 48px); gap: 1px; padding: 4px 0; }
html[data-density="compact"] .day b { font-size: 15px; }
html[data-density="compact"] .day.on::after { bottom: 3px; width: 3px; height: 3px; }
html[data-density="compact"] .plan-main { margin-top: 10px; }
html[data-density="compact"] .plan-sheet { padding: 13px 16px; }
html[data-density="compact"] .plan-sheet h2 { font-size: 17px; }
html[data-density="compact"] .plan-sheet-actions { margin: 10px 0 12px; gap: 7px; }
html[data-density="compact"] .plan-task-list li { padding: 8px 0 8px 34px; }
html[data-density="compact"] .plan-task-list li::before { width: 22px; height: 22px; top: 8px; font-size: 11.5px; }

/* Mistakes, Grade, Diagnosis compact density */
html[data-density="compact"] .review-toolbar { margin-bottom: 8px; min-height: 34px; }
html[data-density="compact"] .mistake-filters { margin-bottom: 8px; gap: 5px; }
html[data-density="compact"] .mistake-card { padding: 9px 13px; gap: 4px 14px; }
html[data-density="compact"] .mistake-main { gap: 3px; }
html[data-density="compact"] .mistake-card h3 { font-size: 13.5px; line-height: 1.3; }
html[data-density="compact"] .mistake-stem { font-size: 13px; line-height: 1.48; -webkit-line-clamp: 2; }
html[data-density="compact"] .mistake-actions { flex-direction: row; align-items: center; gap: 4px; padding-top: 0; }
html[data-density="compact"] .grade-ledger { padding: 12px 15px; }
html[data-density="compact"] .grade-score-num { font-size: 30px; }
html[data-density="compact"] .grade-summary { min-height: 48px; padding: 7px 12px; gap: 8px; }
html[data-density="compact"] .topic-grid { gap: 8px; }
html[data-density="compact"] .topic-card { padding: 11px 13px; gap: 6px; }

/* Bank, Buddy, Photo, Paper, Teacher compact density */
html[data-density="compact"] .library { gap: 10px; }
html[data-density="compact"] .library-toolbar { padding: 8px 10px; gap: 8px; }
html[data-density="compact"] .library-card { padding: 11px 14px; gap: 8px; }
html[data-density="compact"] .library-card h2 { font-size: 14.5px; }
html[data-density="compact"] .library-stem { font-size: 13.5px; line-height: 1.56; }
html[data-density="compact"] .library-options { padding: 6px 10px; gap: 2px 14px; }
html[data-density="compact"] .library-option { padding: 2px 0; font-size: 13px; line-height: 1.45; }
html[data-density="compact"] .library-card-foot { padding-top: 8px; gap: 6px; }
html[data-density="compact"] .buddy-app { gap: 8px; }
html[data-density="compact"] .buddy-qcard { padding: 10px 13px; gap: 6px; }
html[data-density="compact"] .buddy-stem { padding: 8px 10px; font-size: 13.5px; line-height: 1.52; max-height: 130px; }
html[data-density="compact"] .buddy-messages { padding: 10px 12px; gap: 8px; }
html[data-density="compact"] .buddy-prompt-row { padding: 8px 11px; gap: 9px; }
html[data-density="compact"] .photo { gap: 10px; }
html[data-density="compact"] .photo-grid { gap: 10px; }
html[data-density="compact"] .photo-card { padding: 12px 14px; gap: 9px; }
html[data-density="compact"] .photo-upload { min-height: 148px; padding: 14px 12px; }
html[data-density="compact"] .paper-selected-row { padding: 6px 2px; gap: 8px; }
html[data-density="compact"] .ts-shell { padding: 12px 0 8px; gap: 10px; }
html[data-density="compact"] .ts-header { padding: 11px 14px; }
html[data-density="compact"] .ts-kpis { gap: 8px; }
html[data-density="compact"] .ts-kpi { padding: 9px 12px; gap: 2px; }
html[data-density="compact"] .ts-kpi strong { font-size: 19px; }
html[data-density="compact"] .ts-card { padding: 13px 15px; gap: 10px; }
html[data-density="compact"] .ts-mod-btn { padding: 9px 11px; gap: 3px; }
html[data-density="compact"] .ts-accordion-sum { min-block-size: 36px; padding: 7px 11px; font-size: 13px; }

/* Mobile compact density: maximize at-a-glance information while preserving comfortable tap targets */
@media (max-width: 700px) {
  html[data-density="compact"] { --tabbar: 54px; --gutter: 10px; }
  html[data-density="compact"] .mobile-brand { height: calc(44px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0; }
  html[data-density="compact"] .mobile-tabs a,
  html[data-density="compact"] .mobile-tabs button { font-size: 10px; gap: 1px; }
  html[data-density="compact"] .mobile-tabs a > i svg,
  html[data-density="compact"] .mobile-tabs button > i svg { width: 17px; height: 17px; }
  html[data-density="compact"] #main {
    margin: 0; border-radius: 0; border: 0; box-shadow: none;
    padding: 8px var(--gutter) calc(var(--tabbar) + 18px + env(safe-area-inset-bottom));
  }
  html[data-density="compact"] .adp-home { gap: 8px; }
  html[data-density="compact"] .adp-bar { gap: 6px; }
  html[data-density="compact"] .adp-exam-btn { min-height: 28px; font-size: 12px; padding: 0 6px; }
  html[data-density="compact"] .adp-bar-stats { font-size: 11.5px; }
  html[data-density="compact"] .adp-focus-card { padding: 11px 12px; gap: 8px; }
  html[data-density="compact"] .adp-focus-grid { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  /* Horizontal sleek dark score strip on compact mobile */
  html[data-density="compact"] .adp-score-panel {
    order: -1;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 4px 12px;
    padding: 8px 11px;
  }
  html[data-density="compact"] .adp-score-num-row { grid-column: 1; grid-row: 1 / 3; margin: 0; }
  html[data-density="compact"] .adp-score-num-row strong { font-size: 26px; }
  html[data-density="compact"] .adp-score-num-row span { font-size: 11px; }
  html[data-density="compact"] .adp-score-head { grid-column: 2; grid-row: 1; font-size: 11px; }
  html[data-density="compact"] .adp-score-track { grid-column: 2; grid-row: 2; margin: 0; height: 6px; }
  html[data-density="compact"] .adp-score-scale { display: none; }
  html[data-density="compact"] .adp-focus-card h1 { font-size: 16.5px; line-height: 1.28; }
  html[data-density="compact"] .adp-focus-sub {
    font-size: 12px; line-height: 1.45;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  html[data-density="compact"] .adp-focus-actions { gap: 6px; }
  html[data-density="compact"] .adp-focus-actions > .primary { flex: 1 1 0; min-height: 40px; padding: 0 10px; font-size: 13px; }
  html[data-density="compact"] .adp-focus-actions > .secondary { flex: 0 1 auto; min-height: 40px; padding: 0 10px; font-size: 12.5px; }
  html[data-density="compact"] .adp-focus-actions > .ghost { min-height: 32px; padding: 0 6px; font-size: 12px; }
  /* 3-column compact sprint cards on mobile */
  html[data-density="compact"] .adp-sprint-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  html[data-density="compact"] .adp-sprint-btn { padding: 8px 8px 7px; gap: 3px; min-block-size: 58px; }
  html[data-density="compact"] .adp-sprint-ico,
  html[data-density="compact"] .adp-sprint-arrow { display: none; }
  html[data-density="compact"] .adp-sprint-top { margin-bottom: 0; }
  html[data-density="compact"] .adp-sprint-tag { font-size: 10px; padding: 1px 5px; }
  html[data-density="compact"] .adp-sprint-btn strong { font-size: 12px; line-height: 1.25; }
  html[data-density="compact"] .adp-sprint-btn small {
    font-size: 10.5px; line-height: 1.3;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden;
  }
  /* Keep 2x4 module grid on compact mobile so all 8 modules fit at once */
  html[data-density="compact"] .adp-mod-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html[data-density="compact"] .adp-mod-row {
    padding: 8px 10px; gap: 5px 6px; min-block-size: 46px;
    border-right: 1px solid rgba(15, 23, 42, 0.055);
    border-bottom: 1px solid rgba(15, 23, 42, 0.055);
  }
  html[data-density="compact"] .adp-mod-row:nth-child(2n) { border-right: 0; }
  html[data-density="compact"] .adp-mod-row:nth-last-child(-n+2) { border-bottom: 0; }
  html[data-density="compact"] .adp-mod-row strong { font-size: 12.5px; }
  html[data-density="compact"] .adp-mod-row-val { font-size: 10.5px; gap: 3px; }
  html[data-density="compact"] .adp-mod-row-val b { font-size: 11px; }
  html[data-density="compact"] .adp-mod-arrow { display: none; }
  /* Mistakes compact mobile */
  html[data-density="compact"] .mistake-card { grid-template-columns: minmax(0, 1fr); padding: 9px 11px; gap: 5px; }
  html[data-density="compact"] .mistake-actions { justify-content: flex-start; gap: 4px; }
  html[data-density="compact"] .mistake-actions .study-btn { min-height: 36px; padding: 0 9px; font-size: 12px; }
  html[data-density="compact"] .adp-step-item p,
  html[data-density="compact"] .adp-chip-row { padding-left: 0; }
}

@media (pointer: coarse) {
  html[data-density="compact"] .btn,
  html[data-density="compact"] .primary,
  html[data-density="compact"] .secondary,
  html[data-density="compact"] .study-btn { min-height: 40px; }
  html[data-density="compact"] .btn-sm { min-height: 36px; }
  html[data-density="compact"] .chip,
  html[data-density="compact"] .topic-pick { min-height: 34px; }
  html[data-density="compact"] .settings-segmented > button { min-height: 40px; }
  html[data-density="compact"] input[type="text"],
  html[data-density="compact"] input[type="search"],
  html[data-density="compact"] input[type="number"],
  html[data-density="compact"] input[type="date"],
  html[data-density="compact"] input:not([type]),
  html[data-density="compact"] select,
  html[data-density="compact"] textarea { min-height: 40px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  dialog.sheet, .account-popover { transition-duration: 0.1s !important; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

@media (forced-colors: active) {
  .rail-nav a.active, .mobile-tabs a.active, .segmented > [aria-current="page"] {
    outline: 2px solid Highlight; outline-offset: -2px;
  }
}

/* Registered custom properties for smooth pointer-spotlight radius transitions */
@property --spot-inner {
  syntax: "<length-percentage>";
  inherits: true;
  initial-value: 0px;
}
@property --spot-outer {
  syntax: "<length-percentage>";
  inherits: true;
  initial-value: 0px;
}

/* Pointer spotlight (non-essential visual polish; all content stays fully readable & keyboard reachable) */
[data-spotlight] {
  position: relative;
  --mx: 50%;
  --my: 50%;
  --spot-inner: 0px;
  --spot-outer: 0px;
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  [data-spotlight]::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
    transition: --spot-inner 0.22s ease-out, --spot-outer 0.26s ease-out, opacity 0.22s ease-out;
    mask-image: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), #000 var(--spot-inner, 0px), transparent var(--spot-outer, 0px));
    -webkit-mask-image: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), #000 var(--spot-inner, 0px), transparent var(--spot-outer, 0px));
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
    opacity: 0;
  }
  [data-spotlight="light"]::after {
    background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(59, 91, 219, 0.048), transparent 72%);
  }
  [data-spotlight="card"]::after {
    background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(59, 91, 219, 0.04), transparent 70%);
  }
  [data-spotlight="dark"]::after {
    background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(148, 178, 255, 0.16), rgba(92, 124, 250, 0.04) 55%, transparent 75%);
  }
  [data-spotlight]:hover {
    --spot-inner: 48px;
    --spot-outer: 240px;
  }
  [data-spotlight="dark"]:hover {
    --spot-inner: 28px;
    --spot-outer: 165px;
  }
  [data-spotlight]:hover::after {
    opacity: 1;
  }
}

/* Primary button specular sheen & arrow glide */
.primary, .btn-primary, .study-primary {
  position: relative;
  overflow: hidden;
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .primary::after, .btn-primary::after, .study-primary::after {
    content: "";
    position: absolute;
    inset: -20% auto -20% -60%;
    width: 48%;
    pointer-events: none;
    background: linear-gradient(108deg, transparent 0%, rgba(255, 255, 255, 0.16) 50%, transparent 100%);
    transform: translateX(-100%) skewX(-18deg);
    transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .primary:hover:not(:disabled)::after,
  .btn-primary:hover:not(:disabled)::after,
  .study-primary:hover:not(:disabled)::after {
    transform: translateX(460%) skewX(-18deg);
  }
  .primary > svg:last-child, .btn-primary > svg:last-child {
    transition: transform 0.2s cubic-bezier(0.22, 1.15, 0.36, 1);
    transition-timing-function: linear(0, 0.42 18%, 1.06 46%, 0.99 72%, 1);
  }
  .primary:hover:not(:disabled) > svg:last-child,
  .btn-primary:hover:not(:disabled) > svg:last-child {
    transform: translateX(3px);
  }
}

/* Sliding segmented thumb (physics-based linear() easing with cubic-bezier fallback) */
.segmented.has-slider {
  position: relative;
}
.segmented.has-slider > :not(.seg-thumb) {
  position: relative;
  z-index: 1;
}
.segmented.has-slider > :is([aria-current="page"], [aria-selected="true"], [aria-checked="true"], .on) {
  background: transparent;
  box-shadow: none;
}
.segmented.has-slider > .seg-thumb {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  display: block;
  min-height: 0;
  padding: 0;
  margin: 0;
  pointer-events: none;
  border-radius: var(--r-xs);
  background: var(--surface);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.08),
    0 0 0 1px rgba(15, 23, 42, 0.045);
  transition: transform 0.26s cubic-bezier(0.22, 1.08, 0.36, 1), width 0.24s ease-out, height 0.24s ease-out;
  transition-timing-function: linear(0, 0.38 14%, 0.94 34%, 1.04 50%, 0.995 74%, 1), ease-out, ease-out;
  will-change: transform, width;
}

/* Subtle GPU stagger reveal on view entry */
@media (prefers-reduced-motion: no-preference) {
  @keyframes rise-in {
    from { opacity: 0; transform: translate3d(0, 7px, 0); }
    to { opacity: 1; transform: translate3d(0, 0, 0); }
  }
  .adp-home > .adp-bar { animation: rise-in 0.24s var(--ease) both; }
  .adp-home > .adp-focus-card { animation: rise-in 0.3s var(--ease) 0.03s both; }
  .adp-home .adp-sprint-btn:nth-child(1) { animation: rise-in 0.28s var(--ease) 0.07s both; }
  .adp-home .adp-sprint-btn:nth-child(2) { animation: rise-in 0.28s var(--ease) 0.11s both; }
  .adp-home .adp-sprint-btn:nth-child(3) { animation: rise-in 0.28s var(--ease) 0.15s both; }
  .adp-home .adp-mod-list { animation: rise-in 0.3s var(--ease) 0.17s both; }
  .adp-plan-card { animation: rise-in 0.28s var(--ease) 0.02s both; }
  .plan-calendar { animation: rise-in 0.28s var(--ease) 0.07s both; }
  .mistake-card:nth-child(1) { animation: rise-in 0.22s var(--ease) 0.02s both; }
  .mistake-card:nth-child(2) { animation: rise-in 0.22s var(--ease) 0.045s both; }
  .mistake-card:nth-child(3) { animation: rise-in 0.22s var(--ease) 0.07s both; }
  .mistake-card:nth-child(4) { animation: rise-in 0.22s var(--ease) 0.095s both; }
  .mistake-card:nth-child(5) { animation: rise-in 0.22s var(--ease) 0.12s both; }
  .mistake-card:nth-child(6) { animation: rise-in 0.22s var(--ease) 0.145s both; }
  .mistake-card:nth-child(7) { animation: rise-in 0.22s var(--ease) 0.17s both; }
  .mistake-card:nth-child(8) { animation: rise-in 0.22s var(--ease) 0.195s both; }
}

/* Compact density overrides for 3D icon assets */
html[data-density="compact"] .adp-sprint-art { width: 28px; height: 28px; }
html[data-density="compact"] .buddy-empty-art { width: 46px; height: 46px; }
html[data-density="compact"] .photo-lens-art { width: 46px; height: 46px; }
@media (max-width: 700px) {
  html[data-density="compact"] .adp-sprint-art-wrap { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  [data-spotlight]::after, .seg-thumb { transition: none !important; }
  .primary::after, .btn-primary::after, .study-primary::after { display: none; }
}

@media print {
  html, body { background: #fff !important; background-image: none !important; }
  .app-rail, .mobile-brand, .mobile-tabs, #notice, .skip-main, .contextbar, .account-popover { display: none !important; }
  #main { margin: 0 !important; padding: 0 !important; width: auto !important; max-width: none !important; }
  #main > * { max-width: none !important; }
}
