/* Number Blocks — e-ink-first design system (Phase 0 skeleton)
   Rules: #000 on #FFF only. No transitions/animations. State via fill
   inversion, border weight, hatching. Tap targets >= 64px. */

:root {
  --ink: #000;
  --paper: #fff;
  --border-thin: 2px solid var(--ink);
  --border-thick: 4px solid var(--ink);
  --tap-min: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* the hidden attribute must always win over any display: rule below
   (e.g. .menu-overlay sets display:flex, which would otherwise show it) */
[hidden] { display: none !important; }

/* Intentionally NO transition/animation properties anywhere in this file.
   The only motion in the app is the JS-driven stepped squeegee sweep (eink.js). */

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  /* lock the page: it fills the viewport and never scrolls as a whole */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chrome {
  padding: 8px 16px;
  border-bottom: var(--border-thin);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}

.brand {
  font-size: clamp(1rem, 2.5vw, 1.5rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Header menu button (Parents / Switch player) */
.menu-btn {
  min-width: 48px;
  min-height: 48px;
  font-size: 1.5rem;
  border: var(--border-thin);
  padding: 4px 12px;
  line-height: 1;
}

/* Menu overlay */
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 8px;
}
.menu-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
  border: var(--border-thick);
  padding: 12px;
  min-width: min(80vw, 260px);
}
.menu-item {
  border: var(--border-thin);
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  padding: 12px 16px;
  text-align: left;
}

#screen {
  /* the one scrollable region, as a fallback — the page body stays locked.
     Content is sized to fit a mobile viewport so this rarely engages.
     `safe center` centers content that fits but top-aligns overflowing content
     so its top stays reachable/scrollable (avoids the flex-centering clip bug). */
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding: 12px;
  overflow-y: auto;
}

.chip {
  display: inline-block;
  border: var(--border-thin);
  padding: 4px 12px;
  font-weight: 700;
}

button, .tap-target {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  background: var(--paper);
  color: var(--ink);
  border: var(--border-thick);
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 800;
  cursor: pointer;
}

button:active, .tap-target:active {
  /* pressed state = full inversion (e-ink safe, no transition) */
  background: var(--ink);
  color: var(--paper);
}

/* Update chip: fixed, unobtrusive, high-contrast. */
.update-chip {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 9997;
  min-height: 44px;
  border: var(--border-thick);
  background: var(--ink);
  color: var(--paper);
  font-weight: 800;
  padding: 8px 16px;
}

/* Device settings row in the Parent Area */
.device-settings {
  border-top: var(--border-thin);
  margin-top: 24px;
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* E-ink invert-flash: full-screen black -> white to clear ghosting.
   State swap is instantaneous (no CSS transition) — JS toggles .clear. */
.eink-flash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--ink);
  pointer-events: none;
}
.eink-flash.clear { background: var(--paper); }

/* Squeegee sweep overlay. Motion comes entirely from JS-stepped inline
   transforms (deliberately NOT CSS-animated — e-ink needs discrete frames). */
.squeegee-overlay {
  position: fixed;
  z-index: 9998;
  pointer-events: none; /* taps pass through — never blocks input */
  overflow: hidden;
}
.squeegee-blade {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;              /* the 1px blade */
  height: 100%;
  background: var(--ink);
}
.squeegee-bot {
  position: absolute;
  top: 50%;
  left: 0;
  margin-top: -0.6em;
  font-size: 1.2em;
  font-weight: 900;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
}

/* Mastery grid (reusable stats component) */
.mastery { width: min(94vw, 560px); }

.mastery-grid {
  display: grid;
  gap: 3px;
  margin: 0 auto;
}

.m-cell {
  aspect-ratio: 1;
  min-width: 0;               /* let cells shrink to fit the grid on phones */
  min-height: 0;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(0.5rem, 2.2vw, 1rem);
  font-weight: 700;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m-cell.mastered { background: var(--ink); color: var(--paper); }

.m-cell.struggling {
  /* diagonal hatch — reads as "in progress" without color or gradient */
  background: repeating-linear-gradient(
    45deg, var(--paper), var(--paper) 3px, var(--ink) 3px, var(--ink) 5px
  );
  color: var(--ink);
}

.m-cell.sel { outline: 4px solid var(--ink); outline-offset: -2px; }

.mastery-detail {
  text-align: center;
  font-weight: 700;
  margin-top: 16px;
  min-height: 1.5em;
}

/* Stats dashboard */
.stats-view { width: min(94vw, 640px); margin: 0 auto; }
.stats-game { margin-top: 24px; }
.stats-game h3 { margin-bottom: 8px; }
.stats-totals { font-weight: 700; margin: 8px 0; }

/* Count-to-100 game (3-choice) */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: min(96vw, 640px);
}

