/* Popdeck — "cute but calm" (spec §9). Tokens first; everything else reads from them. */

:root {
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F1EA;
  --ink: #24222E;
  --muted: #6E6A7C;
  --line: #E8E4DA;
  --zh: #E8634A;
  --ko: #4F8FE0;
  --ja: #D96A9A;
  --pop: #F5B83D;
  --pop-soft: rgba(245, 184, 61, .18);
  --good: #3F9C6B;
  --kernel: #FFF4DA;
  --accent: var(--zh);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(36, 34, 46, .06), 0 8px 24px rgba(36, 34, 46, .06);
  --ui: "Nunito", "M PLUS Rounded 1c", system-ui, -apple-system, sans-serif;
  --target: "Noto Sans SC", "Noto Sans KR", "Noto Sans JP", "PingFang SC", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17161C; --surface: #221F29; --surface-2: #2A2632; --ink: #EEEAF4; --muted: #A29DB0;
    --line: #36313F; --zh: #FF8770; --ko: #7DB0FF; --ja: #F291BC; --pop: #FFCB5C;
    --pop-soft: rgba(255, 203, 92, .14); --good: #6CC896; --kernel: #FFF1CF;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17161C; --surface: #221F29; --surface-2: #2A2632; --ink: #EEEAF4; --muted: #A29DB0;
  --line: #36313F; --zh: #FF8770; --ko: #7DB0FF; --ja: #F291BC; --pop: #FFCB5C;
  --pop-soft: rgba(255, 203, 92, .14); --good: #6CC896; --kernel: #FFF1CF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

[data-lang="ko"] { --accent: var(--ko); }
[data-lang="ja"] { --accent: var(--ja); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.target { font-family: var(--target); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ── layout ── */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; text-decoration: none; }
.brand svg, .brand img, #brand-pop { width: 30px; height: 30px; display: inline-block; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 700; font-size: 15px;
}
.nav a.active, .nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav .badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
main { max-width: 860px; margin: 0 auto; padding: 28px 20px 80px; }
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; gap: 8px; }
  .nav a { padding: 6px 8px; font-size: 14px; }
  .brand span:last-child { display: none; }
  main { padding: 20px 16px 80px; }
}

h1 { font-size: 30px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.01em; }
h2 { font-size: 21px; margin: 0 0 12px; }
h3 { font-size: 17px; margin: 0 0 8px; }
p { margin: 0 0 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }

/* ── controls ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  border-radius: 999px; padding: 11px 22px; font-weight: 800; font-size: 16px; text-decoration: none;
  background: var(--surface-2); color: var(--ink); transition: transform .12s ease, background .12s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.pop { background: var(--pop); color: #2B2210; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.small { padding: 6px 14px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }
.btn.block { width: 100%; }

label.field { display: block; font-weight: 700; font-size: 14px; }
label.field > span { display: block; margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 12px; font-weight: 600;
}
textarea { min-height: 120px; resize: vertical; font-family: var(--target); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px;
  cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.chip[disabled] { opacity: .55; cursor: default; }
.chip .soon { font-size: 11px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.lang-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.toggle input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(18px); }

/* ── upload ── */
.drop {
  display: block;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: var(--radius);
  padding: 34px 20px; text-align: center; background: var(--accent-soft); cursor: pointer; transition: background .15s, transform .15s;
}
.drop.over { transform: scale(1.01); background: color-mix(in srgb, var(--accent) 22%, transparent); }
.drop strong { font-size: 18px; }
.drop input { display: none; }
.file-picked { font-weight: 800; }

/* ── usage pill ── */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  background: var(--pop-soft); font-weight: 700; font-size: 14px;
}

/* ── coverage hero ── */
.hero { text-align: center; padding: 28px 22px; position: relative; z-index: 2; }
.hero .pop-wrap { width: 96px; height: 96px; margin: 0 auto 8px; position: relative; }
.hero .big { font-size: 22px; font-weight: 700; }
.hero .big b { font-size: 46px; color: var(--accent); display: inline-block; min-width: 2.4ch; font-variant-numeric: tabular-nums; }
.meter { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; position: relative; max-width: 460px; margin: 16px auto 6px; }
.meter > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: inherit; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.meter > .target-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .35; }
.meter-labels { display: flex; justify-content: space-between; max-width: 460px; margin: 0 auto; font-size: 12px; color: var(--muted); font-weight: 700; }

