/* Mochi Mountain — the lesson runner and the celebration that follows.
   Owner: js/screens/lesson.js + js/screens/complete.js.
   Only .scr-lesson-* and .scr-complete-* live here; .btn .tile .bar .banner
   .hearts .chip .stars .card .ring belong to css/components.css.

   Both screens are FULL HEIGHT: the router hides the top bar and the bottom nav
   for the whole of a lesson, so these two files own the entire viewport.

       header   fixed height, never scrolls
       body     the only scroller (min-height:0 is what makes that true)
       footer   pinned, safe-area padded

   Everything below is sized to survive 320x568 with the on-screen keyboard open
   on the typing card, which is the smallest real thing a child will hold. */

/* ==========================================================================
   1. Lesson — shell
   ========================================================================== */

.scr-lesson{
  position:relative;
  display:flex; flex-direction:column;
  height:100vh;
  height:100dvh;               /* shrinks with the keyboard on modern engines */
  max-height:100dvh;
  overflow:hidden;
  background:var(--bg);
}

/* --- header --- */

.scr-lesson-head{
  position:relative; z-index:2; flex:0 0 auto;
  padding:var(--sp-3) var(--sp-4);
  padding-top:calc(var(--sp-3) + env(safe-area-inset-top));
  background:var(--bg);
}
.scr-lesson-head-inner{
  display:flex; align-items:center; gap:var(--sp-3);
  width:100%; max-width:var(--shell); margin-inline:auto;
}
.scr-lesson-head .bar{ flex:1 1 auto; min-width:0; }
.scr-lesson-head .hearts{ flex:0 0 auto; }

.scr-lesson-infinity{
  flex:0 0 auto;
  min-width:44px; min-height:44px;
  display:flex; align-items:center; justify-content:center;
  font-size:26px; font-weight:800; line-height:1;
  color:var(--brand);
}

/* the combo flag — floats under the header so nothing above it ever reflows */
.scr-lesson-flag{
  position:absolute; left:0; right:0; bottom:-13px;
  display:flex; justify-content:center;
  pointer-events:none;
}
.scr-lesson-flag:empty{ display:none; }

/* --- body: the one scrolling region --- */

.scr-lesson-body{
  flex:1 1 auto; min-height:0;
  overflow-y:auto; overflow-x:hidden;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  scrollbar-gutter:stable;
}
.scr-lesson-ex{
  width:100%; max-width:var(--shell); margin-inline:auto;
  padding:var(--sp-4) var(--sp-4) var(--sp-5);
}
/* while the banner is up the exercise is frozen (js also sets [inert]) */
.scr-lesson-ex.scr-lesson-locked{ pointer-events:none; }

/* the banner covers the footer and a little of the body — give the body room so
   the revealed answer can still be scrolled into view */
.scr-lesson.scr-lesson-hasbanner .scr-lesson-ex{ padding-bottom:calc(var(--sp-7) + var(--sp-6)); }

/* --- footer --- */

.scr-lesson-foot{
  flex:0 0 auto;
  padding:var(--sp-3) var(--sp-4);
  padding-bottom:calc(var(--sp-3) + env(safe-area-inset-bottom));
  background:var(--bg);
  border-top:2px solid var(--line);
}
.scr-lesson-foot-inner{
  width:100%; max-width:var(--shell); margin-inline:auto;
}

/* --- the answer, written out inside the feedback banner --- */

.scr-lesson-ans{
  display:flex; flex-direction:column; gap:1px;
  overflow-wrap:anywhere;
}
.scr-lesson-ans-jp    { font-size:20px; font-weight:800; line-height:1.3;  color:var(--ink); }
.scr-lesson-ans-romaji{ font-size:14px; font-weight:700; line-height:1.25; color:var(--ink-soft); }
.scr-lesson-ans-en    { font-size:15px; font-weight:700; line-height:1.25; color:var(--ink); }

/* ==========================================================================
   2. Lesson — out of hearts / nothing to climb
      Deliberately plain: a mascot, a sentence, a countdown, two ways forward.
      There is no third option, and there is nothing to buy.
   ========================================================================== */

.scr-lesson-out{
  display:flex; flex-direction:column; align-items:center;
  gap:var(--sp-4); text-align:center;
  width:100%; max-width:var(--shell); margin-inline:auto;
  padding:var(--sp-6) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom));
}
.scr-lesson-out .mochi{ margin-bottom:calc(var(--sp-2) * -1); }
.scr-lesson-out-copy{
  font-size:16px; font-weight:700; line-height:1.45; color:var(--ink-soft);
  max-width:30ch;
}
.scr-lesson-out-timer{
  padding:8px var(--sp-4);
  font-size:14px; font-weight:800; letter-spacing:.02em;
  color:var(--ink); background:var(--surface);
  border:2px solid var(--line); border-radius:var(--r-pill);
}
.scr-lesson-out-actions{
  display:flex; flex-direction:column; gap:var(--sp-3);
  width:100%; margin-top:var(--sp-2);
}

/* ==========================================================================
   3. Complete — shell
   ========================================================================== */

.scr-complete{
  display:flex; flex-direction:column;
  height:100vh; height:100dvh; max-height:100dvh;
  overflow:hidden;
  background:var(--bg);
}
.scr-complete-body{
  flex:1 1 auto; min-height:0;
  overflow-y:auto; overscroll-behavior:contain;
  display:flex; flex-direction:column; align-items:center; gap:var(--sp-4);
  width:100%; max-width:var(--shell); margin-inline:auto;
  padding:var(--sp-5) var(--sp-4) var(--sp-5);
  padding-top:calc(var(--sp-5) + env(safe-area-inset-top));
}

