/* ---------- Fonts (bundled, offline) ---------- */
@font-face { font-family: 'Public Sans'; src: url(fonts/public-sans-latin-wght-normal.woff2) format('woff2'); font-weight: 100 900; font-style: normal; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Public Sans'; src: url(fonts/public-sans-latin-ext-wght-normal.woff2) format('woff2'); font-weight: 100 900; font-style: normal; unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Public Sans'; src: url(fonts/public-sans-latin-wght-italic.woff2) format('woff2'); font-weight: 100 900; font-style: italic; }
@font-face { font-family: 'Source Serif 4'; src: url(fonts/source-serif-4-latin-wght-normal.woff2) format('woff2'); font-weight: 200 900; font-style: normal; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF; }
@font-face { font-family: 'Source Serif 4'; src: url(fonts/source-serif-4-latin-ext-wght-normal.woff2) format('woff2'); font-weight: 200 900; font-style: normal; unicode-range: U+0100-02AF, U+1E00-1EFF, U+2020, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Source Serif 4'; src: url(fonts/source-serif-4-latin-wght-italic.woff2) format('woff2'); font-weight: 200 900; font-style: italic; }
@font-face { font-family: 'Alegreya'; src: url(fonts/alegreya-latin-wght-normal.woff2) format('woff2'); font-weight: 400 900; font-style: normal; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF; }
@font-face { font-family: 'Alegreya'; src: url(fonts/alegreya-latin-ext-wght-normal.woff2) format('woff2'); font-weight: 400 900; font-style: normal; unicode-range: U+0100-02AF, U+1E00-1EFF, U+2020, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Alegreya'; src: url(fonts/alegreya-latin-wght-italic.woff2) format('woff2'); font-weight: 400 900; font-style: italic; }

/* ---------- Tokens ---------- */
:root, [data-app="law"] {
  --bg: #eef1f5; --surface: #ffffff; --sunk: #e4e9f0; --ink: #142033; --muted: #5a6779; --line: #d3dae4; --line-strong: #b9c3d1;
  --accent: #a87b1f; --accent-ink: #ffffff; --accent-soft: #f4ead3;
  --link: #24497a; --good: #2e7d4f; --good-soft: #e3f1e8; --bad: #b0322a; --bad-soft: #f8e5e2; --warn: #8a5a00; --warn-soft: #fbefd5;
  --side: #142033; --side-ink: #c9d3e1; --side-ink-strong: #ffffff; --side-active: #22314a;
  --reading: 'Source Serif 4', Georgia, serif; --ui: 'Public Sans', 'Segoe UI', system-ui, sans-serif; --phrase: 'Source Serif 4', Georgia, serif;
  --r-sm: 6px; --r: 10px; --r-lg: 16px;
}
[data-app="spanish"] {
  --bg: #edf2ef; --surface: #ffffff; --sunk: #e1e9e5; --ink: #10302a; --muted: #557069; --line: #d0dcd6; --line-strong: #b3c6bd;
  --accent: #d98e1f; --accent-ink: #1f1302; --accent-soft: #fbecd4;
  --link: #1f6f62; --side: #10302a; --side-ink: #c4d8d1; --side-ink-strong: #ffffff; --side-active: #1b4339;
  --phrase: 'Alegreya', Georgia, serif; --reading: 'Public Sans', 'Segoe UI', sans-serif;
}
[data-theme="dark"][data-app="law"] {
  --bg: #0f1620; --surface: #16202d; --sunk: #1c2838; --ink: #e6ebf2; --muted: #9aa8bb; --line: #273447; --line-strong: #3a4a61;
  --accent: #d2a447; --accent-ink: #1a1203; --accent-soft: #33291a; --link: #8fb4e8;
  --good: #63c48b; --good-soft: #17301f; --bad: #ef7a6e; --bad-soft: #3a1c19; --warn: #e3b341; --warn-soft: #33290f;
  --side: #0b111a; --side-active: #1c2838;
}
[data-theme="dark"][data-app="spanish"] {
  --bg: #0d1714; --surface: #14231f; --sunk: #1a2d28; --ink: #e4eeea; --muted: #94aca4; --line: #23382f; --line-strong: #345247;
  --accent: #e9a33f; --accent-ink: #1f1302; --accent-soft: #33280f; --link: #7fd1c0;
  --good: #63c48b; --good-soft: #15301f; --bad: #ef7a6e; --bad-soft: #3a1c19; --warn: #e3b341; --warn-soft: #33290f;
  --side: #09110f; --side-active: #1a2d28;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; box-sizing: border-box; background: var(--bg); color: var(--ink); font: 15.5px/1.55 var(--ui); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
a { color: var(--link); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

#app { display: grid; grid-template-columns: 248px 1fr; height: 100%; }
#app.tutor-open { grid-template-columns: 248px 1fr 420px; }

/* ---------- Sidebar ---------- */
#side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 22px 14px 18px; gap: 18px; overflow-y: auto; }
#brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 4px; }
#brand img { width: 40px; height: 40px; border-radius: 9px; }
#brand .title { font-weight: 750; font-size: 16.5px; color: var(--side-ink-strong); line-height: 1.2; }
#brand .sub { font-size: 12.5px; opacity: .75; }
#navlinks { display: flex; flex-direction: column; gap: 2px; }
.navgroup { font-size: 12px; opacity: .55; padding: 14px 12px 4px; }
.navbtn { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; border: 0; background: transparent; text-align: left; cursor: pointer; color: var(--side-ink); font-size: 14.5px; }
.navbtn:hover { background: var(--side-active); color: var(--side-ink-strong); }
.navbtn.active { background: var(--side-active); color: var(--side-ink-strong); box-shadow: inset 3px 0 0 var(--accent); }
.navbtn svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.navbtn .count { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 0 8px; font-size: 12px; font-weight: 700; min-width: 22px; text-align: center; }
#sidefoot { margin-top: auto; font-size: 12.5px; padding: 0 10px; opacity: .8; line-height: 1.5; }

/* ---------- Main ---------- */
#main { overflow-y: auto; padding: 36px 48px 80px; scroll-behavior: smooth; }
.wrap { max-width: 900px; margin: 0 auto; }
.wrap.narrow { max-width: 760px; }
h1 { font-size: 30px; line-height: 1.15; margin: 0 0 8px; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 20px; margin: 30px 0 12px; font-weight: 700; }
h3 { font-size: 16.5px; margin: 0 0 6px; font-weight: 700; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.lede { font-size: 16.5px; color: var(--muted); max-width: 62ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; }
.panel + .panel { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.ok { color: var(--good); } .no { color: var(--bad); }

.btn { border: 1px solid var(--line-strong); background: var(--surface); padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14.5px; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--ink); background: var(--sunk); }
.btn.big { padding: 13px 24px; font-size: 16px; border-radius: 12px; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px 8px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--sunk); color: var(--muted); }
.tag.policy { background: var(--warn-soft); color: var(--warn); }
.tag.ai { background: var(--accent-soft); color: var(--ink); }
.tag.done { background: var(--good-soft); color: var(--good); }

.bar { height: 8px; background: var(--sunk); border-radius: 8px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 8px; transition: width .35s ease; }

/* ---------- Today ---------- */
.today { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; margin-top: 24px; }
.plan { list-style: none; padding: 0; margin: 0; counter-reset: plan; }
.plan li { display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; align-items: center; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; }
.plan li .num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; border: 2px solid var(--line-strong); color: var(--muted); }
.plan li.done .num { background: var(--good); border-color: var(--good); color: #fff; }
.plan li.done .what { color: var(--muted); }
.plan li.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan .what { font-weight: 650; }
.plan .why { font-size: 13.5px; color: var(--muted); }
.side-stack > * + * { margin-top: 14px; }
.ready-num { font-family: var(--reading); font-size: 44px; font-weight: 650; line-height: 1; }
.days { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin-top: 10px; }
.days span { aspect-ratio: 1; border-radius: 4px; background: var(--sunk); }
.days span.on { background: var(--accent); }
.days span.now { outline: 2px solid var(--ink); outline-offset: 1px; }
input[type=date], input[type=text] { background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; color-scheme: light dark; }
input[type=date]:focus, input[type=text]:focus { border-color: var(--accent); }
.setup { display: grid; gap: 14px; }

/* ---------- Lessons (binder) ---------- */
.unit { display: grid; grid-template-columns: 56px 1fr; gap: 0 16px; margin-bottom: 22px; }
.unit-tab { grid-row: span 2; align-self: start; background: var(--ink); color: var(--bg); border-radius: 10px 0 0 10px; padding: 12px 0; text-align: center; font-family: var(--reading); font-weight: 700; font-size: 20px; position: sticky; top: 0; }
[data-app="spanish"] .unit-tab { font-family: var(--phrase); }
.unit-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 8px; }
.unit-head h3 { font-size: 18px; margin: 0; }
.lesson-list { display: grid; gap: 8px; }
.lesson-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 14px; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; width: 100%; }
.lesson-row:hover { border-color: var(--line-strong); background: var(--surface); box-shadow: 0 1px 0 var(--line); }
.lesson-row .check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; font-size: 13px; color: #fff; }
.lesson-row.done .check { background: var(--good); border-color: var(--good); }
.lesson-row.next { border-color: var(--accent); }
.lesson-row .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.lesson-row .t { font-weight: 600; }
.lesson-row .b { color: var(--muted); font-size: 13.5px; }

/* ---------- Player ---------- */
.player-top { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.player-top .where { min-width: 0; }
.player-top .where .u { font-size: 13px; color: var(--muted); }
.player-top .where .l { font-weight: 700; }
.steps { flex: 1; display: flex; gap: 4px; }
.steps i { flex: 1; height: 6px; border-radius: 4px; background: var(--sunk); }
.steps i.d { background: var(--accent); }
.steps i.c { background: var(--ink); }
.step { animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 4px var(--r-lg) var(--r-lg) 4px; padding: 30px 36px 26px 44px; box-shadow: inset 4px 0 0 var(--line); }
.page h2 { font-family: var(--reading); font-size: 25px; margin: 0 0 14px; line-height: 1.2; }
.page .body { font-family: var(--reading); font-size: 17.5px; line-height: 1.7; max-width: 68ch; }
[data-app="spanish"] .page .body { font-size: 16.5px; line-height: 1.65; }
.page .body p { margin: 0 0 14px; }
.page .body ul, .page .body ol { margin: 0 0 14px; padding-left: 24px; }
.page .body li { margin-bottom: 6px; }
.page .body b, .page .body strong { font-weight: 700; }
.page .body table { border-collapse: collapse; width: 100%; margin: 6px 0 16px; font-family: var(--ui); font-size: 14.5px; line-height: 1.45; }
.page .body td, .page .body th { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.page .body th { font-weight: 650; color: var(--muted); border-bottom: 2px solid var(--line-strong); }
.key { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 12px 0 16px; font-family: var(--ui); font-size: 15px; line-height: 1.55; }
.cite-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line-strong); font-size: 13px; color: var(--muted); align-items: center; }
.cite-tabs .lbl { margin-right: 4px; }
.cite-tabs a, .cite-tabs span.c { background: var(--sunk); color: var(--ink); text-decoration: none; padding: 3px 10px 3px 8px; border-radius: 0 6px 6px 0; border-left: 3px solid var(--accent); }
.cite-tabs a:hover { background: var(--accent-soft); }

.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 26px 28px; }
.qtext { font-size: 19px; font-weight: 650; margin: 10px 0 18px; line-height: 1.4; }
.scene { font-family: var(--reading); background: var(--sunk); padding: 14px 18px; border-radius: 10px; margin-bottom: 14px; line-height: 1.6; }
.opts { display: grid; gap: 10px; }
.opt { text-align: left; padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; font-size: 15.5px; transition: border-color .12s, background .12s; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .k { width: 26px; height: 26px; border-radius: 7px; background: var(--sunk); display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .k { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.fb { margin-top: 16px; padding: 14px 18px; border-radius: 12px; line-height: 1.55; }
.fb.good { background: var(--good-soft); } .fb.bad { background: var(--bad-soft); } .fb.info { background: var(--sunk); }
.fb .v { font-weight: 750; margin-bottom: 4px; }
.fb.good .v { color: var(--good); } .fb.bad .v { color: var(--bad); }
.fb .quote { font-family: var(--reading); font-style: italic; margin-top: 8px; padding-left: 12px; border-left: 3px solid var(--line-strong); }
.actions { display: flex; gap: 10px; margin-top: 20px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); }
textarea.answer, input.answer { width: 100%; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 15px; resize: vertical; outline: none; font-size: 16px; }
textarea.answer:focus, input.answer:focus { border-color: var(--accent); background: var(--surface); }
input.answer { font-size: 19px; font-family: var(--phrase); }
.model { white-space: pre-wrap; font-family: var(--reading); }

/* Spanish phrase display */
.phrase-big { font-family: var(--phrase); font-size: 38px; font-weight: 600; line-height: 1.2; margin: 14px 0 6px; }
.phrase-en { font-size: 17px; color: var(--muted); }
.pron { font-size: 14px; color: var(--muted); margin-top: 6px; }
.audio-row { display: flex; gap: 8px; margin: 16px 0 6px; flex-wrap: wrap; }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 58px; padding: 10px; border-radius: 12px; border: 1.5px dashed var(--line-strong); margin-bottom: 12px; background: var(--bg); }
.tiles.bank { border-style: solid; border-color: var(--line); background: transparent; }
.tile { padding: 8px 14px; border-radius: 9px; background: var(--surface); border: 1.5px solid var(--line-strong); cursor: pointer; font-size: 18px; font-family: var(--phrase); box-shadow: 0 2px 0 var(--line); }
.tile:hover { border-color: var(--accent); }
.tile.used { opacity: .2; pointer-events: none; box-shadow: none; }
.accents { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.accents button { padding: 4px 11px; border-radius: 8px; background: var(--sunk); border: 1px solid var(--line); cursor: pointer; font-size: 16px; font-family: var(--phrase); }

/* Mic */
.mic { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 12px 14px; background: var(--sunk); border-radius: 12px; flex-wrap: wrap; }
.mic .rec { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--bad); color: #fff; cursor: pointer; display: grid; place-items: center; }
.mic .rec svg { width: 20px; height: 20px; }
.mic .rec.on { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(176,50,42,.5); } 50% { box-shadow: 0 0 0 10px rgba(176,50,42,0); } }
.heard { font-family: var(--phrase); font-size: 18px; }
.heard .miss { color: var(--bad); text-decoration: underline wavy; }
.heard .hit { color: var(--good); }

/* Review */
.flash { min-height: 260px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 34px; }
.flash .front { font-size: 23px; font-weight: 650; font-family: var(--reading); }
.flash .back { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 19px; }
[data-app="spanish"] .flash .back { font-family: var(--phrase); font-size: 28px; font-weight: 600; }
.rate { display: flex; gap: 10px; justify-content: center; margin-top: 22px; }
.rate .btn { min-width: 110px; }
.rate small { display: block; font-weight: 400; font-size: 12px; opacity: .75; }

/* Chat (tutor + role-play) */
#tutor { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#tutor.closed { display: none; }
.tutor-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
#tutor-log, .chat-log { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 11px 14px; border-radius: 14px; white-space: pre-wrap; font-size: 14.5px; line-height: 1.55; max-width: 92%; }
.msg.user { background: var(--ink); color: var(--bg); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--sunk); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.err { background: var(--bad-soft); color: var(--bad); }
.msg .es { font-family: var(--phrase); font-size: 19px; }
.msg .en { font-size: 13.5px; opacity: .75; margin-top: 4px; }
.msg .fix { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-strong); font-size: 13.5px; }
.chat-form { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea { flex: 1; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: none; outline: none; }
.chat-form textarea:focus { border-color: var(--accent); }
.roleplay { display: grid; grid-template-rows: auto 1fr auto; height: calc(100vh - 150px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.roleplay .chat-log { background: var(--bg); }
.rp-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.choice { text-align: left; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 18px; cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice .t { font-weight: 700; margin-bottom: 4px; }
.choice .b { color: var(--muted); font-size: 14px; }
.choice.done { border-color: var(--good); }

#toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 12px; opacity: 0; transition: .2s; pointer-events: none; font-weight: 600; }
#toast.show { opacity: 1; transform: translateX(-50%); }

.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 13.5px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field input, .field select { background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.seg { display: inline-flex; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.search { width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 15px; outline: none; margin-bottom: 16px; font-size: 15.5px; }
.search:focus { border-color: var(--accent); }
.phrase { display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: center; padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.phrase:hover { background: var(--surface); }
.phrase .es { font-family: var(--phrase); font-size: 19px; font-weight: 600; }
.phrase .en { color: var(--muted); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.done-card { text-align: center; padding: 40px 30px; }
.done-card .big { font-family: var(--reading); font-size: 52px; font-weight: 650; line-height: 1; }
[data-app="spanish"] .done-card .big { font-family: var(--phrase); }

@media (max-width: 1100px) { .today { grid-template-columns: 1fr; } #main { padding: 28px 28px 60px; } }

/* Page compatibility (course pages) */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; }
.card h3 { margin-top: 0; }
.card ul { margin: 6px 0 0; padding-left: 22px; line-height: 1.6; }
.pill { display: inline-flex; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--sunk); color: var(--muted); }
.pill.policy { background: var(--warn-soft); color: var(--warn); }
.pb-best { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 6px 0 16px; }
.pb-best > div { background: var(--bg); border-radius: 12px; padding: 14px 16px; }
.pb-best .t { font-family: var(--reading); font-size: 30px; font-weight: 650; line-height: 1.1; }
.pb-best .l { font-size: 13px; color: var(--muted); }

/* Smaller windows: tutor slides over the page instead of squeezing it; slimmer sidebar */
@media (max-width: 1240px) {
  #app, #app.tutor-open { grid-template-columns: 216px 1fr; }
  #tutor { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 90vw); z-index: 20; box-shadow: -12px 0 32px rgba(0,0,0,.18); }
  #side { padding: 18px 10px 14px; }
  #brand img { width: 34px; height: 34px; }
}

.msg .md { white-space: normal; }
.msg .md p { margin: 0 0 8px; }
.msg .md p:last-child, .msg .md ul:last-child, .msg .md ol:last-child { margin-bottom: 0; }
.msg .md .md-h { font-weight: 700; margin-top: 4px; }
.msg .md ul, .msg .md ol { margin: 0 0 8px; padding-left: 20px; }
.msg .md li { margin: 2px 0; }
.msg .md code { font-size: 13px; background: var(--line); padding: 1px 4px; border-radius: 4px; }

/* Yes/no dialog */
.modal-bg, .sheet-bg { position: fixed; inset: 0; background: rgba(8, 14, 24, .45); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadein .15s ease; }
.modal { background: var(--surface); color: var(--ink); border-radius: var(--r-lg); padding: 22px 22px 18px; width: min(420px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal p { margin: 0 0 16px; font-size: 16px; line-height: 1.5; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Bottom tab bar + sheet: phone only */
#tabbar { display: none; }
.sheet-bg { align-items: flex-end; padding: 0; }
.sheet { background: var(--side); color: var(--side-ink); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 10px 12px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px; animation: up .2s ease; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 8px; }
.sheet-head h3 { margin: 0; color: var(--side-ink-strong); font-size: 17px; }
.sheet-head .icon-btn { color: var(--side-ink); }
.sheet .navbtn { padding: 14px 12px; font-size: 16px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Touch screens: no keyboard shortcut hints */
@media (hover: none) { .keyhint { display: none !important; } }

@media (max-width: 760px) {
  html, body { height: 100%; }
  #app, #app.tutor-open { display: block; height: 100%; }
  #side { display: none; }
  #main { height: 100%; box-sizing: border-box; padding: 18px 16px calc(92px + env(safe-area-inset-bottom)); }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--side); border-top: 1px solid rgba(255,255,255,.06); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  #tabbar .tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; color: var(--side-ink); font-size: 11.5px; font-weight: 600; padding: 6px 2px; border-radius: 10px; cursor: pointer; opacity: .8; }
  #tabbar .tab svg { width: 22px; height: 22px; }
  #tabbar .tab.active { color: var(--accent); opacity: 1; }
  #tabbar .tab .count { position: absolute; top: 0; left: calc(50% + 6px); background: var(--accent); color: var(--accent-ink); border-radius: 9px; font-size: 10.5px; padding: 0 5px; min-width: 18px; text-align: center; line-height: 17px; }
  #tutor { position: fixed; inset: 0; width: 100vw; height: 100%; z-index: 50; border-left: 0; padding-top: env(safe-area-inset-top, 0px); box-sizing: border-box; }
  #tutor-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  body:has(#app.tutor-open) #tabbar { display: none; }
  .today, .pb-best, .choice-grid { grid-template-columns: 1fr !important; }
  h1 { font-size: 26px; }
  .opt { padding: 14px 14px; }
  .actions { flex-wrap: wrap; }
}
@media (max-width: 760px) {
  .panel, .card, .qcard { padding: 18px 16px; }
  .page { padding: 20px 16px 18px 22px; }
  .roleplay { height: calc(100dvh - 130px - env(safe-area-inset-bottom)); }
  .modal .row .btn { flex: 1; }
}
@media (max-width: 760px) {
  .unit { grid-template-columns: 40px 1fr; gap: 0 10px; }
  .unit-tab { font-size: 17px; padding: 9px 0; border-radius: 8px; }
  .unit > :not(.unit-tab):not(.unit-head) { grid-column: 1 / -1; }
  .lesson-row { gap: 10px; padding: 12px 12px; }
}
@media (max-width: 760px) { .unit-tab { grid-row: auto; position: static; } }
.rp-choices { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 8px; }
.rp-choices:empty { display: none; }
.rp-choices .opt { padding: 10px 14px; text-align: left; grid-template-columns: 1fr; }
.roleplay { grid-template-rows: auto 1fr auto auto; }
@media (max-width: 760px) {
  .roleplay .chat-form textarea { flex: 1 1 100%; }
  .roleplay .chat-form { gap: 8px; padding: 10px 12px; }
  .roleplay .chat-form .btn { flex: 1; }
  .rp-choices { padding: 0 12px 8px; }
  .accent-bar, .accents { flex-wrap: wrap; }
}
@media (max-width: 760px) { .roleplay .accents { display: none; } }
