/* Road Knowledge Buddy — sector road knowledge study aid (indigo).
 * Sister app to Bell Code Buddy. Browse / Cards / Quiz / Order over ROAD_DATA. */
:root {
  --bg: #eef3fb;
  --surface: #ffffff;
  --surface-2: #e3ecf8;
  --text: #14233b;
  --text-2: #56657f;
  --line: #d6e0ef;
  --accent: #0e63c9;
  --accent-2: #3f86e6;
  --accent-soft: #e1ecfc;
  --on-accent: #ffffff;
  --ok: #15834b;
  --ok-soft: #e4f4ea;
  --bad: #c9362b;
  --bad-soft: #fbe9e7;
  --warn: #b25a00;
  --warn-soft: #fdefdb;
  --rail: #aebfd8;
  --gi: #2aa19a;
  --poi: #d98a00;
  --fixed-red: #e0362b;
  --shadow: 0 2px 3px rgba(13, 38, 76, .06), 0 10px 28px rgba(13, 38, 76, .10);
  --header-bg: rgba(255, 255, 255, .94);
  --tab-bg: rgba(255, 255, 255, .92);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1320;
    --surface: #14202f;
    --surface-2: #1d2c3f;
    --text: #eef3fb;
    --text-2: #a6b6cd;
    --line: #28384c;
    --accent: #5aa0ff;
    --accent-2: #7db5ff;
    --accent-soft: #16273e;
    --ok: #34c06e;
    --ok-soft: #14301f;
    --bad: #ee6060;
    --bad-soft: #3a1a1a;
    --warn: #e09b4a;
    --warn-soft: #36260f;
    --rail: #3c506b;
    --gi: #45cabf;
    --poi: #e6ab3f;
    --fixed-red: #ff5b50;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .5);
    --header-bg: rgba(11, 19, 32, .95);
    --tab-bg: rgba(20, 32, 47, .94);
  }
}

/* ---- Mode 2 (Road Knowledge) recolours the accent to indigo ---- */
body.mode-road {
  --accent: #5a37c9;
  --accent-2: #7b5be0;
  --accent-soft: #ece8fb;
}
@media (prefers-color-scheme: dark) {
  body.mode-road {
    --accent: #9a7bf0;
    --accent-2: #b79bff;
    --accent-soft: #241a44;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  border-top: 6px solid var(--accent);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
}
.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.train-roundel { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); overflow: hidden; }
.app-title { margin: 0; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; min-width: 0; flex: 1 1 auto; }
.brand-name { color: var(--text); font-size: 16px; font-weight: 800; letter-spacing: -.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.product-name { color: var(--text-2); font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; margin-top: 4px; }
.training-badge {
  flex: 0 0 auto; white-space: nowrap; color: var(--accent);
  border: 1px solid currentColor; border-radius: 4px; padding: 3px 5px;
  font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text-2); transition: background .15s ease; }
.icon-btn:active { background: var(--surface-2); }

