/* Mochi Mountain — shared components.
   Implements docs/UI-KIT.md exactly. This file (and only this file) owns the shared
   class names. Colours come from tokens in css/base.css — no literal hex lives here.

   Layering: chrome 40 · feedback banner 60 · fx 90 (set in js/fx.js) · overlay 100. */

/* ==========================================================================
   1. App chrome — markup is emitted by js/main.js, styled here.
   ========================================================================== */

#topbar{
  position:sticky; top:0; z-index:40; flex:0 0 auto;
  background:var(--bg); border-bottom:2px solid var(--line);
  padding-top:env(safe-area-inset-top);
}
.topbar-inner{ height:var(--topbar-h); gap:var(--sp-3); }

.topbar-avatar{
  flex:0 0 auto; width:48px; height:48px;
  display:grid; place-items:center;
  font-size:24px; line-height:1;
  background:var(--brand-soft);
  border:2px solid var(--line); border-radius:var(--r-pill);
  transform:translateY(0); transition:transform .07s ease-out;
  -webkit-tap-highlight-color:transparent;
}
.topbar-avatar:active{ transform:translateY(2px); }

#nav{
  position:sticky; bottom:0; z-index:40; flex:0 0 auto;
  background:var(--surface); border-top:2px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
}
.nav-inner{
  display:grid; grid-auto-flow:column; grid-auto-columns:1fr;
  height:var(--nav-h); max-width:var(--shell); margin-inline:auto;
}
.nav-btn{
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  min-height:var(--nav-h); padding:6px 2px;
  color:var(--ink-soft); -webkit-tap-highlight-color:transparent;
}
.nav-icon{
  font-size:20px; line-height:1; padding:5px 14px;
  border:2px solid transparent; border-radius:var(--r-pill);
}
.nav-label{ font-size:11px; font-weight:800; letter-spacing:.04em; }
.nav-btn.is-on{ color:var(--brand-dark); }
.nav-btn.is-on .nav-label{ font-weight:800; }
.nav-btn.is-on .nav-icon{ background:var(--brand-soft); border-color:var(--brand); }
.nav-btn:active .nav-icon{ transform:translateY(1px); }

/* ==========================================================================
   2. Pressable button — the signature control.
      The bottom border IS the edge. On :active the button drops by --edge and the
      edge turns transparent (background-clip:padding-box lets the page show through),
      so the visible face lands exactly where the edge was. Geometry never changes,
      which means a disabled -> enabled swap can never reflow a footer.
   ========================================================================== */

.btn{
  --btn-h:48px;
  --btn-bg:var(--surface);
  --btn-fg:var(--ink);
  --btn-edge:var(--line);

  display:inline-flex; align-items:center; justify-content:center; gap:var(--sp-2);
  min-height:var(--btn-h); padding:8px var(--sp-5);
  font-family:inherit; font-size:15px; font-weight:800; line-height:1.15;
  letter-spacing:.06em; text-transform:uppercase; text-align:center;
  color:var(--btn-fg);
  background:var(--btn-bg); background-clip:padding-box;
  border:0 solid transparent; border-bottom:var(--edge) solid var(--btn-edge);
  border-radius:var(--r-md);
  transform:translateY(0);
  transition:transform .07s ease-out;      /* transform only — never box-shadow */
  cursor:pointer; user-select:none; -webkit-user-select:none;
  -webkit-tap-highlight-color:transparent; touch-action:manipulation;
}
.btn:active:not(:disabled){
  transform:translateY(var(--edge));
  border-bottom-color:transparent;
}
.btn:disabled{
  background:var(--line); color:var(--ink-soft);
  border-bottom-color:transparent;
  cursor:not-allowed; transform:none;
}

.btn-primary{ --btn-bg:var(--brand); --btn-fg:var(--surface); --btn-edge:var(--brand-dark); }
.btn-ok     { --btn-bg:var(--ok);    --btn-fg:var(--surface); --btn-edge:var(--ok-dark); }
.btn-bad    { --btn-bg:var(--bad);   --btn-fg:var(--surface); --btn-edge:var(--bad-dark); }