/* ── word list ── */
.words { list-style: none; margin: 0; padding: 0; }
.word {
  display: grid; grid-template-columns: minmax(92px, auto) 1fr auto; gap: 4px 16px; align-items: center;
  padding: 14px 4px; border-bottom: 1px solid var(--line); transition: opacity .2s, transform .2s;
}
.word:last-child { border-bottom: 0; }
.word .w { font-family: var(--target); font-size: 26px; line-height: 1.1; }
.word .r { font-size: 13px; color: var(--muted); display: block; }
.word .m { font-size: 15px; }
.word .ex { font-family: var(--target); font-size: 14px; color: var(--muted); margin-top: 2px; }
.word .note { font-size: 13px; font-style: italic; color: var(--muted); }
.word .meta { font-size: 12px; color: var(--muted); font-weight: 700; }
.word .acts { display: flex; gap: 6px; }
.word.removed, .word.known { opacity: .45; }
.word.known .w::after { content: " ✓"; color: var(--good); font-size: 18px; }
.word.leaving { transform: translateX(14px); opacity: 0; }
.icon-btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; height: 34px; padding: 0 12px;
  font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.ok:hover { border-color: var(--good); color: var(--good); }
@media (max-width: 600px) {
  .word { grid-template-columns: 1fr auto; }
  .word .body { grid-column: 1 / -1; grid-row: 2; }
}

.tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.lvl { background: var(--accent-soft); color: var(--accent); }

/* ── export menu ── */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 240px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 6px;
}
.menu-list button, .menu-list a {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; text-decoration: none; font-weight: 700;
}
.menu-list button:hover, .menu-list a:hover { background: var(--surface-2); }
.menu-list small { display: block; font-weight: 600; color: var(--muted); }

/* ── study ── */
.study { max-width: 520px; margin: 0 auto; }
.flip { perspective: 1200px; height: 360px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .3s cubic-bezier(.3, 1.4, .5, 1); transform-style: preserve-3d; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; box-shadow: var(--shadow);
}
.face.back { transform: rotateY(180deg); }
.face .w { font-family: var(--target); font-size: 56px; line-height: 1.15; }
.face .r { color: var(--muted); font-size: 18px; min-height: 26px; }
.face .m { font-size: 19px; margin: 10px 0; }
.face .ex { font-family: var(--target); font-size: 18px; background: var(--pop-soft); border-radius: 12px; padding: 8px 14px; margin-top: 6px; }
.face .note { font-size: 14px; font-style: italic; color: var(--muted); margin-top: 8px; }
.face .hint { position: absolute; bottom: 14px; font-size: 13px; color: var(--muted); }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.ratings .btn { flex-direction: column; gap: 0; padding: 10px 6px; border-radius: 14px; }
.ratings .btn small { font-weight: 600; font-size: 11px; opacity: .75; }
.rate-1 { background: color-mix(in srgb, var(--zh) 18%, var(--surface)); }
.rate-2 { background: color-mix(in srgb, var(--pop) 22%, var(--surface)); }
.rate-3 { background: color-mix(in srgb, var(--good) 20%, var(--surface)); }
.rate-4 { background: color-mix(in srgb, var(--ko) 20%, var(--surface)); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ── library ── */
.show-group h3 { display: flex; align-items: center; gap: 8px; }
.deck-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  text-decoration: none; border: 1px solid var(--line); background: var(--surface); margin-bottom: 8px;
}
.deck-row:hover { border-color: var(--accent); }
.deck-row .cov { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

/* ── pricing ── */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.plan { text-align: center; }
.plan.best { border: 2px solid var(--accent); }
.plan .price { font-size: 32px; font-weight: 800; }
.plan ul { text-align: left; padding-left: 20px; margin: 12px 0 18px; }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 700; transition: all .2s; z-index: 50; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Pop the mascot ── */
.pop-svg { width: 100%; height: 100%; overflow: visible; }
.pop-svg .kernel { fill: var(--kernel); stroke: #3A3344; stroke-width: 2.4; }
.pop-svg .butter { fill: var(--pop); }
.pop-svg .eye { fill: #2B2533; }
.pop-svg .cheek { fill: #F7A38E; opacity: .55; }
.pop-svg .mouth { fill: none; stroke: #2B2533; stroke-width: 2.4; stroke-linecap: round; }
.pop-svg .pan { fill: #5B5468; }
.pop-svg .flag-pole { stroke: #5B5468; stroke-width: 2.5; }
.pop-svg .flag { fill: var(--accent); }
.pop-svg .zz { fill: var(--muted); font: 800 14px var(--ui); }
.pop-svg .q { fill: var(--accent); font: 900 20px var(--ui); }

.pop-wiggle .body { animation: wiggle .7s ease-in-out infinite; transform-origin: 50px 70px; }
.pop-bounce .body { animation: bounce .4s cubic-bezier(.3, 1.6, .5, 1) 1; transform-origin: 50px 85px; }
.pop-sleep .body { animation: breathe 3s ease-in-out infinite; transform-origin: 50px 85px; }
.pop-flag .flag-g { animation: flag .6s ease-out 1; transform-origin: 70px 60px; }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(6deg) translateY(-4px); } }
@keyframes bounce { 0% { transform: scale(1, 1); } 30% { transform: scale(1.15, .85) translateY(4px); } 60% { transform: scale(.92, 1.1) translateY(-14px); } 100% { transform: scale(1); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03, .97); } }
@keyframes flag { 0% { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.15) rotate(4deg); } 100% { transform: scale(1); } }

.bowl { width: 220px; height: 16px; border-radius: 0 0 999px 999px; background: var(--surface-2); margin: 10px auto 0; overflow: hidden; border: 2px solid var(--line); border-top: 0; }
.bowl > i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--kernel) 0 10px, var(--pop) 10px 13px); transition: width .4s; }

