/* ============================================================
   Number Quest — Full Stylesheet
   Warm, chunky, tactile toy aesthetic.
   Fraunces (headings) + Nunito (body)
   ============================================================ */

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; touch-action: manipulation; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  font-weight: 700;
  background: #fdf6e3;
  color: #2a1a0a;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Screens ---- */
.screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  background: #fdf6e3;
}
.screen.active { display: flex; }

/* ---- Typography ---- */
h1, h2 { font-family: "Fraunces", Georgia, serif; }

/* ---- Colour tokens ---- */
:root {
  --sun:    #f9a825;
  --sun-d:  #c67c00;
  --berry:  #c2185b;
  --leaf:   #388e3c;
  --sky:    #0288d1;
  --cream:  #fdf6e3;
  --brown:  #2a1a0a;
  --brown2: #6b4a2a;
  --card:   #fff8e7;
  --shadow: rgba(42, 26, 10, 0.18);
  --radius: 20px;
}

/* ---- Buttons ---- */
.btn-primary {
  background: var(--sun); color: var(--brown);
  border: 3px solid var(--brown); border-radius: 999px;
  font: 800 16px/1 "Nunito", sans-serif;
  padding: 14px 28px; cursor: pointer;
  box-shadow: 0 5px 0 var(--sun-d);
  transition: transform .1s, box-shadow .1s;
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--sun-d); }
.btn-primary.full { width: 100%; text-align: center; }
.btn-primary.big { font-size: 20px; padding: 18px 36px; }

.btn-ghost {
  background: transparent; color: var(--brown2);
  border: 2px solid var(--brown2); border-radius: 999px;
  font: 700 15px/1 "Nunito", sans-serif;
  padding: 10px 22px; cursor: pointer;
}
.btn-ghost:active { opacity: .7; }

.btn-danger {
  background: #f44336; color: #fff;
  border: 3px solid var(--brown); border-radius: 999px;
  font: 800 15px/1 "Nunito", sans-serif;
  padding: 12px 24px; cursor: pointer;
}

.btn-back {
  background: var(--card); color: var(--brown2);
  border: 2px solid #d4b896; border-radius: 999px;
  font: 700 14px/1 "Nunito", sans-serif;
  padding: 8px 18px; cursor: pointer;
  white-space: nowrap;
}

