:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f3f4f6);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2f7de1);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --brand: #f0592a;
  --brand2: #ffb627;
  --ok: #22a55a;
  --ok-bg: color-mix(in srgb, #22a55a 14%, var(--bg));
  --bad: #e5484d;
  --bad-bg: color-mix(in srgb, #e5484d 13%, var(--bg));
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([style*="--tg-theme-bg-color"]) {
    --bg: #17181c; --bg2: #0e0f12; --text: #f1f2f4; --hint: #8d929b; --card: #1f2126;
  }
}
.backbar { position: sticky; top: 0; z-index: 9; width: 100%; text-align: left; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bg2); color: var(--brand); font-weight: 600; font-size: 17px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); }
.hidden { display: none !important; }
#app { padding: 12px 16px calc(84px + var(--safe-b)); max-width: 560px; margin: 0 auto; }
#app.player-mode { padding: 0; max-width: none; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid var(--sep); padding: 6px 4px calc(6px + var(--safe-b)); z-index: 10; }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; color: var(--hint); padding: 2px 0; }
.tabs button span { font-size: 21px; filter: grayscale(1); opacity: .65; }
.tabs button.on { color: var(--brand); font-weight: 600; }
.tabs button.on span { filter: none; opacity: 1; }

/* generic */
h1 { font-size: 24px; margin: 6px 0 12px; letter-spacing: -.3px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.btn { display: block; width: 100%; padding: 14px 16px; border-radius: 14px; font-weight: 650; font-size: 16px;
  background: var(--brand); color: #fff; text-align: center; transition: transform .08s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; }
.btn.ghost { background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--text); }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn + .btn { margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 99px;
  background: var(--card); font-weight: 600; font-size: 14px; }
.bar { height: 8px; border-radius: 99px; background: var(--sep); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand2), var(--brand));
  border-radius: 99px; transition: width .35s; }
.list-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px;
  background: var(--card); border-radius: 14px; margin-bottom: 8px; }
.list-item .emoji { font-size: 26px; width: 34px; text-align: center; }
.list-item .title { font-weight: 600; }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.toast { position: fixed; left: 16px; right: 16px; top: 12px; z-index: 50; background: var(--text); color: var(--bg);
  padding: 12px 14px; border-radius: 14px; font-size: 14px; animation: drop .25s; }
@keyframes drop { from { transform: translateY(-20px); opacity: 0; } }