.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i {
  position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; border-radius: 45% 55% 50% 50%;
  background: var(--kernel); border: 2px solid var(--pop); animation: kernel .9s cubic-bezier(.2, .7, .4, 1) forwards;
}
@keyframes kernel {
  0% { transform: translate(-50%, -50%) scale(.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1); opacity: 0; }
}

.fade-in { animation: fadeUp .18s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .confetti { display: none; }
}

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 16px 40px; }
.footer a { color: var(--muted); }
.legal { max-width: 720px; margin: 0 auto; line-height: 1.6; }
.legal h2 { margin: 12px 0 0; font-size: 18px; }
.legal ul { padding-left: 20px; margin: 0; }

/* ── deck screen v2: toolbar, selectable rows, export sheet ── */
.deck-hero { padding: 20px 22px; }
.deck-hero .big { margin: 2px 0 0; }
.deck-hero .big b { font-size: 40px; }
.small-pop { width: 64px !important; height: 64px !important; margin-bottom: 2px !important; }
.btn.disabled { opacity: .5; }

.toolbar { position: sticky; top: 58px; z-index: 5; padding: 14px 16px; display: grid; gap: 10px; }
.tool-row { gap: 10px; }
.tool-row input[type="search"] { flex: 1; min-width: 180px; }
.tool-row select { width: auto; }
.small-chip { padding: 4px 12px; font-size: 13px; }
.toggle.small { font-size: 14px; gap: 8px; }
.toggle.small input { width: 34px; height: 20px; }
.toggle.small input::after { width: 14px; height: 14px; }
.toggle.small input:checked::after { transform: translateX(14px); }
.select-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; font-size: 14px; }
.check-all { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.link-btn { background: none; border: 0; padding: 4px 8px; border-radius: 8px; font-weight: 800; font-size: 13px; color: var(--accent); cursor: pointer; }
.link-btn:hover { background: var(--accent-soft); }
input[type="checkbox"].pick, #check-all { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }

#words { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
#words .word {
  grid-template-columns: 22px 30px minmax(84px, auto) 1fr auto; padding: 12px 16px; cursor: pointer;
  border-left: 3px solid transparent; user-select: none;
}
#words .word:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
#words .word.is-selected { background: var(--accent-soft); border-left-color: var(--accent); }
#words .word.is-known .w, #words .word.is-known .m { opacity: .6; }
#words .word.is-known .w::after { content: none; }
.word .head { display: flex; flex-direction: column; }
.play {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface);
  font-size: 11px; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 0 0 0 2px;
}
.play:hover { border-color: var(--accent); color: var(--accent); }
.known-pill { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; border: 0; background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); cursor: pointer; white-space: nowrap; }
.known-pill.soft { background: var(--surface-2); color: var(--muted); cursor: default; }
.freq { display: inline-block; width: 46px; height: 5px; border-radius: 99px; background: var(--surface-2); vertical-align: middle; margin: 0 4px 0 6px; overflow: hidden; }
.freq i { display: block; height: 100%; background: var(--pop); border-radius: inherit; }
.word .meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .toolbar { position: static; }
  .tool-row { flex-wrap: nowrap; }
  .tool-row input[type="search"] { min-width: 0; }
  .tool-row select { max-width: 42%; }
  #words .word { grid-template-columns: 22px 30px 1fr auto; padding: 12px; }
  #words .word .body { grid-column: 3 / -1; grid-row: 2; }
  #words .word .acts { grid-column: 4; grid-row: 1; }
}

