:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #7a7a80;
  --line: #e6e4de;
  --accent: #d4351c;
  --accent-soft: #fbe7e3;
  --gold: #e8a700;
  --good: #2f9e44;
  --good-soft: #e3f4e6;
  --bad: #d4351c;
  --masc: #2b6cb0;
  --fem: #c2255c;
  --neut: #2f9e44;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --card: #1f1f21;
    --text: #f2f2f3;
    --muted: #9a9aa1;
    --line: #2e2e31;
    --accent: #ff5a3c;
    --accent-soft: #3a1f19;
    --good: #51cf66;
    --good-soft: #1b3320;
    --bad: #ff6b5a;
    --masc: #74a9f0;
    --fem: #f783ac;
    --neut: #69db7c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-top: calc(env(safe-area-inset-top) + 52px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 76px);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h2 { margin: 0 0 8px; font-size: 20px; }

/* header + tabs */
.top {
  position: fixed; inset: 0 0 auto; z-index: 10;
  padding: env(safe-area-inset-top) 12px 0;
  height: calc(env(safe-area-inset-top) + 52px);
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; display: grid; place-items: center; font-size: 20px; border-radius: 12px; cursor: pointer; }
.icon-btn.back { font-size: 32px; line-height: 1; margin-left: -6px; }
.tabs {
  position: fixed; inset: auto 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabs .ti { font-size: 20px; height: 26px; line-height: 26px; font-weight: 700; }
.tabs a.active { color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

/* building blocks */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; border: 1px solid var(--line); }
.card.list { padding: 0; overflow: hidden; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.sec small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.sec.level { display: flex; align-items: center; gap: 8px; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); }
.sec.level small { margin-left: auto; color: var(--muted); font-size: 13px; }
.lvl {
  display: inline-grid; place-items: center; min-width: 34px; height: 24px; padding: 0 6px; margin-right: 8px;
  border-radius: 7px; font-size: 13px; font-weight: 800; color: #fff; background: var(--muted); vertical-align: 3px;
}
.sec.level .lvl { margin-right: 0; vertical-align: 0; }
.lvl-A1 { background: #2f9e44; }
.lvl-A2 { background: #1c7ed6; }
.lvl-B1 { background: #e8a700; }
.lvl-B2 { background: #d4351c; }
.intro { color: var(--muted); margin: 0 4px 14px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 24px; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer;
}
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); margin-top: 24px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:active { transform: scale(.98); }
.link { display: block; margin: 14px auto 0; border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 14px; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row.locked { opacity: .55; }
.rank { width: 28px; flex: none; text-align: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 22px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--line); }
.dot.learning { background: var(--gold); }
.dot.known { background: var(--good); }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 99px; transition: width .3s; }
.bar.slim { height: 4px; margin-bottom: 8px; }

.hero-num { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.hero-num b { font-size: 44px; line-height: 1; }
.hero-num span { color: var(--muted); }
.hero-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 8px 0 4px; }

.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 0; border-radius: 8px; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 10px; font-size: 16px; }

/* gender colours */
.g-n-m { color: var(--masc); }
.g-n-f { color: var(--fem); }
.g-n-n { color: var(--neut); }

/* flashcards */
.flash { position: relative; min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; cursor: pointer; }
.flash.revealed { cursor: default; }
.flash .say { position: absolute; top: 10px; right: 10px; }
.flash-de { font-size: 38px; font-weight: 700; line-height: 1.15; word-break: break-word; }
.flash-en { font-size: 22px; margin-top: 10px; }
.flash .tap { margin-top: 12px; }
.forms { color: var(--muted); font-size: 14px; margin-top: 8px; }
.tag { position: absolute; top: 14px; left: 14px; font-size: 12px; color: var(--muted); background: var(--line); padding: 3px 8px; border-radius: 99px; }
.tag.new { background: var(--accent-soft); color: var(--accent); }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grades .again { color: var(--bad); }
.grades .good { background: var(--good); border-color: var(--good); color: #fff; }
.grades .easy { color: var(--good); }
.done { text-align: center; }
.big-emoji { font-size: 48px; }

/* sentences & tappable words */
.sent { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sent:last-child { border-bottom: 0; }
.sent-row { display: flex; gap: 8px; align-items: flex-start; }
.sent .de { flex: 1; margin: 0; font-size: 18px; line-height: 1.6; }
.sent .en { display: none; margin: 4px 0 0; color: var(--muted); font-size: 15px; font-style: italic; }
.sent.open .en { display: block; }
.sent.open .tr { background: var(--accent-soft); color: var(--accent); }
.sent-tools { display: flex; gap: 4px; flex: none; }
.mini { border: 1px solid var(--line); background: var(--card); border-radius: 8px; min-width: 34px; height: 30px; font-size: 12px; font-weight: 700; cursor: pointer; }
.w { cursor: pointer; border-bottom: 1px dotted transparent; border-radius: 3px; }
.w:hover, .w:active { background: var(--accent-soft); }
.w.unk { border-bottom-color: var(--gold); }
.name { font-weight: 600; }
.story h2 { margin-bottom: 4px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }

/* grammar */
.lesson-title { font-size: 26px; margin: 4px 4px 12px; }
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 6px 0 12px; font-size: 15px; }
.prose td, .prose th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { color: var(--muted); font-weight: 600; font-size: 13px; }
.prose b { color: var(--accent); }
.quiz .q { font-weight: 600; margin: 0 0 10px; font-size: 17px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; cursor: pointer; text-align: left; }
.opt.right { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 600; }
.opt.wrong { background: var(--accent-soft); border-color: var(--bad); color: var(--bad); animation: shake .3s; }
.why { margin: 10px 0 0; color: var(--good); font-size: 14px; }
.done-note { color: var(--good); font-weight: 600; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* lock note */
.lock-note .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 4px 10px; font-size: 14px; cursor: pointer; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bubble { max-width: 88%; padding: 6px 12px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); }
.bubble.them { align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.you { align-self: flex-end; background: var(--accent-soft); border-color: transparent; border-bottom-right-radius: 6px; }
.bubble .sent { border: 0; padding: 4px 0; }
.bubble .de { font-size: 17px; }
.reply-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; flex-wrap: wrap; }
.reply-head span:last-child { display: flex; gap: 6px; }
.reply-opt { display: flex; flex-direction: column; width: 100%; margin-bottom: 8px; font-size: 17px; }
.reply-opt small { color: var(--muted); font-size: 13px; }
.feedback { color: var(--bad); font-size: 14px; margin: 4px 0 0; }

/* settings */
.form label { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.form label:last-child { border-bottom: 0; }
.form select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
textarea { width: 100%; margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px; font-size: 13px; }

/* bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 640px; margin: 0 auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
  animation: up .2s ease-out;
}
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-de { font-size: 30px; font-weight: 700; }
.sheet-en { font-size: 19px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }
.status { font-weight: 600; }
.status.known { color: var(--good); }
.status.learning { color: var(--gold); }
@keyframes up { from { transform: translateY(100%); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(env(safe-area-inset-bottom) + 86px);
  max-width: calc(100% - 32px); width: max-content;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
}
[hidden] { display: none !important; }

/* ---------- native-feel layer ---------- */
html { -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; overscroll-behavior-y: none; }
button, .btn, .row, .tabs a, .opt, .chip, .seg, .icon-btn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ic { display: block; flex: none; }
.icon-btn { color: var(--accent); }
.tabs .ti { height: 26px; display: grid; place-items: center; }
.tabs a.active .ic { stroke-width: 2.4; }

/* iOS large title: page heading collapses into the bar on scroll */
.large-title { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 2px 4px 14px; }
body.has-large .top h1 { opacity: 0; transition: opacity .15s; }
body.has-large.scrolled .top h1 { opacity: 1; }
.top { border-bottom-color: transparent; transition: border-color .15s, background .15s; }
body.scrolled .top, body:not(.has-large) .top { border-bottom-color: var(--line); }
.top h1 { text-align: center; position: absolute; left: 56px; right: 56px; }
.top .icon-btn:last-child { margin-left: auto; }

/* page transitions + press feedback */
#view.enter { animation: pageIn .22s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } }
.row:active, .opt:active, .chip:active { background: var(--line); }
.btn, .row, .opt { transition: transform .08s, background .12s; }
.btn.big { min-height: 52px; font-size: 17px; border-radius: 14px; }

/* home */
.banner { display: flex; align-items: center; gap: 12px; color: var(--text); background: var(--accent-soft); border-color: transparent; }
.banner .ic { color: var(--accent); }
.banner span { flex: 1; display: flex; flex-direction: column; }
.banner small { color: var(--muted); font-size: 13px; }
.hero-top { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.hero-text { flex: 1; min-width: 0; }
.hero-num { margin-bottom: 4px; }
.hero-meta { margin: 0; align-items: center; }
.goal { position: relative; width: 64px; height: 64px; flex: none; }
.goal-num { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 16px; line-height: 1; }
.goal-num small { font-size: 10px; color: var(--muted); font-weight: 600; display: block; text-align: center; }
.ring { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--accent); transition: stroke-dashoffset .5s; }
.streak { display: inline-flex; align-items: center; gap: 3px; color: #f08c00; font-weight: 700; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.level-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.level-card .lvl { margin: 0; align-self: flex-start; }
.level-card small { font-size: 12px; }
.level-card .bar { margin: 2px 0 0; }

/* lists */
.rank { display: grid; place-items: center; height: 28px; }
.rank.tint { color: var(--accent); }
.row.locked .rank { color: var(--muted); }
.badge-done { width: 24px; height: 24px; border-radius: 50%; background: var(--good); color: #fff; display: grid; place-items: center; }
.chev { color: var(--muted); display: grid; place-items: center; }
.lock-ic { color: var(--muted); margin-bottom: 4px; }
.mini { display: inline-grid; place-items: center; }
.toolbar .btn, .row-btns .btn, .reply-head .btn { gap: 6px; }

/* flashcard reveal */
.flash.revealed .flash-en, .flash.revealed .forms { animation: pageIn .2s ease-out; }
.flash .say { color: var(--accent); }

/* settings: data */
.storage-row { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.storage-row .ic { color: var(--good); margin-top: 2px; }
.storage-row div { display: flex; flex-direction: column; gap: 2px; }
.small-print { font-size: 13px; margin: 12px 0 0; }
label.btn { cursor: pointer; }

/* sync */
.steps { margin: 6px 0 12px; padding-left: 22px; font-size: 15px; }
.steps li { margin-bottom: 6px; }
.steps a { color: var(--accent); font-weight: 600; }
.token-row { display: flex; gap: 8px; }
.token-row input { flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
#sync-card .storage-row .ic { color: var(--accent); }
.sync-ok { color: var(--good) !important; }
.sync-error { color: var(--bad) !important; }
.btn[disabled] { opacity: .5; }
.token-form { display: flex; flex-direction: column; gap: 8px; }
.token-form input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
