/* Katakoi styles */
:root {
  --bg: #f7f1e6;
  --bg-2: #efe6d6;
  --surface: #fffaf2;
  --surface-2: #f6eddf;
  --ink: #1f2340;
  --ink-soft: #3a3f63;
  --muted: #5d6283;
  --line: #e2d6c2;
  --accent: #d9432e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe1da;
  --indigo: #2b3a8c;
  --indigo-soft: #e1e5f7;
  --sakura: #f3b7c3;
  --sakura-soft: #fde9ee;
  --matcha: #4f8a3c;
  --matcha-soft: #e2f0d9;
  --gold: #c98a12;
  --gold-soft: #fbefd2;
  --good: #2f7d4f;
  --bad: #c2362a;
  --shadow: 0 1px 2px rgba(31, 35, 64, .06), 0 8px 24px rgba(31, 35, 64, .08);
  --shadow-lg: 0 2px 4px rgba(31, 35, 64, .08), 0 18px 40px rgba(31, 35, 64, .14);
  --radius: 22px;
  --radius-sm: 14px;
  --font-ui: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-jp: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cg fill='none' stroke='%232b3a8c' stroke-opacity='.07' stroke-width='1.5'%3E%3Cpath d='M0 40a40 40 0 0 1 80 0M10 40a30 30 0 0 1 60 0M20 40a20 20 0 0 1 40 0M30 40a10 10 0 0 1 20 0M-40 20a40 40 0 0 1 80 0M-30 20a30 30 0 0 1 60 0M-20 20a20 20 0 0 1 40 0M-10 20a10 10 0 0 1 20 0M40 20a40 40 0 0 1 80 0M50 20a30 30 0 0 1 60 0M60 20a20 20 0 0 1 40 0M70 20a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E");
  --nav-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11132a; --bg-2: #171a36; --surface: #1c2042; --surface-2: #252a52; --ink: #f6efe3; --ink-soft: #e0d8ca;
    --muted: #a9adcb; --line: #333a6a; --accent: #ff6f55; --accent-ink: #1a0e0b; --accent-soft: #4a2423;
    --indigo: #9fb0ff; --indigo-soft: #283161; --sakura: #f6a5b6; --sakura-soft: #432a3c; --matcha: #8fcf72;
    --matcha-soft: #24402a; --gold: #f2c14e; --gold-soft: #463a1d; --good: #7ad694; --bad: #ff8a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 40px rgba(0, 0, 0, .45);
    --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cg fill='none' stroke='%239fb0ff' stroke-opacity='.06' stroke-width='1.5'%3E%3Cpath d='M0 40a40 40 0 0 1 80 0M10 40a30 30 0 0 1 60 0M20 40a20 20 0 0 1 40 0M30 40a10 10 0 0 1 20 0M-40 20a40 40 0 0 1 80 0M-30 20a30 30 0 0 1 60 0M-20 20a20 20 0 0 1 40 0M-10 20a10 10 0 0 1 20 0M40 20a40 40 0 0 1 80 0M50 20a30 30 0 0 1 60 0M60 20a20 20 0 0 1 40 0M70 20a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11132a; --bg-2: #171a36; --surface: #1c2042; --surface-2: #252a52; --ink: #f6efe3; --ink-soft: #e0d8ca;
  --muted: #a9adcb; --line: #333a6a; --accent: #ff6f55; --accent-ink: #1a0e0b; --accent-soft: #4a2423;
  --indigo: #9fb0ff; --indigo-soft: #283161; --sakura: #f6a5b6; --sakura-soft: #432a3c; --matcha: #8fcf72;
  --matcha-soft: #24402a; --gold: #f2c14e; --gold-soft: #463a1d; --good: #7ad694; --bad: #ff8a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 40px rgba(0, 0, 0, .45);
  --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40'%3E%3Cg fill='none' stroke='%239fb0ff' stroke-opacity='.06' stroke-width='1.5'%3E%3Cpath d='M0 40a40 40 0 0 1 80 0M10 40a30 30 0 0 1 60 0M20 40a20 20 0 0 1 40 0M30 40a10 10 0 0 1 20 0M-40 20a40 40 0 0 1 80 0M-30 20a30 30 0 0 1 60 0M-20 20a20 20 0 0 1 40 0M-10 20a10 10 0 0 1 20 0M40 20a40 40 0 0 1 80 0M50 20a30 30 0 0 1 60 0M60 20a20 20 0 0 1 40 0M70 20a10 10 0 0 1 20 0'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg) var(--wave);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
.jp { font-family: var(--font-jp); font-feature-settings: "palt" 0; }
h1, h2, h3 { line-height: 1.15; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--indigo); }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 3px; border-radius: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; z-index: 100; }
.skip:focus { top: 12px; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand b { font-size: 1.25rem; letter-spacing: -.02em; }
.brand small { display: block; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.pill-stat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
  font-weight: 700; font-size: .92rem; white-space: nowrap;
}
.pill-stat .ico { font-size: 1rem; }

main#view { padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); max-width: 760px; margin: 0 auto; }
main#view.wide { max-width: 1040px; }
main#view:focus { outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 54px; border-radius: 16px; text-decoration: none; color: var(--muted); font-size: .78rem; font-weight: 700;
  transition: color .2s, background .2s;
}
.tabbar a svg { width: 26px; height: 26px; transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.tabbar a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.tabbar a[aria-current="page"] svg { transform: translateY(-1px) scale(1.08); }

@media (min-width: 900px) {
  body { padding-left: 104px; }
  .tabbar {
    top: 0; right: auto; width: 104px; bottom: 0; grid-template-columns: 1fr; grid-auto-rows: 84px;
    align-content: center; gap: 8px; padding: 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar a { font-size: .8rem; }
  main#view { padding-bottom: 48px; padding-top: 28px; }
}

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.eyebrow { font-size: .76rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 4px 12px; }
.section-title h2 { font-size: 1.2rem; }
.section-title .jp { color: var(--muted); font-size: .95rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 22px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 1.02rem; text-decoration: none;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000), 0 8px 18px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .12s, box-shadow .12s, filter .2s;
  touch-action: manipulation;
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: 0 3px 0 var(--line), var(--shadow); }
.btn.ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn.indigo { background: var(--indigo); color: var(--surface); box-shadow: 0 4px 0 color-mix(in srgb, var(--indigo) 55%, #000); }
.btn.small { min-height: 42px; padding: 8px 16px; font-size: .92rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); text-decoration: none; font-size: 1.2rem;
}
.icon-btn svg { width: 24px; height: 24px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface); font-weight: 700; font-size: .92rem;
}
.chip[aria-pressed="true"] { border-color: var(--indigo); background: var(--indigo-soft); color: var(--ink); }

.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: inherit; transition: width .5s cubic-bezier(.2, .8, .2, 1); }