/* ---------- main / views ---------- */
#main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px calc(116px + env(safe-area-inset-bottom));
}
.view { max-width: 640px; margin: 0 auto; animation: view-in .22s ease; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- line chips ---------- */
.line-bar {
  display: flex; gap: 7px; overflow-x: auto; padding: 2px 2px 12px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.line-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 700;
  padding: 8px 14px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2);
  transition: transform .1s ease, background .15s ease, color .15s ease, border-color .15s ease;
}
.chip .chip-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--chip-col, var(--accent)); flex: 0 0 auto; }
.chip:active { transform: scale(.96); }
.chip.active { background: var(--chip-col, var(--accent)); border-color: var(--chip-col, var(--accent)); color: #fff; }
.chip.active .chip-dot { background: rgba(255, 255, 255, .9); }

/* sector filter row (above the line chips) */
.sector-filter { padding-bottom: 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.sector-filter .filter-label { flex: 0 0 auto; align-self: center; margin-right: 3px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.sector-filter .sector-chip { font-size: 12.5px; padding: 6px 12px; }

/* ---------- lines: line header + run list ---------- */
.line-title-row { display: flex; align-items: center; gap: 11px; margin: 2px 2px 14px; }
.line-badge {
  display: inline-grid; place-items: center; min-width: 40px; height: 30px; padding: 0 10px;
  border-radius: 8px; background: var(--line-col, var(--accent)); color: #fff;
  font-size: 15px; font-weight: 800; letter-spacing: .01em; flex: 0 0 auto;
}
.line-badge.sm { min-width: 30px; height: 23px; font-size: 12px; border-radius: 6px; padding: 0 7px; }
.line-name { font-size: 18px; font-weight: 850; letter-spacing: -.01em; line-height: 1.15; }
.line-sub { font-size: 12.5px; color: var(--text-2); margin: -8px 2px 14px; line-height: 1.45; }

.run-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-top: 4px solid var(--line-col, var(--accent)); }
.run-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 14px 15px; text-align: left; border-bottom: 1px solid var(--line);
}
.run-row:last-child { border-bottom: 0; }
.run-row:active { background: var(--surface-2); }
.run-main { min-width: 0; flex: 1 1 auto; }
.run-name { font-size: 15.5px; font-weight: 750; line-height: 1.25; }
.run-sub { font-size: 12.5px; color: var(--text-2); margin-top: 3px; line-height: 1.35; }
.run-count {
  flex: 0 0 auto; font-size: 11px; font-weight: 800; color: var(--line-col, var(--accent));
  background: var(--accent-soft); padding: 4px 8px; border-radius: 7px; font-variant-numeric: tabular-nums;
}
.chev { color: var(--text-2); font-size: 22px; line-height: 1; flex: 0 0 auto; }

/* ---------- run detail: station sequence ---------- */
.back-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 14px; font-weight: 700; color: var(--accent);
  padding: 6px 2px; margin: 0 0 6px;
}
.detail-title { font-size: 21px; font-weight: 850; letter-spacing: -.02em; margin: 0; line-height: 1.15; }
.detail-meta { font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-top: 6px; line-height: 1.45; }
.run-note {
  background: var(--accent-soft); color: var(--text);
  border-radius: var(--radius); padding: 11px 14px; margin: 14px 2px 4px;
  font-size: 13px; line-height: 1.5;
}
.dir-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 16px 2px 8px; font-size: 11px; font-weight: 800; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-2);
}

.seq { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px; border-top: 4px solid var(--line-col, var(--accent)); }
.seq-stop { display: flex; gap: 13px; }
.seq-marker { position: relative; flex: 0 0 22px; }
.seq-marker .bar { position: absolute; left: 50%; transform: translateX(-50%); width: 4px; top: 0; bottom: 0; background: var(--line-col, var(--accent)); border-radius: 2px; opacity: .9; }
.seq-stop.first .seq-marker .bar { top: 50%; }
.seq-stop.last .seq-marker .bar { bottom: 50%; }
.seq-marker .node { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3.5px solid var(--line-col, var(--accent)); z-index: 1; }
.seq-stop.term .seq-marker .node { width: 17px; height: 17px; background: var(--line-col, var(--accent)); }
.seq-body { flex: 1 1 auto; min-width: 0; padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.seq-stop:last-child .seq-body { border-bottom: 0; }
.seq-num { font-size: 11px; font-weight: 800; color: var(--text-2); font-variant-numeric: tabular-nums; flex: 0 0 auto; min-width: 18px; }
.seq-name { font-size: 15.5px; font-weight: 700; flex: 1 1 auto; min-width: 0; line-height: 1.25; }
.seq-stop.term .seq-name { font-weight: 850; }
.seq-sector {
  display: flex; align-items: center; gap: 8px; margin: 12px 0 3px; padding: 2px 2px 0;
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--sec-col, var(--accent));
}
.seq-sector::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--sec-col, var(--accent)); flex: 0 0 auto; }
.seq-sector::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.seq-stop:first-child .seq-body, .seq-sector + .seq-stop .seq-body { border-top: 0; }
.seq-tags { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; flex: 0 1 auto; }
.seq-ix { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 5px; color: #fff; letter-spacing: .01em; }

.source-note { font-size: 12px; color: var(--text-2); line-height: 1.5; margin: 16px 2px 0; }

/* ---------- shared meta / scorebar ---------- */
.practice-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.meta-blurb { color: var(--text-2); font-size: 14.5px; font-weight: 600; line-height: 1.4; }
.scorebar { display: flex; gap: 7px; flex: 0 0 auto; }
.score-chip {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--line); border-radius: 99px;
  padding: 7px 11px; color: var(--text-2);
}

