/* ============================================================
   Write My Name — styles
   Two rows of letter cells (demo row on top, practice row below),
   scaled together so the whole first name fits on one screen.
   ============================================================ */
:root {
  --bg:        #fff8e7;
  --panel:     #ffffff;
  --ink-blue:  #1d70b8;
  --accent:    #ff7a1a;
  --accent-2:  #2bb673;
  --pink:      #ff5d8f;
  --purple:    #7b5cff;
  --text:      #2b2b3a;
  --shadow:    0 6px 0 rgba(0,0,0,0.12);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  overscroll-behavior: none; background: var(--bg); color: var(--text);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI Rounded", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
.hidden { display: none !important; }

#play { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 10px; }

/* ---------- top bar ---------- */
#topbar {
  position: relative; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; min-height: 56px;
}
#nameHint { font-size: clamp(18px, 3.4vw, 30px); font-weight: 900; color: var(--ink-blue); }
#setupBtn {
  position: absolute; top: 0; right: 0; max-width: 40%;
  border: none; border-radius: 14px; padding: 10px 14px;
  font-size: 15px; font-weight: 800;
  background: #fff; color: var(--purple); box-shadow: var(--shadow);
  cursor: pointer;
}
#setupBtn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- the two letter rows ---------- */
#rowsWrap {
  position: relative; flex: 1 1 auto;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0; padding: 4px;
}
#nameRows {
  display: flex; flex-direction: column; align-items: center; gap: 26px;
  transform-origin: center center;
}
.letterRow { display: flex; flex-wrap: nowrap; align-items: center; gap: 20px; }

.letterCell {
  position: relative; flex: none;
  background: var(--panel); border-radius: 22px; box-shadow: var(--shadow);
  overflow: hidden;
}
/* Top row: demo cells. Clickable (replays that letter's demo); the ▶ badge
   tells the child so. Hidden in advanced mode (no demos there). */
.topCell { cursor: pointer; }
.topCell::after {
  content: "▶"; position: absolute; top: 4px; left: 6px; z-index: 4;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}
body.adv .topCell::after { display: none; }
/* Bottom row: the cell the child should write in right now glows orange. */
.botCell.active { box-shadow: 0 6px 0 rgba(0,0,0,0.12), 0 0 0 6px var(--accent); }
.botCell.done { box-shadow: 0 6px 0 rgba(0,0,0,0.12), 0 0 0 4px var(--accent-2); }
.botCell.done::after {
  content: "✓"; position: absolute; top: -6px; right: -6px;
  width: 54px; height: 54px; background: var(--accent-2); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 34px; box-shadow: 0 3px 8px rgba(0,0,0,0.25); z-index: 4;
}
/* Red unhappy-face badge: transiently while drawing off the letter band, and
   persistently once too many errors latched (only the undo button clears it). */
.botCell.error::after {
  content: "☹"; position: absolute; top: -6px; right: -6px;
  width: 54px; height: 54px; background: #e23a3a; color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 900; box-shadow: 0 3px 8px rgba(0,0,0,0.25); z-index: 4;
  animation: faceWobble 0.5s ease-in-out infinite alternate;
}
@keyframes faceWobble { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }

/* Per-letter undo button (bottom-left of each practice cell). */
.letterReset {
  position: absolute; bottom: 4px; left: 4px; z-index: 5;
  width: 42px; height: 42px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.97); color: var(--ink-blue);
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  font-size: 24px; font-weight: 900; line-height: 1; padding: 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-family: inherit; -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.letterReset:active { transform: translateY(2px); box-shadow: none; }

.cellLayer, .cellInk, .cellDemo { position: absolute; inset: 0; width: 100%; height: 100%; }
.cellLayer svg { width: 100%; height: 100%; display: block; }
.cellInk { touch-action: none; z-index: 2; }
.cellDemo { z-index: 2; pointer-events: none; }  /* clicks fall through to the cell */