/* home */
.topstats { display: flex; gap: 8px; margin: 2px 0 14px; flex-wrap: wrap; }
.hero { background: linear-gradient(135deg, #ff7a3d, #f0592a 55%, #d9381e); color: #fff; border-radius: 22px;
  padding: 18px; margin-bottom: 12px; box-shadow: 0 8px 24px -10px rgba(240,89,42,.6); }
.hero .kicker { opacity: .85; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.hero .t { font-size: 21px; font-weight: 750; margin: 4px 0 14px; line-height: 1.2; }
.hero .btn { background: #fff; color: #d9381e; }
.goal { display: flex; align-items: center; gap: 12px; }
.ring { width: 52px; height: 52px; flex: none; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px; text-align: left; min-height: 92px;
  display: flex; flex-direction: column; justify-content: space-between; }
.tile .ic { font-size: 26px; }
.tile .t { font-weight: 650; }
.tile .s { color: var(--hint); font-size: 13px; }
.badge { background: var(--brand); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: 12px; font-weight: 700; }

/* player */
.player { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.ptop { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; }
.ptop .x { font-size: 22px; color: var(--hint); width: 28px; }
.ptop .bar { flex: 1; height: 12px; }
.pbody { flex: 1; padding: 14px 16px 16px; display: flex; flex-direction: column; max-width: 560px; width: 100%; margin: 0 auto; }
.pfoot { padding: 12px 16px calc(14px + var(--safe-b)); max-width: 560px; width: 100%; margin: 0 auto; }
.prompt { font-size: 15px; color: var(--hint); font-weight: 600; margin-bottom: 14px; }
.phrase { font-size: 26px; font-weight: 700; line-height: 1.25; letter-spacing: -.2px; }
.trans { font-size: 18px; color: var(--hint); margin-top: 6px; }
.speak { display: inline-flex; align-items: center; justify-content: center; width: 54px; height: 54px; border-radius: 16px;
  background: var(--brand); color: #fff; font-size: 24px; flex: none; box-shadow: 0 4px 0 #c43d18; }
.speak:active { transform: translateY(2px); box-shadow: 0 2px 0 #c43d18; }
.speak.slow { width: 42px; height: 42px; font-size: 19px; background: var(--brand2); box-shadow: 0 4px 0 #d49000; border-radius: 13px; }
.speak.big { width: 96px; height: 96px; font-size: 42px; border-radius: 26px; }
.listen-box { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 18px 0 24px; }
.words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.word { background: var(--bg2); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.word b { font-weight: 650; }
.note { margin-top: 14px; background: color-mix(in srgb, var(--brand2) 16%, var(--bg)); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.credit { font-size: 11px; color: var(--hint); margin-top: 10px; }
.opts { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.opt { padding: 15px 16px; border-radius: 14px; border: 2px solid var(--sep); border-bottom-width: 4px; text-align: left;
  font-size: 17px; background: var(--bg); transition: background .15s, border-color .15s; }
.opt:active { transform: translateY(1px); }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.answer-line { min-height: 64px; border-bottom: 2px solid var(--sep); display: flex; flex-wrap: wrap; gap: 8px;
  align-content: flex-start; padding: 6px 0 10px; margin-bottom: 22px; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tilew { padding: 10px 14px; border-radius: 12px; border: 2px solid var(--sep); border-bottom-width: 4px; font-size: 17px;
  background: var(--bg); font-weight: 550; }
.tilew.used { visibility: hidden; }
.typebox { width: 100%; font-size: 19px; padding: 14px; border-radius: 14px; border: 2px solid var(--sep); background: var(--bg2); outline: none; }
.typebox:focus { border-color: var(--brand); }
.accents { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.accents button { padding: 8px 12px; border-radius: 10px; background: var(--bg2); font-weight: 600; }
.feedback { border-radius: 18px 18px 0 0; padding: 16px 16px calc(14px + var(--safe-b)); animation: up .2s; }
.feedback.ok { background: var(--ok-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback .h { font-weight: 800; font-size: 19px; margin-bottom: 4px; }
.feedback.ok .h { color: var(--ok); }
.feedback.bad .h { color: var(--bad); }
.feedback .es { font-weight: 650; font-size: 17px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.result { text-align: center; padding-top: 8vh; }
.result .big { font-size: 64px; }
.result .stars { font-size: 40px; letter-spacing: 6px; margin: 6px 0; }
.result .nums { display: flex; gap: 10px; justify-content: center; margin: 18px 0; }
.result .num { background: var(--bg2); border-radius: 14px; padding: 10px 16px; min-width: 96px; }
.result .num b { display: block; font-size: 22px; }
.notes { text-align: left; margin: 10px 0 18px; }
.notes div { background: var(--bg2); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; font-size: 15px; }

/* units */
.unit-prog { height: 5px; margin-top: 7px; }
.stars-s { font-size: 13px; letter-spacing: 1px; }
.lesson { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: 14px; background: var(--card); width: 100%; text-align: left; margin-bottom: 8px; }
.lesson .n { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff; font-weight: 700; flex: none; }
.lesson.done .n { background: var(--ok); }
.lesson.locked { opacity: .5; }
.lesson.locked .n { background: var(--hint); }
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 0; background: var(--card); outline: none; margin-bottom: 12px; }
.phr { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.phr:last-child { border-bottom: 0; }
.phr .speak { width: 38px; height: 38px; font-size: 16px; border-radius: 11px; box-shadow: 0 3px 0 #c43d18; }
.phr .es { font-weight: 600; }

/* reader */
.player-audio { width: 100%; margin: 6px 0 4px; }
.sent { padding: 10px 0; border-bottom: 1px solid var(--sep); cursor: pointer; }
.sent:last-child { border-bottom: 0; }
.sent .es { font-size: 18px; line-height: 1.45; }
.sent .ru { color: var(--hint); font-size: 15px; margin-top: 3px; }
.sent .ru.blur { filter: blur(5px); user-select: none; }

/* stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat b { font-size: 22px; display: block; }
.stat span { color: var(--hint); font-size: 13px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: var(--sep); }
.cal .l1 { background: color-mix(in srgb, var(--brand2) 45%, var(--bg)); }
.cal .l2 { background: var(--brand2); }
.cal .l3 { background: var(--brand); }
.cal .today { outline: 2px solid var(--text); outline-offset: 1px; }
.cal .dow { background: none; aspect-ratio: auto; text-align: center; font-size: 11px; color: var(--hint); }
.ach { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach div { background: var(--card); border-radius: 14px; padding: 10px 6px; text-align: center; font-size: 12px; }
.ach div .e { font-size: 28px; display: block; }
.ach div.no { opacity: .35; filter: grayscale(1); }
.rank { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.rank.me { font-weight: 700; color: var(--brand); }
.rank .p { width: 28px; text-align: center; }

/* onboarding */
.ob { padding-top: 6vh; text-align: center; }
.ob .logo { font-size: 72px; }
.ob .opts { margin-top: 22px; }
.feat { text-align: left; margin: 18px 0; }
.feat div { padding: 7px 0; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; font-weight: 600; }
.field select { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--sep); background: var(--card); }
.switch { display: flex; align-items: center; justify-content: space-between; }
.spinner { margin: 30vh auto; width: 34px; height: 34px; border: 3px solid var(--sep); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