.btn-ghost{
  --btn-bg:transparent; --btn-fg:var(--ink-soft); --btn-edge:var(--line);
  border:2px solid var(--line);
}
.btn-ghost:active:not(:disabled){ transform:translateY(2px); border-bottom-color:var(--line); }

.btn-lg   { --btn-h:56px; font-size:17px; padding-inline:var(--sp-6); }
.btn-block{ display:flex; width:100%; }

.btn-icon{
  position:relative;
  width:44px; height:44px; min-height:44px; padding:0;
  font-size:20px; letter-spacing:0;
  color:var(--ink-soft); background:transparent;
  border:0; border-radius:var(--r-pill);
}
/* 44px face, 48px hit area — satisfies both the kit and the 48px tap-target rule. */
.btn-icon::after{ content:''; position:absolute; inset:-2px; border-radius:inherit; }
.btn-icon:active:not(:disabled){ transform:translateY(2px); background:var(--line); }
.btn-icon:disabled{ background:transparent; }

@media (hover:hover){
  .btn:hover:not(:disabled){ filter:brightness(1.04); }
  .btn-ghost:hover:not(:disabled),
  .btn-icon:hover:not(:disabled){ filter:none; background:var(--brand-soft); color:var(--ink); }
}

/* ==========================================================================
   3. Choice tile
      State classes only ever change colour — border widths are constant so a tile
      never reflows (and its neighbours never jump) when it is marked right/wrong.
   ========================================================================== */

.tiles{ display:grid; gap:var(--sp-3); grid-template-columns:minmax(0,1fr); }
.tiles-2col{ grid-template-columns:repeat(2, minmax(0,1fr)); }

.tile{
  position:relative;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  min-height:64px; padding:var(--sp-3) var(--sp-2);
  color:var(--ink); text-align:center; overflow-wrap:anywhere;
  background:var(--surface); background-clip:padding-box;
  border:2px solid var(--line); border-bottom-width:var(--edge);
  border-radius:var(--r-md);
  transform:translateY(0);
  transition:transform .07s ease-out;
  cursor:pointer; user-select:none; -webkit-user-select:none;
  -webkit-tap-highlight-color:transparent; touch-action:manipulation;
}
.tile:active:not(:disabled):not(.is-dim){
  transform:translateY(var(--edge));
  border-bottom-color:transparent;
}

.tile-key{
  position:absolute; top:5px; left:5px;
  width:20px; height:20px;
  display:grid; place-items:center;
  font-size:11px; font-weight:800; line-height:1;
  color:var(--ink-soft); background:var(--bg);
  border:2px solid var(--line); border-radius:6px;
}
@media (hover:none){ .tile-key{ display:none; } }

.tile-emoji { font-size:32px; line-height:1.1; }
.tile-jp    { font-size:20px; font-weight:700; line-height:1.25; }
.tile-romaji{ font-size:13px; font-weight:700; color:var(--ink-soft); line-height:1.2; }

.tile.is-selected{ border-color:var(--brand); background:var(--brand-soft); }
.tile.is-correct { border-color:var(--ok);    background:var(--ok-soft); }
.tile.is-wrong   { border-color:var(--bad);   background:var(--bad-soft); }
.tile.is-dim     { opacity:.45; pointer-events:none; }

/* Never colour alone: right/wrong tiles carry a glyph too. */
.tile.is-correct::after,
.tile.is-wrong::after{
  position:absolute; top:4px; right:7px;
  font-size:15px; font-weight:800; line-height:1;
}
.tile.is-correct::after{ content:'\2713'; color:var(--ok); }
.tile.is-wrong::after  { content:'\2715'; color:var(--bad); }

/* ==========================================================================
   4. Progress bar
   ========================================================================== */