.toast.interactive { pointer-events: auto; }
.toast-undo { background: none; border: 0; color: var(--pop); font-weight: 900; cursor: pointer; padding: 0 0 0 6px; }

dialog.sheet {
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface); color: var(--ink); padding: 22px;
  width: min(560px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet::backdrop { background: rgba(20, 18, 28, .45); }
dialog.sheet[open] { animation: fadeUp .18s ease-out; }
dialog.sheet fieldset { border: 0; padding: 0; margin: 0; }
dialog.sheet legend { font-weight: 800; font-size: 14px; margin-bottom: 8px; padding: 0; }
.layouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.layout { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: pointer; display: grid; gap: 6px; }
.layout.on { border-color: var(--accent); background: var(--accent-soft); }
.layout input { position: absolute; opacity: 0; pointer-events: none; }
.pv { display: flex; align-items: center; gap: 8px; }
.pv-face { flex: 1; min-height: 52px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; text-align: center; }
.pv-word { font-family: var(--target); font-size: 20px; line-height: 1.1; }
.pv-reading { font-size: 11px; color: var(--muted); }
.pv-meaning { font-size: 11px; line-height: 1.2; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-arrow { color: var(--muted); font-weight: 800; }
.layout-label { font-size: 13px; font-weight: 700; }
.export-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.export-actions .btn { flex-direction: column; gap: 0; padding: 10px 6px; border-radius: 14px; }
.export-actions .btn small { font-size: 11px; font-weight: 600; opacity: .75; }
@media (max-width: 480px) { .export-actions { grid-template-columns: repeat(2, 1fr); } }
.big-play { width: 40px; height: 40px; font-size: 14px; margin: 2px auto 4px; }

/* ── study v2: sound on both faces, display options ── */
.face { gap: 4px; }
.face-play { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; font-size: 17px; padding: 0; }
.face .w-small { font-size: 34px; opacity: .85; }
.face .m-big { font-size: 24px; font-weight: 700; max-width: 90%; }
.face .divider { width: 48px; height: 2px; background: var(--line); border-radius: 2px; margin: 8px 0; }
.face .lvl-line { margin-top: 8px; }
.flip { outline: none; }
.flip:focus-visible .face { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }
#study-options .chips .chip { cursor: pointer; }
.flip:not(.flipped) .face.back, .flip.flipped .face.front { pointer-events: none; }
.flip:not(.flipped) .face.front, .flip.flipped .face.back { pointer-events: auto; }
dialog.sheet fieldset + fieldset { margin-top: 18px; }

/* ── study modes ── */
.mode-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.mode-tab { border: 0; background: transparent; border-radius: 999px; padding: 8px 6px; font: 800 13px var(--ui); color: var(--muted); cursor: pointer; }
.mode-tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.swipe-wrap { position: relative; transition: transform .2s ease, opacity .18s ease; touch-action: pan-y; --lean: 0; }
.swipe-tint {
  position: absolute; top: 18px; z-index: 3; padding: 4px 12px; border-radius: 999px; font-weight: 900; font-size: 13px;
  border: 2px solid currentColor; opacity: 0; pointer-events: none; transition: opacity .1s;
}
.swipe-tint.left { left: 18px; color: var(--zh); transform: rotate(-8deg); }
.swipe-tint.right { right: 70px; color: var(--good); transform: rotate(8deg); }
.swipe-wrap[data-lean="left"] .swipe-tint.left, .swipe-wrap[data-lean="right"] .swipe-tint.right { opacity: var(--lean); }
.swipe-wrap[data-lean="left"] .face { box-shadow: 0 0 0 3px color-mix(in srgb, var(--zh) calc(var(--lean) * 60%), transparent), var(--shadow); }
.swipe-wrap[data-lean="right"] .face { box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) calc(var(--lean) * 60%), transparent), var(--shadow); }
.flip { touch-action: pan-y; user-select: none; }
.sort-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sort-btns .btn { border-radius: 14px; padding: 13px 10px; }
.sort-left { background: color-mix(in srgb, var(--zh) 16%, var(--surface)); }
.sort-right { background: color-mix(in srgb, var(--good) 18%, var(--surface)); }
.sort-btns b { font-variant-numeric: tabular-nums; opacity: .7; margin: 0 2px; }
@media (max-width: 480px) { .mode-tab { font-size: 12px; padding: 8px 4px; } }