/* ---------- buttons ---------- */
.action-row { display: flex; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.pill-btn {
  font-size: 15px; font-weight: 600; padding: 11px 20px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 1px 2px rgba(13, 38, 76, .05);
  transition: transform .1s ease, opacity .15s ease;
}
.pill-btn:active { transform: scale(.96); }
.pill-btn:disabled { opacity: .4; }
.pill-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pill-btn.danger { color: var(--bad); border-color: var(--bad); background: none; }

/* ---------- cards (flip flashcards) ---------- */
.flashcard { perspective: 1400px; margin: 0 auto; -webkit-user-select: none; user-select: none; touch-action: pan-y; }
.flashcard-inner {
  position: relative; width: 100%; min-height: 320px;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .7, .2, 1); cursor: pointer;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 28px 22px; text-align: center;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 5px solid var(--accent); overflow-y: auto;
}
.flashcard-back { transform: rotateY(180deg); }
.flashcard-cat { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.flashcard-q { font-size: 21px; font-weight: 800; line-height: 1.25; }
.flashcard-prompt { font-size: 14px; color: var(--text-2); line-height: 1.5; }
.flashcard-a { font-size: 19px; font-weight: 800; line-height: 1.3; }
.flashcard-a-sub { font-size: 14px; color: var(--text-2); line-height: 1.55; }
.flashcard-flip-hint {
  position: absolute; bottom: 12px; left: 0; right: 0;
  font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-2); opacity: .6;
}

/* ---------- quiz / order options ---------- */
.quiz-prompt { font-size: 18px; font-weight: 700; line-height: 1.35; margin: 0 2px 16px; }
.quiz-prompt strong { color: var(--accent); }
.quiz-tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--text-2); display: block; margin-bottom: 7px; }
.options { display: grid; gap: 10px; }
@media (min-width: 560px) { .options.two-col { grid-template-columns: 1fr 1fr; } }
.option-btn {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px 16px; text-align: left;
  font-size: 15px; font-weight: 600; line-height: 1.3;
  transition: transform .1s ease, border-color .15s ease;
}
.option-btn:active { transform: scale(.98); }
.option-btn.correct { border-color: var(--ok); background: var(--ok-soft); animation: opt-pop .32s ease; }
.option-btn.wrong { border-color: var(--bad); background: var(--bad-soft); animation: opt-shake .32s ease; }
.option-btn:disabled { opacity: .96; }
@keyframes opt-pop { 0% { transform: scale(1); } 40% { transform: scale(1.035); } 100% { transform: scale(1); } }
@keyframes opt-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .option-btn.correct, .option-btn.wrong { animation: none; } }
.quiz-explain {
  margin: 16px 2px 0; padding: 13px 15px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); font-size: 14px; line-height: 1.5;
}
.quiz-explain.bad { background: var(--bad-soft); }
.next-row { margin-top: 16px; display: flex; justify-content: center; }

