:root {
  --bg: #f7f3ee;
  --surface: #fffdfa;
  --surface-2: #f0ebe4;
  --ink: #1f1b16;
  --ink-2: #5f574d;
  --ink-3: #958b7f;
  --line: #e4ddd3;
  --red: #c8102e;
  --red-soft: #fbe6e8;
  --teal: #1f7a6d;
  --teal-soft: #dff1ed;
  --amber: #b76e00;
  --amber-soft: #fbefd9;
  --blue: #2f5fb3;
  --blue-soft: #e3ebf8;
  --radius: 18px;
  --tab-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #221e18;
    --surface-2: #2c2720;
    --ink: #f3ede4;
    --ink-2: #c2b8aa;
    --ink-3: #8a8073;
    --line: #3a342b;
    --red: #ff5a6e;
    --red-soft: #3d1d22;
    --teal: #5cc7b4;
    --teal-soft: #173430;
    --amber: #f0b04c;
    --amber-soft: #3a2c14;
    --blue: #8fb1f0;
    --blue-soft: #1c2840;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
h3 { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
h3 small { color: var(--ink-3); font-weight: 500; margin-left: 4px; }
svg { width: 1.2em; height: 1.2em; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
body[data-view="study"] .page { padding-bottom: calc(env(safe-area-inset-bottom) + 16px); min-height: 100dvh; }
.page-title { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; }
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; border: 1px solid var(--line); }
.eyebrow { font-size: 13px; color: var(--ink-3); font-weight: 600; letter-spacing: 0.02em; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.center { text-align: center; }
.warn { color: var(--amber); }
.row-between { display: flex; justify-content: space-between; align-items: baseline; }
.row-between h3 { margin: 0; }

/* buttons */
.primary {
  background: var(--red); color: #fff; font-weight: 700; border-radius: 14px; padding: 14px 18px;
  transition: transform .08s ease, opacity .2s;
}
.primary:active:not(:disabled) { transform: scale(0.98); }
.primary:disabled { background: var(--surface-2); color: var(--ink-3); }
.primary.big { width: 100%; font-size: 19px; padding: 18px; border-radius: 16px; }
.ghost { color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--red); background: var(--red-soft); flex: none; }
.icon-btn svg { width: 22px; height: 22px; }
.back-link { color: var(--red); font-weight: 600; align-self: flex-start; padding: 4px 0; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--ink-3); padding: 6px 18px; min-width: 72px; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.tabbar .active { color: var(--red); font-weight: 700; }

/* home */
.hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-top: 4px; }
.hero h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; }
.hero h1 span { color: var(--red); }
.streak { display: flex; flex-direction: column; align-items: center; background: var(--surface); border-radius: 16px; padding: 8px 12px 6px; border: 1px solid var(--line); min-width: 68px; }
.streak .flame { font-size: 20px; filter: grayscale(1) opacity(.45); line-height: 1; }
.streak.lit .flame { filter: none; }
.streak b { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.streak small { font-size: 10px; color: var(--ink-3); }

.today { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 104px; height: 104px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--red); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: calc(326.7 * (1 - var(--p))); transition: stroke-dashoffset .6s ease; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring-label b { font-size: 28px; font-variant-numeric: tabular-nums; }
.ring-label small { color: var(--ink-3); font-size: 13px; }
.today-text h2 { font-size: 19px; margin-bottom: 10px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 600; }
.pill b { font-size: 17px; margin-right: 2px; font-variant-numeric: tabular-nums; }
.pill.due { background: var(--blue-soft); color: var(--blue); }
.pill.new { background: var(--teal-soft); color: var(--teal); }

.wotd-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; }
.id-text { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; overflow-wrap: anywhere; }
.id-text.xl { font-size: 32px; }
.kana { color: var(--ink-3); font-size: 15px; }
.ja { font-size: 17px; color: var(--ink-2); }
.ja.xl { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.4; }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 96px; align-items: end; margin: 12px 0 14px; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-col small { font-size: 11px; color: var(--ink-3); }
.bar-fill { width: 100%; max-width: 28px; min-height: 3px; border-radius: 6px 6px 3px 3px; background: var(--surface-2); }
.bar-col.met .bar-fill { background: var(--red); }
.progress-line { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter > div, .meter > span { position: absolute; inset: 0 auto 0 0; background: var(--teal-soft); border-radius: 99px; }
.meter > .mature { background: var(--teal); }
.meter.thin { display: block; height: 5px; margin-top: 8px; }
.meter.thin > span { background: var(--teal); }

/* study */
.study-top { display: flex; align-items: center; gap: 12px; }
.study-top .close { background: var(--surface-2); color: var(--ink-2); font-size: 16px; }
.progress { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress div { height: 100%; background: var(--red); border-radius: 99px; transition: width .3s ease; }
.study-top .left { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.stage { flex: 1; display: flex; flex-direction: column; }
.flash { flex: 1; display: flex; flex-direction: column; gap: 18px; background: var(--surface); border-radius: 24px; padding: 18px; border: 1px solid var(--line); animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.flash-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.tag.new { background: var(--teal-soft); color: var(--teal); }
.prompt { font-size: 14px; color: var(--ink-3); margin-left: auto; }
.front { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 14px; min-height: 160px; }
.id-line { display: flex; align-items: center; justify-content: center; gap: 12px; }
.back:empty { display: none; }
.answer { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding-top: 14px; border-top: 1px dashed var(--line); }
.answer .ja { font-size: 21px; color: var(--ink); font-weight: 600; }
.memo { font-size: 14px; color: var(--amber); background: var(--amber-soft); padding: 6px 12px; border-radius: 10px; margin-top: 4px; }
.flash.revealed .front { flex: 0; min-height: 120px; }
.kana.center { text-align: center; padding-bottom: 6px; }

.listen-btn { width: 112px; height: 112px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; }
.listen-btn svg { width: 48px; height: 48px; }
.listen-btn:active { transform: scale(.96); }

.mic-btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 20px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.mic-btn svg { width: 22px; height: 22px; }
.mic-btn.listening { background: var(--red); color: #fff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .75; } }
.heard { font-size: 16px; color: var(--ink-2); min-height: 1.5em; }
.heard .ok, .verdict.ok { color: var(--teal); font-weight: 800; }
.heard .close { color: var(--amber); font-weight: 800; }
.heard .miss, .verdict.miss { color: var(--red); font-weight: 800; }
.verdict { font-size: 18px; text-align: center; margin-bottom: 4px; }

.flash > .grades, .flash > .primary.big { margin-top: auto; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades.two { grid-template-columns: 2fr 1fr; }
.grades.one { grid-template-columns: 1fr; }
.g { border-radius: 14px; padding: 12px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 15px; }
.g small { font-size: 12px; opacity: .75; font-variant-numeric: tabular-nums; }
.g:active { transform: scale(.97); }
.g.again { background: var(--red-soft); color: var(--red); }
.g.hard { background: var(--amber-soft); color: var(--amber); }
.g.good { background: var(--teal-soft); color: var(--teal); }
.g.easy { background: var(--blue-soft); color: var(--blue); }
.grades.two .g, .grades.one .g { padding: 16px; font-size: 17px; }

.build-answer { min-height: 64px; border-radius: 14px; border: 2px dashed var(--line); padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.build-answer.right { border: 2px solid var(--teal); background: var(--teal-soft); }
.build-answer.wrong { border: 2px solid var(--red); background: var(--red-soft); }
.placeholder { color: var(--ink-3); font-size: 14px; }
.build-pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 19px; font-weight: 600; border-bottom: 3px solid var(--line); }
.build-answer .tile { background: var(--surface); }
.tile:active:not(:disabled) { transform: translateY(1px); border-bottom-width: 2px; }

.cloze-text { font-size: 26px; }
.blank { display: inline-block; color: var(--red); border-bottom: 3px solid var(--red); padding: 0 4px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { background: var(--surface-2); border-radius: 14px; padding: 16px 8px; font-size: 19px; font-weight: 700; border: 2px solid transparent; }
.choice.right { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }
.choice.wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); }

.done-page { align-items: center; justify-content: center; text-align: center; min-height: 100dvh; gap: 16px; }
.done-burst { font-size: 72px; animation: pop .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
.done-page h1 { font-size: 36px; color: var(--red); }
.lead { font-size: 19px; }
.streak-msg { font-size: 18px; background: var(--surface); padding: 10px 18px; border-radius: 99px; border: 1px solid var(--line); }
.done-page .primary { max-width: 320px; margin-top: 12px; }

/* lessons */
.lesson-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-item { display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; }
.lesson-item.off { opacity: .5; }
.lesson-no { background: var(--red-soft); color: var(--red); font-weight: 800; font-size: 14px; border-radius: 12px; padding: 10px 8px; min-width: 60px; text-align: center; }
.lesson-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.lesson-body small { color: var(--ink-3); font-size: 13px; }
.lesson-count { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; }
input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--surface-2); position: relative; transition: background .2s; flex: none; margin: 0; border: 1px solid var(--line); }
input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
input[type=checkbox]:checked { background: var(--teal); border-color: var(--teal); }
input[type=checkbox]:checked::after { transform: translateX(20px); }
.audio-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.audio-row small { color: var(--ink-2); }
audio { width: 100%; height: 40px; }
.notes details { border-top: 1px solid var(--line); padding: 10px 0; }
.notes details:first-of-type { border-top: 0; }
.notes summary { font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.notes summary::after { content: "＋"; color: var(--ink-3); }
.notes details[open] summary::after { content: "－"; }
.notes details p { margin-top: 8px; color: var(--ink-2); font-size: 15px; }
.notes b { color: var(--ink); }
.vocab ul { list-style: none; margin: 0; padding: 0; }
.vocab li + li { border-top: 1px solid var(--line); }
.say-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; width: 100%; text-align: left; padding: 10px 0; }
.v-id { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.v-kana { grid-column: 1; font-size: 12px; color: var(--ink-3); }
.v-ja { grid-column: 2; grid-row: 1 / span 2; color: var(--ink-2); font-size: 15px; align-self: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.learned { background: var(--teal); }
.dot.learning { background: var(--amber); }

/* settings */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.form label span { flex: 1; }
select { font: inherit; color: var(--ink); background: var(--surface-2); border: 0; border-radius: 10px; padding: 8px 10px; max-width: 55%; }
input[type=range] { flex: 1; accent-color: var(--red); max-width: 50%; }
.sync { display: flex; flex-direction: column; gap: 12px; }
.sync h3 { margin: 0; }
.sync details summary { color: var(--ink-2); font-weight: 600; cursor: pointer; }
.sync details[open] { display: flex; flex-direction: column; gap: 10px; }
.key { display: block; word-break: break-all; font-size: 13px; background: var(--surface-2); padding: 10px; border-radius: 10px; user-select: all; -webkit-user-select: all; }
.adopt { display: flex; gap: 8px; }
.adopt input { flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn-row { display: flex; gap: 10px; }
.btn-row .ghost { flex: 1; }

@media (min-width: 640px) {
  .page { padding-top: 40px; }
}

/* pop-up sheets: guide + install */
.guide-link { margin-top: 8px; font-size: 13px; font-weight: 700; color: var(--ink-2); background: var(--surface-2); border-radius: 99px; padding: 4px 12px; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgb(20 14 8 / 45%);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease;
}
.sheet-backdrop.closing { opacity: 0; transition: opacity .18s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 24px 24px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 14px 20px calc(env(safe-area-inset-bottom) + 20px); animation: up .25s cubic-bezier(.2, .9, .3, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { font-size: 22px; text-align: center; margin: 4px 0 12px; }
.guide-top { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.sheet-x { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--red); width: 22px; border-radius: 99px; }
.guide-icon { font-size: 44px; text-align: center; line-height: 1.2; }
.guide-body { display: flex; flex-direction: column; gap: 10px; font-size: 16px; color: var(--ink-2); }
.guide-body b { color: var(--ink); }
.guide-list { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.guide-list.types { list-style: none; padding: 0; }
.guide-list.types li { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.guide-list.types b { display: block; color: var(--red); font-size: 14px; }
.guide-grades { display: grid; gap: 8px; }
.guide-grades .g { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; text-align: left; }
.guide-grades .g b { min-width: 4.5em; }
.guide-grades .g span { color: var(--ink); font-size: 14px; line-height: 1.4; }
.guide-grades .g small { color: var(--ink-3); opacity: 1; }
.curve { background: var(--surface-2); border-radius: 14px; padding: 10px 12px 8px; }
.curve svg { width: 100%; height: auto; display: block; }
.curve path { fill: none; stroke-width: 3; stroke-linecap: round; }
.curve .fade { stroke: var(--ink-3); stroke-dasharray: 5 5; }
.curve .keep { stroke: var(--red); }
.curve circle { fill: var(--red); }
.curve small { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--ink-3); }
.curve i { display: inline-block; width: 16px; height: 3px; margin-right: 4px; vertical-align: middle; border-radius: 2px; }
.curve i.k { background: var(--red); }
.curve i.f { background: var(--ink-3); }
.guide-nav { display: flex; gap: 10px; margin-top: 18px; }
.guide-nav .primary { flex: 1; font-size: 17px; }
.guide-nav .ghost { padding: 14px 18px; }
.install { display: flex; flex-direction: column; gap: 6px; }
.install-icon { width: 72px; height: 72px; border-radius: 18px; align-self: center; border: 1px solid var(--line); }
.install .guide-body { margin-top: 10px; }
.install-steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: flex; flex-direction: column; gap: 10px; }
.install-steps li { counter-increment: s; position: relative; padding: 12px 12px 12px 50px; background: var(--surface-2); border-radius: 14px; color: var(--ink); }
.install-steps li::before { content: counter(s); position: absolute; left: 12px; top: 11px; width: 26px; height: 26px; border-radius: 50%; background: var(--red); color: #fff; font-weight: 800; font-size: 14px; display: grid; place-items: center; }
.install-steps small { color: var(--ink-3); }
.inline-icon { width: 22px; height: 22px; vertical-align: -5px; color: var(--blue); }
.install .later { margin-top: 12px; }