.bar{
  --bar-h:16px;
  position:relative; overflow:hidden;
  width:100%; height:var(--bar-h);
  background:var(--line); border-radius:var(--r-pill);
}
.bar-sm{ --bar-h:10px; }
.bar-fill{
  position:relative; display:block;
  width:0; height:100%; max-width:100%;
  background:var(--ok); border-radius:inherit;
  transition:width .3s ease-out;
}
.bar-fill::after{                       /* soft inner highlight */
  content:''; position:absolute; left:6px; right:6px; top:3px;
  height:calc(var(--bar-h) * .22); min-height:2px;
  background:var(--highlight); border-radius:var(--r-pill);
}
.bar-sm .bar-fill::after{ left:4px; right:4px; top:2px; }
.bar-brand .bar-fill{ background:var(--brand); }

/* ==========================================================================
   5. Feedback banner
   ========================================================================== */

.banner{
  position:fixed; inset-inline:0; bottom:0; z-index:60;
  display:grid; grid-template-columns:auto minmax(0,1fr);
  align-items:center; gap:var(--sp-2) var(--sp-3);
  padding:var(--sp-4);
  padding-bottom:calc(var(--sp-4) + env(safe-area-inset-bottom));
  /* keep the content on the app's column on wide screens, background full-bleed */
  padding-inline:max(var(--sp-4), calc((100% - var(--shell)) / 2 + var(--sp-4)));
  border-top:2px solid var(--line);
  background:var(--surface);
}
.banner-icon{
  width:40px; height:40px; display:grid; place-items:center;
  font-size:22px; font-weight:800; line-height:1;
  background:var(--surface); border-radius:var(--r-pill);
}
.banner-copy{ min-width:0; }
.banner-title{ font-size:18px; font-weight:800; }
.banner-sub{ font-size:15px; font-weight:700; color:var(--ink); overflow-wrap:anywhere; }
.banner .btn{ grid-column:1 / -1; width:100%; }

.banner.is-ok { background:var(--ok-soft);  border-top-color:var(--ok);  color:var(--ok); }
.banner.is-bad{ background:var(--bad-soft); border-top-color:var(--bad); color:var(--bad); }
.banner.is-ok  .banner-icon{ color:var(--ok); }
.banner.is-bad .banner-icon{ color:var(--bad); }

/* ==========================================================================
   6. Hearts, chips, stars
   ========================================================================== */

.hearts{ display:inline-flex; align-items:center; gap:3px; }
.heart{
  display:inline-flex; align-items:center; justify-content:center;
  width:16px; height:16px; font-size:15px; line-height:1;
  font-style:normal; color:var(--bad);
}
.heart::before{ content:'\2665\FE0E'; }     /* text presentation, never an emoji glyph */
.heart.is-empty{ color:var(--locked); }

.chip{
  --chip-accent:var(--brand);
  display:inline-flex; align-items:center; gap:5px;
  padding:5px 10px;
  font-size:13px; font-weight:800; line-height:1.1; white-space:nowrap;
  color:var(--ink);
  color:color-mix(in srgb, var(--chip-accent) 55%, var(--ink));
  background:var(--brand-soft);
  background:color-mix(in srgb, var(--chip-accent) 16%, var(--surface));
  border-radius:var(--r-pill);
}
.chip b{ font-weight:800; }
.chip-flame{ --chip-accent:var(--flame); }
.chip-xp   { --chip-accent:var(--gold); }
.chip-gem  { --chip-accent:var(--u7); }
.chip-guard{ --chip-accent:var(--u6); }
.chip.is-cold{
  color:var(--locked-ink); background:var(--line);
  filter:grayscale(1); opacity:.9;
}

.stars{ display:inline-flex; align-items:center; gap:3px; font-size:var(--star-size, 20px); }
.star{
  display:inline-block; font-style:normal; line-height:1;
  color:var(--line);
}
.star::before{ content:'\2605'; font-size:inherit; }
.star.is-on{ color:var(--gold); }

/* ==========================================================================
   7. Card, ring
   ========================================================================== */

.card{
  background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-lg);
  padding:var(--sp-4);
}
.card-flat{ background:var(--brand-soft); border:0; }

