/* Mochi Mountain — exercise layout.
   Owner: js/exercises/*. Every selector here is inside the .ex-* namespace;
   shared classes (.tile, .tiles, .btn, .bar) belong to css/components.css and
   are only ever *used* by these renderers, never restyled.

   Two things this file protects:
     1. Nothing reflows when an answer is marked. State classes change colour and
        reveal an absolutely-positioned glyph; widths, heights and borders hold.
     2. Everything still fits at 320px. Prompt type scales with clamp(), the word
        bank wraps, and the match grid keeps two real columns. */

/* ==========================================================================
   1. Shell + prompt stage
   ========================================================================== */

.ex{
  display:flex; flex-direction:column; gap:var(--sp-5);
  width:100%;
}

.ex-instruction{
  font-size:18px; font-weight:700; line-height:1.3;
  color:var(--ink); text-align:left;
  margin:0;
}

.ex-stage{
  display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  gap:var(--sp-2);
  min-height:96px;
  padding:var(--sp-3) var(--sp-2);
  text-align:center; overflow-wrap:anywhere;
}

.ex-emoji { font-size:clamp(56px, 20vw, 84px); line-height:1; }
.ex-kana  { font-size:clamp(68px, 24vw, 96px); line-height:1.1; font-weight:700; color:var(--ink); }
.ex-jp    { font-size:clamp(30px, 10vw, 40px); line-height:1.25; font-weight:700; color:var(--ink); }
.ex-en    { font-size:clamp(22px, 7vw, 28px);  line-height:1.25; font-weight:800; color:var(--ink); }
.ex-romaji{ font-size:18px; font-weight:700; color:var(--ink-soft); }

/* A Latin label inside a shared .tile (English word, or a romaji reading). */
.ex-tile-en{
  font-size:17px; font-weight:800; line-height:1.25;
  letter-spacing:.01em;
}

/* The card could not be built — kept plain and calm on purpose. */
.ex-stub{ text-align:center; padding-block:var(--sp-6); }

/* ==========================================================================
   2. match — two columns of short cards
      The wrapper IS the grid; the instruction spans both columns.
   ========================================================================== */

.ex.ex-match{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:var(--sp-3);
  align-content:start;
}

.ex-match > .ex-instruction{ grid-column:1 / -1; }

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

.ex-match-jp    { font-size:19px; font-weight:700; line-height:1.25; }
.ex-match-en    { font-size:16px; font-weight:800; line-height:1.2; }
.ex-match-emoji { font-size:24px; line-height:1.1; }
.ex-match-romaji{ font-size:12px; font-weight:700; color:var(--ink-soft); line-height:1.1; }

.ex-match-item.is-selected{ border-color:var(--brand); background:var(--brand-soft); }
.ex-match-item.is-wrong   { border-color:var(--bad);   background:var(--bad-soft); }
.ex-match-item.is-matched{
  border-color:var(--ok); background:var(--ok-soft); color:var(--ok-dark);
  opacity:.75; pointer-events:none; cursor:default;
}

/* Never colour alone: a matched or missed card carries a glyph. */
.ex-match-item.is-matched::after,
.ex-match-item.is-wrong::after{
  position:absolute; top:3px; right:6px;
  font-size:13px; font-weight:800; line-height:1;
}
.ex-match-item.is-matched::after{ content:'\2713'; color:var(--ok); }
.ex-match-item.is-wrong::after  { content:'\2715'; color:var(--bad); }

/* ==========================================================================
   3. build — answer line above a word bank
   ========================================================================== */

.ex-build-answer{
  display:flex; flex-wrap:wrap; align-content:flex-start;
  gap:var(--sp-2);
  min-height:60px;
  padding:var(--sp-2) var(--sp-1);
  border-top:2px dotted var(--line);
  border-bottom:2px dotted var(--line);
}

.ex-build-bank{
  display:flex; flex-wrap:wrap; gap:var(--sp-2);
  justify-content:center;
}

.ex-chunk{
  display:inline-flex; align-items:center; justify-content:center;
  min-height:48px; padding:0 var(--sp-3);
  font-size:19px; font-weight:700; line-height:1.2;
  color:var(--ink); text-align:center;
  background:var(--surface); background-clip:padding-box;
  border:2px solid var(--line); border-bottom-width:3px;
  border-radius:var(--r-sm);
  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;
}
.ex-chunk:active:not(:disabled){
  transform:translateY(3px);
  border-bottom-color:transparent;
}

/* A used chunk keeps its exact footprint, so the bank never reflows under a
   child's finger — it just goes quiet. */
