:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px) }
body { margin: 0 }
img { max-width: 100% }

/* Layout: one narrow column like a stack of index cards; ruled card faces, a bolt-yellow highlight for the one action that matters. */
:root {
  --bg: #eef2f8;
  --paper: #ffffff;
  --ink: #16213a;
  --muted: #5a6680;
  --line: #d3dcec;
  --rule: #b9cdf0;
  --margin: #e8707a;
  --accent: #2459d6;
  --accent-ink: #ffffff;
  --bolt: #ffd23f;
  --bolt-ink: #16213a;
  --good: #1f8a4c;
  --good-bg: #e2f5ea;
  --bad: #c2373f;
  --bad-bg: #fbe5e6;
  --shadow: 0 1px 2px rgba(22,33,58,.08), 0 6px 18px rgba(22,33,58,.08);
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1526; --paper: #18203a; --ink: #e8edf8; --muted: #9aa6c2; --line: #2b3656;
  --rule: #2a3a64; --margin: #b9545d; --accent: #7aa2ff; --accent-ink: #0f1526;
  --bolt: #ffd23f; --bolt-ink: #16213a; --good: #5ad08c; --good-bg: #173326; --bad: #ff8a90; --bad-bg: #3a1c22;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #0f1526; --paper: #18203a; --ink: #e8edf8; --muted: #9aa6c2; --line: #2b3656;
  --rule: #2a3a64; --margin: #b9545d; --accent: #7aa2ff; --accent-ink: #0f1526;
  --bolt: #ffd23f; --bolt-ink: #16213a; --good: #5ad08c; --good-bg: #173326; --bad: #ff8a90; --bad-bg: #3a1c22;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); color-scheme: dark }

* { box-sizing: border-box }
[hidden] { display: none !important }
body { background: var(--bg); color: var(--ink); font: 17px/1.5 var(--body); -webkit-text-size-adjust: 100% }
.wrap { max-width: 560px; margin: 0 auto; padding-block: 18px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 18px }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; line-height: 1.15 }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -.01em }
h2 { font-size: 21px; font-weight: 800 }
p { margin: 0 }
.muted { color: var(--muted) }
.small { font-size: 14px }
.label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--muted) }
.brand { display: flex; align-items: center; gap: 10px }
.logo { width: 38px; height: 38px; flex: none }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow) }
button, .btn { font: 700 16px/1.2 var(--body); border-radius: 12px; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  padding: 13px 16px; cursor: pointer; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center }
button:focus-visible, .btn:focus-within, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px }
button:disabled { opacity: .5; cursor: default }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent) }
.go { background: var(--bolt); color: var(--bolt-ink); border-color: var(--bolt); font-size: 18px }
.ghost { background: transparent; border-color: transparent; color: var(--accent); padding-inline: 8px; min-height: 40px }
.row { display: flex; gap: 10px; flex-wrap: wrap }
.row > * { flex: 1 1 140px }
input[type=text] { font: 17px var(--body); padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100% }
.picker input { position: absolute; opacity: 0; width: 1px; height: 1px }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--bg) }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block }
.thumb button { position: absolute; top: 4px; right: 4px; min-height: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 16px; background: rgba(22,33,58,.75); color: #fff; border: 0 }
.thumb .doc { padding: 8px; font-size: 12px; font-weight: 700; overflow-wrap: anywhere; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center }
.thumb span { position: absolute; left: 4px; bottom: 4px; font-size: 12px; font-weight: 700; background: rgba(22,33,58,.75); color: #fff; border-radius: 6px; padding: 1px 6px }
.status { border-radius: 12px; padding: 12px 14px; background: var(--bg); font-size: 15px }
.status.err { background: var(--bad-bg); color: var(--bad) }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--rule); border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none }
@keyframes spin { to { transform: rotate(360deg) } }

.sets { display: flex; flex-direction: column; gap: 10px }
.set { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); text-align: left; justify-content: flex-start; width: 100%; font-weight: 400 }
.set .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px }
.set .name { font-weight: 700; font-family: var(--display); font-size: 18px }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: var(--bolt); color: var(--bolt-ink); border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: 2px }
.score { font-variant-numeric: tabular-nums; font-weight: 700; font-family: var(--display); font-size: 18px; color: var(--accent) }

.topbar { display: flex; align-items: center; gap: 6px; justify-content: space-between }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 5px }
.tabs button { border: 0; background: transparent; min-height: 44px }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink) }

