/* ============================================================
   Sophia Learns to Read — styles
   A bright, chunky, "Duolingo-ish" look built only with CSS.
   ============================================================ */

:root {
  /* --- Duolingo-flavoured colour palette --- */
  --green:       #58cc02;   /* main action colour              */
  --green-dark:  #46a302;   /* the "3D" shadow under green      */
  --blue:        #1cb0f6;
  --blue-dark:   #1899d6;
  --yellow:      #ffc800;
  --yellow-dark: #e6a900;
  --red:         #ff4b4b;
  --red-dark:    #e63946;
  --purple:      #ce82ff;

  --ink:    #4b4b4b;         /* friendly dark grey text          */
  --ink-2:  #777;
  --line:   #e5e5e5;         /* neutral borders / locked keys    */
  --line-2: #cfcfcf;
  --paper:  #ffffff;
  --sky:    #f7fbff;

  /* Single-story a/g font for early readers, with safe fallbacks */
  --font: 'Andika', 'Comic Sans MS', 'Chalkboard SE', 'Segoe Print', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--sky);
  /* Stop the whole page from scrolling/bouncing on a tablet */
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- App shell: sidebar + main ---------- */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ============================================================
   LEADERBOARD (left, always visible)
   ============================================================ */
.leaderboard {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #fff, #f0f7ff);
  border-right: 3px solid var(--line);
  padding: 16px 12px;
  overflow-y: auto;
}
.leaderboard-title {
  margin: 4px 0 14px;
  font-size: 1.25rem;
  text-align: center;
  color: var(--ink);
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #fff;
  border: 2px solid var(--line);
  transition: transform .25s ease;
}
/* Highlight Sophia's own row */
.lb-row.me {
  background: #eafff0;
  border-color: var(--green);
}
.lb-rank {
  font-weight: 700;
  color: var(--ink-2);
  width: 20px;
  text-align: center;
}
.lb-avatar { font-size: 1.6rem; line-height: 1; }
.lb-name {
  flex: 1;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-points {
  font-weight: 700;
  color: var(--green);
}
.lb-crown {
  position: absolute;
  margin-top: -34px;
  margin-left: -4px;
  font-size: 1.3rem;
  animation: pop .5s ease;
}
/* little bounce when someone moves */
.lb-row.bump { animation: bump .5s ease; }
@keyframes bump {
  0%,100% { transform: translateY(0); }
  40%     { transform: translateY(-6px); }
}

/* ============================================================
   MAIN AREA
   ============================================================ */
.main {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 3px solid var(--line);
  background: #fff;
}
.score-pill {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--yellow-dark);
  background: #fffbe6;
  border: 2px solid var(--yellow);
  border-radius: 999px;
  padding: 4px 16px;
}

.icon-btn {
  font-size: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 12px;
  line-height: 1;
}
.icon-btn:active { background: var(--line); }

/* Every screen fills the space and centres its content */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Big chunky primary button (the Duolingo look) ---------- */
.big-button {
  font-family: var(--font);
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  background: var(--green);
  border: none;
  border-bottom: 5px solid var(--green-dark);   /* the 3D lip */
  border-radius: 18px;
  padding: 16px 40px;
  cursor: pointer;
  transition: transform .05s ease, filter .1s ease;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.big-button:active { transform: translateY(4px); border-bottom-width: 1px; }
.big-button:disabled {
  background: var(--line);
  border-bottom-color: var(--line-2);
  color: #fff;
  cursor: not-allowed;
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
.screen-welcome { justify-content: center; }
.welcome-card {
  text-align: center;
  max-width: 560px;
  width: 100%;
}
.welcome-emoji { font-size: 3.5rem; }
.welcome-title { font-size: 2.4rem; margin: 8px 0 20px; }
.welcome-sub { font-size: 1.15rem; color: var(--ink-2); margin: 18px 0 10px; }

.name-input {
  font-family: var(--font);
  font-size: 1.4rem;
  text-align: center;
  padding: 12px 18px;
  border: 3px solid var(--line);
  border-radius: 16px;
  width: 280px;
  max-width: 90%;
  outline: none;
}
.name-input:focus { border-color: var(--blue); }

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}
.avatar-choice {
  font-size: 2.4rem;
  width: 68px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: #fff;
  cursor: pointer;
  transition: transform .1s ease;
}
.avatar-choice:active { transform: scale(.92); }
.avatar-choice.selected {
  border-color: var(--green);
  background: #eafff0;
  transform: scale(1.08);
}

/* ============================================================
   LEVEL MAP
   ============================================================ */
.map-greeting { font-size: 1.8rem; margin: 6px 0 24px; text-align: center; }
.level-path {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding-bottom: 40px;
}
/* A heading that separates each section of the map. */
.section-title {
  margin: 22px 0 4px;
  font-size: 1.15rem;
  color: var(--ink-2);
  text-align: left;
  border-bottom: 3px solid var(--line);
  padding-bottom: 6px;
}
.section-title:first-child { margin-top: 0; }
/* The levels of one section, laid out in a wrapping row. */
.level-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 22px;
  justify-content: center;
  padding: 6px 0 4px;
}
.level-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 120px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
}