.scr-complete-hero{
  display:flex; flex-direction:column; align-items:center; gap:var(--sp-3);
  text-align:center;
}
.scr-complete-title{ color:var(--ink); }
.scr-complete-sub{ font-size:15px; font-weight:700; max-width:32ch; }
.scr-complete-stars{ --star-size:34px; }

.scr-complete-badges{
  display:flex; flex-wrap:wrap; justify-content:center; gap:var(--sp-2);
}

/* --- three stat tiles, always one row --- */

.scr-complete-stats{
  display:grid; grid-template-columns:repeat(3, minmax(0,1fr));
  gap:var(--sp-2); width:100%;
}
.scr-complete-stat{
  display:flex; flex-direction:column; align-items:center; gap:2px;
  padding:var(--sp-3) var(--sp-2);
  text-align:center; min-width:0;
}
.scr-complete-stat-icon{ font-size:19px; line-height:1.1; }
.scr-complete-stat-value{
  font-size:clamp(18px, 6.4vw, 24px); font-weight:800; line-height:1.15;
  color:var(--ink); font-variant-numeric:tabular-nums;
}
.scr-complete-stat-label{
  font-size:10px; font-weight:800; letter-spacing:.07em; text-transform:uppercase;
  color:var(--ink-soft); line-height:1.2;
}
.scr-complete-stats .scr-complete-stat:nth-child(1) .scr-complete-stat-value{ color:var(--gold); }
.scr-complete-stats .scr-complete-stat:nth-child(2) .scr-complete-stat-value{ color:var(--ok); }

/* --- streak flame --- */

.scr-complete-streak{
  display:flex; flex-direction:column; align-items:center; gap:2px;
  width:100%; text-align:center;
  padding:var(--sp-4) var(--sp-4);
}
.scr-complete-flame{ font-size:36px; line-height:1.1; }
.scr-complete-streak-num{
  font-size:34px; font-weight:800; line-height:1.05; color:var(--flame);
  font-variant-numeric:tabular-nums;
}
.scr-complete-streak-copy{ font-size:16px; font-weight:800; color:var(--ink); }
.scr-complete-guard{
  margin-top:var(--sp-1);
  font-size:13px; font-weight:700; color:var(--ink-soft);
}

/* --- daily goal ring --- */

.scr-complete-goal{
  display:flex; align-items:center; gap:var(--sp-4);
  width:100%; text-align:left;
}
.scr-complete-goal .ring{ --ring-size:58px; --ring-w:4px; flex:0 0 auto; }
.scr-complete-goal-copy{ min-width:0; }
.scr-complete-goal-title{ font-size:16px; font-weight:800; color:var(--ink); }
.scr-complete-goal-sub{ font-size:13px; font-weight:700; color:var(--ink-soft); }

/* --- footer --- */

.scr-complete-foot{
  flex:0 0 auto;
  padding:var(--sp-3) var(--sp-4);
  padding-bottom:calc(var(--sp-3) + env(safe-area-inset-bottom));
  background:var(--bg);
  border-top:2px solid var(--line);
}
.scr-complete-foot-inner{ width:100%; max-width:var(--shell); margin-inline:auto; }

/* ==========================================================================
   4. Small screens (320px) and short ones (the keyboard is open)
   ========================================================================== */

@media (max-width:359px){
  .scr-lesson-head{ padding-inline:var(--sp-3); gap:var(--sp-2); }
  .scr-lesson-ex  { padding-inline:var(--sp-3); }
  .scr-lesson-head-inner{ gap:var(--sp-2); }
  .scr-lesson-foot, .scr-complete-foot{ padding-inline:var(--sp-3); }
  .scr-complete-body{ padding-inline:var(--sp-3); }
  .scr-complete-stat{ padding:var(--sp-3) 4px; }
  .scr-complete-stat-label{ letter-spacing:.03em; }
}

/* Under ~560px tall the keyboard is almost certainly up: shed the decoration and
   give every remaining pixel to the exercise. */
@media (max-height:560px){
  .scr-lesson-head{ padding-block:var(--sp-2); }
  .scr-lesson-ex{ padding-block:var(--sp-3); }
  .scr-lesson-foot{ padding-block:var(--sp-2); }
  .scr-lesson-out{ padding-block:var(--sp-4); gap:var(--sp-3); }
  .scr-lesson-out .mochi{ width:84px; height:84px; }
  .scr-complete-body{ padding-block:var(--sp-3); gap:var(--sp-3); }
  .scr-complete-hero .mochi{ width:88px; height:88px; }
  .scr-complete-flame{ font-size:28px; }
  .scr-complete-streak-num{ font-size:28px; }
}

/* Room to breathe on a tablet or desktop. */
@media (min-width:600px) and (min-height:700px){
  .scr-lesson-ex{ padding-top:var(--sp-5); }
  .scr-complete-body{ gap:var(--sp-5); }
}

/* the read-aloud row sits directly under the instruction, same place every time so a
   child who cannot read can still find it by position */
.scr-lesson-read{ display:flex; margin-top:calc(var(--sp-3) * -1); }