.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s }
.count { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums }

/* index card */
.card-stage { perspective: 1200px }
.card { position: relative; width: 100%; min-height: 300px; border: 0; padding: 0; background: transparent; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2,.7,.2,1); cursor: pointer; display: block; font-weight: 400 }
.card.flipped { transform: rotateY(180deg) }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 44px 22px 34px 44px; overflow: auto;
  background-color: var(--paper);
  background-image: linear-gradient(90deg, transparent 30px, var(--margin) 30px, var(--margin) 32px, transparent 32px),
                    repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
  background-position: 0 0, 0 12px }
.face.back { transform: rotateY(180deg) }
.face .which { position: absolute; top: 12px; left: 44px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--muted) }
.face .hint { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 13px; color: var(--muted) }
.face .txt { font-family: var(--display); font-weight: 600; font-size: clamp(20px, 5.6vw, 26px); line-height: 1.3; white-space: pre-wrap; overflow-wrap: anywhere }
.face.back .txt { font-family: var(--body); font-weight: 400; font-size: clamp(18px, 5vw, 22px) }
.judge { display: grid; grid-template-columns: 1fr 1fr; gap: 10px }
.judge .no { background: var(--bad-bg); color: var(--bad); border-color: transparent }
.judge .yes { background: var(--good-bg); color: var(--good); border-color: transparent }

.q { font-family: var(--display); font-weight: 600; font-size: 21px; line-height: 1.3; white-space: pre-wrap }
.choices { display: flex; flex-direction: column; gap: 10px }
.choice { justify-content: flex-start; text-align: left; font-weight: 400; gap: 12px; white-space: normal; overflow-wrap: anywhere }
.choice b { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 15px }
.choice.right { background: var(--good-bg); border-color: var(--good); color: var(--ink) }
.choice.right b { border-color: var(--good); background: var(--good); color: var(--paper) }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--ink) }
.choice.wrong b { border-color: var(--bad); background: var(--bad); color: var(--paper) }
.why { border-radius: 12px; padding: 12px 14px; font-size: 16px }
.why.ok { background: var(--good-bg) }
.why.no { background: var(--bad-bg) }
.big-score { font-family: var(--display); font-weight: 800; font-size: 56px; line-height: 1; font-variant-numeric: tabular-nums }
.miss { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 15px }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 15px }
@media (prefers-reduced-motion: reduce) { .card { transition: none } .spinner { animation-duration: 3s } }

/* grown-up gate and footer */
.gate { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow: auto;
  padding: calc(24px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)) }
.gate .panel { max-width: 520px; margin: 0 auto }
.gate ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px }
.foot { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 14px }
a { color: var(--accent) }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: var(--display) !important; font-weight: 700 }
.big-code { font-family: var(--display); font-weight: 800; font-size: 40px; letter-spacing: .12em; font-variant-numeric: tabular-nums }

/* tutor */
.wrap > * { min-width: 0 }
.wrap > .wrap { width: 100% }
.chips { max-width: 100%; display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none }
.chip { flex: none; min-height: 40px; padding: 8px 14px; border-radius: 99px; font-size: 15px }
.chip[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent) }
.tabs.four { grid-template-columns: repeat(4, minmax(0, 1fr)) }
.tabs.four button { padding-inline: 4px; font-size: 15px }
.unit-num { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 15px; color: var(--muted) }
.unit-num.done { background: var(--good); border-color: var(--good); color: var(--paper) }
.chat { display: flex; flex-direction: column; gap: 10px }
.bubble { max-width: 88%; padding: 12px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45 }
.bubble.tutor { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow) }
.bubble.kid { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px }
.bubble.thinking { color: var(--muted); font-style: italic }
.quick > * { flex: 1 1 90px; min-height: 40px; padding: 8px 10px; font-size: 14px }
.composer { display: flex; gap: 8px; align-items: flex-end }
.composer .picker { flex: none; width: 48px; padding: 0; position: relative }
.composer textarea { flex: 1; min-width: 0; font: 17px/1.4 var(--body); padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); resize: none; min-height: 48px }
.composer .primary { flex: none }
select, input[type=password] { font: 17px var(--body); padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100% }
textarea:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px }
.feature { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); text-decoration: none }
.feature .muted { color: inherit; opacity: .85 }
h3 { font-size: 18px; font-weight: 800 }
.note { text-align: center }