/* short meaning + optional full definition */
.more-btn { background: none; border: 0; padding: 0 2px; font: 800 12px var(--ui); color: var(--accent); cursor: pointer; }
.word .def { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.face .def { font-size: 13px; color: var(--muted); max-width: 90%; margin-top: 4px; line-height: 1.4; }

/* library */
.lib-tabs { grid-template-columns: 1fr 1fr; max-width: 360px; }
.lib-tabs .mode-tab { text-align: center; text-decoration: none; }
.lib-row { cursor: default; }
.lib-row:hover { border-color: var(--line); }
.preview-note { display: grid; gap: 4px; padding: 14px 18px; border-left: 4px solid var(--pop); }
/* very narrow screens: keep the nav inside the page */
.topbar { min-width: 0; }
.nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex-shrink: 0; }
main { overflow-wrap: anywhere; }
@media (max-width: 380px) { .nav a { padding: 6px 6px; font-size: 13px; } .topbar { gap: 6px; padding: 10px 12px; } }

/* share to library: a quiet ↑ on each of your decks */
.deck-row.has-actions { padding: 0; gap: 0; }
.deck-row .deck-link { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 6px 12px 14px; text-decoration: none; min-width: 0; }
.share-btn {
  flex-shrink: 0; width: 34px; height: 34px; margin-right: 8px; border-radius: 50%; border: 1.5px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 0; opacity: .55;
  transition: opacity .15s, border-color .15s, color .15s;
}
.share-btn svg { width: 17px; height: 17px; }
.deck-row:hover .share-btn, .share-btn:focus-visible { opacity: 1; border-color: var(--line); }
.share-btn:hover { color: var(--accent); border-color: var(--accent) !important; }
.share-btn.shared { opacity: 1; color: #fff; background: var(--accent); }
.share-btn.shared_by_other { opacity: .8; color: var(--accent); }
.share-sheet { width: min(420px, calc(100vw - 24px)); }
.share-sheet h2 { margin: 0; }
.share-sheet p { margin: 0; }
.share-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 14px; }
.share-list span { display: inline-block; min-width: 62px; font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.share-list .yes { color: var(--good); }
.share-list .no { color: var(--muted); }
.deck-row .cov { white-space: nowrap; }

/* ── make page: subtitles first (2/3), import + scratch stacked (1/3) ── */
.icon { width: 22px; height: 22px; display: block; }
.make-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: stretch; }
.make-main { margin: 0; }
.make-main .drop { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 230px; }
.make-main.stack { display: flex; flex-direction: column; }
.make-side { display: grid; grid-template-rows: 1fr 1fr; gap: 16px; }
.make-tile { display: flex; flex-direction: column; justify-content: center; gap: 10px; text-decoration: none; padding: 18px; transition: border-color .15s, transform .15s; }
.make-tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.make-tile strong { display: block; font-size: 16px; }
.make-tile .muted { display: block; line-height: 1.35; margin-top: 2px; }
.tile-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
@media (max-width: 720px) {
  .make-grid { grid-template-columns: 1fr; }
  .make-side { grid-template-rows: none; grid-template-columns: 1fr 1fr; gap: 12px; }
  .make-main .drop { min-height: 180px; }
  .make-tile { padding: 14px; }
}
@media (max-width: 400px) { .make-side { grid-template-columns: 1fr; } .make-tile { flex-direction: row; align-items: center; } }