/* ---------- order game ---------- */
.order-blurb { color: var(--text-2); font-size: 14px; line-height: 1.5; margin: 0 2px 14px; }
.order-blurb strong { color: var(--text); }
.order-slots { display: flex; flex-direction: column; gap: 9px; margin-bottom: 18px; }
.order-slot {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 12px 14px; min-height: 52px; transition: border-color .15s ease, background .15s ease;
}
.order-slot.filled { border-style: solid; box-shadow: var(--shadow); }
.order-slot.correct { border-color: var(--ok); background: var(--ok-soft); }
.order-slot.wrong { border-color: var(--bad); background: var(--bad-soft); }
.order-slot-num { flex: 0 0 24px; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--accent-soft); color: var(--accent); }
.order-slot-name { font-size: 15px; font-weight: 700; flex: 1 1 auto; min-width: 0; }
.order-slot-x { flex: 0 0 auto; color: var(--text-2); font-size: 20px; line-height: 1; padding: 0 4px; }
.order-pool { display: flex; flex-wrap: wrap; gap: 9px; }
.order-tile {
  font-size: 14.5px; font-weight: 700; padding: 11px 15px; border-radius: 99px;
  background: var(--surface); border: 1.5px solid var(--line); box-shadow: var(--shadow);
  transition: transform .1s ease, opacity .15s ease;
}
.order-tile:active { transform: scale(.95); }
.order-tile.used { opacity: 0; pointer-events: none; }

/* ---------- tab bar ---------- */
.app-credit {
  max-width: 640px; margin: 30px auto 0; text-align: center;
  color: var(--text-2); font-size: 12px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; opacity: .7;
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  background: var(--tab-bg); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(13, 38, 76, .07);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1 1 0; min-width: 0; max-width: 130px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-2);
  padding: 6px 2px 4px; border-radius: 14px;
  transition: color .15s ease, background .15s ease;
}
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.active { color: var(--accent); background: var(--accent-soft); }

@media (max-width: 420px) { .training-badge { display: none; } }

/* ---------- settings sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(7, 14, 26, .5); z-index: 30; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 22px calc(26px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
  animation: sheet-up .25s ease;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4.5px; border-radius: 99px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 19px; margin: 0 0 6px; }
.sheet-sub { font-size: 13px; color: var(--text-2); margin: 0 0 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 15.5px; font-weight: 600; }
.setting-row small { display: block; font-weight: 400; color: var(--text-2); }
.sheet .pill-btn.danger { margin-top: 18px; width: 100%; }
.settings-note { margin-top: 16px; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }

/* iOS-style switch */
.switch {
  appearance: none; -webkit-appearance: none;
  width: 50px; height: 30px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line);
  position: relative; transition: background .2s ease; flex: 0 0 auto;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s ease;
}
.switch:checked { background: var(--ok); border-color: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* empty / coverage note */
.coverage-note {
  background: var(--accent-soft); color: var(--text);
  border-radius: var(--radius); padding: 12px 15px;
  font-size: 13px; line-height: 1.5; margin-bottom: 14px;
}
.coverage-note strong { font-weight: 800; }
.empty-note { color: var(--text-2); font-size: 14px; text-align: center; padding: 40px 10px; line-height: 1.5; }

/* larger screens (iPad) */
@media (min-width: 700px) {
  .view { max-width: 720px; }
  .flashcard-inner { min-height: 380px; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

.browse-pane { animation: view-in .2s ease; }

/* ================= Road Knowledge (Mode 2) browse ================= */
.day-group { margin-bottom: 18px; }
.day-title {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em;
  color: var(--accent); margin: 16px 4px 9px; display: flex; align-items: center; gap: 8px;
}
.day-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.loc-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-top: 4px solid var(--accent); }
.loc-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--line); }
.loc-row:last-child { border-bottom: 0; }
.loc-row:active { background: var(--surface-2); }
.loc-seq { flex: 0 0 26px; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 12.5px; font-weight: 800; background: var(--accent-soft); color: var(--accent); }
.loc-row.is-yard .loc-seq { background: var(--warn-soft); color: var(--warn); }
.loc-main { min-width: 0; flex: 1 1 auto; }
.loc-name { font-size: 15.5px; font-weight: 700; line-height: 1.25; }
.loc-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-flags { display: flex; gap: 4px; flex: 0 0 auto; }
.flag-dot { font-size: 9px; font-weight: 800; letter-spacing: .03em; padding: 2px 5px; border-radius: 5px; }
.flag-gi { background: rgba(42, 161, 154, .16); color: var(--gi); }
.flag-yard { background: var(--warn-soft); color: var(--warn); }
.flag-red { background: var(--bad-soft); color: var(--fixed-red); }

