:root {
  --blue: #1d5cb8;
  --blue-deep: #17498f;
  --blue-soft: #e3ecf9;
  --ink: #1b2430;
  --ink-2: #5a6472;
  --ink-3: #8b94a1;
  --paper: #f7f6f2;
  --card: #ffffff;
  --line: #e6e3da;
  --green: #1d8a4e;
  --green-soft: #e2f3e9;
  --red: #c2402e;
  --red-soft: #fbe7e3;
  --amber: #b57912;
  --radius: 16px;
  --tabbar-h: 56px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --shadow: 0 1px 2px rgba(27,36,48,.05), 0 4px 14px rgba(27,36,48,.06);
}
html[data-theme="dark"] {
  --blue: #5b8fe0;
  --blue-deep: #7ba5e8;
  --blue-soft: #1c2a42;
  --ink: #eceae4;
  --ink-2: #a7aeba;
  --ink-3: #767e8b;
  --paper: #10151f;
  --card: #1a2230;
  --line: #2a3345;
  --green: #4cc381;
  --green-soft: #14301f;
  --red: #e5705c;
  --red-soft: #3a1d18;
  --amber: #d9a13c;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.35);
}
* {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;
}
*::-webkit-scrollbar { display: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
html, body {
  height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; height: var(--vvh, 100dvh); max-width: 560px; margin: 0 auto; }
#view { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; position: relative; }

/* ---------- tab bar ---------- */
#tabbar {
  flex: none;
  display: flex;
  height: calc(var(--tabbar-h) + var(--sab));
  padding-bottom: var(--sab);
  background: var(--card);
  border-top: 1px solid var(--line);
}
#tabbar button {
  flex: 1; border: 0; background: none; color: var(--ink-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: inherit; font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
}
#tabbar button svg { width: 23px; height: 23px; }
#tabbar button.active { color: var(--blue); }
body.in-session #tabbar { display: none; }