.ex-chunk.is-used{
  color:transparent;
  background:var(--line);
  border-color:var(--line);
  border-bottom-color:var(--line);
  cursor:default; transform:none;
}
.ex-chunk.is-correct{ border-color:var(--ok); background:var(--ok-soft); color:var(--ok-dark); }
.ex-chunk.is-dim    { opacity:.4; pointer-events:none; }

/* ==========================================================================
   4. type — one romaji input
   ========================================================================== */

.ex-type-form{
  display:flex; flex-direction:column; gap:var(--sp-2);
  width:100%;
}

.ex-type-input{
  width:100%; height:56px;
  padding:0 var(--sp-3);
  font-size:20px; font-weight:700; text-align:center;
  color:var(--ink); background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-md);
  transition:border-color .18s ease-out, background-color .18s ease-out;
}
.ex-type-input::placeholder{ color:var(--ink-soft); font-weight:600; opacity:.7; }
.ex-type-input:focus{ border-color:var(--brand); }
.ex-type-input.is-correct{ border-color:var(--ok);  background:var(--ok-soft); }
.ex-type-input.is-wrong  { border-color:var(--bad); background:var(--bad-soft); }

.ex-type-hint{
  font-size:13px; font-weight:700; line-height:1.3;
  color:var(--ink-soft); text-align:center;
  min-height:18px;
}
.ex-type-hint.is-hint  { color:var(--brand-dark); }
.ex-type-hint.is-answer{ color:var(--bad); font-weight:800; }

/* ==========================================================================
   5. Small screens
   ========================================================================== */

@media (max-width:359px){
  .ex{ gap:var(--sp-4); }
  .ex-stage{ min-height:80px; }
  .ex-match{ gap:var(--sp-2); }
  .ex-match-jp{ font-size:17px; }
  .ex-match-en{ font-size:15px; }
  .ex-chunk{ font-size:17px; padding:0 var(--sp-2); }
}

/* ---------- trace: write the character with a finger --------------------------- */
.ex-trace-stage{ gap:var(--sp-2); }

.ex-trace-svg{
  width:min(78vw, 320px); height:min(78vw, 320px);
  background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-lg);
  touch-action:none;            /* the finger must draw, not scroll the page */
  user-select:none; cursor:crosshair;
}

/* The model is the real font glyph, kept faint so the child's own ink stands out. */
.ex-trace-model{
  font-size:74px; fill:var(--line);
  font-family:var(--font-jp); letter-spacing:0;
}

.ex-trace-guide{
  fill:none; stroke:var(--brand); stroke-opacity:.35;
  stroke-width:9; stroke-linecap:round; stroke-linejoin:round;
  stroke-dasharray:1 12;
}

.ex-trace-dot circle{ fill:var(--line); }
.ex-trace-dot text{ fill:var(--ink-soft); font-size:9px; font-weight:800; }
.ex-trace-dot.is-now circle{ fill:var(--brand); }
.ex-trace-dot.is-now text{ fill:var(--surface); }
.ex-trace-dot.is-done{ opacity:.25; }

.ex-trace-stroke{
  fill:none; stroke:var(--brand); stroke-width:8;
  stroke-linecap:round; stroke-linejoin:round;
}
.ex-trace-live{
  fill:none; stroke:var(--ink); stroke-width:8;
  stroke-linecap:round; stroke-linejoin:round; stroke-opacity:.75;
}
.ex-trace-svg.is-finished .ex-trace-stroke{ stroke:var(--ok); }
.ex-trace-svg.is-finished .ex-trace-guide{ display:none; }

.ex-trace-hint{ min-height:1.4em; text-align:center; }
.ex-trace-actions{ display:flex; justify-content:center; }

@media (prefers-reduced-motion: no-preference){
  .ex-trace-dot.is-now circle{ animation:a-pulse 1.6s ease-in-out infinite; }
}

/* hear-kana: the sound is the question. A big, obvious replay button and nothing else. */
.ex-hear{
  display:inline-flex; align-items:center; justify-content:center;
  width:112px; height:112px; border-radius:var(--r-pill);
  background:var(--brand-soft); border:3px solid var(--brand);
  border-bottom-width:6px; font-size:48px; line-height:1;
  transition:transform .08s var(--ease-pop);
}
.ex-hear:active{ transform:translateY(3px); border-bottom-width:3px; }

/* say-kana: every tile is a speaker. Nothing is written down. */


/* kana-word: the options are pictures, and tapping one says its Japanese word. */
.tile-pic{ font-size:42px; line-height:1; }
