:root, [data-theme="light"] {
  --bg: #F6F7F9; --surface: #FFFFFF; --border: #E3E6EB; --divider: #EEF0F3;
  --text: #141A23; --muted: #4B5563; --subtle: #5B6472;
  --accent: #0F766E; --accent-strong: #115E59; --accent-soft: #E6F4F2; --on-accent: #FFFFFF;
  --hero: #0F766E; --hero-text: #FFFFFF; --hero-sub: #CCFBF1;
  --warm: #9A4A08; --warm-soft: #FFF4E5; --warm-bar: #D97706;
  --track: #E9ECF0; --danger: #B42318; --on-danger: #FFFFFF; --blank: #EEF1F4; --blank-border: #9AA4B2;
  --dark-btn: #000000; --dark-btn-text: #FFFFFF;
  --shadow: 0 1px 2px rgba(20, 26, 35, 0.08);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0E1116; --surface: #171B22; --border: #2A303A; --divider: #232933;
  --text: #E6E8EB; --muted: #C9CED6; --subtle: #9AA4B2;
  --accent: #2DD4BF; --accent-strong: #5EEAD4; --accent-soft: #12302C; --on-accent: #08201D;
  --hero: #134E48; --hero-text: #F0FDFA; --hero-sub: #99F6E4;
  --warm: #FBBF24; --warm-soft: #3A2A0A; --warm-bar: #F59E0B;
  --track: #2A303A; --danger: #F97066; --on-danger: #1B0806; --blank: #222833; --blank-border: #5B6472;
  --dark-btn: #F0F2F5; --dark-btn-text: #0E1116;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* layout */
.screen {
  max-width: 560px; margin: 0 auto; min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 28px) 20px 32px;
  display: flex; flex-direction: column; gap: 18px;
}
.screen.with-tabs { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); }
.screen.narrow { max-width: 440px; }
.row { display: flex; }
.between { justify-content: space-between; }
.center { align-items: center; }
.baseline { align-items: baseline; }
.start { align-items: flex-start; }
.gap { gap: 12px; } .gap-s { gap: 8px; }
.grow { flex: 1 1 auto; }
.min0 { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-s { display: flex; flex-direction: column; gap: 10px; }
.stack-xs { display: flex; flex-direction: column; gap: 5px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.left { text-align: left; align-self: flex-start; }
.nowrap { white-space: nowrap; }

/* type */
.display { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 36px; letter-spacing: -0.5px; margin: 0; }
.display-s { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 30px; letter-spacing: -0.4px; line-height: 1.15; margin: 2px 0 0; }
.h1 { font-size: 26px; margin: 0; }
.h2 { font-size: 20px; font-weight: 700; margin: 0; }
.h3 { font-size: 17px; font-weight: 600; margin: 0; }
.lead { font-size: 16px; color: var(--muted); max-width: 300px; margin: 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; color: var(--subtle); }
.eyebrow.warm, .warm { color: var(--warm); }
.accent { color: var(--accent); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 14px; }
.strong { font-weight: 600; }
.ink { color: var(--text); }
.fine { font-size: 11px; line-height: 16px; color: var(--subtle); text-align: center; margin: 0; }
.verse { font-family: "Source Serif 4", Georgia, serif; font-size: 21px; line-height: 1.6; margin: 0; }
.muted-verse { color: var(--subtle); font-size: 18px; }
.hint { font-size: 14px; color: var(--muted); margin: 0; }
.preview { display: block; font-family: "Source Serif 4", Georgia, serif; font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card-link { text-decoration: none; color: var(--text); }
.card.row { flex-direction: row; }
.card-link:active { transform: scale(0.99); }
.notice-card { border-color: var(--accent); }
.hero { background: var(--hero); color: var(--hero-text); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.hero p { margin: 0; color: var(--hero-sub); }
.hero-sub { font-size: 14px; color: var(--hero-sub); }
.big-num { font-size: 44px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; width: 100%;
  border: 0; border-bottom: 1px solid var(--divider); background: transparent; text-decoration: none; color: var(--text); cursor: pointer;
}
.list-row:last-child { border-bottom: 0; }
.list-row.col { flex-direction: column; align-items: stretch; gap: 7px; }
.list-row strong { display: block; }
.list-row .small { display: block; }
.pill { font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 5px 10px; }
.streak { display: inline-flex; align-items: center; gap: 6px; background: var(--warm-soft); color: var(--warm); border-radius: 999px; padding: 8px 12px; font-weight: 700; }
.meter { flex: 1; height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 999px; }
.warm-meter { height: 10px; flex: none; }
.warm-meter > div { background: var(--warm-bar); }
.notice { background: var(--warm-soft); color: var(--warm); border-radius: 12px; padding: 12px 14px; margin: 0; font-size: 15px; }
.empty-card { align-items: flex-start; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent;
  font-size: 16px; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-dark { background: var(--dark-btn); color: var(--dark-btn-text); }
.btn-light { background: #FFFFFF; color: #0F766E; font-weight: 700; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-danger-ghost { background: transparent; border-color: var(--border); color: var(--danger); }
.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer; text-align: center; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); text-decoration: none; font-weight: 600; min-height: 44px; align-self: flex-start; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); color: var(--text); flex: none; }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field-label { font-size: 14px; font-weight: 600; color: var(--muted); }
input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], input:not([type]), .textarea {
  width: 100%; min-height: 50px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 12px 14px; font-size: 16px;
}
.textarea { font-family: "Source Serif 4", Georgia, serif; font-size: 18px; resize: vertical; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--subtle); font-size: 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
details summary { cursor: pointer; min-height: 28px; }
details[open] summary { margin-bottom: 4px; }

/* segmented controls and chips */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--track); border-radius: 12px; padding: 4px; }
.seg { min-height: 38px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; }
.seg.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -20px; padding: 0 20px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 15px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px max(8px, calc((100vw - 560px) / 2)) calc(env(safe-area-inset-bottom) + 8px);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 50px; text-decoration: none; color: var(--subtle); font-size: 11px; font-weight: 500; }
.tab.active { color: var(--accent); font-weight: 600; }

