/* Nihongo Michi — washi paper, sumi ink, vermilion accents */
:root {
  --ts: 1;            /* text size (Settings → Display → Text size) */
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface2: #f0e9db;
  --surface3: #e8dfcc;
  --ink: #24201b;
  --ink2: #5a5348;
  --muted: #8b8376;
  --line: #e2d9c6;
  --accent: #c8402f;
  --accent-soft: #f6dcd5;
  --accent-ink: #ffffff;
  --indigo: #2e4a7d;
  --indigo-soft: #dde5f3;
  --good: #2c8a57;
  --good-soft: #d9efe1;
  --bad: #c23b2a;
  --bad-soft: #f7dcd7;
  --gold: #c58b1a;
  --gold-soft: #f6e7c4;
  --sidebar: #1e2230;
  --sidebar-ink: #d9d4ca;
  --sidebar-muted: #8e8a83;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 14px rgba(60, 40, 10, .07);
  --shadow-lg: 0 10px 40px rgba(40, 25, 5, .18);
  --radius: 14px;
  --jp: "Yu Gothic", "YuGothic", "Yu Gothic UI", "Meiryo", "MS Gothic", sans-serif;
  --ui: "Segoe UI", "Yu Gothic UI", "Meiryo UI", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15171e;
  --surface: #1e212b;
  --surface2: #262a36;
  --surface3: #30354379;
  --ink: #ece7de;
  --ink2: #bdb6aa;
  --muted: #8a857c;
  --line: #343949;
  --accent: #e2604d;
  --accent-soft: #4a2723;
  --indigo: #7f9ee0;
  --indigo-soft: #26314b;
  --good: #4cc083;
  --good-soft: #1d3a2b;
  --bad: #ef6b58;
  --bad-soft: #452420;
  --gold: #e3ad45;
  --gold-soft: #45391f;
  --sidebar: #101219;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  font-size: calc(15px * var(--ts));
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--indigo); }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

#app { display: flex; height: 100vh; height: 100dvh; }
#tabbar { display: none; }