/* ---------- Home ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 28px; padding: 22px 20px;
  background: radial-gradient(120% 140% at 100% 0%, #d8692a 0%, #c23a2b 40%, #6e2a63 78%, #2b3a8c 100%);
  color: #fff; box-shadow: var(--shadow-lg);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 190px; height: 190px; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
}
.hero .bigkana { position: absolute; right: 14px; bottom: -22px; font-size: 128px; line-height: 1; opacity: .2; font-weight: 700; pointer-events: none; }
.hero h1 { font-size: 1.55rem; position: relative; z-index: 1; max-width: 16ch; }
.hero p { position: relative; z-index: 1; opacity: .95; margin-top: 6px; max-width: 36ch; }
.hero .row { position: relative; z-index: 1; margin-top: 16px; }
.hero .btn { background: #fff; color: #9b2a1b; box-shadow: 0 4px 0 rgba(0, 0, 0, .18); }
.hero .btn.ghost { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .5); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border-radius: 18px; padding: 12px; box-shadow: var(--shadow); text-align: center; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { font-size: .78rem; color: var(--muted); font-weight: 700; }

.goal { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; width: 64px; height: 64px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 800; font-size: .9rem; }

/* Lesson path */
.path { display: grid; gap: 12px; }
.lesson {
  position: relative; display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 14px;
  padding: 14px 14px 14px 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  text-decoration: none; color: inherit; border: 2px solid transparent;
  transition: transform .18s cubic-bezier(.3, 1.5, .5, 1), border-color .2s;
}
.lesson:hover { transform: translateY(-2px); border-color: var(--line); }
.lesson:active { transform: scale(.985); }
.lesson .ring { width: 60px; height: 60px; }
.lesson .ring > span { width: 48px; height: 48px; font-size: 1.5rem; font-weight: 700; }
.lesson h3 { font-size: 1.05rem; }
.lesson p { font-size: .88rem; color: var(--muted); margin-top: 2px; }
.lesson .chars { font-size: .95rem; color: var(--ink-soft); letter-spacing: .12em; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson.locked { opacity: .72; }
.lesson.locked .ring > span { filter: grayscale(1); }
.lesson .tag { font-size: .72rem; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: var(--indigo-soft); color: var(--indigo); white-space: nowrap; }
.lesson.next { border-color: var(--accent); }
.lesson.next .tag { background: var(--accent); color: var(--accent-ink); }
.stars { color: var(--gold); letter-spacing: 1px; font-size: .95rem; white-space: nowrap; }
.stars .off { color: var(--line); }
.hanko {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none;
  border: 3px solid var(--accent); color: var(--accent); font-weight: 900; font-size: 1.35rem; transform: rotate(-8deg);
  font-family: var(--font-jp); opacity: .9; background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.stamp-in { animation: stamp .5s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes stamp { from { transform: rotate(-30deg) scale(2.2); opacity: 0; } to { transform: rotate(-8deg) scale(1); opacity: .9; } }

/* ---------- Kana card ---------- */
.lesson-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lesson-head .grow h2 { font-size: 1rem; }
.lesson-head .progress { margin-top: 6px; }
.kcard { position: relative; background: var(--surface); border-radius: 30px; box-shadow: var(--shadow-lg); overflow: hidden; }
.kcard-top {
  position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  padding: 18px 18px 10px;
  background: radial-gradient(100% 120% at 0% 0%, var(--sakura-soft), transparent 60%), radial-gradient(90% 90% at 100% 100%, var(--indigo-soft), transparent 70%);
}
.kchar-wrap { display: flex; align-items: center; gap: 14px; min-width: 0; }
.kchar {
  font-family: var(--font-jp); font-weight: 600; line-height: 1; letter-spacing: -.02em;
  font-size: clamp(104px, 34vw, 190px); color: var(--ink);
  text-shadow: 0 6px 0 color-mix(in srgb, var(--sakura) 45%, transparent);
  animation: inkdrop .55s cubic-bezier(.2, 1.3, .4, 1) both;
}
.kchar.two { font-size: clamp(82px, 25vw, 150px); }
@keyframes inkdrop { from { opacity: 0; transform: translateY(14px) scale(.9); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
.kmeta { display: grid; gap: 8px; justify-items: start; min-width: 0; }
.kmeta .romaji { overflow-wrap: anywhere; line-height: 1.1; }
.romaji { font-size: clamp(1.6rem, 7vw, 2.3rem); font-weight: 900; color: var(--accent); letter-spacing: .02em; }
.hira { font-size: .9rem; color: var(--muted); font-weight: 700; }
.hira .jp { font-size: 1.15rem; color: var(--ink-soft); }
.play {
  position: relative; display: grid; place-items: center; width: 84px; height: 84px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--accent) 60%, #000), 0 10px 26px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform .12s; touch-action: manipulation;
}
.play svg { width: 38px; height: 38px; }
.play:active { transform: translateY(3px) scale(.97); }
.play.playing::before, .play.playing::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--accent); opacity: 0;
  animation: ripple 1.1s ease-out infinite;
}
.play.playing::after { animation-delay: .45s; }
@keyframes ripple { from { transform: scale(.9); opacity: .7; } to { transform: scale(1.45); opacity: 0; } }
.play.sm { width: 52px; height: 52px; }
.play.sm svg { width: 24px; height: 24px; }
.speed { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }
.speed .chip { min-height: 34px; padding: 4px 10px; font-size: .8rem; }

.sounds { padding: 2px 18px 4px; color: var(--muted); font-weight: 600; }
.sounds b { color: var(--ink); font-weight: 700; }
.kmeta .romaji.long { font-size: 1.2rem; }

.mnemo {
  position: relative; margin: 14px; padding: 20px 18px 22px; border-radius: 24px; overflow: hidden;
  background: linear-gradient(160deg, var(--gold-soft), var(--sakura-soft) 70%);
  border: 2px dashed color-mix(in srgb, var(--gold) 45%, transparent);
}
.mnemo .eyebrow { color: var(--gold); }
.mnemo-body { display: grid; grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 10px; margin-top: 4px; }
@media (min-width: 620px) { .mnemo-body { grid-template-columns: auto 1fr; justify-items: start; text-align: left; gap: 18px; align-items: center; } }
.mnemo .emoji {
  font-size: clamp(72px, 22vw, 110px); line-height: 1; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .15));
  animation: popin .7s .15s cubic-bezier(.2, 1.7, .4, 1) both;
}
.mnemo .emoji.wiggle { animation: wiggle .6s ease-in-out; }
@keyframes popin { from { transform: scale(0) rotate(-25deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg) scale(1.08); } 75% { transform: rotate(10deg) scale(1.08); } }
.mnemo .text { font-size: clamp(1.15rem, 4.6vw, 1.45rem); font-weight: 700; line-height: 1.35; color: var(--ink); animation: fadeup .5s .3s both; }
mark { background: linear-gradient(transparent 55%, color-mix(in srgb, var(--accent) 35%, transparent) 0); color: inherit; padding: 0 2px; }
@keyframes fadeup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.mnemo.no-emoji .mnemo-body { grid-template-columns: 1fr; }