/* letter rails: light-blue band (width set from JS), rounded, dim */
.cellLayer #strokes {
  stroke: #c9d8e8 !important;
  stroke-linecap: round !important; stroke-linejoin: round !important;
  opacity: 0.9;
}
/* "Check tracing" off → hide the light-blue bands; the child draws on the
   dashed guides + lined paper only. visibility (not display:none) keeps the
   letter geometry measurable in every browser. */
body.no-track .cellLayer #strokes { visibility: hidden !important; }
/* hide any arrow/line artwork the guides group carries; keep the numbers text */
.cellLayer #guides path, .cellLayer #guides line,
.cellLayer #guides polyline, .cellLayer #guides polygon { display: none !important; }
/* "Dashed guides" off → hide the stroke-order numbers too (the dashed lines
   themselves are canvas-drawn and simply not painted). */
body.no-guides .cellLayer #guides { display: none !important; }
/* #bbox / #lines are authoring metadata — never displayed, but keep them
   measurable (visibility, not display:none, so getBBox works everywhere). */
.cellLayer #bbox, .cellLayer #lines { visibility: hidden !important; }

.missingGlyph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 320px; font-weight: 900; color: #eef1f6;
}
.missingGlyph span { font-size: 44px; color: #ffb27a; font-weight: 800; }

.overlay-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 20px; font-size: 24px; font-weight: 800; color: var(--text);
  white-space: pre-line; background: rgba(255,248,231,0.92); z-index: 10;
}

/* ---------- bottom controls ---------- */
#controls { flex: 0 0 auto; display: flex; gap: 14px; justify-content: center; padding-top: 6px; }
.bigBtn {
  border: none; border-radius: 18px; padding: 16px 26px;
  font-size: 22px; font-weight: 800; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .08s ease; text-decoration: none;
}
.bigBtn:active { transform: translateY(3px); box-shadow: none; }
.bigBtn.ghost   { background: #fff; color: var(--ink-blue); }
.bigBtn.primary { background: var(--accent-2); color: #fff; }

/* ---------- parent settings modal ---------- */
/* z-index 120: above the intro screen (100) — the settings auto-open over the
   intro on first run so the parent can enter the name before anything else. */
#settingsModal {
  position: fixed; inset: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(43, 43, 58, 0.6); touch-action: auto;
}
#settingsCard {
  width: min(440px, 100%); background: var(--panel);
  border-radius: 24px; box-shadow: var(--shadow);
  padding: 20px 22px; max-height: 90vh; overflow: auto;
}
#settingsCard h2 { margin: 0 0 14px; color: var(--purple); font-size: 26px; text-align: center; }
.toggleBtn {
  display: block; width: 100%; margin: 0 0 12px;
  padding: 14px 14px; border: 3px solid #e3e3ee; border-radius: 16px;
  background: #fff; color: var(--purple);
  font-size: 17px; font-weight: 800; cursor: pointer;
  font-family: inherit; -webkit-user-select: none; user-select: none;
  box-shadow: var(--shadow);
}
.toggleBtn.on { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.toggleBtn:active { transform: translateY(3px); box-shadow: none; }
.setupField { display: block; margin: 0 0 14px; font-size: 18px; font-weight: 800; color: var(--text); }
.setupField input {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px 14px; font-size: 22px; font-weight: 800;
  border: 3px solid #e3e3ee; border-radius: 14px;
  color: var(--ink-blue); background: #fff;
  -webkit-user-select: text; user-select: text;
}
.setupField input:focus { outline: none; border-color: var(--accent); }
.sliderRow { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sliderRow input[type="range"] {
  flex: 1 1 auto; height: 6px; border-radius: 3px; appearance: auto;
  background: #e3e3ee; outline: none; cursor: pointer;
}
.sliderRow span { min-width: 40px; text-align: right; font-size: 15px; color: var(--ink-blue); font-weight: 800; }
#setupNote { margin: 4px 0 16px; font-size: 14px; color: #8a8a99; text-align: center; }
#settingsBar { display: flex; gap: 12px; justify-content: center; margin-top: 6px; }

/* ===========================================================
   Intro / Start screen
   =========================================================== */
#introScreen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
#introScreen.hidden { display: none !important; }
#introCard {
  text-align: center; max-width: 420px;
  background: var(--panel); border-radius: 28px; box-shadow: var(--shadow);
  padding: 36px 28px 28px;
}
#introCard h1 { color: var(--ink-blue); font-size: clamp(28px, 6vw, 40px); font-weight: 900; margin: 0 0 10px; }
.introKid { color: var(--text); font-size: clamp(18px, 4vw, 22px); font-weight: 800; margin: 0 0 24px; }
#introCard .bigBtn { width: 100%; margin-bottom: 12px; }
#parentLink { display: block; margin-top: 18px; color: var(--purple); font-size: 15px; font-weight: 800; text-decoration: none; }
#parentLink:hover { text-decoration: underline; }

/* ===========================================================
   Parent / Teacher docs modal
   =========================================================== */
#parentDocs {
  position: fixed; inset: 0; z-index: 110;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(43, 43, 58, 0.6); touch-action: auto;
}
#parentDocsCard {
  width: min(480px, 100%); background: var(--panel);
  border-radius: 24px; box-shadow: var(--shadow);
  padding: 24px 24px 20px; max-height: 86vh; overflow: auto;
}
#parentDocsCard h2 { color: var(--purple); font-size: 24px; text-align: center; margin: 0 0 18px; }
#parentDocsCard h3 { color: var(--ink-blue); font-size: 18px; margin: 0 0 6px; }
#parentDocsCard p { color: var(--text); font-size: 15px; line-height: 1.5; margin: 0 0 14px; }
#parentDocs .docSection { margin-bottom: 16px; }
#parentDocsClose { width: 100%; margin-top: 8px; }

