@property --a1 { syntax: '<color>'; inherits: true; initial-value: #cc4a2d; }
@property --p { syntax: '<number>'; inherits: false; initial-value: 0; }

/* ---------- Tokens: warm paper + ink, one accent per region ---------- */
:root {
  --a1: #cc4a2d; --on-a1: #fff;
  --soft: color-mix(in srgb, var(--a1) 11%, var(--surface));
  --us: #2d5bd0; --au: #1f7a55; --uk: #8e2c48; --ph: #9a6a00; --gold: #e2a019; --good: #1f8f5a; --bad: #c8412f;
  --bg: #faf7f2; --surface: #fff; --surface-2: #f3eee6; --seg: #fff;
  --border: #e8e1d6; --border-2: #d8cfc1;
  --text: #1e1b17; --muted: #6e665b;
  --shadow: 0 1px 2px rgba(30, 27, 23, .04), 0 10px 30px -18px rgba(30, 27, 23, .2);
  --r: 18px; --ease: cubic-bezier(.22, 1, .36, 1); --spring: cubic-bezier(.34, 1.4, .64, 1);
  --font: 'Google Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
  transition: --a1 .6s var(--ease);
}
:root[data-region=us] { --a1: #2d5bd0; }
:root[data-region=au] { --a1: #1f7a55; }
:root[data-region=uk] { --a1: #8e2c48; }
:root[data-region=ph] { --a1: #9a6a00; }
:root[data-theme=dark] {
  --a1: #ff8466; --on-a1: #1a1714;
  --us: #86a8ff; --au: #5ccf98; --uk: #f08aa6; --ph: #f2c14e; --gold: #f5c04a; --good: #5ccf98; --bad: #ff8a76;
  --bg: #161412; --surface: #1f1c19; --surface-2: #29251f; --seg: #3a342d;
  --border: #322d27; --border-2: #453e36;
  --text: #f3efe9; --muted: #a69d91;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px -18px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
:root[data-theme=dark][data-region=us] { --a1: #86a8ff; }
:root[data-theme=dark][data-region=au] { --a1: #5ccf98; }
:root[data-theme=dark][data-region=uk] { --a1: #f08aa6; }
:root[data-theme=dark][data-region=ph] { --a1: #f2c14e; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html:has(dialog[open]) { overflow: hidden; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 15.5px/1.55 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden; transition: background-color .4s, color .4s;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--a1); outline-offset: 2px; }
::selection { background: var(--soft); color: var(--text); }
[hidden] { display: none !important; }
.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
.grow { flex: 1; }
.tab, .chip, .btn, .pill, .icon-btn, .w-open, .w-save, .fc, .opt, .rd-btn, .rd-menu button { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 40; padding-top: env(safe-area-inset-top); background: var(--bg); border-bottom: 1px solid transparent; transition: border-color .3s, background-color .4s; }
.topbar.scrolled { border-color: var(--border); }
.bar { display: flex; align-items: center; gap: 16px; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.brand em { font-style: normal; color: var(--a1); }
.logo { width: 34px; height: 34px; border-radius: 9px; display: block; }

.tabs { position: relative; display: flex; gap: 2px; padding: 4px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.tabs { margin: 0 auto; }
.ink { position: absolute; left: 0; top: 0; z-index: 0; border-radius: 10px; background: var(--seg); box-shadow: 0 1px 2px rgba(30, 27, 23, .1), 0 2px 8px -3px rgba(30, 27, 23, .12); pointer-events: none; }
.ready .ink { transition: transform .45s var(--ease), width .45s var(--ease), height .45s var(--ease); }
.tab {
  position: relative; z-index: 1; overflow: hidden; display: flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px;
  font-weight: 500; font-size: 14px; color: var(--muted); transition: color .25s;
}
.tab:hover, .tab[aria-current=page] { color: var(--text); }
.tab .i { width: 18px; height: 18px; transition: color .25s; }
.tab[aria-current=page] .i { color: var(--a1); }
.actions { display: flex; align-items: center; gap: 8px; }
.flag { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1px var(--border-2); flex: none; }
.flags { display: inline-flex; flex: none; }
.flags img + img { margin-left: -6px; }
.flags img { box-shadow: 0 0 0 1.5px var(--surface); }

.icon-btn {
  position: relative; overflow: hidden; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: var(--muted);
  transition: background-color .2s, color .2s, transform .25s var(--spring);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn.sm .i { width: 17px; height: 17px; }
#themeBtn { border: 1px solid var(--border); background: var(--surface); }
#themeBtn .i { animation: spinIn .5s var(--spring); }
#themeBtn .sun, :root[data-theme=dark] #themeBtn .moon { display: none; }
:root[data-theme=dark] #themeBtn .sun { display: block; }

/* ---------- Page layout ---------- */
main { padding-bottom: 48px; }
.view { display: none; }
.view.active { display: block; }
.view.active > * { animation: rise .5s var(--ease) both; }
.view.active > :nth-child(2) { animation-delay: .05s; }
.view.active > :nth-child(3) { animation-delay: .1s; }
.view.active > :nth-child(4) { animation-delay: .15s; }
.view.active > :nth-child(5) { animation-delay: .2s; }
.view.active > :nth-child(6) { animation-delay: .25s; }
.view.active > .rate { animation: none; }
#v-learn, #v-quiz { max-width: 640px; margin-inline: auto; }

.hero { margin: 40px 0 26px; }
.eyebrow { display: block; margin-bottom: 8px; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.eyebrow b { color: var(--a1); font-weight: 700; }
h1 { margin: 0 0 10px; font-size: clamp(34px, 5.2vw, 54px); line-height: 1.08; letter-spacing: -.025em; font-weight: 700; }
h1 em { font-style: normal; color: var(--a1); }
.lead { margin: 0; max-width: 600px; color: var(--muted); font-size: clamp(15px, 1.5vw, 17px); }
.meta { margin: 4px 0 14px; color: var(--muted); font-size: 13.5px; }
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); transition: background-color .4s, border-color .25s; }

/* ---------- Controls ---------- */
.btn {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 20px;
  border-radius: 12px; font-weight: 500; font-size: 15px; white-space: nowrap; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: transform .25s var(--spring), background-color .2s, border-color .2s, filter .2s;
}
.btn:hover { border-color: var(--border-2); }
.btn:active { transform: scale(.97); }
.btn .i { width: 18px; height: 18px; }
.btn.primary { background: var(--a1); border-color: var(--a1); color: var(--on-a1); }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.rec { background: var(--bad); border-color: var(--bad); color: #fff; animation: recPulse 1.4s ease-in-out infinite; }
.btn.on, .w-save.on { color: var(--a1); }
.btn.on .i, .w-save.on .i { fill: currentColor; animation: pop .4s var(--spring); }
.link { font-size: 13.5px; font-weight: 500; color: var(--a1); padding: 6px 10px; border-radius: 8px; transition: background-color .2s; }
.link:hover { background: var(--soft); }
.pill {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 99px;
  font-size: 13.5px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); transition: border-color .2s, transform .25s var(--spring);
}
.pill .i { width: 16px; height: 16px; color: var(--a1); }
.pill:hover { border-color: var(--border-2); }
.pill:active { transform: scale(.95); }
.chip {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px; border-radius: 99px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); font-size: 14px; font-weight: 500; color: var(--text);
  transition: background-color .2s, color .2s, border-color .2s, transform .25s var(--spring);
}
.chip:hover { border-color: var(--border-2); }
.chip:active { transform: scale(.96); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip-sm { font-size: 12.5px; font-weight: 500; padding: 4px 10px; border-radius: 99px; background: var(--surface); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; animation: pop .35s var(--spring); }
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; margin: 0 -2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.cats::-webkit-scrollbar { display: none; }
.cats .chip { flex: none; scroll-snap-align: start; }
.modes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stats span { padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; color: var(--muted); }
.stats b { display: inline-block; margin-left: 3px; color: var(--text); font-weight: 700; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--muted); cursor: pointer; -webkit-user-select: none; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch i { position: relative; flex: none; width: 38px; height: 22px; border-radius: 99px; background: var(--border-2); transition: background-color .25s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .35s var(--spring); }
.switch input:checked + i { background: var(--a1); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--a1); outline-offset: 2px; }
.mic {
  position: relative; flex: none; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; color: var(--on-a1); background: var(--a1);
  transition: transform .3s var(--spring), background-color .3s;
}
.mic:hover { transform: scale(1.05); }
.mic:active { transform: scale(.94); }
.mic::before, .mic::after { content: ''; position: absolute; inset: 0; border-radius: inherit; border: 2px solid var(--bad); opacity: 0; pointer-events: none; }
.listening .mic { background: var(--bad); color: #fff; }
.listening .mic::before { animation: pulse 1.6s var(--ease) infinite; }
.listening .mic::after { animation: pulse 1.6s .8s var(--ease) infinite; }

/* ---------- Dictionary ---------- */
.search { position: relative; display: flex; align-items: center; }
.search > .i { position: absolute; left: 18px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 56px; padding: 0 64px 0 50px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  outline: none; font-size: 16px; -webkit-appearance: none; appearance: none; transition: border-color .2s, box-shadow .2s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--a1); box-shadow: 0 0 0 4px var(--soft); }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }
.search.big { position: sticky; top: calc(76px + env(safe-area-inset-top)); z-index: 30; max-width: 720px; margin-bottom: 22px; }
.search .mic.sm { position: absolute; right: 6px; width: 44px; height: 44px; border-radius: 12px; }

.wod { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end; padding: 26px 28px; margin-bottom: 28px; background: var(--soft); border-color: transparent; box-shadow: none; }
.wod-tag { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--a1); }
.wod h2 { margin: 6px 0; font-size: clamp(40px, 6vw, 56px); font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.wod-def { margin: 0; font-size: 17px; font-weight: 500; }
.wod-ex, .d-ex, .fc-ex { margin: 8px 0 0; color: var(--muted); font-style: italic; }
.wod-r { display: grid; gap: 14px; justify-items: end; }
.wod-act { display: flex; gap: 8px; }

.w-top { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.w-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.w-card { animation: rise .45s var(--ease) both; animation-delay: var(--d); transition: transform .3s var(--ease), border-color .2s, box-shadow .3s, background-color .4s; }
.w-grid.still .w-card { animation: none; }
.w-open { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; height: 100%; padding: 16px 18px; text-align: left; border-radius: inherit; }
.w-word { margin-top: 6px; padding-right: 30px; font-size: 21px; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; }
.w-def { color: var(--muted); font-size: 14.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.w-eq { margin-top: auto; padding-top: 10px; display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 500; }
.w-eq .flag { width: 15px; height: 15px; }
.w-eq em { font-style: normal; color: var(--muted); }
.w-badge { margin-left: 2px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 700; color: var(--good); background: color-mix(in srgb, var(--good) 13%, transparent); }
.w-save { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); transition: color .2s, background-color .2s, transform .3s var(--spring); }
.w-save:hover { background: var(--surface-2); color: var(--text); }
.w-save:active { transform: scale(.85); }
.lookup { margin: 28px 0 8px; color: var(--muted); }
.lookup p { margin: 0 0 10px; }

/* ---------- Word detail sheet ---------- */
dialog { padding: 0; border: 0; background: none; color: var(--text); width: min(520px, calc(100% - 32px)); max-width: none; max-height: none; overflow: visible; }
dialog::backdrop { background: rgba(20, 18, 15, .45); animation: fade .25s var(--ease); }
.sheet {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 24px;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .45); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow: auto; overscroll-behavior: contain;
}
dialog[open] .sheet { animation: popIn .4s var(--spring); }
dialog.closing .sheet { animation: popOut .2s ease-in forwards; }
dialog.closing::backdrop { animation: fade .2s reverse forwards; }
.close { position: absolute; top: 14px; right: 14px; }
.d-head { padding-right: 40px; margin-bottom: 12px; }
.d-word { margin: 8px 0 2px; font-size: clamp(36px, 8vw, 48px); font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.d-phon { min-height: 1.4em; color: var(--muted); }
.d-say { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.d-sec { padding: 16px 0; border-top: 1px solid var(--border); }
.d-sec h4 { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.d-def { margin: 0; font-size: 17px; font-weight: 500; }
.d-ex { display: flex; align-items: center; gap: 6px; }
.d-sec ol { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.d-sec li .d-ex { display: block; font-size: 14px; margin-top: 3px; }
.d-eq { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; margin-bottom: 4px; border-radius: 14px; background: var(--surface-2); }
.d-eq .flag { width: 28px; height: 28px; }
.d-eq > div { flex: 1; min-width: 0; display: grid; }
.d-eq small { font-size: 12.5px; color: var(--muted); }
.d-eq b { font-size: 17px; font-weight: 700; }
.d-fil { margin: 0; }
.d-practice { display: flex; align-items: center; gap: 14px; padding: 16px 0; border-top: 1px solid var(--border); }
.d-res { font-size: 14px; color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.d-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 6px; }
.lk.loading { color: var(--muted); padding: 6px 0 12px; animation: blink 1.2s ease-in-out infinite; }
.sheet > .toast { position: sticky; bottom: 0; margin-top: 14px; text-align: center; }

/* ---------- Flashcards (index cards) ---------- */
.fc-stats { margin: 4px 0 18px; }
.fc-scene { perspective: 1400px; }
.fc-scene.enter { animation: stageIn .45s var(--ease); }
.fc { position: relative; height: 340px; cursor: pointer; border-radius: 20px; transform-style: preserve-3d; -webkit-transform-style: preserve-3d; transition: transform .7s var(--spring); }
.fc.flipped { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px 28px 24px;
  text-align: center; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.fc-face::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: var(--rc, var(--a1)); }
.fc-back { transform: rotateY(180deg); background: repeating-linear-gradient(var(--surface) 0 33px, var(--border) 33px 34px); }
.fc-word { font-size: clamp(40px, 8vw, 60px); font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.fc-hint { font-size: 13px; color: var(--muted); }
.fc-def { margin: 0; max-width: 440px; font-size: 20px; font-weight: 500; line-height: 1.4; }
.fc-ex { max-width: 440px; margin: 0; }
.rate { display: flex; gap: 10px; margin-top: 18px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .3s var(--ease), transform .3s var(--ease); }
.revealed .rate { opacity: 1; transform: none; pointer-events: auto; }
.rate .btn { flex: 1; height: 58px; flex-direction: column; gap: 0; line-height: 1.25; }
.rate b { font-weight: 700; }
.rate small { font-size: 12px; opacity: .75; }
.fc-done { padding: 34px 24px; text-align: center; }
.fc-done .big { font-size: 48px; }
.fc-done h3 { margin: 6px 0 4px; font-size: 22px; }
.fc-done p { margin: 0 0 18px; color: var(--muted); }
.kbd-hint { margin-top: 18px; color: var(--muted); font-size: 13px; }
kbd { font: 500 11.5px var(--font); padding: 2px 7px; border-radius: 6px; border: 1px solid var(--border-2); border-bottom-width: 2px; background: var(--surface); }

/* ---------- Quiz ---------- */
.quiz { padding: 22px; }
.stage.enter { animation: stageIn .45s var(--ease); }
.ask { margin: 22px 0 8px; color: var(--muted); font-size: 14.5px; }
.q-word { margin-top: 8px; font-size: clamp(36px, 7vw, 52px); font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.q-word::first-letter { text-transform: uppercase; }
.q-play { width: 76px; height: 76px; margin-top: 14px; }
.q-play .i { width: 28px; height: 28px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.opts.long { grid-template-columns: 1fr; }
.opt {
  position: relative; overflow: hidden; min-height: 56px; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  text-align: left; font-size: 15.5px; font-weight: 500; transition: transform .25s var(--spring), background-color .2s, border-color .2s, opacity .2s;
}
.opt::first-letter { text-transform: uppercase; }
.opt:disabled { cursor: default; color: var(--text); }
.opts.done .opt:not(.correct):not(.wrong) { opacity: .45; }
.opt.correct { background: color-mix(in srgb, var(--good) 12%, var(--surface)); border-color: var(--good); animation: bump .45s var(--spring); }
.opt.wrong { background: color-mix(in srgb, var(--bad) 10%, var(--surface)); border-color: var(--bad); animation: shake .4s; }
.confetti { position: fixed; z-index: 200; width: 8px; height: 12px; border-radius: 2px; pointer-events: none; animation: burst 1s cubic-bezier(.15, .7, .3, 1) forwards; }

/* ---------- My Words ---------- */
.dash { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 14px; margin-bottom: 14px; }
.prog-card { display: flex; align-items: center; gap: 22px; padding: 24px; }
.prog-card h3 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.prog-card p { margin: 0; color: var(--muted); }
.ring-prog {
  --p: 0; position: relative; flex: none; width: 112px; height: 112px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--a1) calc(var(--p) * 1%), var(--surface-2) 0); transition: --p 1.2s var(--ease);
}
.ring-prog::before { content: ''; position: absolute; inset: 10px; border-radius: 50%; background: var(--surface); }
.ring-prog span { position: relative; font-size: 24px; font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stat { padding: 16px 18px; display: grid; gap: 2px; animation: rise .45s var(--ease) both; animation-delay: var(--d); }
.stat-e { font-size: 22px; }
.stat b { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat span:last-child { font-size: 13.5px; color: var(--muted); }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { padding: 6px 6px 8px; }
.panel-h { display: flex; align-items: center; justify-content: space-between; min-height: 50px; padding: 6px 12px 2px; }
.panel h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15.5px; font-weight: 700; }
.panel h3 .i { width: 18px; height: 18px; color: var(--a1); }
.hist { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; scrollbar-width: thin; }
.hist li { display: flex; align-items: center; gap: 4px; padding-right: 6px; animation: rise .4s var(--ease) both; animation-delay: var(--d, 0ms); }
.hist .muted { padding: 8px 12px 12px; color: var(--muted); font-size: 14px; }
.h-item { position: relative; overflow: hidden; flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 12px; transition: background-color .2s; }
.h-item:hover { background: var(--surface-2); }
.h-src { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-out { font-weight: 500; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.h-out .flag { width: 15px; height: 15px; vertical-align: -2px; }
.h-tag { margin-top: 2px; font-size: 12px; font-weight: 500; color: var(--a1); }
.bars { display: grid; gap: 14px; padding: 4px 16px 16px; }
.bar-h { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
.bar-h span:last-child { color: var(--muted); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--a1); animation: grow 1s var(--ease) both; }

/* ---------- Translator ---------- */
.lang-bar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); }
.select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none; width: 100%; min-width: 0; height: 46px; padding: 0 40px 0 14px; border-radius: 12px;
  border: 1px solid var(--border); font-weight: 500; font-size: 15px; cursor: pointer; text-overflow: ellipsis; transition: border-color .2s, box-shadow .2s;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857c70' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 13px center / 16px;
}
.select:hover { border-color: var(--border-2); }
.select:focus-visible { outline: none; border-color: var(--a1); box-shadow: 0 0 0 4px var(--soft); }
.select option { background: var(--surface); color: var(--text); }
.swap { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.swap .i { transition: transform .5s var(--spring); }
.swap.flip .i { transform: rotate(180deg); }
.panes { display: grid; grid-template-columns: 1fr 1fr; }
.pane { position: relative; display: flex; flex-direction: column; min-height: 260px; }
.pane + .pane { border-left: 1px solid var(--border); }
.out { background: var(--surface-2); border-bottom-right-radius: var(--r); }
textarea { flex: 1; width: 100%; min-height: 180px; padding: 20px 22px; border: 0; background: none; resize: none; outline: none; font-size: clamp(18px, 2vw, 21px); line-height: 1.45; }
textarea::placeholder { color: var(--muted); }
.output { flex: 1; padding: 20px 22px; font-size: clamp(18px, 2vw, 21px); font-weight: 500; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; transition: opacity .3s; }
.output .ph { color: var(--muted); font-weight: 400; }
.output .w { display: inline-block; animation: wordIn .45s var(--ease) both; }
.out::before { content: ''; position: absolute; left: 0; right: 0; top: -1px; height: 2px; opacity: 0; transition: opacity .3s; background: linear-gradient(90deg, transparent, var(--a1), transparent) no-repeat; background-size: 40% 100%; }
.out.loading::before { opacity: 1; animation: scan 1.1s linear infinite; }
.out.loading .output { opacity: .45; }
.foot { display: flex; align-items: center; gap: 6px; min-height: 64px; padding: 10px 12px 12px 14px; }
.count { margin-right: 4px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { margin-left: 6px; font-size: 13.5px; color: var(--muted); }
.listening .hint { color: var(--text); }
.wave { display: none; align-items: center; gap: 3px; height: 22px; margin-left: 8px; }
.listening .wave { display: flex; }
.wave i { width: 3px; height: 100%; border-radius: 3px; background: var(--bad); animation: eq 1s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: -.25s; }
.wave i:nth-child(3) { animation-delay: -.5s; }
.wave i:nth-child(4) { animation-delay: -.15s; }
.wave i:nth-child(5) { animation-delay: -.65s; }
#starBtn.on { color: var(--gold); }
#starBtn.on .i { fill: currentColor; animation: pop .4s var(--spring); }
.phrases { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 30px; }
.phrases .chip { animation: rise .45s var(--ease) both; animation-delay: var(--d); }

/* ---------- Toasts, ripple, footer ---------- */
.toasts {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 300;
  display: grid; gap: 8px; justify-items: center; width: max-content; max-width: calc(100% - 32px); pointer-events: none;
}
.toast { padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .4); animation: toastIn .4s var(--spring); }
.toast.out { animation: toastOut .3s var(--ease) forwards; }
.ripple { position: absolute; border-radius: 50%; transform: scale(0); background: currentColor; opacity: .12; pointer-events: none; animation: ripple .6s var(--ease) forwards; }
.bump { animation: bump .45s var(--spring); }
.foot-note { padding: 24px 20px 40px; text-align: center; color: var(--muted); font-size: 12.5px; }

@media (hover: hover) {
  .w-card:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: 0 1px 2px rgba(30, 27, 23, .05), 0 16px 32px -20px rgba(30, 27, 23, .3); }
  .opt:hover:not(:disabled) { border-color: var(--text); }
}

/* ---------- Theme switch reveal (View Transitions) ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { animation: reveal .6s var(--ease); }

/* ---------- Keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes wordIn { from { opacity: 0; transform: translateY(6px); } }
@keyframes scan { from { background-position: -60% 0; } to { background-position: 160% 0; } }
@keyframes pulse { from { transform: scale(1); opacity: .7; } to { transform: scale(1.8); opacity: 0; } }
@keyframes eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes bump { 40% { transform: scale(1.08); } }
@keyframes spinIn { from { transform: rotate(-90deg) scale(.5); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes popOut { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes sheetDown { to { transform: translateY(100%); } }
@keyframes stageIn { from { opacity: 0; transform: translateX(20px); } }
@keyframes burst { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }
@keyframes recPulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--bad) 20%, transparent); } }
@keyframes blink { 50% { opacity: .5; } }
@keyframes grow { from { width: 0; } }
@keyframes reveal { from { clip-path: circle(0 at var(--cx, 50%) var(--cy, 0)); } to { clip-path: circle(150vmax at var(--cx, 50%) var(--cy, 0)); } }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .tab { padding: 8px 11px; }
}
@media (max-width: 900px) {
  .bar { height: 60px; gap: 10px; }
  .brand { font-size: 18px; }
  .logo { width: 30px; height: 30px; border-radius: 8px; }
  .actions { margin-left: auto; }
  /* Native-style bottom tab bar */
  .tabs {
    position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; margin: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--border); border-radius: 0; background: var(--surface);
  }
  .tabs .ink { background: var(--soft); box-shadow: none; border-radius: 14px; }
  .tab { flex-direction: column; justify-content: center; gap: 3px; min-height: 54px; padding: 6px 2px; border-radius: 14px; font-size: 11px; }
  .tab[aria-current=page] { color: var(--a1); }
  .tab .i { width: 21px; height: 21px; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .foot-note { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .hero { margin: 20px 0 18px; }
  .search.big { top: calc(66px + env(safe-area-inset-top)); margin-bottom: 18px; }
  .cats { margin: 0 -20px; padding: 2px 20px 12px; scroll-padding: 0 20px; }
  .phrases { flex-wrap: nowrap; overflow-x: auto; margin: 16px -20px 26px; padding: 2px 20px 6px; scrollbar-width: none; }
  .phrases::-webkit-scrollbar { display: none; }
  .phrases .chip { flex: none; }
  .wod { grid-template-columns: 1fr; padding: 22px; }
  .wod-r { justify-items: start; }
  .duo, .dash { grid-template-columns: 1fr; }
  .panes { grid-template-columns: 1fr; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .out { border-bottom-left-radius: var(--r); }
  .pane { min-height: 0; }
  .lang-bar { padding: 10px; gap: 8px; }
  .select { height: 44px; padding: 0 30px 0 12px; font-size: 16px; background-position: right 10px center; }
  .swap { width: 42px; height: 42px; }
  textarea, .output { padding: 18px; min-height: 130px; }
  .fc { height: 320px; }
  .quiz { padding: 18px; }
  .d-actions { grid-template-columns: 1fr; }
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; }
  .sheet { border-radius: 24px 24px 0 0; border-bottom: 0; padding: 20px 20px calc(22px + env(safe-area-inset-bottom)); max-height: 90vh; max-height: 90dvh; }
  .sheet::before { content: ''; display: block; width: 38px; height: 5px; border-radius: 9px; background: var(--border-2); margin: -6px auto 14px; }
  dialog[open] .sheet { animation: sheetUp .45s var(--ease); }
  dialog.closing .sheet { animation: sheetDown .22s ease-in forwards; }
}
@media (max-width: 520px) {
  .w-grid, .opts { grid-template-columns: 1fr; }
  .prog-card { padding: 20px; gap: 18px; }
  .ring-prog { width: 92px; height: 92px; }
  .wod-act { flex-wrap: wrap; }
  .stat-grid { gap: 10px; }
}
@media (max-width: 420px) {
  .count, .hint { display: none; }
  .switch span { font-size: 12.5px; }
}
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  .foot-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Search clear state, install hint, backup ---------- */
.search.has-q .mic { background: var(--surface-2); color: var(--text); }
.install {
  position: fixed; z-index: 50; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(440px, calc(100% - 24px));
  display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 12px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 20px 50px -20px rgba(30, 27, 23, .45); animation: installIn .5s var(--spring);
}
.install img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.install p { flex: 1; margin: 0; font-size: 13.5px; line-height: 1.4; color: var(--muted); }
.install p b { display: block; font-size: 14.5px; color: var(--text); }
.install p .i { width: 16px; height: 16px; vertical-align: -3px; color: #0a84ff; }
.install .btn { height: 38px; padding: 0 14px; }
.backup { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; padding: 18px 20px; }
.backup h3 { margin: 0 0 2px; font-size: 15.5px; }
.backup p { margin: 0; max-width: 480px; color: var(--muted); font-size: 14px; }
.backup-act { display: flex; gap: 8px; }
@keyframes installIn { from { opacity: 0; transform: translate(-50%, 20px); } }
@media (max-width: 900px) { .install { bottom: calc(82px + env(safe-area-inset-bottom)); } }

/* ---------- Multi-country equivalents ---------- */
.w-eq { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.w-eq > span { display: inline-flex; align-items: center; gap: 6px; }
.d-eq + .d-eq { margin-top: 8px; }

/* ---------- Country dropdown ---------- */
.region-dd { position: relative; }
.rd-btn {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px 0 9px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 500; transition: border-color .2s;
}
.rd-btn:hover { border-color: var(--border-2); }
.rd-cur { display: inline-flex; align-items: center; gap: 8px; }
.rd-btn > .i { width: 16px; height: 16px; color: var(--muted); transition: transform .25s var(--ease); }
.rd-btn[aria-expanded=true] > .i { transform: rotate(180deg); }
.rd-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px; padding: 6px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 20px 40px -16px rgba(30, 27, 23, .35);
  transform-origin: top right; animation: menuIn .2s var(--ease);
}
.rd-menu button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14.5px; font-weight: 500; text-align: left; transition: background-color .15s; }
.rd-menu button:hover { background: var(--surface-2); }
.rd-menu button[aria-selected=true] { background: var(--soft); color: var(--a1); }
.rd-menu button[aria-selected=true]::after { content: '✓'; margin-left: auto; font-weight: 700; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px) scale(.97); } }

/* Opening the sheet focuses the dialog itself; no ring needed there */
dialog:focus, dialog:focus-visible { outline: none; }
