/* Mia's World — overlay styling.
   Design rule from PRD section 7: an attention-training game must not compete
   for attention. No flashing, no bounce, no timers, restrained motion. */

:root {
  --ink: #2f2a26;
  --ink-soft: #6b6058;
  --paper: #fffaf3;
  --sky: #9fd8f0;
  --accent: #4a6fa5;
  --accent-warm: #f59f2b;
  --correct: #3f9d5a;
  --retry: #c8792b;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(60, 45, 30, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  /* Stop iOS text-size adjustment from breaking the reading layout. */
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  color: var(--ink-soft);
  background: var(--sky);
  z-index: 50;
}

#game-root {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

#game-root canvas { display: block; }

/* ---- overlay panels ------------------------------------------------------ */

#ui-root {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px;
  background: rgba(40, 30, 20, 0.42);
  z-index: 30;
}

#ui-root.is-open { display: grid; }

.mw-panel {
  width: min(660px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 30px 24px;
  animation: mw-rise 180ms ease-out;
}

@keyframes mw-rise {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .mw-panel { animation: none; }
}

/* Always-available way out of a panel. Sits top-start so it never competes with
   the primary action, but is a full 56px target for small hands. */
.mw-panel { position: relative; }

/* Fixed to the VIEWPORT, not the panel. Panels scroll internally, so an
   absolutely-positioned close button scrolls out of reach on a long panel —
   which is exactly how the wardrobe ended up feeling impossible to shut. */
.mw-panel__exit {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  inset-inline-end: max(16px, env(safe-area-inset-right));
  z-index: 5;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(40, 30, 20, 0.28);
}

.mw-panel__exit:hover, .mw-panel__exit:focus-visible { background: #ded2c2; }

.mw-panel__eyebrow {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.mw-panel__title {
  margin: 0 0 14px;
  font-size: 1.6rem;
  line-height: 1.25;
}

.mw-speaker {
  display: inline-block;
  background: #ece2d5;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.95rem;
  margin-bottom: 12px;
}

/* Reading comfort: generous line height and a measure short enough for a
   7-year-old to track without losing the line. */
.mw-story-text {
  font-size: 1.35rem;
  line-height: 1.85;
  margin: 0 0 22px;
  max-width: 46ch;
}

.mw-word {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  border-bottom: 2px dotted #c3a98a;
  padding: 0;
  cursor: pointer;
}

.mw-word:hover, .mw-word:focus-visible { background: #fdf0d8; }

.mw-bubble {
  display: block;
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 1rem;
  line-height: 1.5;
}

.mw-bubble strong { display: block; font-size: 1.05rem; }
.mw-bubble em { display: block; opacity: 0.75; font-size: 0.9rem; margin-top: 4px; }

.mw-fallback-note {
  font-size: 0.9rem;
  color: var(--retry);
  background: #fdf3e6;
  border-radius: 10px;
  padding: 8px 12px;
}

/* ---- questions ----------------------------------------------------------- */

.mw-choices { display: grid; gap: 12px; margin: 6px 0 16px; }

.mw-choice {
  font: inherit;
  font-size: 1.2rem;
  text-align: start;
  padding: 18px 20px;
  min-height: 64px;              /* comfortable target for small hands */
  border: 3px solid #e3d5c3;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.mw-choice:hover:not(:disabled) { border-color: var(--accent); }
.mw-choice:disabled { opacity: 0.55; cursor: default; }

.mw-feedback { font-size: 1.1rem; line-height: 1.6; min-height: 1.6em; }
.mw-feedback.is-correct { color: var(--correct); font-weight: 600; }
.mw-feedback.is-retry { color: var(--retry); }

.mw-story-recap {
  font-size: 1.05rem;
  line-height: 1.75;
  background: #f5ece0;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 16px;
}

.mw-story-recap.is-hidden { display: none; }
.mw-sentence.is-highlighted { background: #ffe9a8; border-radius: 4px; }

/* ---- buttons ------------------------------------------------------------- */

.mw-panel__actions { display: flex; gap: 12px; justify-content: flex-end; }

.mw-btn {
  font: inherit;
  font-size: 1.15rem;
  min-height: 64px;
  padding: 16px 30px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.mw-btn--secondary { background: #ded2c2; color: var(--ink); }
.mw-btn:disabled { opacity: 0.45; cursor: default; }

/* The reading button stays dim until the minimum read time passes, so it reads
   as "not yet" rather than "broken". */
.mw-btn.is-waiting { background: #b9c6d8; }

/* Visible countdown beside that button. Without it, a disabled button with no
   feedback simply looks like the game has hung. */
.mw-panel__actions--reading { align-items: center; }

.mw-wait {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: #e6dbcc;
  overflow: hidden;
}

.mw-wait__fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent-warm);
  transition: width linear;
}

@media (prefers-reduced-motion: reduce) {
  .mw-wait__fill { transition: none; }
}

/* ---- language panel ------------------------------------------------------ */

.mw-lang-row { margin-bottom: 20px; }
.mw-lang-row__label { font-size: 1rem; color: var(--ink-soft); margin-bottom: 8px; }
.mw-lang-row__options { display: flex; flex-wrap: wrap; gap: 10px; }

.mw-lang {
  font: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 12px 18px;
  border: 3px solid #e3d5c3;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
}

.mw-lang.is-active { border-color: var(--accent); background: #eaf1fa; }
.mw-lang__flag { font-size: 1.3rem; }
.mw-hint { font-size: 0.95rem; color: var(--ink-soft); }

/* ---- toasts -------------------------------------------------------------- */

#toast-root {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
}

.mw-toast {
  background: rgba(47, 42, 38, 0.92);
  color: #fff;
  padding: 14px 22px;
  border-radius: 999px;
  font-size: 1.05rem;
  opacity: 0;
  transition: opacity 260ms ease;
}

.mw-toast.is-in { opacity: 1; }

/* ---- touch controls ------------------------------------------------------ */

#touch-controls {
  position: fixed;
  inset: auto 0 0 0;
  display: none;
  justify-content: space-between;
  padding: 0 max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  pointer-events: none;
}

#touch-controls.is-visible { display: flex; }

.pad { display: flex; gap: 14px; pointer-events: auto; }

.pad-btn {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 1.6rem;
  cursor: pointer;
  /* Prevents the iOS long-press callout while playing. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.pad-btn.is-pressed { background: rgba(255, 255, 255, 0.95); }
.pad-btn--jump { background: rgba(245, 159, 43, 0.82); }

/* Landscape phones have little vertical room; shrink rather than overlap. */
@media (max-height: 480px) {
  .pad-btn { width: 62px; height: 62px; font-size: 1.3rem; }
  .mw-story-text { font-size: 1.15rem; line-height: 1.6; }
}

/* ---- fullscreen button --------------------------------------------------- */

/* Deliberately outside #ui-root: that container is the panel overlay, and
   Phaser input is muted whenever it has children. */
#fullscreen-btn {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  /* Sits BELOW the in-game HUD bar (which occupies the top ~84px) so the two
     never overlap. */
  top: max(98px, calc(env(safe-area-inset-top) + 98px));
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 250, 243, 0.78);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  z-index: 15;                 /* above the canvas, below panels (30) */
  box-shadow: 0 3px 10px rgba(40, 30, 20, 0.2);
}

#fullscreen-btn:hover { background: rgba(255, 250, 243, 0.95); }

/* Give the canvas the whole window once we are fullscreen. */
:fullscreen #game-root, :-webkit-full-screen #game-root { inset: 0; }