/* app.css — shared skeleton, per-book accent theme (body[data-book]).
   Animations: transform + opacity only, 150-400ms (celebrations <=1.5s),
   every animation gated by prefers-reduced-motion (gate 6). */

:root {
  --bg: #f7f8fa;        --card: #ffffff;   --ink: #1a2233;  --muted: #66738a;
  --ok: #16a34a;        --bad: #dc2626;    --warn: #d97706;
  --accent: #1d4ed8;    --accent2: #c026d3;
  --radius: 16px;       --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(16,24,40,.08);
  --ease-pop: cubic-bezier(.34,1.56,.64,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
  --t-fast: 150ms; --t-med: 300ms; --t-slow: 800ms;
}
/* Theme: html[data-theme] = "light" | "dark" (reader's choice) or absent
   (Device mode — follow prefers-color-scheme). Dark tokens therefore apply
   when the device prefers dark AND the reader hasn't forced light, OR when
   the reader forced dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg:#0f1420; --card:#1a2233; --ink:#eef2f8; --muted:#8fa0b8;
          --shadow: 0 2px 12px rgba(0,0,0,.35); }
}
:root[data-theme="dark"] { --bg:#0f1420; --card:#1a2233; --ink:#eef2f8; --muted:#8fa0b8;
          --shadow: 0 2px 12px rgba(0,0,0,.35); }
[data-book="part107"] { --accent:#1d4ed8; --accent2:#c026d3; }
[data-book="cdl"]     { --accent:#111827; --accent2:#f59e0b; }
[data-book="ea-part1"]{ --accent:#0f5132; --accent2:#1e3a8a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-book="cdl"] { --accent:#f59e0b; --accent2:#94a3b8; }
  :root:not([data-theme="light"]) [data-book="ea-part1"] { --accent:#34d399; --accent2:#93c5fd; }
  :root:not([data-theme="light"]) [data-book="part107"] { --accent:#60a5fa; --accent2:#e879f9; }
}
:root[data-theme="dark"] [data-book="cdl"] { --accent:#f59e0b; --accent2:#94a3b8; }
:root[data-theme="dark"] [data-book="ea-part1"] { --accent:#34d399; --accent2:#93c5fd; }
:root[data-theme="dark"] [data-book="part107"] { --accent:#60a5fa; --accent2:#e879f9; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 17px; line-height: 1.5;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--accent); }
input, select { font: inherit; }

#app { max-width: 720px; margin: 0 auto; padding: 12px 14px 84px; }
@media (min-width: 760px) { #app { padding-top: 20px; } }

/* ---------- header ---------- */
.hdr { display: flex; align-items: center; gap: 10px; padding: 6px 2px 12px; }
.hdr h1 { font-size: 18px; font-weight: 700; flex: 1; min-width: 0;
          white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr .chip { flex: none; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; font-size: 20px;
           display: inline-flex; align-items: center; justify-content: center; }

/* ---------- chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px;
        background: var(--card); border: 1px solid rgba(128,140,160,.25);
        border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); }
.chip b { color: var(--ink); }
.chip.accent { border-color: var(--accent); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin-bottom: 8px; }
.card h3 { font-size: 14px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.big-num { font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.mid-num { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* book picker */
.bookcard { display: block; width: 100%; text-align: left; position: relative;
            border-left: 6px solid var(--bc, var(--accent)); }
.bookcard .title { font-weight: 700; font-size: 17px; }
.bookcard:hover, .bookcard:focus-visible { outline: 2px solid var(--bc, var(--accent)); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
       min-height: 48px; padding: 10px 18px; border-radius: var(--radius-sm);
       background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
       border: 1px solid transparent; }
.btn.secondary { background: transparent; color: var(--ink);
                 border-color: rgba(128,140,160,.35); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad); }
.btn:disabled { opacity: .45; cursor: default; }
.btn .dur { font-weight: 400; font-size: 13px; opacity: .85; }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.btnrow .btn { flex: 1 1 auto; }

/* Press-state contract (6.3): every tappable element responds <=16ms.
   Disabled elements: opacity only — silence signals "nothing happened". */
@media (prefers-reduced-motion: no-preference) {
  .btn, .option, .bookcard, .tab, .iconbtn, .chipbtn, .card.tappable {
    transition: transform 80ms var(--ease-pop), box-shadow 80ms; }
  .btn:active:not(:disabled), .option:active:not(.locked), .bookcard:active,
  .tab:active, .iconbtn:active, .chipbtn:active, .card.tappable:active {
    transform: scale(.97); box-shadow: none; }
}

/* ---------- tabs ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        display: flex; background: var(--card); box-shadow: 0 -2px 12px rgba(16,24,40,.10);
        padding-bottom: env(safe-area-inset-bottom, 0); }
.tab { flex: 1; min-height: 56px; display: flex; flex-direction: column;
       align-items: center; justify-content: center; gap: 2px;
       font-size: 11px; color: var(--muted); position: relative; }
.tab .ticon { font-size: 22px; line-height: 1; display: inline-block; }
.tab.active { color: var(--accent); font-weight: 700; }
.tab .badge { position: absolute; top: 4px; right: calc(50% - 22px);
              background: var(--accent2); color: #fff; font-size: 10px; font-weight: 700;
              border-radius: 999px; min-width: 16px; height: 16px; line-height: 16px;
              padding: 0 4px; text-align: center; }
@media (prefers-reduced-motion: no-preference) {
  .tab.active .ticon { animation: tabpop 200ms var(--ease-pop); }
  @keyframes tabpop { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
}
body.exam-focus .tabs { display: none; } /* focus mode: no tabs during an exam */

/* ---------- question card ---------- */
.qwrap { max-width: 640px; margin: 0 auto; }
.progress-dots { display: flex; gap: 5px; justify-content: center; margin: 6px 0 12px; flex-wrap: wrap; }
.pdot { width: 8px; height: 8px; border-radius: 50%; background: rgba(128,140,160,.3); }
.pdot.done { background: var(--accent); }
.pdot.now { background: var(--accent2); }
.stem { font-size: 19px; line-height: 1.5; font-weight: 600; margin-bottom: 14px; }
.options { display: grid; gap: 10px; }
.option { display: flex; gap: 10px; align-items: flex-start; text-align: left;
          background: var(--bg); border: 2px solid rgba(128,140,160,.25);
          border-radius: var(--radius-sm); padding: 12px 14px; font-size: 17px;
          min-height: 48px; width: 100%; }
.option .letter { font-weight: 800; color: var(--muted); flex: none; }
.option.picked { border-color: var(--accent); }
.option.correct { border-color: var(--ok); background: rgba(22,163,74,.08); }
.option.wrong { border-color: var(--bad); background: rgba(220,38,38,.08); }
.option.locked { cursor: default; }
.option:disabled { opacity: .55; }

@media (prefers-reduced-motion: no-preference) {
  .qcard.correct-anim { animation: cardpulse 250ms var(--ease-pop); }
  @keyframes cardpulse { 0% { transform: scale(1); } 50% { transform: scale(1.02); } 100% { transform: scale(1); } }
  .qcard.wrong-anim { animation: cardshake 250ms linear; }
  @keyframes cardshake { 0%,100% { transform: translateX(0); }
    17%,50%,83% { transform: translateX(-6px); } 33%,66% { transform: translateX(6px); } }
  .option.correct .letter { animation: glowin 200ms var(--ease-out) 200ms backwards; }
  @keyframes glowin { from { opacity: 0; } to { opacity: 1; } }
  .explain { animation: slideup var(--t-med) var(--ease-out); }
  @keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
  .screen-in { animation: screenin var(--t-fast) var(--ease-out); }
  @keyframes screenin { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
  body.exam-focus .screen-in { animation: none; } /* zero distraction in exam mode */
}
.checkmark path { stroke: var(--ok); stroke-width: 3; fill: none;
  stroke-dasharray: 30; stroke-dashoffset: 0; }
@media (prefers-reduced-motion: no-preference) {
  .checkmark path { animation: drawcheck 300ms var(--ease-out); }
  @keyframes drawcheck { from { stroke-dashoffset: 30; } to { stroke-dashoffset: 0; } }
}
.explain { background: var(--bg); border-radius: var(--radius-sm);
           padding: 12px 14px; margin-top: 12px; font-size: 15px; }
.explain .loc { color: var(--muted); font-size: 13px; margin-top: 6px; }
.qtools { display: flex; gap: 14px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.qtools button { color: var(--muted); font-size: 14px; min-height: 44px; }
.qtools button.on { color: var(--accent); font-weight: 700; }

/* ---------- speech bubble (Conviction tease) ---------- */
.tease { position: relative; background: var(--card); border: 2px solid var(--accent2);
         border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.tease::before { content: ""; position: absolute; top: -10px; left: 28px;
  border: 10px solid transparent; border-bottom-color: var(--accent2); border-top: 0; }
@media (prefers-reduced-motion: no-preference) {
  .tease { animation: wobblein 300ms var(--ease-pop); transform-origin: 20% 0; }
  @keyframes wobblein { 0% { transform: scale(.8) rotate(-2deg); opacity: 0; }
    70% { transform: scale(1.05) rotate(.5deg); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
  .option.shimmy { animation: shimmy 400ms ease-in-out 2; }
  @keyframes shimmy { 0%,100% { transform: translateX(0); } 25% { transform: translateX(3px); } 75% { transform: translateX(-3px); } }
}
.stamp { display: inline-block; font-weight: 900; font-size: 22px; padding: 4px 12px;
         border: 3px solid currentColor; border-radius: 8px; }
.stamp.gotcha { color: var(--warn); }
.stamp.lock { color: var(--ok); }
@media (prefers-reduced-motion: no-preference) {
  .stamp { animation: stampin 250ms var(--ease-pop); }
  @keyframes stampin { 0% { transform: rotate(-8deg) scale(1.4); opacity: 0; }
    100% { transform: rotate(-3deg) scale(1); opacity: 1; } }
}

/* ---------- exam chrome ---------- */
.exam-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.exam-timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; }
.exam-timer.warn { color: var(--warn); }
.exam-timer.red { color: var(--bad); }
@media (prefers-reduced-motion: no-preference) {
  .exam-timer.warn { animation: timerpulse 1s ease-in-out infinite; }
  .exam-timer.red.finalten { animation: timerscale 1s ease-in-out infinite; }
  @keyframes timerpulse { 50% { opacity: .45; } }
  @keyframes timerscale { 50% { transform: scale(1.12); } }
}
.exam-bar { height: 4px; background: rgba(128,140,160,.2); border-radius: 2px; margin-bottom: 14px; }
.exam-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.flagged { color: var(--warn) !important; font-weight: 700; }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.qnav button { width: 40px; height: 40px; border-radius: 8px; background: var(--bg);
               border: 1px solid rgba(128,140,160,.3); font-size: 13px; font-variant-numeric: tabular-nums; }
.qnav button.answered { background: var(--accent); color: #fff; border-color: transparent; }
.qnav button.flag { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.qnav button.now { outline: 2px solid var(--accent2); }

/* ---------- launch countdown ---------- */
.launch { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
          align-items: center; justify-content: center; background: var(--bg); }
.launch .num { font-size: 96px; font-weight: 900; font-variant-numeric: tabular-nums; }
.launch .num.c3 { color: var(--accent); } .launch .num.c2 { color: var(--accent2); }
.launch .num.c1 { color: var(--ok); } .launch .num.go { color: var(--ok); }
@media (prefers-reduced-motion: no-preference) {
  .launch .num { animation: punchin 400ms var(--ease-pop); }
  @keyframes punchin { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
  .launch .num.go { animation: goburst 400ms var(--ease-pop); }
  @keyframes goburst { 0% { transform: scale(1); } 60% { transform: scale(1.3); } 100% { transform: scale(1.15); } }
  .launch.away { animation: slideaway 250ms var(--ease-out) forwards; }
  @keyframes slideaway { to { transform: translateY(-100%); opacity: 0; } }
  .launch .ringwrap svg circle.sweep { animation: sweep 900ms linear; }
  @keyframes sweep { from { stroke-dashoffset: 226; } to { stroke-dashoffset: 0; } }
}

/* ---------- blitz ---------- */
.blitz-ring { position: relative; width: 64px; height: 64px; margin: 0 auto 8px; }
.blitz-ring svg { transform: rotate(-90deg); }
.blitz-ring .ring-fill { stroke: var(--accent); }
.blitz-ring.warn .ring-fill { stroke: var(--warn); }
.blitz-ring.red .ring-fill { stroke: var(--bad); }
.blitz-ring .t { position: absolute; inset: 0; display: flex; align-items: center;
                 justify-content: center; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: no-preference) {
  .blitz-ring.red { animation: timerpulse 500ms ease-in-out infinite; }
}

/* ---------- flashcards ---------- */
.fcstage { position: relative; height: 340px; margin-bottom: 12px; touch-action: pan-y; }
.fcard { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
         text-align: center; padding: 22px; background: var(--card); border-radius: var(--radius);
         box-shadow: var(--shadow); font-size: 18px; user-select: none; cursor: grab;
         backface-visibility: hidden; }
.fcard .src { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 12px; color: var(--muted); }
.fcard.under { transform: scale(.95); }
@media (prefers-reduced-motion: no-preference) {
  .fcard.spring { transition: transform 300ms var(--ease-pop); }
  .fcard.fly { transition: transform 250ms var(--ease-out), opacity 250ms; opacity: 0; }
  .fcard.pop { transition: transform 250ms var(--ease-out); }
}
.srsrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.srsrow .btn { min-height: 52px; font-size: 14px; }
.srs-again { background: var(--bad); } .srs-hard { background: var(--warn); }
.srs-good { background: var(--accent); } .srs-easy { background: var(--ok); }

/* ---------- progress ---------- */
.readiness-dial { text-align: center; padding: 20px 16px; }
.rings { display: grid; gap: 12px; }
.ringrow { display: flex; align-items: center; gap: 12px; }
.ringrow .ring { width: 52px; height: 52px; flex: none; }
.ring { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(128,140,160,.2); stroke-width: 5; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; }
@media (prefers-reduced-motion: no-preference) {
  .ring-fill { transition: stroke-dashoffset 600ms var(--ease-out); }
}
.ringrow.weakest .ring-fill { stroke: var(--accent2); }
.flame { font-size: 34px; display: inline-block; }
@media (prefers-reduced-motion: no-preference) {
  .flame.bounce { animation: flamebounce 400ms var(--ease-pop); }
  @keyframes flamebounce { 0% { transform: scale(1); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
}
.calstrip { display: flex; gap: 4px; margin-top: 8px; }
.calday { flex: 1; height: 26px; border-radius: 6px; background: rgba(128,140,160,.18);
          display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.calday.met { background: var(--ok); color: #fff; }
.calday.frozen { background: #7dd3fc; color: #075985; }
.trophies { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.trophy { text-align: center; padding: 10px 4px; border-radius: var(--radius-sm);
          background: var(--bg); font-size: 12px; color: var(--muted); }
.trophy .e { font-size: 26px; display: block; filter: grayscale(1); opacity: .4; }
.trophy.won { color: var(--ink); }
.trophy.won .e { filter: none; opacity: 1; }
.spark { width: 100%; height: 60px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark circle { fill: var(--accent2); }

/* ---------- badge modal / overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10,15,25,.62);
           display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--card); border-radius: var(--radius); padding: 28px 22px;
         max-width: 380px; width: 100%; text-align: center; }
.modal .bige { font-size: 64px; display: block; margin-bottom: 8px; }
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: badgein 400ms var(--ease-pop); }
  @keyframes badgein { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
}

/* ---------- misc ---------- */
.fx-confetti { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.toast { position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
         background: var(--ink); color: var(--bg); border-radius: 999px;
         padding: 8px 18px; font-size: 14px; z-index: 40; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: screenin 200ms var(--ease-out); }
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chipbtn { border: 1px solid rgba(128,140,160,.35); border-radius: 999px;
           padding: 7px 14px; font-size: 14px; color: var(--muted); min-height: 40px; }
.chipbtn.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.footer-disc { font-size: 12px; color: var(--muted); padding: 18px 4px 8px; text-align: center; }

/* ---------- progress transfer QR ---------- */
.qrbox { background: #fff; border-radius: var(--radius-sm); padding: 10px;
         display: flex; justify-content: center; margin: 10px auto; max-width: 340px; }
.qrbox canvas { max-width: 100%; height: auto; image-rendering: pixelated; }

/* ---------- question search ---------- */
mark { background: var(--accent2); color: #fff; border-radius: 3px; padding: 0 2px; }
.sr-list { display: grid; gap: 6px; margin-top: 8px; }
.sr-row { display: block; width: 100%; text-align: left; background: var(--bg);
          border: 1px solid rgba(128,140,160,.25); border-radius: var(--radius-sm);
          padding: 10px 12px; min-height: 48px; }
.sr-row .sr-stem { display: block; font-size: 15px; }
.sr-row .sr-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.sr-detail { margin: 2px 0 6px; }
.sr-detail .explain { font-size: 14px; }
.switchrow { display: flex; align-items: center; justify-content: space-between;
             min-height: 48px; gap: 10px; }
.switch { position: relative; width: 48px; height: 28px; border-radius: 999px;
          background: rgba(128,140,160,.35); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
                 border-radius: 50%; background: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .switch::after { transition: transform 200ms var(--ease-pop); }
}
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }
input.txt { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-sm);
            border: 1px solid rgba(128,140,160,.4); background: var(--bg); color: var(--ink); }
textarea.txt { width: 100%; min-height: 120px; padding: 10px; border-radius: var(--radius-sm);
               border: 1px solid rgba(128,140,160,.4); background: var(--bg); color: var(--ink); font: inherit; }
.kbd-hint { display: none; }
@media (min-width: 760px) { .kbd-hint { display: block; font-size: 12px; color: var(--muted); text-align: center; margin-top: 8px; } }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.flip { display: inline-block; }
@media (prefers-reduced-motion: no-preference) {
  .flip.flap { animation: flap 400ms var(--ease-out); transform-origin: 50% 0; }
  @keyframes flap { 0% { transform: rotateX(-90deg); } 100% { transform: rotateX(0); } }
  .fcinner.flipping { animation: cardflip 250ms var(--ease-out); }
  @keyframes cardflip { 0% { transform: rotateY(90deg); } 100% { transform: rotateY(0); } }
}
.banner { border: 2px solid var(--accent2); border-radius: var(--radius);
          padding: 14px; margin-bottom: 12px; background: var(--card); }
.banner h2 { color: var(--accent2); }
.statebanner { background: rgba(217,119,6,.12); border: 1px solid var(--warn);
               border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; margin: 10px 0; }

/* Reduced motion: instant states everywhere (QA gate 6). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