/* ---------- progress modal (parent) ---------- */
#progressModal {
  position: fixed; inset: 0; z-index: 115;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(43, 43, 58, 0.6); touch-action: auto;
}
#progressCard {
  width: min(720px, 100%); background: var(--panel);
  border-radius: 24px; box-shadow: var(--shadow);
  padding: 20px 22px; max-height: 90vh;
  display: flex; flex-direction: column;
}
#progressCard h2 { margin: 0 0 6px; color: var(--purple); font-size: 26px; text-align: center; }
#progressNote { margin: 0 0 12px; font-size: 14px; color: #8a8a99; text-align: center; }
#progressList {
  flex: 1 1 auto; min-height: 80px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: flex; flex-direction: column; gap: 12px;
}
.tryRow { border: 3px solid #e3e3ee; border-radius: 16px; padding: 10px 12px; }
.tryHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.tryDate { font-size: 15px; font-weight: 800; color: var(--ink-blue); }
.trySave {
  border: none; border-radius: 10px; padding: 8px 12px;
  font-size: 14px; font-weight: 800; font-family: inherit;
  background: #fff; color: var(--purple); box-shadow: var(--shadow); cursor: pointer;
}
.trySave:active { transform: translateY(2px); box-shadow: none; }
.trySvg svg { width: 100%; height: auto; display: block; }
.tryEmpty { text-align: center; color: #8a8a99; font-size: 17px; font-weight: 800; padding: 24px 8px; }
#progressBar { display: flex; justify-content: center; margin-top: 12px; }

/* ---------- celebration ---------- */
#celebrate { position: fixed; inset: 0; z-index: 70; overflow: hidden; pointer-events: none; }
.confetti {
  position: absolute; top: -40px; width: 13px; height: 20px; border-radius: 3px; opacity: 0.95;
  animation: fall linear infinite;
}
@keyframes fall {
  0% { transform: translateY(-40px) rotateZ(0deg); }
  100% { transform: translateY(110vh) rotateZ(720deg); }
}
