/* ===== Nihongo Academy — clean study UI ===== */
:root {
  --bg: #f6f7fb;
  --bg-soft: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2230;
  --text-soft: #5a6478;
  --text-faint: #8b93a7;
  --border: #e6e9f2;
  --border-strong: #d4d9e6;
  --accent: #5b6cff;
  --accent-soft: #eef0ff;
  --good: #16a34a;
  --good-soft: #e7f7ec;
  --bad: #e23b54;
  --bad-soft: #fdeaee;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(20,28,50,.04), 0 8px 24px rgba(20,28,50,.06);
  --shadow-lg: 0 12px 40px rgba(20,28,50,.12);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 980px;
  --jp: "Noto Sans JP", system-ui, sans-serif;
  --serif: "Noto Serif JP", Georgia, serif;
}
body[data-theme="dark"] {
  --bg: #0e1118;
  --bg-soft: #141925;
  --surface: #171c28;
  --surface-2: #1d2433;
  --text: #e8ebf3;
  --text-soft: #aab3c7;
  --text-faint: #76809a;
  --border: #262d3d;
  --border-strong: #333c50;
  --accent: #8b98ff;
  --accent-soft: #1d2540;
  --good: #4ade80;
  --good-soft: #16321f;
  --bad: #fb7185;
  --bad-soft: #3a1a22;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", var(--jp);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body.no-furigana rt { display: none; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
ruby rt { font-size: .58em; color: var(--text-faint); font-weight: 500; user-select: none; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #9b6cff);
  color: #fff; font-family: var(--jp); font-weight: 900; font-size: 22px;
  box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: -.01em; }
.brand-text small { color: var(--text-faint); font-size: 11.5px; }
.topnav { display: flex; align-items: center; gap: 10px; }
.navlink { color: var(--text-soft); font-weight: 600; font-size: 14px; padding: 8px 10px; border-radius: 8px; }
.navlink:hover { background: var(--bg-soft); color: var(--text); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-soft); font-size: 13px; font-weight: 600;
  padding: 7px 11px; border-radius: 999px; transition: .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip b { color: var(--accent); }
.chip-jp { font-family: var(--jp); font-weight: 700; }

/* ===== Layout ===== */
.view { max-width: var(--maxw); margin: 0 auto; padding: 30px 22px 70px; }
.footer {
  max-width: var(--maxw); margin: 0 auto; padding: 24px 22px 40px;
  color: var(--text-faint); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap;
}
.footer .dot { opacity: .5; }

/* ===== Home hero ===== */
.hero {
  background: linear-gradient(135deg, var(--accent), #9b6cff 90%);
  color: #fff; border-radius: 22px; padding: 34px 34px 30px;
  position: relative; overflow: hidden; box-shadow: var(--shadow-lg);
  margin-bottom: 26px;
}
.hero::after {
  content: "学"; position: absolute; right: -10px; bottom: -40px;
  font-family: var(--jp); font-weight: 900; font-size: 220px; opacity: .12; line-height: 1;
}
.hero h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.02em; }
.hero p { margin: 0; max-width: 560px; opacity: .92; font-size: 15px; }
.hero .hero-jp { font-family: var(--jp); font-weight: 700; opacity: .9; font-size: 14px; letter-spacing: .12em; margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 22px 0 28px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { color: var(--text-faint); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.section-title { font-size: 14px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 14px; }

/* ===== Track cards ===== */
.track-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.track-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); transition: .18s; display: flex; flex-direction: column; gap: 12px;
  position: relative; overflow: hidden;
}
.track-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.track-top { display: flex; align-items: center; gap: 14px; }
.track-icon {
  width: 52px; height: 52px; border-radius: 14px; flex: none;
  display: grid; place-items: center; font-family: var(--jp); font-weight: 900; font-size: 26px; color: #fff;
}
.track-name { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.track-name .jp { font-family: var(--jp); color: var(--text-faint); font-weight: 700; font-size: 13px; margin-left: 6px; }
.track-desc { color: var(--text-soft); font-size: 13.5px; min-height: 38px; }
.track-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.track-meta { font-size: 12.5px; color: var(--text-faint); font-weight: 600; }
.levels { display: inline-flex; gap: 5px; }
.lvl {
  font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); letter-spacing: .03em;
}
.lvl.n2 { background: #e7f0ff; color: #2563eb; }
.lvl.n1 { background: #fdeaf0; color: #db2777; }
body[data-theme="dark"] .lvl.n2 { background: #16243f; color: #7fb0ff; }
body[data-theme="dark"] .lvl.n1 { background: #34182a; color: #f59ac4; }

/* progress bar */
.bar { height: 7px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s ease; }

/* ===== Back link / breadcrumb ===== */
.crumb { display: inline-flex; align-items: center; gap: 7px; color: var(--text-soft); font-weight: 600; font-size: 13.5px; margin-bottom: 18px; }
.crumb:hover { color: var(--accent); }

/* ===== Track page header ===== */
.track-head { display: flex; align-items: center; gap: 18px; margin-bottom: 6px; }
.track-head .track-icon { width: 62px; height: 62px; font-size: 30px; }
.track-head h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.track-head .jp { font-family: var(--jp); color: var(--text-faint); font-weight: 700; }
.track-head p { margin: 4px 0 0; color: var(--text-soft); font-size: 14px; }

/* ===== Lesson list ===== */
.lesson-list { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.lesson-row {
  display: flex; align-items: center; gap: 16px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: .15s;
}
.lesson-row:hover { transform: translateX(3px); border-color: var(--border-strong); }
.lesson-no {
  width: 40px; height: 40px; flex: none; border-radius: 11px; display: grid; place-items: center;
  background: var(--bg-soft); color: var(--text-soft); font-weight: 800; font-size: 15px;
}
.lesson-row.done .lesson-no { background: var(--good-soft); color: var(--good); }
.lesson-info { flex: 1; min-width: 0; }
.lesson-info .t { font-weight: 700; font-size: 15.5px; }
.lesson-info .s { color: var(--text-faint); font-size: 12.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lesson-info .jp { font-family: var(--jp); }
.lesson-score { font-size: 12.5px; font-weight: 700; color: var(--good); }
.lesson-cta { color: var(--text-faint); font-size: 20px; }

/* ===== Lesson player ===== */
.player { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; }
.player-head { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }
.player-head .ph-title { font-weight: 700; font-size: 15px; flex: 1; }
.player-head .ph-step { font-size: 12.5px; color: var(--text-faint); font-weight: 700; }
.pbar { height: 4px; background: var(--bg-soft); }
.pbar > i { display: block; height: 100%; background: var(--accent); transition: width .35s ease; }
.player-body { padding: 30px 28px; min-height: 320px; }
.player-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 14px; padding: 11px 20px; border-radius: 11px; transition: .15s;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }

/* intro screen */
.intro-screen { text-align: center; padding: 16px 8px; }
.intro-screen .big-jp { font-family: var(--jp); font-weight: 900; font-size: 46px; letter-spacing: .02em; margin-bottom: 6px; }
.intro-screen h2 { margin: 4px 0 2px; font-size: 22px; }
.intro-screen .lead { color: var(--text-soft); max-width: 520px; margin: 12px auto 22px; font-size: 15px; }
.pill-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.pill { background: var(--bg-soft); color: var(--text-soft); font-size: 12.5px; font-weight: 700; padding: 6px 13px; border-radius: 999px; }

/* ===== Study cards ===== */
.jp-line { font-family: var(--jp); }
.speak {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--accent);
  width: 30px; height: 30px; border-radius: 9px; display: inline-grid; place-items: center;
  font-size: 14px; vertical-align: middle; flex: none;
}
.speak:hover { background: var(--accent-soft); }

/* kanji card */
.kanji-card { display: grid; grid-template-columns: 150px 1fr; gap: 26px; align-items: start; }
.kanji-glyph { font-family: var(--serif); font-weight: 700; font-size: 110px; line-height: 1; text-align: center; }
.kanji-glyph .meaning { display: block; font-family: "Inter"; font-size: 14px; font-weight: 700; color: var(--text-soft); margin-top: 10px; }
.read-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.read-tag { font-size: 11px; font-weight: 800; color: var(--text-faint); width: 42px; padding-top: 3px; }
.read-vals { font-family: var(--jp); font-weight: 700; font-size: 17px; }
.mnemonic { background: var(--accent-soft); color: var(--text); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; margin: 14px 0; }
.compound-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.compound { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--border); }
.compound .w { font-family: var(--jp); font-weight: 700; font-size: 17px; }
.compound .r { color: var(--text-faint); font-size: 13px; font-family: var(--jp); }
.compound .m { color: var(--text-soft); font-size: 13.5px; margin-left: auto; text-align: right; }

/* generic teaching card */
.tcard h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.tcard .head-jp { font-family: var(--jp); font-weight: 900; font-size: 30px; letter-spacing: -.01em; margin-bottom: 2px; line-height: 1.25; }
.tcard .sub { color: var(--text-soft); font-size: 14px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 14px; margin: 14px 0; font-size: 14px; }
.kv dt { color: var(--text-faint); font-weight: 700; font-size: 12.5px; }
.kv dd { margin: 0; }
.nuance { background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; color: var(--text-soft); }
.examples { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.example { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.example .ej { font-family: var(--jp); font-size: 17px; font-weight: 500; display: flex; gap: 10px; align-items: flex-start; }
.example .ee { color: var(--text-soft); font-size: 13.5px; margin-top: 5px; }

/* spelling group */
.sgroup .item { border-top: 1px solid var(--border); padding: 12px 0; }
.sgroup .item:first-child { border-top: none; }
.sgroup .form { font-family: var(--jp); font-weight: 800; font-size: 20px; }
.sgroup .gm { color: var(--text-soft); font-size: 13.5px; }

/* passage */
.passage { font-family: var(--serif); font-size: 18px; line-height: 2.05; }
.passage.hidden-text { filter: blur(6px); user-select: none; }
.passage-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.glossary { margin-top: 22px; }
.glossary h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin: 0 0 8px; }
.gl-item { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-top: 1px dashed var(--border); font-size: 14px; }
.gl-item .w { font-family: var(--jp); font-weight: 700; }
.gl-item .r { color: var(--text-faint); font-size: 12.5px; font-family: var(--jp); }
.gl-item .m { color: var(--text-soft); margin-left: auto; }
.translation { margin-top: 16px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--text-soft); font-size: 14px; }

/* ===== Quiz ===== */
.quiz .qnum { font-size: 12.5px; font-weight: 800; color: var(--accent); letter-spacing: .04em; }
.quiz .qprompt { font-size: 19px; font-weight: 600; margin: 8px 0 20px; font-family: var(--jp); line-height: 1.7; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  text-align: left; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 13px 16px; font-size: 15px; font-family: var(--jp); transition: .12s;
  display: flex; align-items: center; gap: 12px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt .mark { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .mark { background: var(--good); border-color: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .mark { background: var(--bad); border-color: var(--bad); color: #fff; }

.fill-wrap { display: flex; gap: 10px; flex-wrap: wrap; }
.fill-input {
  flex: 1; min-width: 220px; font-family: var(--jp); font-size: 17px; padding: 12px 14px;
  border: 1.5px solid var(--border-strong); border-radius: 11px; background: var(--surface); color: var(--text);
}
.fill-input:focus { outline: none; border-color: var(--accent); }

.order-pool, .order-built { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; min-height: 44px; }
.order-built { border: 1.5px dashed var(--border-strong); border-radius: 11px; padding: 8px; background: var(--surface-2); }
.token { font-family: var(--jp); font-weight: 700; font-size: 15px; padding: 9px 14px; border-radius: 10px; border: 1.5px solid var(--border-strong); background: var(--surface); }
.token:hover { border-color: var(--accent); }

.feedback { margin-top: 18px; border-radius: 12px; padding: 14px 16px; font-size: 14px; display: none; }
.feedback.show { display: block; }
.feedback.ok { background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 30%, transparent); }
.feedback.no { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); }
.feedback .verdict { font-weight: 800; margin-bottom: 4px; }
.feedback .verdict.ok { color: var(--good); }
.feedback .verdict.no { color: var(--bad); }

/* ===== Results / explanation ===== */
.result { text-align: center; }
.score-ring {
  width: 130px; height: 130px; border-radius: 50%; margin: 6px auto 14px; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg-soft) 0);
  position: relative;
}
.score-ring::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--surface); }
.score-ring .val { position: relative; z-index: 1; font-size: 30px; font-weight: 800; }
.result h2 { margin: 6px 0 2px; }
.result .sub { color: var(--text-soft); }
.explain-box {
  text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin: 24px 0 8px;
}
.explain-box h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); display: flex; gap: 8px; align-items: center; }
.explain-box .body { font-size: 14.5px; line-height: 1.8; }
.explain-box .body .jp-line { font-family: var(--jp); }
.result-actions { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

/* toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 50;
}

/* empty / loading */
.empty { text-align: center; color: var(--text-faint); padding: 60px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; font-family: var(--jp); }

@media (max-width: 620px) {
  .stats { grid-template-columns: 1fr; }
  .kanji-card { grid-template-columns: 1fr; gap: 14px; }
  .kanji-glyph { font-size: 84px; }
  .hero { padding: 26px 22px; }
  .player-body { padding: 22px 18px; }
}
