:root {
  color-scheme: light;
  --ink: #102f38;
  --ink-soft: #45616a;
  --paper: #f7f4ec;
  --paper-strong: #fffdf8;
  --line: #d7d8cf;
  --brand: #123b4a;
  --brand-2: #1d6470;
  --accent: #e4793c;
  --accent-soft: #fff0e5;
  --good: #176849;
  --bad: #a33b32;
  --warning: #8b5b12;
  --shadow: 0 14px 36px rgba(16, 47, 56, .11);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}
button, input, select { font: inherit; }
button, select, input[type="text"], .file-button, .button-link { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, select:focus-visible, input:focus-visible, .file-button:focus-within, .button-link:focus-visible {
  outline: 3px solid rgba(228, 121, 60, .45);
  outline-offset: 2px;
}
.skip-link { position: fixed; top: -100px; left: 12px; z-index: 1000; background: white; padding: 10px 14px; }
.skip-link:focus { top: 12px; }
.hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  color: white;
  background: rgba(18, 59, 74, .97);
  box-shadow: 0 8px 26px rgba(9, 32, 39, .18);
}
.brand { display: flex; align-items: center; gap: 10px; border: 0; color: inherit; background: transparent; text-align: left; padding: 0; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--accent); font: 800 22px/1 Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand small { color: #c9d8dc; font-size: 11px; letter-spacing: .04em; }
.utility-nav { display: flex; gap: 4px; overflow-x: auto; }
.utility-nav button { border: 0; border-radius: 12px; color: white; background: transparent; padding: 8px 10px; white-space: nowrap; }
.utility-nav button:active { background: rgba(255,255,255,.12); }
.app-status { padding: 8px 16px; color: #d8e8eb; background: #0d2e39; font-size: 13px; text-align: center; }

main { width: min(1440px, 100%); margin: 0 auto; }
.view { display: none; padding: 20px 14px 96px; }
.view.active { display: block; }
.hero-copy { padding: 24px 4px 16px; }
.hero-copy h1, .page-view h1 { margin: 0; font: 700 clamp(30px, 7vw, 52px)/1.08 Georgia, "Times New Roman", serif; letter-spacing: -.03em; }
.hero-copy p:last-child { max-width: 760px; color: var(--ink-soft); }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .15em; }

.part-grid { display: grid; gap: 14px; }
.part-card {
  position: relative;
  overflow: hidden;
  min-height: 220px;
  padding: 20px;
  border: 1px solid rgba(16, 47, 56, .11);
  border-radius: var(--radius);
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}
.part-card::after { content: ""; position: absolute; right: -34px; bottom: -50px; width: 160px; height: 160px; border: 26px solid color-mix(in srgb, var(--card-color) 24%, transparent); border-radius: 50%; }
.part-card[data-part="5"] { --card-color: #e4793c; }
.part-card[data-part="6"] { --card-color: #2f7f73; }
.part-card[data-part="7"] { --card-color: #365d8a; }
.part-number { color: var(--card-color); font: 800 54px/1 Georgia, serif; }
.part-card h2 { margin: 4px 0 2px; font-size: 22px; }
.part-card .big-count { margin: 0 0 10px; color: var(--ink-soft); }
.metric-row { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0 16px; font-size: 13px; }
.metric-row strong { color: var(--ink); }
.part-card .start-part { position: relative; z-index: 1; width: 100%; }

.primary, .secondary, .danger, .file-button, .icon-button, .button-link {
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 9px 14px;
  font-weight: 750;
}
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.primary { color: white; background: var(--brand); }
.primary:active { background: #092d38; }
.secondary, .icon-button, .file-button { color: var(--ink); border-color: var(--line); background: var(--paper-strong); }
.button-link.secondary { color: var(--ink); border-color: var(--line); background: var(--paper-strong); }
.danger { color: var(--bad); border-color: #e8bbb6; background: #fff5f4; }
.icon-button[aria-pressed="true"] { color: white; border-color: var(--accent); background: var(--accent); }

.filter-card, .storage-card, .record-summary, .report-box, .settings-grid, .notice, .warning-box {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-strong);
}
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading h1, .section-heading h2 { margin: 0; }
.filter-grid { display: grid; gap: 12px; margin-top: 18px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 750; }
select, input[type="text"] { width: 100%; padding: 8px 11px; color: var(--ink); border: 1px solid var(--line); border-radius: 12px; background: white; }
.filter-counts { display: grid; gap: 8px; margin-top: 16px; }
.filter-count { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #edf1ef; font-size: 13px; }
.resume-banner { margin-bottom: 8px; padding: 14px; border: 1px solid #edc091; border-radius: 16px; background: var(--accent-soft); }
.install-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 18px;
  padding: 18px;
  border: 1px solid #9dc9cf;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #e9f7f7, #fffdf8);
  box-shadow: var(--shadow);
}
.install-card h2 { margin: 0; font-size: 24px; }
.install-card p:last-child { margin: 6px 0 0; color: var(--ink-soft); }
.install-card.installed { border-color: #8bc4ad; background: #effaf5; }
.install-card.available { border-color: #e6ad75; background: #fff5e9; }
.install-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: 8px; }

.practice-view { padding: 0 0 max(112px, calc(84px + env(safe-area-inset-bottom))); }
.practice-topbar { position: sticky; top: 72px; z-index: 14; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 14px; background: rgba(247,244,236,.97); border-bottom: 1px solid var(--line); }
.practice-identity { min-width: 0; text-align: center; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.practice-progress { font-size: 13px; font-weight: 800; }
.practice-layout { display: grid; min-height: calc(100vh - 150px); }
.material-pane, .question-pane { min-width: 0; padding: 14px; }
.material-pane { background: #e7ece9; }
.question-pane { background: var(--paper-strong); }
.pane-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.pane-heading h2 { margin: 0; font-size: 20px; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; color: var(--brand); border-radius: 999px; background: #d4e4e4; font-size: 12px; font-weight: 800; }
.material-pages { display: grid; gap: 12px; }
.material-image-button { width: 100%; min-height: 44px; padding: 0; border: 0; border-radius: 12px; background: white; box-shadow: 0 6px 24px rgba(16,47,56,.12); overflow: hidden; }
.material-image-button img { display: block; width: 100%; height: auto; object-fit: contain; }
.image-caption { display: block; padding: 7px 10px; color: var(--ink-soft); font-size: 12px; text-align: left; }
.source-note { padding: 11px; border-left: 4px solid var(--accent); background: var(--accent-soft); font-size: 13px; }
.state-buttons { display: flex; gap: 6px; }
.choice-list { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin: 16px 0; }
.choice-button { min-height: 64px; border: 2px solid var(--line); border-radius: 15px; color: var(--ink); background: white; font-size: 18px; font-weight: 850; }
.choice-button[aria-checked="true"] { color: white; border-color: var(--brand-2); background: var(--brand-2); }
.choice-button.correct { border-color: var(--good); box-shadow: inset 0 0 0 2px var(--good); }
.choice-button.wrong { border-color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
.submit-answer { width: 100%; }
.answer-feedback { min-height: 34px; font-weight: 800; }
.answer-feedback.good { color: var(--good); }
.answer-feedback.bad { color: var(--bad); }
.group-navigation { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.question-chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.question-chip { min-width: 48px; border: 1px solid var(--line); border-radius: 999px; background: white; }
.question-chip.active { color: white; border-color: var(--brand); background: var(--brand); }
.question-chip.done::after { content: "✓"; margin-left: 3px; color: var(--good); }
.question-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px 10px max(8px, env(safe-area-inset-bottom)); background: rgba(255,253,248,.97); box-shadow: 0 -10px 28px rgba(16,47,56,.14); }
.question-actions button { padding-inline: 7px; font-size: 12px; }

.page-view { max-width: 1120px; margin: 0 auto; }
.storage-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.storage-card p { margin: 2px 0 0; color: var(--ink-soft); }
.offline-packs { display: grid; gap: 12px; margin-top: 16px; }
.pack-card { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper-strong); }
.pack-title { display: flex; justify-content: space-between; gap: 12px; }
.pack-meta { color: var(--ink-soft); font-size: 13px; }
.pack-status { font-weight: 850; }
.pack-status.complete { color: var(--good); }
.pack-card button { width: 100%; margin-top: 10px; }
.download-progress { margin-top: 16px; padding: 16px; border-radius: 16px; color: white; background: var(--brand); }
.download-progress progress { width: 100%; height: 16px; }
.offline-actions, .record-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.privacy-note { color: var(--ink-soft); font-size: 13px; }
.record-summary { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.summary-metric { padding: 12px; border-radius: 14px; background: #edf1ef; }
.summary-metric strong, .summary-metric span { display: block; }
.summary-metric strong { font-size: 22px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.report-box:empty { display: none; }
.settings-grid { display: grid; gap: 14px; }
.settings-grid > div { min-width: 0; }
.settings-grid span { display: block; color: var(--ink-soft); font-size: 13px; }
code { display: block; overflow-wrap: anywhere; color: var(--brand); }
.warning-box { color: #673f07; border-color: #e4c58c; background: #fff7df; }
.edge-tools { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-strong); }
.edge-tool-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.edge-status-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.edge-status-grid > div { min-width: 0; padding: 12px; border-radius: 14px; background: #edf1ef; }
.edge-status-grid span, .edge-status-grid strong { display: block; overflow-wrap: anywhere; }
.edge-status-grid span { color: var(--ink-soft); font-size: 12px; }
.edge-diagnostic-list { margin: 8px 0 0; padding-left: 20px; }
#edge-diagnostic-output:empty { display: none; }

dialog { border: 0; padding: 0; }
dialog::backdrop { background: rgba(7, 24, 30, .74); }
.import-dialog { width: min(960px, calc(100% - 20px)); max-height: calc(100vh - 20px); border-radius: 20px; }
.dialog-shell { padding: 18px; overflow: auto; max-height: calc(100vh - 20px); }
.import-file-summaries { display: grid; gap: 10px; margin-top: 14px; }
.file-summary { padding: 12px; border: 1px solid var(--line); border-radius: 14px; }
.file-summary h3 { margin: 0 0 6px; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary-table th, .summary-table td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.dialog-actions { position: sticky; bottom: -18px; display: flex; justify-content: flex-end; gap: 8px; padding: 14px 0 0; background: white; }

.image-viewer { width: 100vw; height: 100vh; max-width: none; max-height: none; background: #07181e; }
.image-viewer[open] { display: grid; grid-template-rows: auto 1fr; }
.viewer-toolbar { display: flex; gap: 6px; overflow-x: auto; padding: max(8px, env(safe-area-inset-top)) 8px 8px; background: #0e2d37; }
.viewer-toolbar button { flex: 0 0 auto; color: white; border: 1px solid #54727b; border-radius: 11px; background: #173f4b; padding: 7px 11px; }
.viewer-stage { position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.viewer-stage:active { cursor: grabbing; }
.viewer-stage img { position: absolute; left: 50%; top: 50%; max-width: none; max-height: none; transform-origin: center; user-select: none; -webkit-user-drag: none; }
.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 100; transform: translate(-50%, 30px); max-width: calc(100% - 24px); padding: 11px 15px; border-radius: 999px; color: white; background: #0c2f3a; opacity: 0; pointer-events: none; transition: .2s ease; text-align: center; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .view { padding: 30px 28px 110px; }
  .part-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .filter-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .filter-counts { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .offline-packs { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .record-summary { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .settings-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .question-actions { left: auto; width: min(720px, 50vw); }
}

@media (max-width: 719px) {
  .install-card { align-items: stretch; flex-direction: column; }
  .install-actions > * { flex: 1 1 100%; }
  .edge-status-grid { grid-template-columns: 1fr; }
  .edge-tool-actions > * { flex: 1 1 100%; }
  .edge-tools .section-heading { align-items: stretch; flex-direction: column; }
}

@media (min-width: 920px) and (orientation: landscape) {
  .practice-layout { grid-template-columns: minmax(0, 1.1fr) minmax(420px, .9fr); height: calc(100vh - 142px); }
  .material-pane, .question-pane { overflow: auto; }
  .question-pane { padding: 22px; }
  .question-actions { position: sticky; bottom: 0; width: auto; margin: 24px -22px -22px; }
}

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