:root {
  --bg: #fdf6ef;
  --surface: #ffffff;
  --surface-2: #f5ece2;
  --ink: #23201d;
  --ink-soft: #7a706a;
  --line: #e5d9cc;
  --accent: #c8442b;
  --accent-soft: #fbe6e0;
  --gold: #d99518;
  --radius: 18px;
  --shadow: 0 2px 4px rgba(35, 32, 29, .05), 0 10px 28px rgba(35, 32, 29, .09);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151a;
    --surface: #221f26;
    --surface-2: #2b272f;
    --ink: #f2ede8;
    --ink-soft: #a49c96;
    --line: #363039;
    --accent: #ff7a5c;
    --accent-soft: #3a2320;
    --gold: #f0b544;
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .38);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; line-height: 1.2; }
.sub { margin: 4px 0 0; color: var(--ink-soft); font-size: .85rem; }
.empty { color: var(--ink-soft); text-align: center; padding: 2rem 1rem; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem
           max(1.25rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* ── Deck list ───────────────────────────────────────────── */
.home-head { margin-bottom: 1.5rem; }
.home-head h1 { font-size: 1.6rem; letter-spacing: -.02em; }
.deck-list { display: flex; flex-direction: column; gap: .75rem; }
.deck {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.deck:active { transform: scale(.985); }
.deck:hover { border-color: var(--accent); }
.deck-name { font-weight: 650; font-size: 1.02rem; }
.deck-meta { color: var(--ink-soft); font-size: .8rem; margin-top: 2px; }
.deck-count {
  margin-left: auto;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 700;
  padding: .3rem .6rem;
  border-radius: 999px;
}

/* ── Study header ────────────────────────────────────────── */
.study-head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.head-mid { flex: 1; min-width: 0; }
.head-mid h2 { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.star.on { color: var(--gold); border-color: var(--gold); }

/* ── Progress ────────────────────────────────────────────── */
.progress-wrap { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s ease; }
.counter { margin: 0; font-size: .8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; flex: none; }

/* ── Card ────────────────────────────────────────────────── */
.card {
  perspective: 1400px;
  height: clamp(240px, 42vh, 340px);
  margin-bottom: 1.1rem;
  cursor: pointer;
  outline: none;
  touch-action: pan-y;
}
.card-inner {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .8, .3, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card:focus-visible .card-inner { box-shadow: 0 0 0 3px var(--accent); border-radius: var(--radius); }
.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); background: var(--surface-2); }
.lang {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.word {
  margin: 0;
  font-size: clamp(1.7rem, 8vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -.02em;
  text-align: center;
  text-wrap: balance;
}
.note { margin: 0; font-size: .9rem; color: var(--ink-soft); text-align: center; font-style: italic; }
.hint { font-size: .75rem; color: var(--ink-soft); opacity: .75; }

/* ── Nav + tools ─────────────────────────────────────────── */
.nav { display: flex; gap: .6rem; margin-bottom: 1rem; }
.nav-btn {
  flex: none;
  width: 58px; height: 52px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
}
.nav-btn:active { background: var(--surface-2); }
.nav-btn:disabled { opacity: .35; cursor: default; }
.flip-btn {
  flex: 1;
  width: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 650;
}
.tools { display: flex; flex-wrap: wrap; gap: .5rem; }
.tool {
  flex: 1;
  min-width: 104px;
  padding: .6rem .5rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
}
.tool.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .card-inner, #progress-fill, .deck { transition: none; }
}