.btn-play {
  background: var(--leaf); color: #fff;
  border: 3px solid var(--brown); border-radius: 999px;
  font: 900 22px/1 "Fraunces", serif;
  padding: 16px 48px; cursor: pointer;
  box-shadow: 0 6px 0 #1b5e20;
  letter-spacing: .04em;
  transition: transform .1s, box-shadow .1s;
}
.btn-play:active { transform: translateY(4px); box-shadow: 0 2px 0 #1b5e20; }

.btn-quit {
  background: #ff5252; color: #fff;
  border: 2px solid var(--brown); border-radius: 999px;
  font: 900 13px/1 "Nunito", sans-serif;
  width: 36px; height: 36px;
  cursor: pointer; flex-shrink: 0;
}

/* ---- PROFILES screen ---- */
.top-brand {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 28px 16px 4px;
}
.brand-title {
  font-size: clamp(28px, 6vw, 44px); color: var(--sun-d);
  text-shadow: 0 3px 0 rgba(0,0,0,.12);
}
.brand-star { font-size: 28px; }
.brand-sub { text-align: center; font-size: 16px; color: var(--brown2); padding-bottom: 12px; }

.profile-grid {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 16px; padding: 12px 20px; flex: 1;
}
.profile-card {
  background: var(--card);
  border: 3px solid #d4b896; border-radius: var(--radius);
  padding: 20px 24px; cursor: pointer; text-align: center;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform .1s;
  width: clamp(120px, 28vw, 160px);
}
.profile-card:active { transform: scale(.96); }
.profile-avatar { font-size: clamp(36px, 8vw, 52px); line-height: 1; }
.profile-name { font-size: clamp(13px, 2.5vw, 16px); font-weight: 800; margin-top: 6px; }
.profile-theme { font-size: 12px; color: var(--brown2); margin-top: 4px; }
.profile-card.empty { opacity: .5; cursor: default; border-style: dashed; }

.footer-row {
  display: flex; justify-content: center;
  padding: 16px; gap: 12px;
}

/* ---- GATE screen ---- */
.gate-card {
  background: var(--card);
  border: 3px solid #d4b896; border-radius: var(--radius);
  padding: 32px 28px; max-width: 400px; width: 90%;
  margin: auto; box-shadow: 0 6px 0 var(--shadow); text-align: center;
}
.gate-icon { font-size: 48px; margin-bottom: 12px; }
.gate-title { font-size: 22px; margin-bottom: 12px; }
.gate-q { font-size: 16px; line-height: 1.5; color: var(--brown2); margin-bottom: 16px; }
.gate-input {
  width: 100%; font: 800 20px/1 "Nunito", sans-serif;
  border: 3px solid #d4b896; border-radius: 14px;
  padding: 12px; text-align: center; background: var(--cream);
  margin-bottom: 8px;
}
.gate-msg { color: var(--berry); font-size: 14px; min-height: 20px; margin-bottom: 12px; }
.gate-btns { display: flex; justify-content: space-between; gap: 12px; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; border-bottom: 2px solid #e8d5b7;
  background: var(--card); flex-shrink: 0;
}
.toolbar-title { font-size: clamp(16px, 3vw, 20px); flex: 1; }

/* ---- GROWNUP screen ---- */
.manage-panel { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.backup-row { border-top: 2px solid #e8d5b7; margin-top: 4px; }
.backup-row h3 { font-size: 15px; color: var(--brown2); margin-bottom: 8px; }
.manage-list { display: flex; flex-direction: column; gap: 10px; }
.manage-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 2px solid #d4b896; border-radius: 14px;
  padding: 12px 16px; cursor: pointer;
}
.manage-row:active { opacity: .8; }
.mr-avatar { font-size: 30px; line-height: 1; }
.mr-name { font-size: 16px; font-weight: 800; flex: 1; }
.mr-theme { font-size: 13px; color: var(--brown2); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- EDITOR screen ---- */
.editor-body {
  padding: 16px 20px; display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; flex: 1;
}
.field-label { font-size: 13px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--brown2); }
.field-input {
  width: 100%; font: 800 16px/1 "Nunito", sans-serif;
  border: 3px solid #d4b896; border-radius: 14px;
  padding: 12px; background: var(--cream); color: var(--brown);
}
.avatar-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.avatar-pick {
  font-size: 32px; background: var(--card); border: 3px solid #d4b896;
  border-radius: 14px; padding: 8px; cursor: pointer; line-height: 1;
  transition: transform .1s;
}
.avatar-pick[data-selected="true"] { border-color: var(--sun); background: #fff8d6; transform: scale(1.15); }

.theme-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-pick {
  flex: 1; min-width: 120px; max-width: 180px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 3px solid #d4b896; border-radius: 14px;
  padding: 14px 8px; cursor: pointer;
}
.theme-pick[data-selected="true"] { border-color: var(--sun); background: #fff8d6; }
.tp-emoji { font-size: 32px; line-height: 1; }
.tp-label { font-size: 12px; font-weight: 800; text-align: center; }

.skill-group { display: flex; flex-direction: column; gap: 8px; }
.skill-group h3 { font-size: 13px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--brown2); }
.skill-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #e8d5b7; color: var(--brown);
  border: 2px solid #c8b090; border-radius: 999px;
  font: 700 13px/1 "Nunito", sans-serif;
  padding: 7px 14px; cursor: pointer;
}
.chip[data-on="true"] { background: var(--leaf); color: #fff; border-color: #1b5e20; }

.narrate-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 2px solid #d4b896; border-radius: 14px;
  padding: 14px 16px; cursor: pointer; font-size: 15px;
}
.narrate-row input { width: 22px; height: 22px; cursor: pointer; accent-color: var(--leaf); }

.editor-footer {
  display: flex; justify-content: space-between; gap: 12px;
  padding-top: 8px; padding-bottom: 24px;
}

/* ---- HOME screen ---- */
.home-header {
  background: var(--card); border-bottom: 2px solid #e8d5b7;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 4px;
  flex-shrink: 0;
}
.home-back { align-self: flex-start; }
.home-namerow { display: flex; align-items: center; gap: 10px; }
.home-name { font-size: clamp(18px, 4vw, 24px); font-weight: 900; flex: 1; }
.streak-badge {
  background: var(--sun); color: var(--brown);
  border: 2px solid var(--brown); border-radius: 999px;
  font-size: 13px; font-weight: 900; padding: 4px 12px;
}
.home-chapter {
  font-size: 13px; color: var(--brown2); padding: 4px 0;
  font-weight: 800;
}
.build-stage {
  flex: 1; position: relative; overflow: hidden;
  border-bottom: 2px solid #e8d5b7;
}
.chars-bar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 4px; padding: 8px 14px;
  background: var(--card); border-bottom: 2px solid #e8d5b7;
  min-height: 52px;
}
.home-footer {
  padding: 12px 20px 20px; display: flex; justify-content: center;
  background: var(--card);
}

/* ---- GAME screen ---- */
.game-header {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-bottom: 2px solid #e8d5b7;
  padding: 10px 14px; flex-shrink: 0;
}
.progress-rail {
  flex: 1; height: 14px; background: #e8d5b7;
  border: 2px solid #c8b090; border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--leaf), #81c784);
  border-radius: 999px; transition: width .3s;
}
.progress-text { font-size: 13px; font-weight: 800; white-space: nowrap; }
.score-badge {
  background: var(--sun); color: var(--brown);
  border: 2px solid var(--brown); border-radius: 999px;
  font-size: 13px; font-weight: 900; padding: 4px 12px; white-space: nowrap;
}
.game-wrap { flex: 1; display: flex; flex-direction: column; padding: 8px; overflow-y: auto; }

/* ---- PLACEMENT screen ---- */
.placement-header {
  background: var(--card); border-bottom: 2px solid #e8d5b7;
  padding: 10px 16px; flex-shrink: 0; text-align: center;
}
.placement-title { font-size: clamp(14px, 2.5vw, 18px); font-weight: 900; color: var(--brown); }
.placement-hint { font-size: 13px; color: var(--brown2); margin-top: 2px; }
.placement-canvas {
  flex: 1; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}

/* Slot highlight pulse */
@keyframes slotPulse {
  from { box-shadow: 0 0 0 4px rgba(255,184,77,.4); }
  to   { box-shadow: 0 0 0 12px rgba(255,184,77,.0); }
}

/* Variants tray */
.variants-tray {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 20;
  background: rgba(253, 246, 227, 0.96);
  border-top: 3px solid #d4b896;
  padding: 10px 12px 14px;
}
.variants-row {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}
.variant-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 3px solid #d4b896; border-radius: 16px;
  padding: 12px 16px; cursor: pointer; min-width: 90px;
  box-shadow: 0 4px 0 var(--shadow); transition: transform .15s;
  touch-action: none;
}
.variant-tile:active, .variant-tile.drag-over { transform: scale(1.1); border-color: var(--sun); }
.vt-emoji { font-size: 44px; line-height: 1; }
.vt-label { font-size: 12px; font-weight: 800; text-align: center; }

