@font-face { font-family: 'Lexend'; font-weight: 400; font-display: swap; src: url(../fonts/lexend-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Lexend'; font-weight: 600; font-display: swap; src: url(../fonts/lexend-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Lexend'; font-weight: 700; font-display: swap; src: url(../fonts/lexend-latin-700-normal.woff2) format('woff2'); }

:root {
  --ground: #E9F2EE; --paper: #FFFFFF; --ink: #1E2B26; --muted: #3E5149; --line: #D3E2DA; --soft: #F2F7F4;
  --green: #2F7D4F; --green-d: #24633E; --orange: #FFE3C2; --orange-t: #7A3E00;
  --thing: #DCE8FF; --thing-t: #1D4FA8; --doing: #FFE1C7; --doing-t: #9A4300; --desc: #FFF1B8; --desc-t: #6E5600; --help: #E4E9E7; --help-t: #3E5149;
  --bad: #C7362F; --ui: 'Lexend', 'Segoe UI', system-ui, sans-serif;
  --jp: 'Klee One', 'Hiragino Mincho ProN', 'YuKyokasho Yoko', 'Yu Mincho', serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--ui); font-size: 18px; line-height: 1.55; letter-spacing: 0.01em; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
h1 { margin: 0; font-size: 28px; line-height: 1.25; font-weight: 700; }
h2 { margin: 0; font-size: 20px; font-weight: 700; }
p { margin: 0; }
svg { display: block; }
.jp { font-family: var(--jp); font-weight: 600; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }

#bg { position: fixed; left: 0; right: 0; bottom: 0; height: 78vh; z-index: 0; pointer-events: none; display: flex; justify-content: center; }
#bg .tree { width: 100%; max-width: 760px; height: 100%; }
.tree .new { animation: grow-in 1.6s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes grow-in { from { opacity: 0; transform: scale(0.2); } to { opacity: 1; transform: scale(1); } }
#app { position: relative; z-index: 1; }
#print { display: none; }

.page { max-width: 620px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; gap: 16px;
  padding: max(28px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
.card { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); background: rgba(255, 255, 255, 0.86); border-radius: 22px; padding: 16px 18px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.push { margin-top: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; background: var(--paper); border-radius: 999px; font-size: 14px; font-weight: 600; }
.chip.warn { background: var(--orange); color: var(--orange-t); }
.label { font-size: 13px; font-weight: 700; color: var(--green-d); letter-spacing: 0.06em; text-transform: uppercase; }
.week-tag { font-size: 15px; font-weight: 600; color: var(--green-d); }

.btn { min-height: 58px; padding: 10px 20px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; border-radius: 20px; border: 2px solid #A9C4B5; background: var(--paper); font-size: 17px; font-weight: 600; text-align: center; flex: 1; }
.btn.primary { background: var(--green); border-color: var(--green); color: #FFF; font-weight: 700; font-size: 18px; }
.btn.big { min-height: 64px; width: 100%; font-size: 19px; }
.btn.small { min-height: 46px; font-size: 15px; flex: none; }
.btn:disabled { opacity: 0.5; }
.btn:active, .opt:active, .block:active { transform: translateY(1px); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.iconbtn { width: 48px; height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: var(--paper); border: 0; border-radius: 16px; }
.iconbtn svg, .btn svg, .round svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.round { width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--green); color: #FFF; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.round svg { width: 28px; height: 28px; }
:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }

/* checklist */
.task { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.task:last-child { border-bottom: 0; }
.tick { width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; border: 3px solid var(--green); display: flex; align-items: center; justify-content: center; }
.task.done .tick { background: var(--green); }
.tick svg { width: 18px; height: 18px; fill: none; stroke: #FFF; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.task-t { font-size: 17px; font-weight: 600; line-height: 1.3; }
.task.done .task-t { color: var(--muted); text-decoration: line-through; }
.task-s { font-size: 14px; color: var(--muted); }
.pts { font-size: 14px; font-weight: 700; color: var(--green-d); white-space: nowrap; }
.task.locked { opacity: 0.55; }

/* progress bar */
.bar { display: grid; gap: 6px; flex: 1; }
.bar i { height: 10px; border-radius: 5px; background: var(--paper); }
.bar i.on { background: var(--green); }

/* learn */
.big-char { font-family: var(--jp); font-weight: 600; font-size: 150px; line-height: 1; }
.big-char.kanji { font-size: 130px; }
.sound { font-size: 44px; font-weight: 700; letter-spacing: 0.04em; }
.mean { font-size: 26px; font-weight: 700; line-height: 1.3; }
.pad-host { width: 100%; max-width: 300px; aspect-ratio: 1; margin: 0 auto; background: var(--paper); border-radius: 24px; overflow: hidden; }
.pad-svg { width: 100%; height: 100%; touch-action: none; }
.pad-svg path, .pad-svg polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 5.2; }
.pad-svg .guide { stroke: var(--line); stroke-width: 0.6; stroke-dasharray: 2.2 2.8; }
.pad-svg .meas path { stroke: none; }
.pad-svg .ghost path { stroke: #DCE7E1; }
.pad-svg .faint path { stroke: #A9C4B5; }
.pad-svg .done path { stroke: var(--ink); }
.pad-svg .cur path { stroke: #E0533F; }
.pad-svg .user polyline { stroke: var(--ink); opacity: 0.75; stroke-width: 4.4; }
.pad-svg .user polyline.bad { stroke: var(--bad); opacity: 0; transition: opacity 0.45s; }
.pad-svg .dot circle { fill: #FFF; stroke: #E0533F; stroke-width: 1.4; }
.pad-svg .dot text { font-family: var(--ui); font-size: 6.4px; font-weight: 700; fill: #E0533F; }
.pad-svg.win .done path { stroke: var(--green); transition: stroke 0.3s; }

/* word tags: colour + shape, never colour alone */
.word { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px; width: 100%; border: 0; text-align: left; }
.word .jp { font-size: 30px; line-height: 1.2; }
.word .rd { font-size: 14px; color: inherit; opacity: 0.85; }
.word .en { font-size: 16px; font-weight: 600; }
.tag-t { background: var(--thing); color: var(--thing-t); }
.tag-d { background: var(--doing); color: var(--doing-t); }
.tag-s { background: var(--desc); color: var(--desc-t); }
.tag-h, .tag-x { background: var(--help); color: var(--help-t); }
.shape { width: 26px; height: 26px; flex-shrink: 0; }
.shape svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.legend .shape, .legend .shape svg { width: 18px; height: 18px; }

/* sentence blocks */
.slots { min-height: 96px; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 12px; border: 2px dashed #A9C4B5; border-radius: 18px; background: rgba(255,255,255,0.6); }
.pool { display: flex; flex-wrap: wrap; gap: 8px; min-height: 80px; }
.block { border: 0; border-radius: 14px; padding: 6px 12px 8px; display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.block ruby { font-family: var(--jp); font-weight: 600; font-size: 28px; }
.block rt { font-family: var(--ui); font-size: 11px; font-weight: 600; }
.block .gl { font-size: 12px; font-weight: 600; }
.slots.ok { border-color: var(--green); border-style: solid; background: #EAF6EE; }
.slots.no { animation: shake 0.4s; border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.helpnote { font-size: 15px; background: var(--help); border-radius: 14px; padding: 10px 14px; }

/* quiz */
.q-prompt { font-size: 22px; font-weight: 700; text-align: center; }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.opt { min-height: 96px; border-radius: 20px; border: 3px solid transparent; background: var(--paper); font-size: 26px; font-weight: 700; padding: 8px; }
.opt.jp { font-size: 52px; }
.opt.right { border-color: var(--green); background: #EAF6EE; }
.opt.wrong { border-color: var(--bad); background: #FBEAE9; }
.feedback { min-height: 30px; text-align: center; font-weight: 700; }

/* homework */
.write-list { display: flex; flex-direction: column; gap: 10px; }
.write-row { display: flex; align-items: center; gap: 8px; }
.write-row .jp { font-size: 34px; width: 74px; text-align: center; }
.boxes { display: flex; gap: 4px; flex: 1; }
.boxes i { flex: 1; max-width: 44px; aspect-ratio: 1; border: 2px solid var(--line); border-radius: 8px; background: var(--paper); }
.photo { width: 100%; max-height: 260px; object-fit: contain; border-radius: 16px; background: #DDE6E1; }
.score { font-size: 40px; font-weight: 700; color: var(--green-d); }
.res-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.res-row:last-child { border-bottom: 0; }
.res-row .jp { font-size: 34px; width: 56px; text-align: center; }
.res-row.bad .jp { color: var(--bad); }
.dots-anim { display: flex; gap: 10px; justify-content: center; }
.dots-anim i { width: 14px; height: 14px; border-radius: 50%; background: var(--green); animation: bob 1s ease-in-out infinite; }
.dots-anim i:nth-child(2) { animation-delay: 0.15s; } .dots-anim i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob { 0%, 100% { transform: translateY(0); opacity: 0.5; } 50% { transform: translateY(-8px); opacity: 1; } }
.linkbtn { background: none; border: 0; padding: 8px 4px; font-size: 14px; color: var(--muted); text-decoration: underline; }
.note { background: var(--orange); color: var(--orange-t); border-radius: 16px; padding: 12px 16px; font-weight: 600; }

/* grow screen */
.grow-page { text-align: center; }
.grow-page h1 { font-size: 32px; }

/* settings */
.field { display: flex; flex-direction: column; gap: 6px; }
.field select, .field input { min-height: 50px; border-radius: 14px; border: 2px solid var(--line); background: var(--paper); padding: 0 12px; }

@media (prefers-reduced-motion: reduce) { .tree .new, .dots-anim i, .slots.no { animation: none; } }

/* printable writing sheet */
@media print {
  #app, #bg { display: none !important; }
  #print { display: block; }
  body { background: #fff; }
  .sheet { font-family: var(--ui); color: #000; }
  .sheet h1 { font-size: 16pt; margin-bottom: 8pt; }
  .sheet .srow { display: flex; gap: 4pt; margin-bottom: 6pt; }
  .sheet .sbox { width: 17mm; height: 17mm; border: 1px solid #999; display: flex; align-items: center; justify-content: center; font-family: var(--jp); font-size: 36pt; color: #000; position: relative; }
  .sheet .sbox.ghost { color: #ccc; }
  .sheet .sbox::before { content: ''; position: absolute; inset: 50% 0 auto 0; border-top: 1px dashed #ddd; }
  .sheet .sbox::after { content: ''; position: absolute; inset: 0 auto 0 50%; border-left: 1px dashed #ddd; }
}
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.page > .btn { flex: none; }