/* import + scratch flows */
.make-flow { max-width: 720px; margin: 0 auto; }
.back-link { padding: 0; align-self: flex-start; text-decoration: none; }
.flow-head { display: flex; gap: 14px; align-items: center; }
.imp-text { min-height: 150px; font-family: var(--target); }
.file-btn { cursor: pointer; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .config-grid { grid-template-columns: 1fr; } }
.config-label { font-weight: 800; font-size: 13px; margin-bottom: 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sep-input { width: 70px !important; padding: 4px 8px !important; border-radius: 999px !important; font-size: 13px !important; }
.imp-table-wrap { overflow-x: auto; margin: 0 -4px; }
.imp-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.imp-table th { text-align: left; padding: 0 4px 8px; }
.imp-table th select { padding: 4px 8px; font-size: 13px; width: 100%; min-width: 96px; }
.imp-table td { padding: 7px 8px; border-top: 1px solid var(--line); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-table td.target { font-size: 17px; }
.imp-table td.skip { opacity: .35; }
.warn { color: var(--zh); margin: 0; }
.create-row { gap: 10px; flex-wrap: nowrap; }
.create-row input { flex: 1; min-width: 0; }
.scratch { padding: 12px 14px; }
.scratch-head, .scratch-row { display: grid; grid-template-columns: 1fr 1fr 2fr 32px; gap: 8px; align-items: center; }
.scratch-head { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 0 4px 6px; }
.scratch-row { padding: 4px 0; }
.scratch-row input { padding: 8px 10px; }
.scratch-row input.target { font-size: 18px; }
.scratch-row.unknown input.target { border-color: color-mix(in srgb, var(--pop) 60%, var(--line)); }
.icon-only { width: 32px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; display: grid; place-items: center; padding: 0; }
.icon-only .icon { width: 16px; height: 16px; }
.icon-only:hover { background: var(--surface-2); color: var(--ink); }
#add-row { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
#add-row .icon { width: 16px; height: 16px; }
@media (max-width: 600px) {
  .scratch-head { display: none; }
  .scratch-row { grid-template-columns: 1fr 1fr 32px; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .scratch-row [data-f="meaning"] { grid-column: 1 / 3; }
}

/* custom decks: no episode coverage */
.deck-hero.is-custom .big, .deck-hero.is-custom .meter, .deck-hero.is-custom #to-target, .deck-hero.is-custom #hero-pop, .deck-hero.is-custom > p.muted:not(.small) { display: none; }
.custom-title { font-size: 26px; margin: 0; }
.btn .icon { width: 16px; height: 16px; }
.scratch-row input, .scratch-row > * { min-width: 0; width: 100%; }

/* ── study: sidebar beside the cards (wide), drawer (narrow) ── */
main:has(.study-layout) { max-width: 1060px; }
.study-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 32px; align-items: start; }
.study-main .study { margin: 0 auto; }
.study-side { position: sticky; top: 78px; display: grid; gap: 22px; }
.side-block { display: grid; gap: 2px; }
.side-label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 10px 4px; }
.side-label .icon-only { width: 26px; height: 26px; }
.side-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 10px;
  text-decoration: none; font-weight: 700; font-size: 14px; color: var(--ink);
}
.side-item:hover { background: var(--surface-2); }
.side-item.on { background: var(--accent-soft); color: var(--accent); }
.side-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.side-item .due { font-size: 12px; font-weight: 800; color: #fff; background: var(--accent); border-radius: 999px; padding: 1px 7px; }
.side-more { display: none; }
.study-side.all-decks .side-more { display: grid; gap: 2px; }
.study-side.all-decks .side-show-all { display: none; }
.side-show-all { justify-self: start; margin-left: 4px; }
.mini-bar { width: 44px; height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; flex-shrink: 0; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.side-progress { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; gap: 8px; box-shadow: var(--shadow); }
.side-title { font-weight: 800; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.side-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s; }
.side-learned { font-size: 13px; color: var(--muted); }
.side-learned b { color: var(--ink); }
.side-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 0; }
.side-stats div { background: var(--surface-2); border-radius: 10px; padding: 6px 8px; }
.side-stats dt { font-size: 11px; color: var(--muted); font-weight: 700; }
.side-stats dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }
.side-progress .link-btn { justify-self: start; padding-left: 0; }
.side-empty {
  display: flex; align-items: center; gap: 10px; text-align: left; border: 1.5px dashed var(--line); background: none; border-radius: 12px;
  padding: 10px 12px; cursor: pointer; color: var(--ink); font: 700 14px var(--ui);
}
.side-empty:hover { border-color: var(--accent); color: var(--accent); }
.side-empty small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }
.scope-btn { display: none; }