.node-circle {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  border-bottom: 7px solid rgba(0,0,0,.18);
  background: var(--blue);
  color: #fff;
}
.level-node.done    .node-circle { background: var(--green); }
.level-node.current .node-circle { background: var(--yellow); animation: bob 1.2s ease-in-out infinite; }
.level-node.locked  .node-circle {
  background: var(--line);
  border-bottom-color: var(--line-2);
  color: #fff;
  cursor: default;
}
.level-node.locked { cursor: default; }
.node-label { font-weight: 700; font-size: 1rem; color: var(--ink); }
.node-sub   { font-size: .8rem; color: var(--ink-2); margin-top: -4px; }
.node-badge {
  position: absolute; top: -6px; right: -6px;
  font-size: 1.4rem;
}
@keyframes bob {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-8px); }
}

/* Grown-ups button under the map */
.grownup-btn {
  margin-top: 30px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-2);
  background: #fff;
  border: 2px dashed var(--line-2);
  border-radius: 14px;
  padding: 12px 22px;
  cursor: pointer;
}
.grownup-btn:active { transform: translateY(2px); }

/* ============================================================
   SOUND STUDIO (parent records the sounds)
   ============================================================ */
.screen-studio { align-items: stretch; }
.studio-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.studio-title { font-size: 1.8rem; margin: 0; }
.studio-intro {
  max-width: 760px;
  color: var(--ink-2);
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 4px 0 16px;
}
.studio-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 760px;
  margin-bottom: 20px;
}
.studio-count { font-weight: 700; color: var(--green); white-space: nowrap; }

.studio-section-title {
  font-size: 1.3rem;
  margin: 18px 0 12px;
  width: 100%;
}
.rec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  width: 100%;
}
.rec-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.rec-card.recorded { border-color: var(--green); background: #f4fff8; }
.rec-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}
.rec-emoji { font-size: 1.7rem; line-height: 1; }
.rec-main  { font-size: 1.7rem; font-weight: 700; }
.rec-main.word { font-size: 1.3rem; }
.rec-info { flex: 1; min-width: 0; }
.rec-hint { font-size: .85rem; color: var(--ink-2); }
.rec-controls { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

.rec-btn {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--ink);
}
.rec-btn.record { color: var(--red); }
.rec-btn.record.recording {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dark);
  animation: pulse-red 1s ease-in-out infinite;
}
.rec-btn.play:disabled { opacity: .35; cursor: default; }
.rec-check { color: var(--green); font-weight: 700; }

@keyframes pulse-red {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,75,75,.5); }
  50%     { box-shadow: 0 0 0 6px rgba(255,75,75,.15); }
}

.studio-note {
  max-width: 760px;
  background: #fffbe6;
  border: 2px solid var(--yellow);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--ink);
  margin-bottom: 16px;
}

/* ============================================================
   LESSON SCREEN
   ============================================================ */
.screen-lesson { justify-content: flex-start; }

.lesson-header {
  width: 100%;
  max-width: 760px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}
.progress-track {
  flex: 1;
  height: 18px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width .35s ease;
}