.ring{
  width:var(--ring-size, 64px); height:var(--ring-size, 64px);
  transform:rotate(-90deg);
  overflow:visible;
}
.ring circle{
  /* The kit's markup carries no cx/cy/r attributes, so the geometry lives here as CSS
     geometry properties. A screen may also set them as attributes — CSS still wins,
     which keeps the dasharray maths below valid either way. */
  cx:18px; cy:18px; r:15.9155px;          /* circumference = 100 → --pct maps 1:1 */
  fill:none; stroke-width:var(--ring-w, 3.6px); stroke-linecap:round;
}
.ring-track{ stroke:var(--line); }
.ring-fill{
  stroke:var(--brand);
  stroke-dasharray:calc(var(--pct, 0) * 1px) 100px;
  transition:stroke-dasharray .5s ease-out;
}

/* ==========================================================================
   8. Overlay layer — dialog + toast (rendered by js/overlay.js)
   ========================================================================== */

#overlay{ position:fixed; inset:0; z-index:100; pointer-events:none; }
#overlay > *{ pointer-events:auto; }

.dialog-backdrop{
  position:absolute; inset:0;
  display:grid; place-items:center;
  padding:var(--sp-4);
  background:var(--scrim);
  background:color-mix(in srgb, var(--ink) 48%, transparent);
}
.dialog{
  width:100%; max-width:320px;
  display:flex; flex-direction:column; gap:var(--sp-3);
  padding:var(--sp-5);
  background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-xl);
  box-shadow:var(--shadow-lg);
}
.dialog-title{ font-size:19px; font-weight:800; }
.dialog-body { font-size:15px; font-weight:600; color:var(--ink-soft); }
.dialog-actions{ display:flex; gap:var(--sp-3); margin-top:var(--sp-1); }
.dialog-actions .btn{ flex:1 1 0; min-width:0; padding-inline:var(--sp-3); }

@media (max-width:360px){
  .dialog{ padding:var(--sp-4); }
  .dialog-actions{ flex-direction:column; }
  .dialog-actions .btn{ width:100%; }
}

.toast{
  position:absolute; left:0; right:0;
  bottom:calc(var(--nav-h) + var(--sp-4) + env(safe-area-inset-bottom));
  width:max-content; max-width:calc(100% - var(--sp-6));
  margin-inline:auto;
  display:inline-flex; align-items:center; gap:var(--sp-2);
  padding:10px var(--sp-4);
  font-size:14px; font-weight:800; color:var(--surface);
  background:var(--ink); border-radius:var(--r-pill);
  box-shadow:var(--shadow-md);
  pointer-events:none;
}
body.in-lesson .toast{ bottom:calc(var(--sp-5) + env(safe-area-inset-bottom)); }

/* ==========================================================================
   9. Mascot wrapper + speech bubble (js/mascot.js)
   ========================================================================== */

.mochi{ flex:0 0 auto; overflow:visible; }

.mochi-say{ display:flex; align-items:center; gap:var(--sp-2); }
.mochi-say.is-right{ flex-direction:row; }
.mochi-say.is-top  { flex-direction:column; align-items:center; gap:var(--sp-3); }

.bubble{
  position:relative;
  max-width:100%;
  padding:var(--sp-3) var(--sp-4);
  font-size:15px; font-weight:700; line-height:1.35; color:var(--ink);
  background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-lg);
}
.bubble::before, .bubble::after{
  content:''; position:absolute; width:0; height:0;
  border:10px solid transparent;
}
.bubble::after{ border-width:8px; }

.bubble.is-left::before { left:-20px; top:50%; margin-top:-10px; border-right-color:var(--line); }
.bubble.is-left::after  { left:-16px; top:50%; margin-top:-8px;  border-right-color:var(--surface); }
.bubble.is-right::before{ right:-20px; top:50%; margin-top:-10px; border-left-color:var(--line); }
.bubble.is-right::after { right:-16px; top:50%; margin-top:-8px;  border-left-color:var(--surface); }
.bubble.is-top::before  { bottom:-20px; left:50%; margin-left:-10px; border-top-color:var(--line); }
.bubble.is-top::after   { bottom:-16px; left:50%; margin-left:-8px;  border-top-color:var(--surface); }