/* ---------------- sidebar ---------------- */
#sidebar {
  width: 236px; flex: none; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-family: var(--jp); font-size: calc(24px * var(--ts)); font-weight: 700;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.brand-name { font-weight: 700; font-size: calc(16px * var(--ts)); letter-spacing: .2px; color: #fff; }
.brand-sub { font-size: calc(11.5px * var(--ts)); color: var(--sidebar-muted); font-family: var(--jp); margin-top: 2px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-sec { font-size: calc(10.5px * var(--ts)); text-transform: uppercase; letter-spacing: 1.2px; color: var(--sidebar-muted); padding: 12px 12px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--sidebar-ink); text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  font-size: calc(14px * var(--ts)); transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-ico { width: 22px; height: 22px; display: grid; place-items: center; flex: none; font-family: var(--jp); font-weight: 700; font-size: calc(16px * var(--ts)); color: var(--sidebar-muted); }
.nav-ico svg { width: 20px; height: 20px; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: calc(11px * var(--ts)); font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.side-foot { margin-top: auto; padding: 12px 8px 4px; display: flex; flex-direction: column; gap: 8px; }
.profile-chip {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 12px; border: 0;
  background: rgba(255,255,255,.06); color: var(--sidebar-ink); cursor: pointer; text-align: left;
}
.profile-chip:hover { background: rgba(255,255,255,.12); }
.profile-chip b { display: block; color: #fff; font-size: calc(14px * var(--ts)); }
.profile-chip span { font-size: calc(11px * var(--ts)); color: var(--sidebar-muted); }
.avatar-letter { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 750; flex: none; box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
#app.picking #sidebar { display: none; }
.profile-screen { max-width: 860px; margin: 0 auto; padding: 70px 32px 60px; text-align: center; }
.profile-screen h1 { margin: 6px 0 4px; font-size: calc(32px * var(--ts)); }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-top: 30px; text-align: left; }
.profile-card { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px 16px; text-align: center; cursor: pointer; border: 2px solid var(--line); }
.profile-card:hover { border-color: var(--indigo); transform: translateY(-2px); }
.profile-card.last { border-color: var(--accent); }
.profile-card .pname { font-size: calc(18px * var(--ts)); font-weight: 750; }
.profile-card .pmeta { font-size: calc(12.5px * var(--ts)); color: var(--muted); line-height: 1.5; }
.profile-card.add { border-style: dashed; color: var(--muted); justify-content: center; }
.profile-card.add .plus { width: 64px; height: 64px; border-radius: 50%; background: var(--surface2); display: grid; place-items: center; font-size: calc(32px * var(--ts)); }
.side-stat { flex: 1; background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px 10px; }
.side-stat b { display: block; font-size: calc(16px * var(--ts)); color: #fff; }
.side-stat span { font-size: calc(11px * var(--ts)); color: var(--sidebar-muted); }

/* ---------------- main ---------------- */
#main { flex: 1; overflow-y: auto; position: relative; }
.page { max-width: 1120px; margin: 0 auto; padding: 28px 36px 60px; }
.page-narrow { max-width: 820px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: calc(28px * var(--ts)); letter-spacing: -.3px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
h2 { font-size: calc(19px * var(--ts)); margin: 28px 0 12px; }
h3 { font-size: calc(16px * var(--ts)); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: calc(13px * var(--ts)); }
.tiny { font-size: calc(11.5px * var(--ts)); }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.hidden { display: none !important; }
.jp { font-family: var(--jp); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card.click { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; }
.card.click:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--surface3); }
.card h3 { margin-top: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px;
  font-size: calc(12px * var(--ts)); font-weight: 600; background: var(--surface2); color: var(--ink2); white-space: nowrap;
}
.pill.red { background: var(--accent-soft); color: var(--accent); }
.pill.blue { background: var(--indigo-soft); color: var(--indigo); }
.pill.green { background: var(--good-soft); color: var(--good); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 600; font-size: calc(14px * var(--ts)); transition: transform .08s, background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.blue { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface2); }
.btn.lg { padding: 13px 26px; font-size: calc(15.5px * var(--ts)); border-radius: 13px; }
.btn.sm { padding: 6px 12px; font-size: calc(13px * var(--ts)); border-radius: 9px; }
/* Google sign-in button, per Google's branding guidelines (white, grey outline, G logo, "Continue with Google") */
.btn.google { background: #fff; border: 1px solid #747775; color: #1f1f1f; border-radius: 20px; height: 40px; padding: 0 14px 0 12px; gap: 10px; font-family: Roboto, var(--ui); font-weight: 500; font-size: calc(14px * var(--ts)); box-shadow: none; }
.btn.google:hover { background: #f7f8f8; }
:root[data-theme="dark"] .btn.google { background: #131314; border-color: #8e918f; color: #e3e3e3; }
:root[data-theme="dark"] .btn.google:hover { background: #1f1f20; }
.btn.icon { padding: 8px; width: 38px; height: 38px; border-radius: 50%; }
.btn.icon.sm { width: 32px; height: 32px; padding: 6px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.rec.on { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(194,59,42,.2); } }

.seg { display: inline-flex; background: var(--surface2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: calc(13px * var(--ts)); color: var(--ink2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

input[type=text], input[type=search], select, textarea {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 11px; padding: 10px 14px; outline: none; width: 100%;
}
input[type=text]:focus, input[type=search]:focus, select:focus, textarea:focus { border-color: var(--indigo); }
input[type=range] { accent-color: var(--accent); }
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--surface3); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

/* progress */
.bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar.green > i { background: var(--good); }
.bar.blue > i { background: var(--indigo); }
.ring { position: relative; display: grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-label { position: absolute; text-align: center; line-height: 1.1; }

/* ---------------- Japanese text ---------------- */
.jpt { font-family: var(--jp); line-height: 1.9; line-break: strict; }   /* strict: a line never starts with ゃ ゅ ょ っ ー */
.jpt ruby { ruby-align: center; }
.jpt rt { font-size: .5em; color: var(--muted); font-weight: 400; letter-spacing: 0; }
.jpt ruby.nf rt { visibility: hidden; }
.jpt ruby.nf:hover rt { visibility: visible; }
.jpt .gap { display: inline-block; width: .32em; }
.jpt .tgt { color: var(--accent); font-weight: 700; }
/* small kana (ゃ ゅ ょ っ …) a clear step smaller than the full-size ones (や ゆ よ つ) */
.sk { font-size: .72em; }
.romaji { color: var(--muted); font-size: .86em; font-style: italic; }
.en { color: var(--ink2); }
.reveal { filter: blur(5px); cursor: pointer; transition: filter .2s; user-select: none; }
.reveal:hover { filter: blur(3px); }
.reveal.shown { filter: none; user-select: auto; cursor: auto; }

.jpline { display: flex; gap: 10px; align-items: flex-start; }
.jpline .body { flex: 1; min-width: 0; }
.say {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; cursor: pointer; flex: none; color: var(--indigo); transition: background .15s;
}
.say:hover { background: var(--indigo-soft); }
.say svg { width: 17px; height: 17px; }
.say.playing { background: var(--indigo); color: #fff; }
.say.slow { color: var(--muted); }
.say.nv { opacity: .4; }

/* ---------------- home ---------------- */
.hero {
  position: relative; overflow: hidden; border-radius: 20px; padding: 28px 30px; color: #fff;
  background: linear-gradient(120deg, #2b3552 0%, #3c4a72 55%, #a8463a 130%);
  box-shadow: var(--shadow-lg);
}
.hero::after {
  content: "道"; position: absolute; right: -10px; bottom: -60px; font-size: calc(240px * var(--ts)); font-family: var(--jp); font-weight: 700;
  color: rgba(255,255,255,.07); pointer-events: none;
}
.hero h1 { margin: 0 0 6px; font-size: calc(27px * var(--ts)); }
/* Tabi the tanuki standing at the edge of the home banner */
.hero.with-mascot { padding-right: 230px; }
.hero.with-mascot::after { display: none; }
.hero-mascot { position: absolute; right: 22px; bottom: -6px; height: 210px; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0,0,0,.28)); }

.mascot { display: block; margin: 0 auto; user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 4px 8px rgba(60,40,10,.18)); }
.mascot-say { display: flex; align-items: center; justify-content: center; gap: 4px; margin-bottom: 6px; }
.mascot-say .mascot { margin: 0; }
.say-bubble {
  position: relative; background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 16px;
  text-align: left; box-shadow: var(--shadow); max-width: 260px; margin-bottom: 40px;
}
.say-bubble::before { content: ""; position: absolute; left: -9px; top: 50%; width: 14px; height: 14px; background: var(--surface); border-left: 1.5px solid var(--line); border-bottom: 1.5px solid var(--line); transform: translateY(-50%) rotate(45deg); }
.say-bubble .jpt { font-size: calc(19px * var(--ts)); font-weight: 700; line-height: 1.5; }
.profile-screen .mascot { margin-bottom: 10px; }
:root[data-theme="dark"] .mascot { filter: drop-shadow(0 0 1px rgba(255,255,255,.35)) drop-shadow(0 4px 10px rgba(0,0,0,.5)); }
.hero .hero-jp { font-family: var(--jp); opacity: .8; font-size: calc(15px * var(--ts)); }
.hero .btn.primary { margin-top: 18px; }
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { font-size: calc(24px * var(--ts)); display: block; letter-spacing: -.5px; }
.stat span { font-size: calc(12.5px * var(--ts)); color: var(--muted); }
.banner { display: flex; gap: 14px; align-items: center; padding: 14px 18px; border-radius: var(--radius); background: var(--gold-soft); border: 1px solid rgba(197,139,26,.3); }
.banner.blue { background: var(--indigo-soft); border-color: rgba(46,74,125,.25); }
.banner .big { font-size: calc(26px * var(--ts)); }

/* ---------------- course map ---------------- */
.level { margin-bottom: 30px; }
.level-head { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.level-badge {
  width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; flex: none;
  font-weight: 800; font-size: calc(19px * var(--ts)); color: #fff; background: var(--indigo); box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.level.locked .level-badge { background: var(--surface3); color: var(--muted); }
.level-head h2 { margin: 0; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.lesson-card { display: flex; gap: 12px; align-items: center; padding: 13px 14px; }
.lesson-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--surface2); display: grid; place-items: center; font-size: calc(22px * var(--ts)); flex: none; }
.lesson-card.done .lesson-ico { background: var(--good-soft); }
.lesson-card.next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lesson-card.locked { opacity: .55; }
.lesson-title { font-weight: 650; font-size: calc(14px * var(--ts)); }
.lesson-sub { font-size: calc(12px * var(--ts)); color: var(--muted); margin-top: 2px; }
.stars { color: var(--gold); letter-spacing: 1px; font-size: calc(12px * var(--ts)); }
.stars .off { color: var(--surface3); }

/* ---------------- player (lessons, reviews, tests) ---------------- */
.player { display: flex; flex-direction: column; min-height: 100%; }
.player-top { display: flex; align-items: center; gap: 14px; padding: 14px 28px; position: sticky; top: 0; background: var(--bg); z-index: 5; border-bottom: 1px solid var(--line); }
.player-top .bar { flex: 1; height: 10px; }
.player-body { flex: 1; display: flex; justify-content: center; padding: 26px 28px 140px; }
.stage { width: 100%; max-width: 780px; }
.step-label { font-size: calc(12.5px * var(--ts)); font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 1.1px; margin-bottom: 10px; }
.step-title { font-size: calc(23px * var(--ts)); font-weight: 700; margin: 0 0 16px; }
.player-foot {
  position: fixed; left: 236px; right: 0; bottom: 0; padding: 16px 28px; background: var(--surface);
  border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 10; transition: background .2s;
}
.player-foot .inner { width: 100%; max-width: 780px; display: flex; align-items: center; gap: 14px; }
.player-foot.good { background: var(--good-soft); border-color: transparent; }
.player-foot.bad { background: var(--bad-soft); border-color: transparent; }
.fb-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: calc(22px * var(--ts)); font-weight: 700; flex: none; }
.good .fb-icon { background: var(--good); }
.bad .fb-icon { background: var(--bad); }
.fb-title { font-weight: 800; font-size: calc(17px * var(--ts)); }
.good .fb-title { color: var(--good); }
.bad .fb-title { color: var(--bad); }
.fb-detail { font-size: calc(14px * var(--ts)); color: var(--ink2); margin-top: 2px; }
.fb-detail .jpt { line-height: 1.6; }

/* learn cards */
.big-jp { font-family: var(--jp); font-size: calc(46px * var(--ts)); font-weight: 600; line-height: 1.6; }
.big-jp rt { font-size: .38em; }
.huge-char { font-family: var(--jp); font-size: calc(150px * var(--ts)); line-height: 1.1; font-weight: 500; text-align: center; }
.learn-card { text-align: center; padding: 30px 28px; }
.learn-card .en { font-size: calc(20px * var(--ts)); margin-top: 6px; color: var(--ink); }
.learn-card .romaji { font-size: calc(16px * var(--ts)); }
.learn-card .note { margin-top: 16px; padding: 12px 16px; background: var(--surface2); border-radius: 11px; color: var(--ink2); font-size: calc(14px * var(--ts)); text-align: left; }
.learn-actions { display: flex; gap: 8px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.kana-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.kana-tile { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 12px 8px; text-align: center; cursor: pointer; transition: transform .1s; }
.kana-tile:hover { transform: translateY(-2px); border-color: var(--indigo); }
.kana-tile .k { font-family: var(--jp); font-size: calc(38px * var(--ts)); line-height: 1.3; }
.kana-tile .r { font-weight: 700; color: var(--accent); }
.kana-tile .m { font-size: calc(11.5px * var(--ts)); color: var(--muted); margin-top: 6px; line-height: 1.35; text-align: left; }
.mnemonic { background: var(--gold-soft); border-radius: 12px; padding: 12px 16px; text-align: left; font-size: calc(14.5px * var(--ts)); }
.mnemonic b { color: var(--gold); }
.goal-list { list-style: none; padding: 0; margin: 0; }
.goal-list li { padding: 9px 0 9px 32px; position: relative; border-bottom: 1px dashed var(--line); }
.goal-list li::before { content: "✓"; position: absolute; left: 4px; top: 8px; width: 20px; height: 20px; border-radius: 50%; background: var(--good-soft); color: var(--good); font-size: calc(12px * var(--ts)); display: grid; place-items: center; font-weight: 800; }
.grammar-card .pattern { display: inline-block; font-family: var(--jp); font-size: calc(18px * var(--ts)); background: var(--indigo-soft); color: var(--indigo); padding: 6px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 600; }
.grammar-card .explain { font-size: calc(15px * var(--ts)); line-height: 1.65; color: var(--ink2); }
.grammar-card .explain b { color: var(--ink); }
.examples { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.example { padding: 10px 14px; background: var(--surface2); border-radius: 12px; }
.example .jpt { font-size: calc(18px * var(--ts)); }
.dialog-lines { display: flex; flex-direction: column; gap: 12px; }
.dline { display: flex; gap: 12px; align-items: flex-start; }
.dline.me { flex-direction: row-reverse; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--indigo-soft); display: grid; place-items: center; font-size: calc(20px * var(--ts)); flex: none; }
.dline.me .avatar { background: var(--accent-soft); }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; padding: 10px 14px; max-width: 78%; box-shadow: var(--shadow); }
.dline.me .bubble { border-radius: 16px 4px 16px 16px; background: var(--accent-soft); border-color: transparent; }
.bubble .who { font-size: calc(11.5px * var(--ts)); font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.bubble .jpt { font-size: calc(17px * var(--ts)); }
.dline.active .bubble { outline: 2px solid var(--indigo); }
.culture { border-left: 4px solid var(--accent); }

/* exercises */
.prompt-box { text-align: center; margin: 10px 0 24px; }
.prompt-box .big-jp { font-size: calc(40px * var(--ts)); }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choices.one { grid-template-columns: 1fr; }
.choice {
  position: relative; text-align: left; padding: 14px 16px 14px 46px; border-radius: 13px; border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; transition: border-color .12s, background .12s, transform .08s; min-height: 58px;
  display: flex; flex-direction: column; justify-content: center;
}
.choice:hover:not(:disabled) { border-color: var(--indigo); }
.choice:active:not(:disabled) { transform: translateY(1px); }
.choice .key { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border-radius: 7px; border: 1.5px solid var(--line); font-size: calc(12px * var(--ts)); font-weight: 700; color: var(--muted); display: grid; place-items: center; }
.choice .jpt { font-size: calc(19px * var(--ts)); line-height: 1.75; }
.choice.big .jpt { font-size: calc(30px * var(--ts)); }
.choice.sel { border-color: var(--indigo); background: var(--indigo-soft); }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; }
.type-wrap { max-width: 560px; margin: 0 auto; }
.type-input { font-family: var(--jp); font-size: calc(24px * var(--ts)) !important; padding: 14px 18px !important; text-align: center; border-width: 2px !important; }
.type-input.right { border-color: var(--good) !important; background: var(--good-soft); }
.type-input.wrong { border-color: var(--bad) !important; background: var(--bad-soft); }
.tiles { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; min-height: 58px; }
.answer-line { border-bottom: 2px solid var(--line); padding: 8px 0 12px; margin-bottom: 26px; min-height: 66px; justify-content: flex-start; }
.tile {
  font-family: var(--jp); font-size: calc(18px * var(--ts)); padding: 8px 14px; border-radius: 11px; border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; box-shadow: 0 2px 0 var(--line); transition: transform .08s; line-height: 1.6;
}
.tile:hover { border-color: var(--indigo); }
/* a placed tile leaves a gap: nothing inside it may show (its furigana would) or be tapped */
.tile.used, .tile.used * { visibility: hidden !important; }
.tile.used { pointer-events: none; }
.tile rt { font-size: .5em; color: var(--muted); }
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-item { padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; text-align: center; min-height: 54px; display: grid; place-items: center; transition: .12s; }
.match-item .jpt { font-size: calc(19px * var(--ts)); line-height: 1.6; }
.match-item.sel { border-color: var(--indigo); background: var(--indigo-soft); }
.match-item.ok { border-color: var(--good); background: var(--good-soft); opacity: .45; cursor: default; }
.match-item.no { border-color: var(--bad); background: var(--bad-soft); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.fill-sentence { font-size: calc(26px * var(--ts)); text-align: center; margin: 10px 0 24px; }
.blank { display: inline-block; min-width: 80px; border-bottom: 3px solid var(--indigo); margin: 0 6px; color: var(--indigo); text-align: center; }

/* done screen */
.done-wrap { text-align: center; padding-top: 20px; }
.done-wrap .big-emoji { font-size: calc(64px * var(--ts)); }
.done-stats { display: flex; gap: 14px; justify-content: center; margin: 22px 0; flex-wrap: wrap; }
.done-stats .stat { min-width: 130px; }

/* ---------------- conversations ---------------- */
.convo { display: flex; flex-direction: column; height: 100%; }
.convo-head { padding: 14px 28px; border-bottom: 1px solid var(--line); display: flex; gap: 14px; align-items: center; background: var(--bg); }
.convo-scene { font-size: calc(13px * var(--ts)); color: var(--ink2); }
.chat { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.chat .inner { width: 100%; max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.chat .sys { align-self: center; font-size: calc(13px * var(--ts)); color: var(--muted); background: var(--surface2); padding: 6px 14px; border-radius: 99px; text-align: center; max-width: 90%; }
.chat .fbmsg { align-self: center; max-width: 90%; font-size: calc(13.5px * var(--ts)); padding: 8px 14px; border-radius: 12px; }
.chat .fbmsg.good { background: var(--good-soft); color: var(--good); }
.chat .fbmsg.ok { background: var(--gold-soft); color: var(--gold); }
.chat .fbmsg.bad { background: var(--bad-soft); color: var(--bad); }
.convo-opts { border-top: 1px solid var(--line); background: var(--surface); padding: 16px 28px 20px; }
.convo-opts .inner { max-width: 780px; margin: 0 auto; }
.convo-opt { width: 100%; text-align: left; margin-bottom: 8px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; display: flex; gap: 12px; align-items: center; }
.convo-opt:hover { border-color: var(--indigo); }
.convo-opt .jpt { font-size: calc(17px * var(--ts)); line-height: 1.7; }
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.scene-card { display: flex; gap: 14px; align-items: flex-start; }
.scene-emoji { font-size: calc(34px * var(--ts)); width: 56px; height: 56px; background: var(--surface2); border-radius: 15px; display: grid; place-items: center; flex: none; }

/* ---------------- kana / kanji library ---------------- */
.kana-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 74px)); gap: 8px; }
.kana-grid.wide { grid-template-columns: repeat(5, minmax(0, 90px)); }
.kcell { height: 74px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; position: relative; transition: transform .1s; }
.kcell:hover { transform: translateY(-2px); border-color: var(--indigo); }
.kcell .k { font-family: var(--jp); font-size: calc(28px * var(--ts)); line-height: 1.2; }
.kcell .r { font-size: calc(11.5px * var(--ts)); color: var(--muted); }
.kcell.empty { visibility: hidden; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kcell .dot, .ktile .dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; }
.dot.s1 { background: #e7a13c; } .dot.s2 { background: #64a7d6; } .dot.s3 { background: #3fb27f; } .dot.s4 { background: #8a5cc7; }
.kanji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 8px; }
.ktile { height: 62px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; font-family: var(--jp); font-size: calc(27px * var(--ts)); cursor: pointer; position: relative; }
.ktile:hover { border-color: var(--indigo); }
.ktile.learned { background: var(--good-soft); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }
.sticky { position: sticky; top: 20px; }
.detail-big { font-family: var(--jp); font-size: calc(96px * var(--ts)); text-align: center; line-height: 1.2; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: calc(14px * var(--ts)); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list-row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .jpt { font-size: calc(18px * var(--ts)); }
.chip { display: inline-block; padding: 4px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: calc(13px * var(--ts)); margin: 0 6px 6px 0; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* trace / stroke canvas */
.trace { display: inline-flex; flex-direction: column; gap: 8px; align-items: center; }
.trace-box { position: relative; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; touch-action: none; }
.trace-box canvas, .trace-box svg { position: absolute; inset: 0; }
.trace-box .guide line { stroke: var(--line); stroke-dasharray: 4 5; }
.trace-box .ghost path { fill: none; stroke: var(--surface3); stroke-linecap: round; stroke-linejoin: round; }
.trace-box .anim path { fill: none; stroke: var(--accent); stroke-linecap: round; stroke-linejoin: round; }
.trace-box .nums text { font-size: calc(8px * var(--ts)); fill: var(--muted); font-family: var(--ui); }

/* heatmap */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; }
.heat i { width: 13px; height: 13px; border-radius: 3px; background: var(--surface2); }
.heat i.l1 { background: #f2c4b9; } .heat i.l2 { background: #e48b78; } .heat i.l3 { background: #cf563f; } .heat i.l4 { background: #9e2f1f; }

/* modal / toast */
.modal-back { position: fixed; inset: 0; background: rgba(20, 15, 8, .45); display: grid; place-items: center; z-index: 100; animation: fade .15s; padding: 20px; }
.modal { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; padding: 26px 28px; animation: pop .18s; }
.modal.wide { max-width: 860px; }
.modal h2 { margin-top: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
#toast-root { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: calc(14px * var(--ts)); animation: pop .2s; max-width: 380px; }
.xp-pop { position: fixed; pointer-events: none; font-weight: 800; color: var(--gold); font-size: calc(18px * var(--ts)); animation: rise 1s forwards; z-index: 300; }
@keyframes rise { to { transform: translateY(-40px); opacity: 0; } }
.confetti { position: fixed; top: -10px; width: 9px; height: 14px; z-index: 300; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

.kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: calc(11px * var(--ts)); color: var(--muted); }
table.tbl { width: 100%; border-collapse: collapse; font-size: calc(14px * var(--ts)); }
table.tbl td, table.tbl th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.passage { font-size: calc(19px * var(--ts)); line-height: 2.1; padding: 22px 26px; }

.jpt ruby.nf.peek rt { visibility: visible; }
.boot-note { max-width: 640px; margin: 80px auto; padding: 0 20px; text-align: center; color: var(--muted); }
.boot-note h1 { color: var(--ink); }
.site-links { margin-top: 26px; font-size: calc(13px * var(--ts)); color: var(--muted); }
.site-links a { color: var(--muted); }
.install-tip { display: flex; gap: 12px; align-items: center; text-align: left; }

@media (max-width: 1000px) {
  .stat-tiles, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .choices { grid-template-columns: 1fr; }
}

/* touch screens: no keyboard-shortcut hints */
@media (hover: none) {
  .kbd-hint { display: none; }
}

/* ---------------- phones ---------------- */
@media (max-width: 760px) {
  body { font-size: calc(15px * var(--ts)); }
  /* 16px stops iPhones zooming in when a text box gets focus */
  input[type=text], input[type=search], input[type=number], select, textarea { font-size: calc(16px * var(--ts)); }
  #app { flex-direction: column; }
  #sidebar { display: none; }
  #main { flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
  #main::-webkit-scrollbar { width: 0; }

  /* bottom tab bar */
  #tabbar {
    display: flex; flex: none; justify-content: space-around; background: var(--sidebar);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  #app.picking #tabbar, #app:has(.player, .convo) #tabbar { display: none; }
  .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px 4px; border: 0; background: none;
    color: var(--sidebar-muted); font-size: calc(10.5px * var(--ts)); font-weight: 600; position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .tab .nav-ico { color: inherit; }
  .tab.active { color: #fff; }
  .tab.active .nav-ico { color: var(--accent); }
  .tab .nav-badge { position: absolute; top: 1px; left: calc(50% + 6px); margin: 0; font-size: calc(10px * var(--ts)); padding: 0 5px; }
  .more-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .more-item {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: 14px; border: 1px solid var(--line);
    background: var(--surface); cursor: pointer; font-size: calc(13px * var(--ts)); font-weight: 600; color: var(--ink);
  }
  .more-item .nav-ico { color: var(--indigo); width: 26px; height: 26px; font-size: calc(20px * var(--ts)); }
  .more-item .nav-ico svg { width: 22px; height: 22px; }

  /* pages */
  .page { padding: 16px 14px 40px; padding-top: calc(16px + env(safe-area-inset-top)); }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: calc(24px * var(--ts)); }
  h2 { font-size: calc(18px * var(--ts)); margin: 22px 0 10px; }
  .card { padding: 14px 15px; }
  .g2, .g3, .gauto { grid-template-columns: minmax(0, 1fr); }
  .stat-tiles, .g4 { gap: 10px; }
  .stat { padding: 11px 13px; }
  .stat b { font-size: calc(20px * var(--ts)); }
  .hero { padding: 20px 18px; border-radius: 16px; }
  .hero h1 { font-size: calc(22px * var(--ts)); }
  .hero::after { font-size: calc(170px * var(--ts)); bottom: -44px; }
  .hero.with-mascot { padding-right: 18px; padding-bottom: 22px; }
  .hero.with-mascot .btn.primary { position: relative; z-index: 1; }
  .hero-mascot { height: 118px; right: 8px; bottom: -4px; }
  .hero.with-mascot > div:not(.hero-jp) { padding-right: 104px; }   /* the lesson line stays clear of Tabi */
  .say-bubble { max-width: 200px; padding: 8px 12px; }
  .say-bubble .jpt { font-size: calc(17px * var(--ts)); }
  .btn.lg { padding: 12px 20px; font-size: calc(15px * var(--ts)); }
  /* lists: the Japanese takes the space it needs and the English stays in a right-hand column */
  .list-row { padding: 12px 14px; }
  .list-row > .grow { min-width: 0; }
  .list-row > .en { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
  .list-row.wrap { flex-wrap: wrap; }
  /* phrasebook: a whole phrase is too long to share a line, so the English sits right-aligned underneath */
  .list-row.phrase { flex-wrap: wrap; row-gap: 4px; }
  .list-row.phrase > .grow { flex: 1 1 calc(100% - 60px); }
  .list-row.phrase > .en { margin-left: auto; max-width: none !important; }
  /* settings rows: a control drops below its text when there's no room */
  .list-row.setting { flex-wrap: wrap; }
  .list-row.setting > .grow, .banner > .grow { flex: 1 1 190px; }
  .banner { flex-wrap: wrap; }
  .banner > .btn { margin-left: auto; }
  .review-hero { flex-wrap: wrap; gap: 16px !important; padding: 16px !important; }
  .review-hero > .grow { flex: 1 1 150px; }
  .review-hero > .btn { flex: 1 1 100%; }
  .lessons { grid-template-columns: minmax(0, 1fr); }
  table.tbl { display: block; overflow-x: auto; }
  .profile-screen { padding: 34px 16px 40px; padding-top: calc(34px + env(safe-area-inset-top)); }
  .profile-screen h1 { font-size: calc(26px * var(--ts)); }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
  .profile-card { padding: 18px 10px; }
  .heat { overflow-x: auto; }

  /* lesson / review / test player */
  .player-top { padding: 10px 12px; gap: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .player-top > .small { min-width: 0 !important; max-width: 32vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .player-body { padding: 18px 14px 170px; }
  .player-foot { left: 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .player-foot .inner { gap: 10px; flex-wrap: wrap; }
  .player-foot .inner > .btn { margin-left: auto; }
  .fb-icon { width: 36px; height: 36px; font-size: calc(18px * var(--ts)); }
  .fb-title { font-size: calc(16px * var(--ts)); }
  .step-title { font-size: calc(20px * var(--ts)); }
  .big-jp { font-size: calc(34px * var(--ts)); }
  .prompt-box .big-jp { font-size: calc(30px * var(--ts)); }
  .huge-char { font-size: calc(110px * var(--ts)); }
  .learn-card { padding: 20px 14px; }
  .learn-card .en { font-size: calc(18px * var(--ts)); }
  .fill-sentence { font-size: calc(21px * var(--ts)); }
  .choice { padding: 12px 12px 12px 42px; min-height: 52px; }
  .choice .jpt { font-size: calc(18px * var(--ts)); }
  .match-grid { gap: 10px 10px; }
  .match-item { padding: 10px 8px; font-size: calc(14px * var(--ts)); }
  .match-item .jpt { font-size: calc(17px * var(--ts)); }
  .tile { font-size: calc(17px * var(--ts)); padding: 7px 11px; }
  .bubble { max-width: 86%; }
  .passage { font-size: calc(17px * var(--ts)); padding: 16px 14px; }
  .done-stats .stat { min-width: 0; flex: 1 1 40%; }

  /* conversations */
  .convo-head { flex-wrap: wrap; padding: 10px 12px; gap: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .convo-head .scene-emoji { display: none; }
  .convo-head .grow { flex-basis: calc(100% - 60px); }
  .chat { padding: 16px 12px; }
  .convo-opts { padding: 12px 12px calc(14px + env(safe-area-inset-bottom)); }
  .convo-opt .jpt { font-size: calc(16px * var(--ts)); }

  /* dialogs become bottom sheets */
  .modal-back { padding: 0; place-items: end stretch; }
  .modal, .modal.wide {
    max-width: none; border-radius: 18px 18px 0 0; max-height: 92dvh;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  #toast-root { left: 12px; right: 12px; bottom: calc(74px + env(safe-area-inset-bottom)); align-items: center; }
  .detail-big { font-size: calc(76px * var(--ts)); }
}