/* Dragging clone */
.drag-clone {
  position: fixed; z-index: 9999; pointer-events: none;
  font-size: 56px; line-height: 1;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.4));
}

/* Piece pop animation */
@keyframes piecePop {
  from { transform: translate(-50%,-50%) scale(0.3) rotate(-15deg); opacity: 0; }
  to   { transform: translate(-50%,-50%) scale(1) rotate(0deg);     opacity: 1; }
}

/* Character float */
@keyframes charFloat {
  from { transform: translateY(0px); }
  to   { transform: translateY(-12px); }
}

/* ---- CHAPTER COMPLETE screen ---- */
.chapter-celebrate {
  background: linear-gradient(135deg, #fff8d6 0%, #ffeaa7 100%);
  align-items: center; justify-content: center;
}
.ch-card {
  background: var(--card);
  border: 4px solid var(--sun); border-radius: 28px;
  padding: 36px 32px; max-width: 400px; width: 90%;
  box-shadow: 0 8px 0 var(--sun-d); text-align: center;
}
.ch-emoji { font-size: 72px; line-height: 1; margin-bottom: 8px; }
.ch-name { font-size: clamp(20px, 4vw, 28px); color: var(--brown); margin-bottom: 10px; }
.ch-msg { font-size: 15px; color: var(--brown2); line-height: 1.6; margin-bottom: 12px; }
.ch-stars { font-size: 36px; color: var(--sun); margin-bottom: 20px; }

/* ---- STORY MODE screen ---- */
.story-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.7);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