.game-prompt {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
}

/* Addition: the equation shown large */
.add-eq {
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

/* Spelling: speaker + blanked word */
.spell-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.spell-speaker {
  min-width: 72px;
  min-height: 72px;
  font-size: 2rem;
  border: var(--border-thick);
}
.spell-word {
  display: flex;
  gap: 12px;
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 900;
  line-height: 1;
}
.spell-blank { border-bottom: 8px solid var(--ink); min-width: 0.7em; text-align: center; }

/* shared prompt wrapper for adaptive games */
.adaptive-prompt { text-align: center; }

/* the count-from number, shown really large under the prompt */
.game-prompt-num {
  font-size: clamp(4rem, 30vh, 12rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  min-height: clamp(4rem, 30vh, 12rem); /* reserve space so target 1 (empty) doesn't jump */
}

.game-msg {
  font-weight: 700;
  min-height: 1.5em; /* reserved — no layout-shift repaint on miss messages */
  text-align: center;
}

.game-progress {
  font-weight: 700;
  opacity: 0.8;
}

/* the 3 answer buttons */
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
}

.choice {
  min-width: 120px;
  min-height: 120px;
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  padding: 16px 24px;
}

.game-back {
  align-self: flex-start;
  margin-bottom: 8px;
}

/* Celebration */
.celebrate {
  text-align: center;
  border: var(--border-thick);
  background: var(--ink);
  color: var(--paper);
  padding: 32px 48px;
}

.celebrate-num {
  font-size: clamp(4rem, 25vh, 10rem);
  font-weight: 900;
  line-height: 1;
}

.celebrate-sub {
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 800;
  margin-top: 8px;
}

.celebrate-actions { justify-content: center; margin-top: 24px; }

/* Utility: hatched = struggling state (used by mastery grid later) */
.hatch {
  background: repeating-linear-gradient(
    45deg,
    var(--paper), var(--paper) 4px,
    var(--ink) 4px, var(--ink) 6px
  );
}

/* Login screen */
.login-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
}

.login-email {
  border: var(--border-thick);
  padding: 0 16px;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  width: min(90vw, 420px);
}

.login-msg {
  margin-top: 16px;
  font-weight: 700;
  min-height: 1.5em; /* reserve space — avoid layout shift repaints */
}

/* PIN pad */
.pin-entry { text-align: center; }

.pin-dots {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 20px 0 8px;
}

.pin-dot {
  width: 20px;
  height: 20px;
  border: var(--border-thin);
  border-radius: 50%;
}

.pin-dot.filled { background: var(--ink); }

.pin-msg, .form-msg {
  font-weight: 700;
  min-height: 1.5em; /* reserve space — no layout-shift repaints */
  margin: 8px 0;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(var(--tap-min), 96px));
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

/* Profiles / Parent Area */
.profile-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 24px 0;
}

.profile-tile, .game-tile {
  /* vh-aware so several tiles fit a short mobile screen without scrolling */
  font-size: clamp(1.25rem, 4.5vh, 2.5rem);
  padding: clamp(8px, 2vh, 16px) clamp(20px, 6vw, 32px);
  width: min(80vw, 360px);
}

.game-tiles {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vh, 16px);
  margin-top: clamp(12px, 3vh, 24px);
}

/* secondary (non-game) tile — lighter weight so the game tile leads */
.game-tile-secondary {
  font-size: clamp(1rem, 3vh, 1.5rem);
  padding: clamp(6px, 1.5vh, 12px) 24px;
  width: min(70vw, 300px);
}

.parent-area {
  width: min(92vw, 640px);
  margin: 0 auto;
}

.parent-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}

.parent-row {
  border: var(--border-thin);
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions button, .settings-form button, .chip-btn {
  min-height: 44px;
  min-width: 44px;
  font-size: 1rem;
  border: var(--border-thin);
  padding: 4px 12px;
}

.settings-form {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.settings-form input[type="number"] { width: 90px; padding: 8px; border: var(--border-thin); }

.parent-footer { margin-top: 24px; }

#status-chip { border: none; padding: 0; display: flex; gap: 8px; }

/* Placeholder boot screen */
.boot {
  text-align: center;
}
.boot .big {
  font-size: clamp(3rem, 30vh, 12rem);
  font-weight: 900;
  line-height: 1;
}