.ksection { padding: 4px 18px 16px; }
.ksection h3 { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.warn {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 16px;
  background: var(--accent-soft); color: var(--ink);
}
.warn .twins { display: flex; gap: 6px; flex-wrap: wrap; }
.twin { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 12px; background: var(--surface); border: 0; font-weight: 700; min-height: 44px; }
.twin .jp { font-size: 1.6rem; line-height: 1; }
.twin small { color: var(--muted); }
.warn p { font-size: .92rem; margin-top: 6px; }

.strokes-box { display: flex; align-items: center; gap: 14px; }
.strokes-svgs { display: flex; gap: 6px; }
.strokes-svgs svg { width: 112px; height: 112px; background: var(--surface-2); border-radius: 16px; }
.strokes-svgs .guide { stroke: var(--line); stroke-width: .6; stroke-dasharray: 3 3; }
.strokes-svgs .ghost { fill: none; stroke: color-mix(in srgb, var(--ink) 12%, transparent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.strokes-svgs .ink { fill: none; stroke: var(--ink); stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.strokes-svgs .ink.now { stroke: var(--accent); }
.strokes-svgs .num { font-size: 8px; fill: var(--accent); font-weight: 800; font-family: var(--font-ui); }
.strokes-svgs .small-char { transform-origin: 50% 100%; }

.words { display: grid; gap: 8px; }
.word {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; text-align: left;
  padding: 10px 12px; border-radius: 16px; border: 0; background: var(--surface-2); min-height: 60px; width: 100%;
  transition: transform .15s;
}
.word:active { transform: scale(.98); }
.word .em { font-size: 2rem; line-height: 1; text-align: center; }
.word .jp { font-size: 1.35rem; font-weight: 700; }
.word .jp .hl { color: var(--accent); }
.word small { display: block; color: var(--muted); font-weight: 600; }
.word .spk { width: 22px; height: 22px; color: var(--accent); }

.card-nav { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); display: grid; grid-template-columns: auto 1fr; gap: 10px; margin-top: 14px; z-index: 5; }
@media (min-width: 900px) { .card-nav { bottom: 16px; } }
.dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 12px 0 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); width: 20px; border-radius: 6px; }
.dots i.seen { background: color-mix(in srgb, var(--accent) 45%, var(--line)); }

.slide-in-right { animation: slideR .35s cubic-bezier(.2, .9, .3, 1) both; }
.slide-in-left { animation: slideL .35s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes slideR { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideL { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Practice ---------- */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.game-tile {
  position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center;
  padding: 16px; border-radius: var(--radius); text-decoration: none; color: var(--ink); background: var(--surface); box-shadow: var(--shadow);
  overflow: hidden; border: 2px solid transparent; transition: transform .18s cubic-bezier(.3, 1.5, .5, 1), border-color .2s; min-height: 96px;
}
.game-tile:hover { transform: translateY(-2px); border-color: var(--line); }
.game-tile .gi { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; font-size: 2rem; font-family: var(--font-jp); font-weight: 700; }
.game-tile h3 { font-size: 1.08rem; }
.game-tile p { font-size: .88rem; color: var(--muted); margin-top: 2px; }
.game-tile .best { font-size: .78rem; font-weight: 800; color: var(--gold); margin-top: 4px; }
.t1 .gi { background: var(--accent-soft); color: var(--accent); }
.t2 .gi { background: var(--indigo-soft); color: var(--indigo); }
.t3 .gi { background: var(--sakura-soft); color: var(--ink); }
.t4 .gi { background: var(--matcha-soft); color: var(--matcha); }
.t5 .gi { background: var(--gold-soft); color: var(--gold); }
.t6 .gi { background: var(--surface-2); color: var(--ink); }

.scope { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.scope::-webkit-scrollbar { display: none; }
.scope .chip { flex: none; }

.game-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.game-head .progress { flex: 1; height: 14px; }
.combo { font-weight: 900; color: var(--gold); min-width: 3ch; text-align: right; }
.timer { font-weight: 900; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.timer.low { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.15); } }

.prompt {
  display: grid; place-items: center; text-align: center; min-height: 210px; padding: 18px; border-radius: 28px;
  background: var(--surface); box-shadow: var(--shadow-lg); position: relative;
}
.prompt .q { font-size: .95rem; font-weight: 700; color: var(--muted); }
.prompt .big { font-family: var(--font-jp); font-size: clamp(96px, 30vw, 160px); line-height: 1.05; font-weight: 600; animation: inkdrop .45s cubic-bezier(.2, 1.3, .4, 1) both; }
.prompt .big.word-big { font-size: clamp(48px, 14vw, 88px); letter-spacing: .04em; }
.prompt .play { margin-top: 12px; }
.prompt .tip { font-size: .95rem; margin-top: 4px; color: var(--ink-soft); max-width: 40ch; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.opt {
  position: relative; min-height: 76px; border-radius: 20px; border: 2px solid var(--line); background: var(--surface);
  font-weight: 800; font-size: 1.35rem; box-shadow: 0 4px 0 var(--line); transition: transform .1s, box-shadow .1s, background .2s, border-color .2s;
  touch-action: manipulation; padding: 8px 10px;
}
.opt .k { position: absolute; left: 10px; top: 6px; font-size: .7rem; color: var(--muted); font-weight: 800; }
.opt.jp-opt { font-family: var(--font-jp); font-size: 2.4rem; font-weight: 600; }
.opt.meaning { font-size: 1.05rem; }
.opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.opt.correct { background: var(--matcha-soft); border-color: var(--good); box-shadow: 0 4px 0 var(--good); animation: bounce .4s; }
.opt.wrong { background: var(--accent-soft); border-color: var(--bad); box-shadow: 0 4px 0 var(--bad); animation: shake .4s; }
.opt[disabled] { cursor: default; }
@keyframes bounce { 40% { transform: scale(1.06); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.listen-big { width: 120px; height: 120px; }
.listen-big svg { width: 54px; height: 54px; }

.typein { display: flex; gap: 8px; margin-top: 14px; }
.typein input {
  flex: 1; min-width: 0; min-height: 56px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  padding: 10px 16px; font-size: 1.2rem; font-weight: 700;
}
.typein input:focus { border-color: var(--indigo); outline: none; }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  border-radius: 26px 26px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .18); animation: sheet .3s cubic-bezier(.2, .9, .3, 1) both;
  background: var(--surface); max-height: 78vh; max-height: 78dvh; overflow-y: auto; overscroll-behavior: contain;
}
.feedback .inner { max-width: 720px; margin: 0 auto; }
.feedback.good { background: var(--matcha-soft); }
.feedback.bad { background: var(--accent-soft); }
.feedback h3 { font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.feedback .fb-mnemo { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; margin: 10px 0 14px; padding: 12px; border-radius: 18px; background: var(--surface); }
.feedback .fb-mnemo .emoji { font-size: 54px; line-height: 1; animation: popin .5s cubic-bezier(.2, 1.7, .4, 1) both; }
.feedback .fb-mnemo .jp { font-size: 2.2rem; }
.feedback .fb-mnemo p { font-weight: 700; }
@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
@media (min-width: 900px) { .feedback { left: 104px; } }

.results { text-align: center; }
.results .medal { font-size: 84px; line-height: 1; animation: popin .7s cubic-bezier(.2, 1.7, .4, 1) both; }
.results h2 { font-size: 1.6rem; margin-top: 8px; }
.results .big-stars { font-size: 2.4rem; color: var(--gold); letter-spacing: 6px; margin: 6px 0; }
.results .big-stars .off { color: var(--line); }
.review-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.review-list button { min-width: 56px; min-height: 56px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-family: var(--font-jp); font-size: 1.5rem; }

/* Memory match */
.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 560px; margin: 0 auto; }
.mcard { aspect-ratio: 4 / 5; perspective: 700px; border: 0; background: none; padding: 0; }
.mcard .in { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.3, 1.3, .5, 1); }
.mcard.up .in, .mcard.done .in { transform: rotateY(180deg); }
.mcard .face { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: var(--shadow); }
.mcard .back { background: var(--indigo) var(--wave); color: rgba(255, 255, 255, .85); font-size: 1.6rem; font-family: var(--font-jp); }
:root[data-theme="dark"] .mcard .back { background-color: var(--indigo-soft); }
.mcard .front { background: var(--surface); transform: rotateY(180deg); font-weight: 800; font-size: 1.3rem; padding: 4px; text-align: center; }
.mcard .front.jp { font-size: 2.2rem; font-weight: 600; }
.mcard.done .front { background: var(--matcha-soft); }
.mcard.miss .front { background: var(--accent-soft); }

/* ---------- Chart ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .82rem; font-weight: 700; color: var(--muted); margin: 6px 2px 14px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 5px; vertical-align: -2px; margin-right: 5px; border: 2px solid var(--line); }
.chart-sec { margin-bottom: 22px; }
.chart-sec h2 { font-size: 1.05rem; margin: 0 2px 10px; }
.chart-head, .chart-row { display: grid; grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); gap: 6px; }
.chart-head { margin-bottom: 4px; }
.chart-head span { text-align: center; font-size: .76rem; font-weight: 800; color: var(--muted); text-transform: uppercase; }
.chart-row + .chart-row { margin-top: 6px; }
.chart-flow { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.cell {
  position: relative; display: grid; place-items: center; align-content: center; min-height: 64px; padding: 6px 2px;
  border-radius: 14px; border: 2px solid var(--line); background: var(--surface); transition: transform .15s; min-width: 0;
}
.cell:hover { transform: translateY(-2px); }
.cell:active { transform: scale(.95); }
.cell .jp { font-size: clamp(1.4rem, 6vw, 2rem); line-height: 1.1; font-weight: 600; }
.cell small { font-size: .72rem; font-weight: 800; color: var(--muted); }
.cell.empty { border: 0; background: transparent; pointer-events: none; }
.cell.m1, .legend .m1 { background: var(--sakura-soft); border-color: var(--sakura); }
.cell.m2, .legend .m2 { background: var(--indigo-soft); border-color: color-mix(in srgb, var(--indigo) 50%, transparent); }
.cell.m3, .legend .m3 { background: var(--matcha-soft); border-color: var(--matcha); }
.cell.m4, .legend .m4 { background: var(--gold-soft); border-color: var(--gold); }
.cell.m4::after { content: "★"; position: absolute; top: 2px; right: 5px; font-size: .62rem; color: var(--gold); }
.legend .m0 { background: var(--surface); }

/* ---------- Sheet (modal) ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 30, .45); display: grid; align-items: end; justify-items: center; animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(100%, 720px); max-height: 92vh; max-height: 92dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 28px 28px 0 0; padding: 12px 12px calc(env(safe-area-inset-bottom) + 16px);
  animation: sheet .32s cubic-bezier(.2, .9, .3, 1) both;
}
@media (min-width: 900px) { .overlay { align-items: center; padding-left: 104px; } .sheet { border-radius: 28px; } }
.sheet-head { display: flex; justify-content: flex-end; padding: 0 0 8px; }

/* ---------- Me / settings ---------- */
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .grow b { display: block; }
.set-row .grow small { color: var(--muted); }
.switch { position: relative; width: 58px; height: 34px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); transition: transform .25s cubic-bezier(.3, 1.4, .5, 1); }
.switch input:checked + span { background: var(--matcha); }
.switch input:checked + span::after { transform: translateX(24px); }
.switch input:focus-visible + span { outline: 3px solid var(--indigo); outline-offset: 3px; }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--surface-2); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; font-weight: 800; font-size: .86rem; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); }
textarea.io { width: 100%; min-height: 110px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); padding: 10px; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); font-weight: 700; font-size: .88rem; }
.badge.off { opacity: .45; filter: grayscale(1); }
.credits p + p { margin-top: 8px; }