/* ---------- shared ---------- */
.page { padding: calc(14px + var(--sat)) 18px 26px; min-height: 100%; }
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 22px 0 8px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px 16px; border-radius: 13px;
  border: 1px solid var(--blue); background: var(--blue); color: #fff;
  font-family: inherit; font-size: 15.5px; font-weight: 700;
}
.btn:active { opacity: .88; }
.btn.secondary { background: var(--card); color: var(--blue); }
.btn.ghost { background: none; border-color: var(--line); color: var(--ink-2); font-weight: 600; }
.btn.danger { background: var(--card); border-color: var(--red); color: var(--red); }
.btn.small { width: auto; padding: 9px 14px; font-size: 14px; }
.btn:disabled { opacity: .45; }
.icon-btn {
  flex: none; width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 20px; height: 20px; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; margin: 0 -18px; padding: 2px 18px 6px; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
}
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; }
.pill.b2 { background: var(--blue-soft); color: var(--blue-deep); }
.pill.c1 { background: #f1e7d6; color: #8a6a1f; }
html[data-theme="dark"] .pill.c1 { background: #38300f; color: #d9b85c; }
.pill.slang { background: #efe3f5; color: #7a3fa8; }
html[data-theme="dark"] .pill.slang { background: #2e1a3d; color: #c294e8; }
.pill.spain { background: var(--green-soft); color: var(--green); }
.hidden { display: none !important; }

/* ---------- practice home ---------- */
.wordmark { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.wordmark .name { font-size: 28px; font-weight: 800; letter-spacing: -.03em; color: var(--blue-deep); }
.wordmark .today { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.azulejo { height: 10px; border-radius: 5px; margin: 0 0 16px;
  background-image: repeating-linear-gradient(45deg, var(--blue) 0 8px, transparent 8px 16px),
                    repeating-linear-gradient(-45deg, var(--blue) 0 8px, transparent 8px 16px);
  background-color: var(--blue-soft); opacity: .55; }
.mode-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.mode-row {
  display: flex; align-items: center; gap: 13px; padding: 14px 15px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: left; width: 100%; font-family: inherit; color: var(--ink);
}
.mode-row:active { transform: scale(.99); }
.mode-ic {
  flex: none; width: 42px; height: 42px; border-radius: 12px;
  background: var(--blue-soft); color: var(--blue-deep);
  display: flex; align-items: center; justify-content: center;
}
.mode-ic svg { width: 22px; height: 22px; }
.mode-tx { flex: 1; min-width: 0; }
.mode-tx .t { font-size: 15.5px; font-weight: 700; }
.mode-tx .d { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; }
.mode-meta { flex: none; font-size: 12px; font-weight: 700; color: var(--ink-3); text-align: right; }
.mode-row .chev { flex: none; color: var(--ink-3); }
.mode-row .chev svg { width: 16px; height: 16px; display: block; }

/* ---------- session ---------- */
.session { display: flex; flex-direction: column; min-height: 100%; padding: calc(10px + var(--sat)) 18px calc(14px + var(--sab)); }
.session-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.session-top .count { flex: none; font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.progress { flex: 1; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--blue); border-radius: 3px; transition: width .25s ease; }
.q-card { padding: 22px 20px; margin-bottom: 14px; }
.q-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin-bottom: 10px; }
.q-sentence { font-size: 20px; font-weight: 600; letter-spacing: -.01em; line-height: 1.5; }
.q-sentence .blank { color: var(--blue); font-weight: 800; letter-spacing: .06em; }
.q-sentence .filled { color: var(--green); font-weight: 800; }
.q-sentence .filled.wrong { color: var(--red); text-decoration: line-through; }
.q-hint { display: inline-block; margin-top: 10px; padding: 4px 11px; border-radius: 8px; background: var(--blue-soft); color: var(--blue-deep); font-size: 13.5px; font-weight: 600; }
.q-tags { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.explain { border-radius: 13px; background: var(--blue-soft); color: var(--ink); padding: 13px 15px; font-size: 14px; margin-bottom: 14px; }
.explain .x-t { font-weight: 700; color: var(--blue-deep); margin-bottom: 3px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.explain .notes { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(0,0,0,.08); color: var(--ink-2); font-size: 13.5px; }
html[data-theme="dark"] .explain .notes { border-top-color: rgba(255,255,255,.1); }
.result-line { display: flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.result-line.good { color: var(--green); }
.result-line.bad { color: var(--red); }
.result-line svg { width: 21px; height: 21px; flex: none; }

/* flashcard */
.flash {
  position: relative; padding: 30px 22px; min-height: 240px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  margin-bottom: 14px; cursor: pointer;
}
.flash .q-sentence { font-size: 22px; }
.flash .flip-hint { position: absolute; bottom: 13px; left: 0; right: 0; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.flash .back-sent { font-size: 21px; font-weight: 700; line-height: 1.5; }
.flash .back-sent .filled { color: var(--blue); }
.flash .speaker-float { position: absolute; top: 12px; right: 12px; }
.two-col { display: flex; gap: 10px; }
.two-col .btn { flex: 1; }
.btn.knew { background: var(--green); border-color: var(--green); }
.btn.missed { background: var(--card); border-color: var(--red); color: var(--red); }

/* answer bar (fill blank / listening) */
.answer-zone { margin-top: auto; padding-top: 12px; }
.accent-row { display: flex; gap: 7px; margin-bottom: 9px; }
.accent-row button {
  flex: 1; padding: 7px 0; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 16px; font-weight: 600; font-family: inherit;
}
.answer-row { display: flex; gap: 9px; }
.answer-row input {
  flex: 1; min-width: 0; padding: 13px 15px; border-radius: 13px; font-size: 17px; font-family: inherit;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink); outline: none;
}
.answer-row input:focus { border-color: var(--blue); }
.answer-row .btn { width: auto; padding: 0 22px; }

/* options (multiple choice) */
.options { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.opt {
  padding: 14px 16px; border-radius: 13px; text-align: left; width: 100%;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 16.5px; font-weight: 600; font-family: inherit;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.opt svg { width: 19px; height: 19px; flex: none; }
.opt.picked-good { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.opt.picked-bad { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.opt.reveal-good { border-color: var(--green); color: var(--green); }
.opt.dim { opacity: .5; }

/* matching */
.match-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 9px; margin-bottom: 14px; }
.match-tile {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 12px; font-family: inherit; color: var(--ink); text-align: left;
  font-size: 13.5px; font-weight: 600; line-height: 1.35; min-height: 52px;
  display: flex; align-items: center;
}
.match-tile.ans { text-align: center; justify-content: center; font-size: 15px; }
.match-tile.sel { border-color: var(--blue); background: var(--blue-soft); }
.match-tile.done { border-color: var(--green); background: var(--green-soft); color: var(--green); opacity: .75; }
.match-tile.err { border-color: var(--red); background: var(--red-soft); }

/* sentence building */
.build-answer {
  min-height: 58px; border: 1.5px dashed var(--line); border-radius: 13px;
  padding: 9px; display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 13px; background: var(--card);
}
.word-chip {
  padding: 8px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 15.5px; font-weight: 600; font-family: inherit;
  box-shadow: var(--shadow);
}
.build-pool { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 16px; }
.build-pool .word-chip.used { opacity: .25; pointer-events: none; }

/* listening */
.listen-hero { display: flex; flex-direction: column; align-items: center; padding: 26px 20px; margin-bottom: 14px; }
.listen-hero .big-speaker {
  width: 74px; height: 74px; border-radius: 50%; border: 0;
  background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(29,92,184,.35);
}
.listen-hero .big-speaker svg { width: 32px; height: 32px; }
.listen-hero .cap { margin-top: 12px; font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.listen-hero.playing .big-speaker { animation: pulse 1.1s ease infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* word race */
.race-hud { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.race-timer { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.race-timer.low { color: var(--red); }
.race-score { font-size: 15px; font-weight: 700; color: var(--ink-2); }
.race-score b { color: var(--blue); font-size: 19px; }

/* scenario intro */
.scenario-hero { padding: 24px 20px; text-align: center; margin-bottom: 16px; }
.scenario-hero .flag { font-size: 34px; margin-bottom: 10px; }
.scenario-hero h2 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.scenario-hero p { color: var(--ink-2); font-size: 14.5px; margin-top: 7px; line-height: 1.5; }

/* results */
.results { display: flex; flex-direction: column; min-height: 100%; padding: calc(24px + var(--sat)) 18px calc(16px + var(--sab)); }
.score-ring-wrap { display: flex; flex-direction: column; align-items: center; margin: 12px 0 20px; }
.score-big { font-size: 46px; font-weight: 800; letter-spacing: -.03em; }
.score-big span { color: var(--ink-3); font-size: 24px; font-weight: 700; }
.score-cap { color: var(--ink-2); font-size: 14px; font-weight: 600; margin-top: 2px; }
.score-best { margin-top: 9px; font-size: 12.5px; font-weight: 700; color: var(--amber); }
.missed-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.missed-item { padding: 12px 14px; font-size: 14px; }
.missed-item .m-sent { font-weight: 600; }
.missed-item .m-sent .filled { color: var(--green); font-weight: 800; }
.missed-item .m-expl { color: var(--ink-2); font-size: 13px; margin-top: 3px; }
.results .stack { margin-top: auto; display: flex; flex-direction: column; gap: 9px; }

/* ---------- cards tab ---------- */
.search-row { display: flex; align-items: center; gap: 9px; background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 0 8px 0 13px; margin-bottom: 12px; }
.search-row svg { width: 17px; height: 17px; color: var(--ink-3); flex: none; }
.search-row input { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 12px 0; font-size: 15.5px; font-family: inherit; color: var(--ink); }
.search-row .clear-x { flex: none; width: 30px; height: 30px; border: 0; background: none; color: var(--ink-3); display: flex; align-items: center; justify-content: center; }
.search-row .clear-x svg { width: 15px; height: 15px; color: var(--ink-3); }
.card-row { padding: 13px 15px; width: 100%; text-align: left; font-family: inherit; display: block; }
.card-row .c-sent { font-size: 14.5px; font-weight: 600; line-height: 1.4; }
.card-row .c-sent .filled { color: var(--blue); font-weight: 800; }
.card-row .c-meta { display: flex; gap: 6px; margin-top: 7px; align-items: center; flex-wrap: wrap; }
.card-row .c-topic { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.card-list { display: flex; flex-direction: column; gap: 8px; }
.empty-note { text-align: center; color: var(--ink-3); font-size: 14px; padding: 34px 0; font-weight: 600; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { padding: 15px; }
.stat-box .v { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.stat-box .k { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-top: 2px; }
.week-chart { display: flex; align-items: flex-end; gap: 7px; height: 110px; padding: 14px 15px 8px; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week-bar { width: 100%; max-width: 26px; border-radius: 5px; background: var(--blue); min-height: 3px; }
.week-col.today .week-bar { background: var(--green); }
.week-day { font-size: 10.5px; font-weight: 700; color: var(--ink-3); }
.mode-stat-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; font-size: 14px; font-weight: 600; }
.mode-stat-row + .mode-stat-row { border-top: 1px solid var(--line); }
.mode-stat-row .r { color: var(--ink-2); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- settings ---------- */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 9px;
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink-2);
}
.seg button.on { background: var(--blue); color: #fff; }
.set-group { padding: 15px; margin-bottom: 12px; }
.set-group > .g-label { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.voice-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; }
.voice-row + .voice-row { border-top: 1px solid var(--line); }
.voice-row .v-name { font-size: 14px; font-weight: 600; }
.voice-row .v-lang { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.voice-row .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.voice-row.on .radio { border-color: var(--blue); background: radial-gradient(circle, var(--blue) 0 55%, transparent 60%); }
input[type="range"] { width: 100%; accent-color: var(--blue); height: 28px; }
.range-val { text-align: center; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-top: 2px; }
.about-line { text-align: center; color: var(--ink-3); font-size: 12.5px; font-weight: 600; padding: 8px 0 4px; }

/* ---------- sheets & banners ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15,20,30,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 40;
}
.sheet {
  width: 100%; max-width: 560px; background: var(--paper);
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + var(--sab));
  max-height: 82dvh; overflow-y: auto;
}
.sheet h3 { font-size: 17px; font-weight: 800; margin-bottom: 4px; }
.sheet p { font-size: 14px; color: var(--ink-2); margin-bottom: 16px; }
.sheet .stack { display: flex; flex-direction: column; gap: 9px; }
.banner {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--sab) + 14px);
  max-width: 528px; margin: 0 auto; z-index: 50;
  background: var(--ink); color: var(--paper); border-radius: 13px;
  display: flex; align-items: center; gap: 10px; padding: 11px 12px 11px 16px;
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.banner .b-act { flex: none; border: 0; border-radius: 9px; padding: 7px 13px; font-family: inherit; font-size: 13.5px; font-weight: 700; background: var(--card); color: var(--ink); }
.banner .b-x { flex: none; border: 0; background: none; color: inherit; opacity: .7; width: 28px; height: 28px; font-size: 15px; }

/* detail sheet sentence */
.detail-sent { font-size: 19px; font-weight: 700; line-height: 1.5; margin: 4px 0 10px; }
.detail-sent .filled { color: var(--blue); }