/* Background panel behind stage */
.sm-bg {
  position: fixed; inset: 0;
  background: rgba(10, 4, 40, 0.78);
  backdrop-filter: blur(3px);
}

/* Main story stage */
.sm-stage {
  position: relative; z-index: 10;
  width: 100%; max-width: 640px;
  background: var(--card);
  border-top: 4px solid #d4b896;
  border-radius: 28px 28px 0 0;
  padding: 20px 20px 28px;
  display: flex; flex-direction: column; gap: 12px;
  max-height: 80vh;
  cursor: pointer;
  box-shadow: 0 -8px 32px rgba(0,0,0,.4);
}

/* Character portrait */
.sm-portrait {
  display: flex; align-items: center; gap: 14px;
  flex-shrink: 0;
}
.sm-avatar { font-size: 56px; line-height: 1; }
.sm-name { font-size: 18px; font-weight: 900; color: var(--brown); }
.sm-title { font-size: 12px; font-weight: 800; color: var(--brown2); margin-top: 2px; }

/* Dialogue bubble */
.sm-bubble {
  background: white; border: 3px solid #d4b896; border-radius: 18px;
  padding: 16px 18px; min-height: 80px; max-height: 200px; overflow-y: auto;
  font-size: clamp(16px, 2.5vw, 20px); line-height: 1.6; font-weight: 700;
  color: var(--brown);
  flex-shrink: 0;
}
@keyframes smPop {
  from { transform: scale(0.95); opacity: .5; }
  to   { transform: scale(1);    opacity: 1; }
}
.sm-pop { animation: smPop .2s ease-out; }

/* Tap hint */
.sm-tap-hint {
  text-align: right; font-size: 12px; font-weight: 800;
  color: var(--brown2); opacity: .6;
  flex-shrink: 0;
}

/* Replay narration button */
.sm-speak-btn {
  position: absolute; top: 16px; right: 16px;
  background: var(--sun); border: 2px solid var(--brown);
  border-radius: 999px; font-size: 18px;
  width: 40px; height: 40px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Choice question */
.sm-choice-q {
  font-size: clamp(15px, 2.5vw, 18px); font-weight: 800; margin-bottom: 14px; line-height: 1.4;
}
.sm-choices { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.sm-choice-btn {
  flex: 1; min-width: 130px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--card); border: 3px solid #d4b896; border-radius: 18px;
  padding: 16px 12px; cursor: pointer; font: 800 14px/1.3 "Nunito", sans-serif;
  box-shadow: 0 4px 0 var(--shadow); transition: transform .15s;
}
.sm-choice-btn:active { transform: scale(0.96); }
.sm-choice-emoji { font-size: 36px; line-height: 1; }
.sm-choice-label { color: var(--brown); text-align: center; }

/* ---- END screen ---- */
.end-inner {
  display: flex; flex-direction: column; align-items: center;
  gap: 16px; padding: 32px 20px; max-width: 500px; margin: auto; text-align: center;
}
.end-title { font-size: clamp(24px, 5vw, 36px); color: var(--sun-d); }
.end-stars { font-size: 44px; color: var(--sun); }
.end-msg { font-size: 18px; color: var(--brown2); }
.end-chapter-info {
  background: var(--card); border: 2px solid #d4b896; border-radius: 14px;
  padding: 10px 18px; font-size: 14px; font-weight: 800;
}
.end-build-mini {
  width: 100%; max-width: 340px; height: 220px;
  border: 3px solid #d4b896; border-radius: 18px; overflow: hidden;
  position: relative; background: #87ceeb;
}

/* ---- Responsive adjustments ---- */
@media (min-width: 600px) {
  .profile-card { width: 160px; }
  .theme-pick { min-width: 140px; }
  .sm-stage { border-radius: 28px; margin-bottom: 24px; }
}

@media (max-height: 700px) {
  .sm-stage { max-height: 92vh; }
  .sm-bubble { min-height: 60px; }
  .ch-card { padding: 24px 20px; }
}

/* ---- Confetti ---- */
@keyframes confettiFall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(320px) rotate(720deg); opacity: 0; }
}