/* ---------- Toast & confetti ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 70px); z-index: 80; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 800; box-shadow: var(--shadow-lg);
  animation: toast 2.6s cubic-bezier(.2, .9, .3, 1) both; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -16px); } 12%, 82% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; width: 100%; height: 100%; }
.xp-float { position: fixed; z-index: 85; font-weight: 900; color: var(--gold); pointer-events: none; animation: xpfloat 1s ease-out both; text-shadow: 0 2px 0 rgba(0, 0, 0, .1); }
@keyframes xpfloat { from { opacity: 0; transform: translateY(0) scale(.8); } 20% { opacity: 1; } to { opacity: 0; transform: translateY(-50px) scale(1.15); } }

.empty-state { text-align: center; padding: 28px 16px; }
.empty-state .em { font-size: 64px; }
.loading { display: grid; place-items: center; min-height: 60vh; font-size: 3rem; color: var(--accent); font-family: var(--font-jp); animation: pulse 1.2s infinite; }

@media (max-width: 380px) {
  body { font-size: 16px; }
  .brand small { display: none; }
  .pill-stat { padding: 5px 9px; font-size: .85rem; }
  .lesson { grid-template-columns: 54px 1fr auto; gap: 10px; }
  .lesson .ring { width: 54px; height: 54px; }
  .lesson .ring > span { width: 42px; height: 42px; font-size: 1.3rem; }
  .play { width: 72px; height: 72px; }
  .strokes-svgs svg { width: 96px; height: 96px; }
}

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