/* ---------- Mochi mascot fills -------------------------------------------------
   js/mascot.js used to carry these as inline style attributes. A strict CSP
   (style-src 'self') drops inline styles, and a dropped `fill` reverts to its
   INITIAL value — black — which turned Mochi into a featureless blob. Classes are
   served from this stylesheet, so the policy stays strict and the colours survive. */
.mochi .m-body      { fill:var(--surface); }
.mochi .m-arm       { fill:var(--surface); stroke:var(--mochi-line); }
.mochi .m-ink       { fill:var(--ink); }
.mochi .m-ink-soft  { fill:var(--ink-soft); }
.mochi .m-gold      { fill:var(--gold); }
.mochi .m-tear      { fill:var(--u6); }
.mochi .m-blush     { fill:var(--brand); opacity:.55; }
.mochi .m-line      { fill:none; stroke:var(--ink); }
.mochi .m-brand-line{ fill:none; stroke:var(--brand); }

.ring-gold{ stroke:var(--gold); }

/* ---------- speaker button (ui.js speakerBtn) -----------------------------------
   Only ever rendered when the device actually has a Japanese voice, so it is never a
   dead control. Big enough for a five-year-old thumb. */
.speak-btn{
  display:inline-flex; align-items:center; justify-content:center;
  width:52px; height:52px; border-radius:var(--r-pill);
  background:var(--brand-soft); border:2px solid var(--brand);
  border-bottom-width:var(--edge);
  transition:transform .08s var(--ease-pop);
  flex:0 0 auto; user-select:none;
}
.speak-btn:active{ transform:translateY(var(--edge)); border-bottom-width:2px; }
.speak-icon{ font-size:24px; line-height:1; }
.tile .speak-btn{ width:40px; height:40px; }

/* ---------- read-aloud button (ui.js readAloudBtn) ------------------------------
   The child this is built for cannot read the instruction, the English word or the
   Japanese — but understands all three by ear. This button is how they ask again. */
.read-btn{
  display:inline-flex; align-items:center; gap:var(--sp-2);
  min-height:48px; padding:0 var(--sp-4);
  border-radius:var(--r-pill);
  background:var(--brand-soft); color:var(--brand-dark);
  border:2px solid var(--brand); border-bottom-width:var(--edge);
  font-weight:800; font-size:14px; letter-spacing:.06em;
  transition:transform .08s var(--ease-pop);
  user-select:none;
}
.read-btn:active{ transform:translateY(var(--edge)); border-bottom-width:2px; }
.read-icon{ font-size:22px; line-height:1; }
.read-btn.is-playing{ background:var(--brand); color:var(--surface); }

/* ---------- kana picture hint (ui.js kanaHint) ----------------------------------
   The picture and the Japanese word it shows, side by side. Tapping or hovering says
   the WORD — あり — because an ant that only ever says "あ" is a contradiction a child
   has to resolve on their own. */
.kana-hint{
  display:inline-flex; align-items:center; gap:var(--sp-3);
  padding:var(--sp-2) var(--sp-4); min-height:56px;
  background:var(--surface); border:2px solid var(--line);
  border-bottom-width:var(--edge); border-radius:var(--r-md);
  transition:transform .08s var(--ease-pop);
  align-self:center; user-select:none;
}
.kana-hint:active{ transform:translateY(var(--edge)); border-bottom-width:2px; }
.kana-hint:hover{ border-color:var(--brand); }
.kana-hint-pic{ font-size:32px; line-height:1; }
.kana-hint-word{ font-size:22px; font-weight:800; color:var(--ink); }
.kana-hint-en{ font-size:13px; font-weight:700; color:var(--ink-soft); }
.kana-note{
  color:var(--ink-soft); text-align:center; max-width:34ch;
  margin-inline:auto; padding:var(--sp-2) var(--sp-3);
  background:var(--brand-soft); border-radius:var(--r-md);
}