/* welcome */
.welcome { gap: 24px; padding-top: calc(env(safe-area-inset-top) + 56px); }
.welcome-top { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.logo { width: 72px; height: 72px; border-radius: 20px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }
.quote { margin: 0; }
.quote .verse { font-size: 20px; }

/* practice */
.practice { display: flex; flex-direction: column; gap: 16px; }
.practice-top { display: flex; align-items: center; gap: 14px; }
.bar { flex: 1; height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.verse-card { gap: 16px; }
.tokens { display: flex; flex-wrap: wrap; column-gap: 7px; row-gap: 8px; align-items: center; }
.tok.peeked { color: var(--accent); }
.tok.ok { color: var(--text); }
.tok.missed { color: var(--danger); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.blank { height: 30px; border-radius: 7px; border: 1px dashed var(--blank-border); background: var(--blank); padding: 0; cursor: pointer; }
.letter { color: var(--subtle); letter-spacing: 1px; min-width: 14px; }
.letter.next { color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 0 5px; font-weight: 700; }
.shake { animation: shake 0.3s; color: var(--danger) !important; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.letter-input { font-family: "Source Serif 4", Georgia, serif; font-size: 22px; border: 2px solid var(--accent) !important; text-align: center; }
.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; }
.verse-card .stat { background: var(--bg); }
.stat span { font-size: 12px; color: var(--subtle); }
.stat strong { font-size: 19px; }
.slider { display: flex; flex-direction: column; gap: 8px; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.grade-panel { gap: 10px; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grade { min-height: 64px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; padding: 6px 2px; }
.grade span { font-size: 12px; color: var(--subtle); }
.grade.suggested { border: 2px solid var(--accent); background: var(--accent-soft); }
.center-screen { min-height: 60dvh; display: flex; align-items: center; justify-content: center; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; max-width: 340px; }
.empty .btn { width: 100%; }

/* challenges */
.challenge { flex-direction: row; align-items: center; gap: 18px; }
.ring { position: relative; width: 116px; height: 116px; flex: none; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-label strong { font-size: 26px; }
.ring-label span { font-size: 12px; color: var(--subtle); }
.ring-track { stroke: var(--track); }
.ring-fill { stroke: var(--warm-bar); }
.badges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 8px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.badge-icon { width: 56px; height: 56px; border-radius: 28px; display: flex; align-items: center; justify-content: center; background: var(--surface); border: 1px dashed var(--blank-border); color: var(--subtle); }
.badge-icon.earned { background: var(--warm-soft); border: 0; color: var(--warm); }

/* sheet + toast */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 24px 20px calc(env(safe-area-inset-bottom) + 20px); display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px); transform: translate(-50%, 20px); opacity: 0; transition: 0.25s; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 500; z-index: 30; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
