:root {
  --paper: #FAF6EE;
  --ink: #2A2A35;
  --ink-2: #5E5A66;
  --line: #E3D9C8;
  --line-2: #EFE7D8;
  --indigo: #26385F;
  --indigo-d: #16223D;
  --indigo-l: #EEF1F8;
  --sakura: #F4B3BF;
  --sakura-l: #FBE3E8;
  --plum: #8A4B57;
  --matcha: #4A6A32;
  --matcha-l: #E2EBD8;
  --shu: #C8452F;
  --shu-l: #FDF1EE;
  --sand: #8A7A62;
  --white: #FFFFFF;
  --nav-h: 76px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); }
body {
  font-family: 'Zen Maru Gothic', system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(140,110,70,0.07) 1px, transparent 1.3px), radial-gradient(rgba(140,110,70,0.05) 1px, transparent 1.3px);
  background-size: 7px 7px, 11px 11px;
  background-position: 0 0, 3px 5px;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; position: relative; }
a { color: var(--indigo); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.jp { font-size: 12px; font-weight: 700; color: var(--plum); }
.muted { color: var(--ink-2); font-size: 13px; }
.kanji { font-family: 'Yuji Syuku', serif; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.screen { padding: 22px 18px calc(var(--nav-h) + 28px); display: flex; flex-direction: column; gap: 18px; }
.screen.no-nav { padding-bottom: 32px; min-height: 100dvh; }
.screen.welcome { justify-content: center; }
.screen.welcome .cta-bottom { margin-top: 24px; }
.cta-bottom { margin-top: auto; }
@media (min-height: 880px) {
  .screen.no-nav { justify-content: center; }
  .screen.no-nav .cta-bottom { margin-top: 28px; }
}
.topbar { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 20px; }
.icon-btn { width: 44px; height: 44px; border: none; border-radius: 99px; background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); text-decoration: none; flex-shrink: 0; }
.title { font-size: 26px; font-weight: 700; }

.card { background: var(--white); border: 1.5px solid var(--line); border-radius: 20px; padding: 16px; box-shadow: 0 4px 0 rgba(140,110,70,0.08); }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.btn { min-height: 52px; padding: 0 22px; border: none; border-radius: 99px; background: var(--indigo); color: var(--white); font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; box-shadow: 0 5px 0 var(--indigo-d); transition: transform .12s ease; }
.btn:active { transform: translateY(2px); box-shadow: 0 3px 0 var(--indigo-d); }
.btn[disabled] { background: var(--line); color: #6E6658; box-shadow: none; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.light { background: var(--white); color: var(--indigo); box-shadow: none; }
.btn-ghost { min-height: 44px; padding: 0 16px; border: 2px solid var(--indigo); border-radius: 99px; background: transparent; color: var(--indigo); font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn-ghost.red { border-color: var(--shu); color: #B23A26; }
.chip { min-height: 44px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: 99px; background: var(--white); font-size: 14px; font-weight: 700; }
.chip.on { border: 2px solid var(--indigo); background: var(--indigo); color: var(--white); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 14px; font-weight: 700; }
.input { min-height: 52px; padding: 0 16px; border: 2px solid var(--line); border-radius: 16px; background: var(--white); font-size: 16px; width: 100%; }
.input:focus { outline: none; border-color: var(--indigo); }

/* Hero video */
.hero { position: relative; margin: -22px -18px 0; aspect-ratio: 16/9; overflow: hidden; }
.hero video, .hero img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0%; display: block; }
.hero::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 90px; background: linear-gradient(rgba(250,246,238,0), var(--paper)); }
.hero.enter { animation: enter-stage 1s cubic-bezier(.22,1,.36,1) both; }
.hero.enter + .speech { animation-delay: .55s; }
@keyframes enter-stage { from { transform: translateX(90px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hero.enter, .hero.enter + .speech { animation: none; } }
.pill { position: absolute; top: 16px; left: 16px; z-index: 1; background: rgba(255,255,255,.9); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 700; }
.speech { background: var(--white); border: 2px solid #2B2F4A; border-radius: 4px 22px 22px 22px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 6px 0 rgba(43,47,74,.08); position: relative; }
.speech h1 { font-size: 20px; line-height: 1.35; }
.lift { margin-top: -60px; z-index: 1; }

/* Speaker (soft-edged Hana) */
.speaker { display: flex; align-items: center; gap: 6px; }
.face { width: 92px; height: 92px; flex-shrink: 0; margin-left: -10px; -webkit-mask-image: radial-gradient(circle, #000 50%, transparent 70%); mask-image: radial-gradient(circle, #000 50%, transparent 70%); }
.face video, .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.speaker .speech { flex: 1; border-radius: 20px 20px 20px 4px; }
.speaker .speech h1 { font-size: 18px; }

/* Today card */
.today { background: var(--indigo); color: var(--white); border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 24px rgba(38,56,95,.22); }
.today .jp { color: #F7C9D1; font-weight: 500; }
.today h2 { font-size: 22px; line-height: 1.25; }

/* Stamps */
.stamps { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.stamp { aspect-ratio: 1; border-radius: 99px; display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--sand); border: 1.5px dashed #D6C9B2; }
.stamp.done { border: 2.5px solid var(--shu); color: var(--shu); background: var(--shu-l); font-family: 'Yuji Syuku', serif; font-size: 20px; transform: rotate(-8deg); }
.stamp.done:nth-child(even) { transform: rotate(7deg); }
.stamp.next { border: 2px dashed var(--indigo); color: var(--indigo); background: var(--indigo-l); font-weight: 700; animation: glow 2s ease infinite; }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(38,56,95,.35); } 50% { box-shadow: 0 0 0 7px rgba(38,56,95,0); } }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile { min-height: 84px; border: 1.5px solid var(--line); border-radius: 20px; background: var(--white); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 700; text-decoration: none; color: var(--ink); box-shadow: 0 3px 0 rgba(140,110,70,.08); }
.tile .dot { width: 36px; height: 36px; border-radius: 99px; display: flex; align-items: center; justify-content: center; }

/* Nav */
.nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--white); border-top: 1.5px solid var(--line); padding: 8px 8px calc(14px + env(safe-area-inset-bottom)); z-index: 10; }
.nav a { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-decoration: none; color: var(--ink-2); font-size: 12px; font-weight: 500; }
.nav a[aria-current="page"] { color: var(--indigo); font-weight: 700; }

/* Chat */
.chat-screen { display: flex; flex-direction: column; height: 100dvh; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 12px; background: var(--white); border-bottom: 1.5px solid var(--line); }
.avatar { width: 48px; height: 48px; border-radius: 99px; overflow: hidden; border: 2px solid var(--indigo); flex-shrink: 0; }
.avatar video, .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 86%; padding: 12px 14px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; animation: rise .35s cubic-bezier(.22,1,.36,1) both; }
.msg.ai { align-self: flex-start; background: var(--white); border: 1.5px solid var(--line); border-radius: 4px 20px 20px 20px; }
.msg.me { align-self: flex-end; background: var(--indigo); color: var(--white); border-radius: 20px 4px 20px 20px; }
.msg.good { background: var(--matcha-l); border: none; }
.msg.bad { background: var(--sakura-l); border: none; }
.quiz { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.quiz .q { font-weight: 700; font-size: 16px; white-space: normal; }
.opt { min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--paper); text-align: left; font-size: 15px; font-weight: 500; }
.opt.right { border: 2px solid var(--matcha); background: var(--matcha-l); font-weight: 700; }
.opt.wrong { border: 2px solid #A0475A; background: var(--sakura-l); }
.opt[disabled] { cursor: default; }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 16px; background: var(--white); border: 1.5px solid var(--line); border-radius: 4px 20px 20px 20px; }
.typing i { width: 7px; height: 7px; border-radius: 99px; background: var(--sand); animation: blinkdot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blinkdot { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
.chat-foot { background: var(--paper); padding: 8px 14px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.chat-foot .chips { flex-wrap: nowrap; overflow-x: auto; }
.chat-foot .chip { white-space: nowrap; font-weight: 500; }
.composer { display: flex; gap: 8px; }
.composer .input { border-radius: 99px; min-height: 48px; }
.send { width: 48px; height: 48px; border: none; border-radius: 99px; background: var(--indigo); color: var(--white); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.done-stamp { align-self: center; width: 110px; height: 110px; border-radius: 99px; border: 4px solid var(--shu); color: var(--shu); background: var(--shu-l); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; animation: stamp .6s cubic-bezier(.3,.7,.4,1) both; }
.done-stamp b { font-family: 'Yuji Syuku', serif; font-size: 50px; font-weight: 400; }
@keyframes stamp { 0% { transform: scale(2.4) rotate(-38deg); opacity: 0; } 45% { transform: scale(.84) rotate(-6deg); opacity: 1; } 65% { transform: scale(1.07) rotate(-11deg); } 100% { transform: scale(1) rotate(-10deg); opacity: 1; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Onboarding */
.progress { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.progress i { height: 8px; border-radius: 99px; background: var(--line); }
.progress i.on { background: var(--indigo); }
.choice { min-height: 64px; padding: 14px 16px; border-radius: 18px; border: 1.5px solid var(--line); background: var(--white); text-align: left; display: flex; align-items: center; gap: 14px; box-shadow: 0 3px 0 rgba(140,110,70,.08); }
.choice.on { border: 2px solid var(--indigo); background: var(--indigo-l); }
.choice .mark { width: 44px; height: 44px; flex-shrink: 0; border-radius: 99px; display: flex; align-items: center; justify-content: center; font-family: 'Yuji Syuku', serif; font-size: 22px; border: 1.5px dashed #D6C9B2; color: var(--sand); }
.choice.on .mark { border: 2.5px solid var(--shu); color: var(--shu); background: var(--shu-l); transform: rotate(-8deg); }
.drop { min-height: 150px; border: 2px dashed #B9AB92; border-radius: 20px; background: var(--white); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px; text-align: center; cursor: pointer; }
.drop.has { border: 2px solid var(--matcha); background: var(--matcha-l); }
.spinner { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--indigo); border-radius: 99px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Flashcards */
.flash-wrap { perspective: 1200px; display: flex; justify-content: center; }
.flash { width: 100%; max-width: 330px; height: 400px; border: none; padding: 0; background: transparent; }
.flash-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3,.7,.3,1.1); }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.face-f, .face-b { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 26px; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 28px; }
.face-f { background: var(--white); border: 2px solid #2B2F4A; box-shadow: 0 8px 0 rgba(43,47,74,.1); align-items: center; text-align: center; }
.face-b { background: var(--indigo); color: var(--white); transform: rotateY(180deg); box-shadow: 0 8px 0 var(--indigo-d); text-align: left; }
.rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.rate button { min-height: 54px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--white); font-weight: 700; }

/* Lists */
.list { background: var(--white); border: 1.5px solid var(--line); border-radius: 18px; display: flex; flex-direction: column; overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--ink); }
.list > *:last-child { border-bottom: none; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats > div { background: var(--white); border: 1.5px solid var(--line); border-radius: 18px; padding: 12px 6px; text-align: center; }
.stats b { display: block; font-size: 26px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; text-align: center; }
.week span { display: block; font-size: 11px; color: var(--ink-2); margin-bottom: 4px; }
.week i { width: 34px; height: 34px; margin: 0 auto; border-radius: 99px; display: flex; align-items: center; justify-content: center; border: 1.5px dashed #D6C9B2; font-style: normal; }
.week i.on { border: 2px solid var(--shu); color: var(--shu); background: var(--shu-l); font-family: 'Yuji Syuku', serif; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); max-width: 90%; background: var(--ink); color: var(--white); padding: 12px 16px; border-radius: 14px; font-size: 14px; z-index: 50; }
body[data-route="sensei"] #toast { bottom: 190px; } /* clear the composer + next-lesson button in chat */
.rise { animation: rise .5s cubic-bezier(.22,1,.36,1) both; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
