:root {
  --brand: #262c7e;
  --bg: #f5f4f0; --panel: #ffffff; --panel-2: #faf9f6; --text: #18181b; --muted: #71717a;
  --line: #e7e5df; --accent: #4f46e5; --accent-2: #6366f1; --accent-soft: #eef0ff; --on-accent: #ffffff;
  --good: #16a34a; --good-soft: #dcfce7; --bad: #dc2626; --bad-soft: #fee2e2;
  --amber: #b45309; --amber-soft: #fef3c7; --mark: #fde68a;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px rgb(0 0 0 / .06);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #c7cbff;
    --bg: #121214; --panel: #1b1b1f; --panel-2: #222227; --text: #f1f1f3; --muted: #9b9ba6;
    --line: #2d2d33; --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #25264a; --on-accent: #0e0e12;
    --good: #4ade80; --good-soft: #15361f; --bad: #f87171; --bad-soft: #3e1a1a;
    --amber: #fbbf24; --amber-soft: #3a2c0b; --mark: #5c4a0c;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 10px; }
h2 { font-size: 20px; letter-spacing: -.01em; margin: 0 0 8px; }
p { margin: 0 0 12px; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 .4em; border: 1px solid currentColor; border-radius: 6px;
  font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; opacity: .55; text-align: center;
}
@media (hover: none) { kbd { display: none; } }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.logo {
  display: grid; place-items: center; height: 32px; padding: 0 10px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent);
  font-size: 16px; font-weight: 800; letter-spacing: -.02em; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
}
.brand-sub { color: var(--muted); font-weight: 500; font-size: 14px; }
@media (max-width: 560px) { .brand-sub { display: none; } }
.top nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.top nav a, .navbtn {
  padding: 6px 12px; border-radius: 999px; color: var(--muted); font-family: inherit; font-weight: 500; font-size: 15px; line-height: 1.4; background: none; border: 0; cursor: pointer;
}
.top nav a:hover, .navbtn:hover { color: var(--text); background: var(--panel); }
.top nav a.on { color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
body.focus .top { display: none; }

main { max-width: 680px; margin: 0 auto; padding: 20px 16px 96px; }

/* surfaces */
.panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel.subtle { background: transparent; box-shadow: none; padding: 12px 16px; }
.narrow { max-width: 380px; margin: 48px auto; }
.center { text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 18px; }
.row.center { justify-content: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--bad); font-weight: 500; }
.inline { display: inline; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 15px; }
.section { margin: 28px 4px 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* inputs and buttons */
input[type=text], input[type=password] {
  width: 100%; padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, input[type=password]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
  font-family: inherit; font-weight: 600; font-size: 15px; line-height: 1.3; cursor: pointer; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.bad { color: var(--bad); }
.btn.big { padding: 14px 20px; font-size: 16px; border-radius: 14px; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font-family: inherit; font-weight: 500; font-size: 14px; line-height: 1.4; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }

/* home */
.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; padding: 16px 20px;
  border-radius: var(--radius); background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); box-shadow: var(--shadow);
}
.banner .muted { color: inherit; opacity: .8; font-size: 14px; }
.banner .count { font-size: 30px; font-weight: 800; }
.drop {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 22px; margin-bottom: 12px;
  border: 1.5px dashed var(--line); border-radius: 14px; background: var(--panel-2); color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop.has-file { border-style: solid; border-color: var(--good); color: var(--text); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-icon { font-size: 18px; }
.episodes { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.ep { display: grid; gap: 8px; padding: 16px 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); color: var(--text); transition: transform .12s, box-shadow .12s; }
.ep:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.ep-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ep-title { font-weight: 650; }
.empty { padding: 16px; }
.pill { flex: none; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.indigo { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--good-soft); color: var(--good); }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar.thin { height: 5px; margin-top: 6px; }
.bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.foot { margin-top: 32px; text-align: center; }

/* episode */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stats div { padding: 12px; border-radius: 14px; background: var(--panel-2); display: grid; }
.stats b { font-size: 24px; letter-spacing: -.02em; }
.stats span { color: var(--muted); font-size: 13px; }
.steps { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.steps li { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 16px 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); }
.steps li.current { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.steps li:not(.current):not(.done) { opacity: .6; }
.steps .num { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; }
.steps .done .num { background: var(--good); border-color: var(--good); color: white; }
.ready-card { text-align: center; padding: 28px 22px; background: linear-gradient(180deg, var(--good-soft), var(--panel)); }
.ready-emoji { font-size: 48px; line-height: 1; margin-bottom: 8px; }

/* focus screens */
.focusbar { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; margin-bottom: 16px; }
.close { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 16px; }
.close:hover { color: var(--text); }
.focus-title { font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focusbar .bar { grid-column: 1 / -1; }
.bar-label { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.card { padding: 26px; }
.kind, .kind-row { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.kind-row { display: flex; justify-content: space-between; align-items: center; }
.lemma { font-size: clamp(32px, 8vw, 44px); font-weight: 750; letter-spacing: -.03em; line-height: 1.15; margin: 6px 0 14px; overflow-wrap: anywhere; }
.quote { margin: 0 0 18px; padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 0 12px 12px 0; }
.quote blockquote { margin: 0 0 6px; font-size: 19px; line-height: 1.45; }
.line-tr { margin-top: 8px; color: var(--muted); font-style: italic; }
mark { background: var(--mark); color: inherit; padding: 0 3px; border-radius: 4px; }
.translation { font-size: 26px; font-weight: 700; color: var(--accent); margin: 2px 0 6px; }
.explain { color: var(--muted); margin: 0 0 16px; }
.answer3 { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 480px) { .answer3 { grid-template-columns: 1fr 1fr; } .answer3 .ghost { grid-column: 1 / -1; order: 3; } }
#back { margin-top: 16px; }

/* drill */
.dots { display: inline-flex; gap: 5px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--good); }
.options { display: grid; gap: 8px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; text-align: left;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); font-family: inherit; font-weight: 500; font-size: 17px; line-height: 1.3; cursor: pointer;
  transition: border-color .12s, background .12s, transform .08s;
}
button.option:hover { border-color: var(--accent); background: var(--accent-soft); }
button.option:active { transform: scale(.985); }
.option.right { border-color: var(--good); background: var(--good-soft); font-weight: 650; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); text-decoration: line-through; }
.option.dim { opacity: .45; }
.answered .option.right { animation: pulse .5s ease; }
.answered .option.wrong { animation: shake .35s ease; }
.feedback { margin-top: 14px; padding: 14px 16px; border-radius: 14px; }
.feedback.good { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback b { margin-right: 8px; }
.feedback .explain { margin: 8px 0 0; }
@keyframes pulse { 50% { transform: scale(1.02); } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.spinner { width: 34px; height: 34px; margin: 6px auto 14px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-ready { position: relative; overflow: hidden; padding: 40px 22px; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: 0; animation: fall 2.6s ease-in 1 forwards; }
.confetti i:nth-child(4n+1) { background: var(--accent); }
.confetti i:nth-child(4n+2) { background: #f59e0b; }
.confetti i:nth-child(4n+3) { background: var(--good); }
.confetti i:nth-child(4n) { background: #ec4899; }
@keyframes fall { 0% { opacity: 1; transform: translateY(0) rotate(0); } 100% { opacity: 0; transform: translateY(340px) rotate(540deg); } }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.chip { position: relative; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 8px 15px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--panel-2);
  font-weight: 500; transition: opacity .25s, background .25s, border-color .25s, color .25s, transform .15s;
}
.chip:hover span { border-color: var(--accent); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
/* calibration: known words pop and leave a ghost outline you can click to bring them back */
.chips.pop .chip input:checked + span { opacity: .28; background: transparent; border-style: dashed; border-color: var(--muted); color: var(--muted); }
.chips.pop .chip:hover input:checked + span { opacity: .6; }
.chip.popping span { animation: pop .38s cubic-bezier(.3, 1.6, .5, 1); }
.chip.popping::after {
  content: ""; position: absolute; inset: -4px; border-radius: 999px; border: 2px solid var(--accent);
  animation: ring .45s ease-out forwards; pointer-events: none;
}
.chip.unpopping span { animation: unpop .3s ease-out; }
@keyframes pop { 0% { transform: scale(1); opacity: 1; } 35% { transform: scale(1.22); opacity: 1; } 100% { transform: scale(.94); } }
@keyframes ring { from { opacity: .9; transform: scale(.9); } to { opacity: 0; transform: scale(1.45); } }
@keyframes unpop { 0% { transform: scale(.8); } 70% { transform: scale(1.06); } 100% { transform: scale(1); } }
/* episode batch: the words you don't know get a red tint */
.chips.unknown .chip input:checked + span { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.dock {
  position: sticky; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 10px 10px 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.dock b { font-size: 18px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.answer3.grades { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 480px) { .answer3.grades .btn { padding-inline: 6px; font-size: 15px; white-space: nowrap; } }

/* wide pages */
main.wide { max-width: 1120px; }
.home { display: grid; gap: 24px; }
@media (min-width: 900px) { .home { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } .home-side { position: sticky; top: 76px; } }
.hero { padding: 8px 4px 18px; }
.hero h1 { font-size: clamp(28px, 4vw, 38px); margin-bottom: 8px; }
.hero p { max-width: 560px; font-size: 17px; }
.upload { padding: 16px; }
.upload-form { display: grid; gap: 10px; }
@media (min-width: 700px) { .upload-form { grid-template-columns: 1.1fr 1fr auto; align-items: stretch; } }
.upload-form .drop, .upload-form input[type=text] { margin: 0; }
.upload-form .drop { padding: 12px 14px; }
.section .muted { font-weight: 500; margin-left: 4px; }
.episodes.grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.ep-num { display: flex; align-items: baseline; gap: 8px; }
.ep-num b { font-size: 30px; letter-spacing: -.03em; }
.episodes .empty { grid-column: 1 / -1; display: grid; justify-items: center; gap: 4px; padding: 36px 16px; text-align: center; border: 1.5px dashed var(--line); border-radius: var(--radius); }
.empty-art { font-size: 40px; }
.home-side .panel { padding: 18px; }
.level { display: grid; gap: 2px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.level b { font-size: 34px; letter-spacing: -.03em; background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tiles > * { display: grid; padding: 10px 12px; border-radius: 12px; background: var(--panel-2); color: var(--text); }
.tiles a:hover { background: var(--accent-soft); }
.tiles b { font-size: 22px; }
.tiles span { font-size: 12px; color: var(--muted); }
.side-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.side-head h2 { font-size: 17px; margin: 0; }
.mini-dict { list-style: none; margin: 0; padding: 0; }
.mini-dict li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.mini-dict li:last-child { border-bottom: 0; }
.mini-dict span { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip p { margin: 4px 0 0; }

/* episode title rename */
.title-row { display: flex; align-items: center; gap: 8px; }
.title-row h1 { margin: 0; }
.iconbtn { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; font-size: 15px; }
.iconbtn:hover { color: var(--accent); border-color: var(--accent); }
.rename { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-top: 4px; }
.rename input { margin: 0; }
.title-row[data-open] { display: none; }
.dict-link { margin-top: 14px; }

/* dictionary */
.dict-head h1 { margin-bottom: 4px; }
.dict-tools { display: grid; gap: 10px; margin-top: 12px; }
@media (min-width: 600px) { .dict-tools { grid-template-columns: 1fr auto; align-items: center; } }
input[type=search] { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); font: inherit; outline: none; }
input[type=search]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.seg a { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg a.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.dict { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dict li {
  display: grid; grid-template-columns: minmax(120px, 1fr) minmax(140px, 1.3fr) auto; grid-template-areas: "word tr act" "line line line";
  gap: 4px 14px; align-items: center; padding: 12px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
}
.dict li.known { background: var(--panel-2); }
@media (max-width: 560px) { .dict li { grid-template-columns: 1fr auto; grid-template-areas: "word act" "tr tr" "line line"; } }
.dict-word { grid-area: word; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dict-word b { font-size: 17px; }
.dict-tr { grid-area: tr; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.dict-line { grid-area: line; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dict-act { grid-area: act; }
.tr-text { padding: 2px 6px; margin-left: -6px; border-radius: 8px; cursor: text; border: 1px dashed transparent; }
.tr-text:hover, .tr-text:focus { border-color: var(--line); outline: none; background: var(--panel-2); }
.tr-text.empty { color: var(--muted); font-style: italic; }
.tr-input { padding: 4px 8px; border: 1px solid var(--accent); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; min-width: 0; width: 100%; box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.tr-text.saved { animation: saved 1s ease; }
@keyframes saved { 0% { background: var(--good-soft); } 100% { background: transparent; } }
.tag { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.indigo { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chipbtn { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-family: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chipbtn:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 560px) {
  .top { flex-wrap: nowrap; gap: 8px; padding: 8px 12px; }
  .top nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -12px; padding-right: 12px; }
  .top nav::-webkit-scrollbar { display: none; }
  .top nav a, .navbtn { padding: 6px 10px; font-size: 14px; white-space: nowrap; }
}

/* preSub wordmark: thin «pre», heavy «Sub», deep navy */
.wordmark { color: var(--brand); font-size: 26px; font-weight: 800; letter-spacing: -.035em; line-height: 1; }
.wordmark .pre { font-weight: 300; letter-spacing: -.02em; }
.tr-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: -6px 0 14px; }
.feedback .tr-meta { margin: 8px 0 0; }