@media (max-width: 900px) {
  .study-layout { grid-template-columns: 1fr; }
  .study-layout > .study-side { display: none; }
  .scope-btn {
    display: inline-flex; align-items: center; gap: 8px; max-width: 100%; margin-bottom: 10px; border: 1.5px solid var(--line);
    background: var(--surface); border-radius: 999px; padding: 6px 14px 6px 10px; font: 800 14px var(--ui); color: var(--ink); cursor: pointer;
  }
  .scope-btn .icon { width: 18px; height: 18px; color: var(--muted); }
  .scope-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

dialog.drawer {
  margin: 0 auto 0 0; height: 100dvh; max-height: 100dvh; width: min(320px, 88vw); border: 0; border-radius: 0 20px 20px 0;
  padding: 16px; background: var(--bg); color: var(--ink); box-shadow: 0 0 40px rgba(0, 0, 0, .25);
}
dialog.drawer::backdrop { background: rgba(20, 18, 28, .4); }
dialog.drawer[open] { animation: slideIn .2s ease-out; }
@keyframes slideIn { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.drawer .study-side { position: static; }

.plan-sheet { width: min(460px, calc(100vw - 24px)); }
.plan-decks { display: grid; gap: 2px; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.plan-deck { display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.plan-deck:hover { background: var(--surface-2); }
.plan-deck input { accent-color: var(--accent); width: 16px; height: 16px; }
.plan-deck span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* collapsible study sidebar (wide screens); the drawer handles narrow ones */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side-hide { width: 28px; height: 28px; margin: -4px -6px -4px 0; }
.drawer .side-hide { display: none; }
@media (min-width: 901px) {
  .study-layout.side-collapsed { grid-template-columns: minmax(0, 1fr); }
  .study-layout.side-collapsed > .study-side { display: none; }
  .study-layout.side-collapsed .scope-btn {
    display: inline-flex; align-items: center; gap: 8px; max-width: 100%; margin-bottom: 10px; border: 1.5px solid var(--line);
    background: var(--surface); border-radius: 999px; padding: 6px 14px 6px 10px; font: 800 14px var(--ui); color: var(--muted); cursor: pointer;
  }
  .study-layout.side-collapsed .scope-btn .icon { width: 18px; height: 18px; }
  .study-layout.side-collapsed .scope-btn:hover { color: var(--ink); border-color: var(--accent); }
}
/* interval under each rating: present but quiet */
.ratings .btn small { font-weight: 500; opacity: .5; font-size: 11px; letter-spacing: .01em; }
.beta-note { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--pop-soft); font-size: 14px; }