.detail-section { margin-top: 18px; }
.detail-section h3 { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 0 2px 9px; }
.card-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }

.diagram-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 12px 8px; overflow: hidden; }
.diagram-dir { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); padding: 0 4px 8px; }
.track-svg { width: 100%; height: auto; display: block; }

.plat-row { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.plat-row:last-child { border-bottom: 0; }
.plat-num { flex: 0 0 auto; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 9px; display: grid; place-items: center; font-size: 14px; font-weight: 800; background: var(--accent); color: var(--on-accent); }
.plat-info { min-width: 0; flex: 1 1 auto; }
.plat-line { font-size: 14.5px; font-weight: 700; line-height: 1.25; }
.plat-line.unknown { color: var(--text-2); font-weight: 600; font-style: italic; }
.plat-note { font-size: 12.5px; color: var(--text-2); margin-top: 2px; line-height: 1.35; }
.plat-dir { flex: 0 0 auto; font-size: 11px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }

.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li { position: relative; padding: 8px 2px 8px 22px; font-size: 14.5px; line-height: 1.45; color: var(--text); border-bottom: 1px solid var(--line); }
.fact-list li:last-child { border-bottom: 0; }
.fact-list li::before { content: ""; position: absolute; left: 4px; top: 15px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.sig-list li::before { border-radius: 2px; background: var(--fixed-red); }
.move-list li::before { border-radius: 2px; background: var(--poi); }
.sig-id { font-weight: 800; font-variant-numeric: tabular-nums; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.fact-chip { font-size: 12.5px; font-weight: 700; padding: 6px 11px; border-radius: 99px; background: var(--surface-2); color: var(--text); }
.control-line { font-size: 14.5px; line-height: 1.45; }
.control-line strong { font-weight: 800; }

.neighbour-row { display: flex; gap: 10px; }
.neighbour-btn { flex: 1 1 0; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 11px 12px; text-align: left; transition: transform .1s ease, border-color .15s ease; }
.neighbour-btn:active { transform: scale(.97); }
.neighbour-btn:disabled { opacity: .4; box-shadow: none; }
.neighbour-dir { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); display: block; margin-bottom: 3px; }
.neighbour-name { font-size: 14.5px; font-weight: 700; line-height: 1.2; }

/* ================= settings: print group ================= */
.setting-group-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 16px 2px 8px; }
.setting-btn-row { display: flex; gap: 9px; margin-bottom: 6px; }
.setting-btn-row .pill-btn { flex: 1 1 0; }

/* ================= printable study sheet ================= */
/* ================= progress (on-device mastery) ================= */
.prog-empty { text-align: center; padding: 36px 18px; color: var(--text-2); }
.prog-empty-emoji { font-size: 40px; margin-bottom: 8px; }
.prog-empty p { font-size: 14.5px; line-height: 1.5; margin: 0 auto 16px; max-width: 30ch; }
.prog-head { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; border-top: 4px solid var(--accent); }
.prog-overall { display: flex; align-items: baseline; gap: 10px; }
.prog-big { font-size: 34px; font-weight: 850; letter-spacing: -.02em; color: var(--accent); line-height: 1; }
.prog-sub { font-size: 13px; font-weight: 600; color: var(--text-2); }
.prog-section { margin-bottom: 18px; }
.prog-h { font-size: 13px; font-weight: 850; letter-spacing: -.01em; margin: 4px 2px 3px; }
.prog-hint { font-size: 12px; color: var(--text-2); margin: 0 2px 10px; line-height: 1.4; }
.prog-row { display: flex; align-items: center; gap: 9px; padding: 8px 2px; }
.prog-badge { flex: 0 0 auto; min-width: 30px; text-align: center; padding: 3px 7px; border-radius: 6px; color: #fff; font-size: 11px; font-weight: 800; }
.prog-name { flex: 0 0 92px; font-size: 12.5px; font-weight: 700; }
.prog-bar { flex: 1 1 auto; height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.prog-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .35s ease; }
.prog-row.weak .prog-fill { background: var(--bad); }
.prog-row.ok .prog-fill { background: #e0922f; }
.prog-row.strong .prog-fill { background: var(--ok); }
.prog-row.new .prog-fill { background: var(--line); }
.prog-val { flex: 0 0 auto; min-width: 74px; text-align: right; font-size: 11.5px; font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.prog-fresh { font-size: 12px; color: var(--text-2); margin: 4px 2px; line-height: 1.4; }
.prog-note { font-size: 11px; color: var(--text-2); margin: 14px 2px 4px; }

#print-root { display: none; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  @page { margin: 12mm 12mm 13mm; }

  .print-doc {
    font: 11px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #111;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  /* ---- branded header ---- */
  .print-head { display: flex; align-items: center; gap: 11px; padding-bottom: 9px; border-bottom: 3px solid #5a37c9; }
  .print-logo { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: #5a37c9; }
  .print-logo svg { width: 22px; height: 22px; }
  .print-head-text { flex: 1 1 auto; min-width: 0; }
  .print-head h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; color: #5a37c9; }
  .print-sub { margin: 1px 0 0; font-size: 11px; color: #444; }
  .print-fold-hint { flex: 0 0 auto; max-width: 48mm; font-size: 8.5px; color: #555; text-align: right; line-height: 1.35; }

  /* ---- line section ---- */
  .print-line-h { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 800; margin: 13px 0 7px; padding-bottom: 4px; border-bottom: 2px solid var(--line-col, #5a37c9); break-after: avoid; }
  .print-badge { flex: 0 0 auto; display: inline-block; min-width: 22px; text-align: center; padding: 2px 7px; border-radius: 5px; background: var(--line-col, #5a37c9); color: #fff; font-size: 12px; font-weight: 800; }
  .print-run { margin: 0 0 10px; break-inside: auto; }
  .print-run-name { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 12px; font-weight: 700; color: #333; margin: 8px 0 3px; break-after: avoid; }
  .print-run-tag { flex: 0 0 auto; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #777; }

  /* ---- fold-over self-test (line on the left, answers on the right of the fold) ---- */
  .fold-cols, .fold-row { display: grid; grid-template-columns: 7mm 6mm 1fr 76mm; }
  .fold-cols { font-size: 8px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: #aaa; margin-bottom: 1px; }
  .fold-cols .fc-write { grid-column: 3; align-self: end; }
  .fold-cols .fc-ans { grid-column: 4; border-left: 1.3px dashed #8f8f8f; padding-left: 9px; color: #8a8a8a; }
  .fold-row { min-height: 6.4mm; break-inside: avoid; }
  .fold-marker { position: relative; }
  .fold-marker::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2.6px; transform: translateX(-50%); background: var(--line-col, #5a37c9); }
  .fold-grid .fold-row:first-child .fold-marker::before { top: 50%; }
  .fold-grid .fold-row:last-child .fold-marker::before { bottom: 50%; }
  .fold-node { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 2.4px solid var(--line-col, #5a37c9); }
  .fold-row.term .fold-node { width: 10px; height: 10px; background: var(--line-col, #5a37c9); }
  .fold-num { align-self: center; font-size: 8.5px; font-weight: 700; color: #888; font-variant-numeric: tabular-nums; }
  .fold-write { align-self: end; border-bottom: 1px solid #d2d2d2; margin: 0 7px 2.4mm 1px; }
  .fold-name { align-self: center; border-left: 1.3px dashed #8f8f8f; padding-left: 9px; font-size: 11px; font-weight: 600; }

  .print-note { margin-top: 14px; padding-top: 6px; border-top: 1px solid #ccc; font-size: 8.5px; color: #666; }
}

