/* ============ Tokens ============ */
:root {
  --bg: #f6f1e7;
  --bg2: #efe7d8;
  --card: #fffdf8;
  --ink: #2b2a33;
  --ink2: #5d5a66;
  --ink3: #8f8a99;
  --line: #e4dccb;
  --ok: #2f9e6a;
  --ok-bg: #e2f5ea;
  --bad: #d4513d;
  --bad-bg: #fbe6e1;
  --warn: #c88a12;
  --warn-bg: #fdf1d6;
  --accent: #6a5acd;
  --accent-ink: #fff;
  --ja: #e2553f;
  --no: #2f6fb0;
  --de: #d39a12;
  --en: #23938a;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 20px rgba(60, 45, 20, .07);
  --shadow-lg: 0 10px 40px rgba(40, 30, 10, .18);
  --r: 18px;
  --r-sm: 12px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-jp: "Klee One", "Noto Sans JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-jp-sans: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16151a; --bg2: #1e1d24; --card: #24232b; --ink: #f1eee7; --ink2: #c3bfcc; --ink3: #8b8796;
    --line: #34323d; --ok: #4cc38a; --ok-bg: #1d3328; --bad: #f07a66; --bad-bg: #3a221e; --warn: #f0b53c; --warn-bg: #3a3020;
    --accent: #9d8ff0; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16151a; --bg2: #1e1d24; --card: #24232b; --ink: #f1eee7; --ink2: #c3bfcc; --ink3: #8b8796;
  --line: #34323d; --ok: #4cc38a; --ok-bg: #1d3328; --bad: #f07a66; --bad-bg: #3a221e; --warn: #f0b53c; --warn-bg: #3a3020;
  --accent: #9d8ff0; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}
[data-lang="ja"] { --accent: var(--ja); }
[data-lang="no"] { --accent: var(--no); }
[data-lang="de"] { --accent: var(--de); }
[data-lang="en"] { --accent: var(--en); }

/* ============ Base ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.5;
  min-height: 100dvh; overflow-x: hidden; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .4em; font-weight: 900; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; }
p { margin: 0 0 .7em; }
.jp { font-family: var(--font-jp); }
.jp-sans { font-family: var(--font-jp-sans); }
.muted { color: var(--ink2); }
.faint { color: var(--ink3); }
.small { font-size: .86rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
kbd { font-family: inherit; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 4px; padding: 0 3px; }

#app { max-width: 760px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#topbar { position: sticky; top: 0; z-index: 20; padding: calc(var(--safe-t) + 10px) 16px 8px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#topbar:empty { display: none; }
#view { flex: 1; padding: 8px 16px calc(96px + var(--safe-b)); outline: none; }
body.immersive #tabbar { display: none; }
body.immersive #view { padding-bottom: calc(24px + var(--safe-b)); }

/* ============ Top bar ============ */
.tb { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.tb-title { font-weight: 900; font-size: 1.1rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 1.15rem; flex: none; }
.icon-btn:active { transform: scale(.95); }
.progress { height: 10px; background: var(--bg2); border-radius: 99px; overflow: hidden; flex: 1; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s cubic-bezier(.3,.9,.4,1); }

/* ============ Tab bar ============ */
#tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; padding: 6px 8px calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
#tabbar .tabs { display: flex; width: 100%; max-width: 760px; }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; text-decoration: none; color: var(--ink3); font-size: .72rem; font-weight: 800; border-radius: 12px; }
#tabbar a .ti { font-size: 1.35rem; line-height: 1.1; filter: grayscale(.7); opacity: .8; transition: transform .2s; }
#tabbar a.on { color: var(--ink); }
#tabbar a.on .ti { filter: none; opacity: 1; transform: translateY(-2px) scale(1.08); }

/* ============ Cards & buttons ============ */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.card.tight { padding: 12px; }
.card.click { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.card.click:active { transform: scale(.985); }
.section-title { margin: 22px 2px 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .09em; color: var(--ink3); font-weight: 900; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.btn { appearance: none; border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 800; font-size: 1rem; background: var(--bg2); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .1s, filter .15s, background .2s; text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 70%, #000); }
.btn.primary:active { box-shadow: none; transform: translateY(3px); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: .9rem; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.ok { background: var(--ok); color: #fff; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; background: var(--bg2); font-weight: 800; font-size: .86rem; border: 0; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.tag { display: inline-block; font-size: .72rem; font-weight: 900; letter-spacing: .04em; padding: 2px 8px; border-radius: 99px; background: var(--bg2); color: var(--ink2); }
.tag.acc { background: color-mix(in srgb, var(--accent) 16%, transparent); color: color-mix(in srgb, var(--accent) 80%, var(--ink)); }

/* ============ Home ============ */
.hello { margin: 6px 2px 14px; }
.hello h1 { font-size: 1.8rem; }
.moods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mood { border: 0; border-radius: var(--r); padding: 14px 8px; background: var(--card); box-shadow: var(--shadow); text-align: center; }
.mood b { display: block; font-size: 1.6rem; line-height: 1.2; }
.mood span { font-weight: 900; display: block; }
.mood small { color: var(--ink3); font-weight: 700; }
.mood:active { transform: scale(.97); }
.langs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lang-card { position: relative; overflow: hidden; border: 0; text-align: left; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; min-height: 132px; display: flex; flex-direction: column; justify-content: space-between; text-decoration: none; color: inherit; }
.lang-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--accent); }
.lang-card .big { font-size: 2rem; line-height: 1; }
.lang-card .nm { font-weight: 900; font-size: 1.1rem; margin-top: 8px; }
.lang-card .nt { color: var(--ink3); font-size: .82rem; font-weight: 700; }
.lang-card .ring { position: absolute; right: 12px; top: 14px; }
.lang-card .focus { position: absolute; right: 10px; bottom: 10px; }
.tip-card { border-left: 5px solid var(--accent); }
.tip-card .lbl { font-size: .74rem; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.4rem; font-weight: 900; }
.stat span { font-size: .76rem; color: var(--ink3); font-weight: 800; }

/* ============ Lang hub ============ */
.hub-hero { border-radius: 24px; padding: 20px; color: #fff; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #1b1630)); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hub-hero h1 { margin: 0; font-size: 1.9rem; }
.hub-hero .native { opacity: .85; font-weight: 700; }
.hub-hero .deco { position: absolute; right: -10px; bottom: -30px; font-size: 7rem; opacity: .15; font-family: var(--font-jp); pointer-events: none; }
.hub-hero .row { margin-top: 14px; }
.hub-hero .btn { background: rgba(255,255,255,.95); color: #222; }
.hub-hero .btn.ghost { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tool { background: var(--card); border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 12px 6px; text-align: center; text-decoration: none; color: inherit; font-weight: 800; font-size: .86rem; border: 0; }
.tool b { display: block; font-size: 1.6rem; line-height: 1.3; }
.units { display: grid; gap: 10px; }
.unit { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 14px; text-decoration: none; color: inherit; }
.unit .em { font-size: 1.7rem; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: color-mix(in srgb, var(--accent) 13%, transparent); flex: none; }
.unit .ti { font-weight: 900; }
.unit .de { font-size: .84rem; color: var(--ink2); line-height: 1.35; }
.unit .meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }

/* ring */
.ring svg { display: block; transform: rotate(-90deg); }
.ring .bg { stroke: var(--bg2); }
.ring .fg { stroke: var(--accent); transition: stroke-dashoffset .6s; }
.ring-wrap { position: relative; display: inline-grid; place-items: center; }
.ring-wrap > span { position: absolute; font-size: .7rem; font-weight: 900; }

/* ============ Unit page ============ */
.unit-hero { display: flex; gap: 14px; align-items: center; }
.unit-hero .em { font-size: 2.6rem; width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 14%, transparent); flex: none; }
.games { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.game-btn { background: var(--card); border: 0; border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 12px; text-align: left; display: flex; gap: 10px; align-items: center; font-weight: 800; }
.game-btn b { font-size: 1.5rem; }
.game-btn small { display: block; color: var(--ink3); font-weight: 700; font-size: .76rem; }
.wordlist { display: grid; gap: 6px; }
.word { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.word .w { font-weight: 800; }
.word .m { color: var(--ink2); font-size: .9rem; }
.word .lvl { width: 26px; display: flex; gap: 2px; }
.word .lvl i { flex: 1; height: 14px; border-radius: 3px; background: var(--bg2); }
.word .lvl i.on { background: var(--accent); }
details.tip { background: var(--card); border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 0; overflow: hidden; }
details.tip + details.tip { margin-top: 8px; }
details.tip summary { list-style: none; padding: 12px 14px; font-weight: 800; cursor: pointer; display: flex; gap: 8px; align-items: center; }
details.tip summary::-webkit-details-marker { display: none; }
details.tip summary::after { content: "＋"; margin-left: auto; color: var(--ink3); }
details.tip[open] summary::after { content: "－"; }
details.tip .body { padding: 0 14px 14px; color: var(--ink2); }
.body b, .tipbox b { color: var(--ink); }
.body table, .tipbox table { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 6px 0; }
.body td, .body th, .tipbox td, .tipbox th { border: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.body th, .tipbox th { background: var(--bg2); }

/* ============ Player (sessions) ============ */
.stage { min-height: calc(100dvh - 180px); display: flex; flex-direction: column; }
.stage > .q { flex: 1; display: flex; flex-direction: column; }
.prompt-lbl { font-weight: 900; color: var(--ink2); font-size: .95rem; margin: 8px 0 12px; display: flex; gap: 8px; align-items: center; }
.big-word { font-size: 2.4rem; font-weight: 900; text-align: center; line-height: 1.15; margin: 14px 0 6px; word-break: break-word; }
.big-word.jp { font-size: 3.2rem; font-weight: 600; }
.big-word.kana { font-size: 5.5rem; font-weight: 600; }
.reading { text-align: center; color: var(--ink2); font-weight: 700; }
.sub { text-align: center; color: var(--ink3); font-weight: 700; font-size: .92rem; }
.speak-btn { border: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); width: 46px; height: 46px; border-radius: 50%; font-size: 1.25rem; display: inline-grid; place-items: center; flex: none; }
.speak-btn.big { width: 92px; height: 92px; font-size: 2.3rem; }
.speak-btn:active { transform: scale(.94); }
.speak-btn.playing { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 15%, transparent); } }
.opts { display: grid; gap: 10px; margin-top: 8px; }
.opts.two { grid-template-columns: 1fr 1fr; }
.opt { border: 0; background: var(--card); box-shadow: var(--shadow), inset 0 0 0 2px var(--line); border-radius: 16px; padding: 15px 14px; font-weight: 800; font-size: 1.05rem; text-align: left; transition: transform .1s, box-shadow .2s, background .2s; display: flex; gap: 10px; align-items: center; min-height: 58px; }
.opt .k { font-size: .75rem; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 7px; background: var(--bg2); color: var(--ink3); flex: none; }
.opt.jp { font-family: var(--font-jp); font-size: 1.5rem; font-weight: 600; justify-content: center; }
.opt:active { transform: scale(.98); }
.opt.ok { background: var(--ok-bg); box-shadow: inset 0 0 0 2px var(--ok); }
.opt.bad { background: var(--bad-bg); box-shadow: inset 0 0 0 2px var(--bad); animation: shake .35s; }
.opt.dim { opacity: .5; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.answer-input { width: 100%; border: 0; border-radius: 16px; padding: 16px; font-size: 1.25rem; font-weight: 700; background: var(--card); box-shadow: var(--shadow), inset 0 0 0 2px var(--line); outline: none; }
.answer-input:focus { box-shadow: var(--shadow), inset 0 0 0 2px var(--accent); }
.answer-input.ok { box-shadow: inset 0 0 0 2px var(--ok); background: var(--ok-bg); }
.answer-input.bad { box-shadow: inset 0 0 0 2px var(--bad); background: var(--bad-bg); }
.ime-preview { min-height: 1.6em; font-family: var(--font-jp); font-size: 1.4rem; text-align: center; color: var(--accent); margin-top: 6px; }
.special-keys { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.special-keys button { border: 0; background: var(--bg2); border-radius: 10px; padding: 8px 12px; font-weight: 800; }
.feedback { position: sticky; bottom: calc(8px + var(--safe-b)); margin-top: 16px; border-radius: 18px; padding: 14px 16px; animation: up .25s ease-out; }
.feedback.ok { background: var(--ok-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback.info { background: var(--card); box-shadow: var(--shadow-lg); }
.feedback h3 { margin: 0 0 4px; }
.feedback.ok h3 { color: var(--ok); }
.feedback.bad h3 { color: var(--bad); }
.feedback .btn { margin-top: 10px; }
.tipbox { margin-top: 8px; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--card) 70%, transparent); font-size: .93rem; color: var(--ink2); }
.tipbox::before { content: "💡 "; }
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
.actions { margin-top: auto; padding-top: 16px; display: flex; gap: 10px; }
.actions .btn { flex: 1; }

/* flashcard */
.flash { perspective: 1200px; margin: 10px 0; }
.flash-inner { position: relative; min-height: 290px; transition: transform .5s cubic-bezier(.3,.9,.4,1); transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.flash-face.back { transform: rotateY(180deg); }
.bridge { margin-top: 10px; font-size: .86rem; color: var(--ink2); background: var(--bg2); border-radius: 10px; padding: 6px 10px; display: inline-block; }
.example { margin-top: 12px; font-size: .98rem; }
.example .t { font-weight: 800; }
.example .tr { color: var(--ink3); font-size: .9rem; }
.gender-der { color: #3b7dd8; } .gender-die { color: #d8475b; } .gender-das { color: #2f9e6a; }
.gender-en { color: #3b7dd8; } .gender-ei { color: #d8475b; } .gender-et { color: #2f9e6a; }

/* match */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.tile { border: 0; min-height: 58px; padding: 10px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow), inset 0 0 0 2px var(--line); font-weight: 800; transition: all .2s; word-break: break-word; }
.tile.jp { font-family: var(--font-jp); font-size: 1.4rem; font-weight: 600; }
.tile.sel { box-shadow: inset 0 0 0 3px var(--accent); transform: scale(1.03); }
.tile.done { opacity: 0; pointer-events: none; transform: scale(.8); }
.tile.bad { animation: shake .35s; box-shadow: inset 0 0 0 2px var(--bad); }
.tile.good { box-shadow: inset 0 0 0 2px var(--ok); background: var(--ok-bg); }

/* build sentence */
.build-target { min-height: 74px; border-radius: 16px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line); padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.build-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.tok { border: 0; padding: 10px 14px; border-radius: 12px; background: var(--card); box-shadow: 0 2px 0 var(--line), inset 0 0 0 2px var(--line); font-weight: 800; font-size: 1.05rem; }
.tok.jp { font-family: var(--font-jp); font-size: 1.25rem; font-weight: 600; }
.tok.used { visibility: hidden; }

/* speak */
.mic-btn { width: 96px; height: 96px; border-radius: 50%; border: 0; font-size: 2.4rem; background: var(--accent); color: #fff; box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 65%, #000), var(--shadow); margin: 18px auto 8px; display: grid; place-items: center; }
.mic-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 65%, #000); }
.mic-btn.rec { animation: rec 1.1s infinite; background: var(--bad); box-shadow: 0 6px 0 #8a2a1e; }
@keyframes rec { 50% { box-shadow: 0 6px 0 #8a2a1e, 0 0 0 16px rgba(212, 81, 61, .2); } }
.wave { height: 44px; display: flex; gap: 3px; align-items: center; justify-content: center; }
.wave i { width: 4px; border-radius: 3px; background: var(--accent); height: 6px; transition: height .08s; }
.heard { margin-top: 10px; font-size: 1.15rem; text-align: center; line-height: 1.8; }
.heard .w-ok { color: var(--ok); font-weight: 800; }
.heard .w-bad { color: var(--bad); font-weight: 800; text-decoration: underline wavy; text-underline-offset: 4px; }
.heard .w-miss { color: var(--ink3); text-decoration: line-through; }
.score-big { font-size: 3rem; font-weight: 900; text-align: center; }

/* write canvas */
.write-wrap { position: relative; width: min(100%, 340px); aspect-ratio: 1; margin: 6px auto; border-radius: 22px; background: var(--card); box-shadow: var(--shadow); overflow: hidden; touch-action: none; }
.write-wrap canvas, .write-wrap svg, .write-wrap .ghost { position: absolute; inset: 0; width: 100%; height: 100%; }
.write-wrap .grid-lines { position: absolute; inset: 0; background:
  linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat,
  linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat; opacity: .8; pointer-events: none; }
.write-wrap .ghost { display: grid; place-items: center; font-family: var(--font-jp); color: var(--ink); opacity: .1; pointer-events: none; font-size: 240px; line-height: 1; }
.write-wrap svg.strokes path { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.write-wrap svg.strokes.ghosted path { stroke: var(--ink3); opacity: .28; }
.write-wrap svg.strokes text { font-size: 8px; fill: var(--accent); font-family: var(--font); font-weight: 900; }
.write-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

/* kana grid */
.kana-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.kana-cell { border: 0; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); padding: 6px 2px 4px; text-align: center; position: relative; min-height: 64px; }
.kana-cell .c { font-family: var(--font-jp); font-size: 1.7rem; line-height: 1.2; font-weight: 600; }
.kana-cell .r { font-size: .7rem; color: var(--ink3); font-weight: 800; }
.kana-cell.empty { background: transparent; box-shadow: none; pointer-events: none; }
.kana-cell .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--bg2); }
.kana-cell .dot.l1 { background: color-mix(in srgb, var(--accent) 40%, var(--bg2)); }
.kana-cell .dot.l2 { background: var(--accent); }
.kana-row-btn { border: 0; background: transparent; color: var(--accent); font-weight: 900; font-size: .8rem; }
.kanji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.kanji-grid .kana-cell { min-height: 82px; }
.kanji-grid .kana-cell .c { font-size: 2.1rem; }

/* games: rain & blitz */
.arena { position: relative; height: min(62dvh, 520px); border-radius: 22px; background: linear-gradient(to bottom, color-mix(in srgb, var(--accent) 8%, var(--card)), var(--card)); box-shadow: var(--shadow); overflow: hidden; }
.drop { position: absolute; padding: 8px 14px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-weight: 900; white-space: nowrap; transform: translateX(-50%); font-size: 1.15rem; }
.drop.jp { font-family: var(--font-jp); font-size: 1.8rem; font-weight: 600; }
.drop.pop { animation: pop .3s forwards; }
@keyframes pop { to { transform: translateX(-50%) scale(1.6); opacity: 0; } }
.arena .floor { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: var(--bad); opacity: .35; }
.hud { display: flex; justify-content: space-between; font-weight: 900; margin-bottom: 8px; }
.blitz-card { text-align: center; padding: 28px 10px; font-size: 2rem; font-weight: 900; transition: transform .2s, opacity .2s; }
.blitz-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.blitz-btns .btn { padding: 18px 0; font-size: 1.2rem; }
.btn.der { background: #3b7dd8; color: #fff; } .btn.die { background: #d8475b; color: #fff; } .btn.das { background: #2f9e6a; color: #fff; }

/* memory */
.mem-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .mem-grid { grid-template-columns: repeat(4, 1fr); } }
.mem { aspect-ratio: 3/4; perspective: 800px; border: 0; background: none; padding: 0; }
.mem-in { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.mem.up .mem-in { transform: rotateY(180deg); }
.mem-f { position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-items: center; padding: 6px; box-shadow: var(--shadow); font-weight: 800; font-size: .95rem; text-align: center; word-break: break-word; }
.mem-f.front { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #000)); color: #fff; font-size: 1.6rem; }
.mem-f.back { background: var(--card); transform: rotateY(180deg); }
.mem-f.back.jp { font-family: var(--font-jp); font-size: 1.6rem; font-weight: 600; }
.mem.got .mem-f.back { background: var(--ok-bg); }

/* end screen */
.end { text-align: center; padding-top: 20px; }
.end .medal { font-size: 4.5rem; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }
.curio { text-align: left; border: 2px dashed color-mix(in srgb, var(--accent) 50%, var(--line)); background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.learned { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; }

/* reading */
.line { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line .o { font-weight: 700; font-size: 1.1rem; cursor: pointer; }
.line .o.jp { font-family: var(--font-jp); font-size: 1.3rem; }
.line .t { color: var(--ink3); font-size: .92rem; }
.line.active .o { color: var(--accent); }
.gloss { display: flex; flex-wrap: wrap; gap: 6px; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 130px; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 18px; box-shadow: var(--shadow); }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.ai { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.bubble .tr { font-size: .85rem; color: var(--ink3); margin-top: 4px; }
.bubble .rm { font-size: .85rem; color: var(--ink2); font-style: italic; }
.bubble .fix { margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: var(--warn-bg); font-size: .9rem; }
.bubble .fix b { color: var(--warn); }
.chat-input { position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); z-index: 25; }
.chat-input .in { max-width: 728px; margin: 0 auto; display: flex; gap: 8px; }
.chat-input input { flex: 1; border: 0; border-radius: 14px; padding: 12px 14px; background: var(--card); box-shadow: var(--shadow), inset 0 0 0 2px var(--line); outline: none; min-width: 0; }
.typing i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink3); margin: 0 2px; 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; } }

/* overlay / modal / toast */
#overlay { position: fixed; inset: 0; z-index: 50; display: none; }
#overlay.on { display: block; }
.scrim { position: absolute; inset: 0; background: rgba(15, 12, 20, .45); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow: auto; background: var(--bg); border-radius: 24px 24px 0 0; padding: 18px 16px calc(20px + var(--safe-b)); box-shadow: var(--shadow-lg); animation: sheet .28s cubic-bezier(.3,.9,.4,1); max-width: 760px; margin: 0 auto; }
.sheet .grab { width: 44px; height: 5px; border-radius: 99px; background: var(--line); margin: -6px auto 12px; }
@keyframes sheet { from { transform: translateY(40%); opacity: .4; } }
#toasts { position: fixed; top: calc(var(--safe-t) + 12px); left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-weight: 800; box-shadow: var(--shadow-lg); animation: up .25s; text-align: center; }
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; z-index: 70; pointer-events: none; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

/* forms */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 800; font-size: .92rem; }
.field input[type=text], .field select { border: 0; border-radius: 12px; padding: 11px 12px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line); outline: none; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 99px; position: relative; transition: background .2s; flex: none; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.code-box { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.2rem; font-weight: 800; letter-spacing: .03em; padding: 12px; text-align: center; background: var(--bg2); border-radius: 12px; user-select: all; }

.empty { text-align: center; padding: 30px 10px; color: var(--ink3); }
.empty b { display: block; font-size: 2.4rem; }
.notice { padding: 10px 12px; border-radius: 12px; background: var(--warn-bg); font-size: .9rem; }

@media (min-width: 640px) {
  .langs { grid-template-columns: repeat(4, 1fr); }
  .tools { grid-template-columns: repeat(6, 1fr); }
  .games { grid-template-columns: repeat(3, 1fr); }
  .kana-grid { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.write-wrap { container-type: inline-size; }
.write-wrap .ghost { font-size: 72cqw; }