/* Prompt (emoji or sentence) */
.prompt-area {
  text-align: center;
  margin: 6px 0 4px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.prompt-emoji { font-size: 5.5rem; line-height: 1; }
/* The one big letter to find in a "Find the Key" round. */
.prompt-key {
  font-size: 7rem;
  line-height: 1;
  font-weight: 700;
  color: var(--blue);
}
.prompt-say   { font-size: 1.1rem; color: var(--ink-2); margin-top: 6px; }

/* Sentence prompt (fill in the blank) */
.sentence {
  font-size: 2rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 720px;
}
.sentence .emoji { font-size: 2.6rem; }
.sentence .blank {
  min-width: 70px;
  border-bottom: 4px dashed var(--blue);
  color: var(--blue);
  text-align: center;
  padding: 0 6px;
}

/* Answer tiles (the letters she is typing) */
.answer-area {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 4px;
  min-height: 70px;
}
.tile {
  width: 58px;
  height: 66px;
  border-radius: 14px;
  border: 3px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: var(--ink);
  cursor: pointer;
}
.tile.filled { border-color: var(--blue); background: #eef8ff; }
.tile.correct { border-color: var(--green); background: #eafff0; color: var(--green-dark); }
.tile.wrong   { border-color: var(--red); background: #ffecec; color: var(--red-dark); }
.tile.shake   { animation: shake .4s ease; }

/* Multiple-choice buttons */
.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 10px;
}
.choice-btn {
  font-family: var(--font);
  font-size: 1.8rem;
  font-weight: 700;
  padding: 14px 30px;
  border-radius: 16px;
  border: 3px solid var(--line);
  border-bottom-width: 5px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.choice-btn:active { transform: translateY(3px); }
.choice-btn.correct { background: var(--green); border-color: var(--green-dark); color: #fff; }
.choice-btn.wrong   { background: var(--red);   border-color: var(--red-dark);   color: #fff; }

/* Helper tool buttons */
.lesson-tools {
  display: flex;
  gap: 12px;
  margin: 12px 0;
}
.tool-btn {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 14px;
  border: 3px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.tool-btn.tool-on { border-color: var(--yellow); background: #fffbe6; color: var(--yellow-dark); }

/* ============================================================
   ON-SCREEN QWERTY KEYBOARD
   ============================================================ */
.keyboard {
  width: 100%;
  max-width: 780px;
  margin-top: auto;      /* push to the bottom of the lesson */
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.key {
  position: relative;
  flex: 1 1 0;
  max-width: 66px;
  height: 62px;
  border-radius: 12px;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key:active { transform: translateY(3px); }
/* tiny uppercase letter in the corner to map physical -> screen */
.key .cap {
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: .7rem;
  color: var(--ink-2);
  font-weight: 700;
}
/* the glowing "next letter" hint */
.key.hint {
  border-color: var(--yellow);
  background: #fff7cc;
  box-shadow: 0 0 0 3px rgba(255,200,0,.45);
  animation: pulse 1.1s ease-in-out infinite;
}
.key.wrong-press { animation: shake .3s ease; }
.key.backspace { flex: 0 0 90px; font-size: 1.4rem; }

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(255,200,0,.45); }
  50%     { box-shadow: 0 0 0 7px rgba(255,200,0,.25); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ============================================================
   LEVEL COMPLETE SCREEN
   ============================================================ */
.screen-done { justify-content: center; }
.done-card { text-align: center; animation: pop .5s ease; }
.done-emoji { font-size: 5rem; }
.done-title { font-size: 2.4rem; margin: 10px 0; }
.done-points {
  font-size: 1.6rem;
  color: var(--yellow-dark);
  font-weight: 700;
  margin-bottom: 24px;
}

/* ============================================================
   CONFETTI CANVAS
   ============================================================ */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

/* ============================================================
   Small screens (portrait phones etc.) — keep it usable
   ============================================================ */
@media (max-width: 640px) {
  .leaderboard { width: 130px; }
  .node-circle { width: 72px; height: 72px; font-size: 2rem; }
  .level-node { width: 100px; }
  .key { height: 52px; font-size: 1.3rem; }
  .prompt-emoji { font-size: 4rem; }
  .prompt-key { font-size: 5rem; }
  .sentence { font-size: 1.5rem; }
}

/* ============================================================
   PASSWORD GATE
   A friendly lock screen shown over everything until the
   password is entered. Client-side only (see index.html).
   ============================================================ */
body.locked { overflow: hidden; }
body.locked #app,
body.locked #confetti { display: none !important; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--green) 0%, var(--blue) 100%);
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: 24px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.10), 0 20px 45px rgba(0, 0, 0, 0.25);
}

.gate-emoji { font-size: 3rem; line-height: 1; margin-bottom: 10px; }
.gate-title { margin: 0 0 6px; font-size: 1.5rem; color: var(--ink); }
.gate-text  { margin: 0 0 22px; color: var(--ink-2); }

.gate-form { display: flex; flex-direction: column; gap: 12px; }

.gate-input {
  font-family: var(--font);
  font-size: 1.25rem;
  text-align: center;
  padding: 14px 16px;
  border: 3px solid var(--line);
  border-radius: 16px;
  outline: none;
  color: var(--ink);
}
.gate-input:focus { border-color: var(--blue); }

.gate-btn {
  font-family: var(--font);
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  background: var(--green);
  border: none;
  border-bottom: 4px solid var(--green-dark);
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
}
.gate-btn:active { transform: translateY(2px); border-bottom-width: 2px; }

.gate-error { margin: 16px 0 0; color: var(--red); font-weight: 700; }

/* ============================================================
   SOUND STUDIO — Export / Import toolbar
   ============================================================ */
.studio-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 18px;
}

.studio-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 12px;
  padding: 9px 14px;
  cursor: pointer;
}
.studio-tool-btn:hover { border-color: var(--blue); color: var(--blue-dark); }
.studio-tool-btn:active { transform: translateY(1px); border-bottom-width: 2px; }
