/*
 * Shared theme for every game on the site.
 *
 * All colour lives in the variables below — the games read the board colours
 * straight off :root, so this block is the single place to retune the look.
 */

:root {
  /* page */
  --bg-top:     #EAF4FF;
  --bg-bottom:  #FFF6EC;
  --surface:    #FFFFFF;
  --surface-2:  #F4F7FD;
  --ink:        #2D3142;
  --muted:      #6B7280;
  --line:       #E3E9F4;

  /* accents */
  --accent:      #5B8DEF;
  --accent-dark: #3E6FD0;
  --warm:        #FF8A5B;
  --success:     #3FAE72;
  --gold:        #F5B93B;

  /* playfield */
  --board-bg:   #EEF2FA;
  --board-line: #DCE3F0;

  /*
   * One colour per digit, read by both the canvas tiles and the how-to-play
   * demo tiles. Deliberately unrelated to which digits pair up — the pairing
   * has to come from the arithmetic, not from matching colours.
   */
  --d1: #F9A8A8; --d2: #FBC98B; --d3: #F7E07E;
  --d4: #BFE39A; --d5: #8FDCC4; --d6: #8FCFEA;
  --d7: #A9B8F0; --d8: #C9A8ED; --d9: #F2A8D8;

  --radius: 16px;
  --shadow: 0 2px 10px rgba(45,49,66,0.08);
  --shadow-lg: 0 8px 30px rgba(45,49,66,0.16);

  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Segoe UI Variable',
          'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  background: linear-gradient(165deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  margin: 0;
}

/* ── game pages ───────────────────────────────────────────── */

/* Fixed footer sits at the bottom, so leave room for it rather than overlapping. */
.game-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 24px 16px 64px;
}

#game {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

canvas {
  border: 2px solid var(--line);
  border-radius: 10px;
  display: block;
}

#info { width: 140px; padding-top: 2px; }
#info h2 {
  margin: 0 0 2px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
#info p { margin: 0 0 16px; font-size: 26px; font-weight: 800; }

.next-block h2 { margin-bottom: 6px; }
.next-block canvas { margin-bottom: 16px; }

/* Shows what the snake is holding, and what it is called. */
.carry-hud { margin-bottom: 16px; }
#carrying {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
#carrying.is-holding { background: #DCE9FF; color: var(--accent-dark); }

/* Reference strip of the number pairs, for anyone still learning them. */
.bonds { margin-bottom: 16px; }
.bonds span {
  display: inline-block;
  background: var(--surface-2);
  color: var(--accent-dark);
  font-size: 11.5px;
  font-weight: 800;
  padding: 4px 7px;
  border-radius: 6px;
  margin: 0 3px 4px 0;
}

/* ── buttons ──────────────────────────────────────────────── */

button {
  padding: 9px 20px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
}
button:hover { background: #E8EEFA; border-color: #C9D6EE; }

.btn-block { width: 100%; margin-bottom: 14px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
  font-size: 15px;
  padding: 11px 30px;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-support {
  display: block;
  background: var(--gold);
  color: #4A3708;
  text-align: center;
  padding: 9px;
  font-weight: 800;
  font-size: 13px;
  text-decoration: none;
  border-radius: 999px;
  margin-bottom: 14px;
}
.btn-support:hover { background: #E9A92C; }

/* ── on-screen d-pad ──────────────────────────────────────── */

#dpad { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-top: 6px; }
.dpad-row { display: flex; gap: 5px; }

.ctrl-btn {
  width: 40px; height: 40px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.ctrl-btn.wide { width: 130px; font-size: 12px; }
.ctrl-btn:hover  { background: #E8EEFA; }
.ctrl-btn:active { background: var(--accent); color: #fff; transform: scale(0.94); }

/* ── "for parents" note ───────────────────────────────────── */

/* Stacks the board and the parent note; .game-page centres this as one unit. */
.game-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.exercise-note {
  max-width: 500px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 15px 19px;
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}
.exercise-note strong {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 3px;
}

/* Flatter inside a card, which already has its own surface and shadow. */
.game-card .exercise-note {
  background: var(--surface-2);
  box-shadow: none;
  padding: 11px 14px;
  margin-bottom: 12px;
  font-size: 12.5px;
  max-width: none;
}

/* ── learning tags ────────────────────────────────────────── */

/* Colour-coded by subject so a parent can tell the category at a glance. */
.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.tag-math   { color: #2C5AA8; background: #DCE9FF; }
.tag-nature { color: #226B47; background: #D6F2E3; }
.tag-logic  { color: #6A3FA0; background: #EADDFB; }
.tag-words  { color: #9A5216; background: #FDE7CE; }

.tag-soft {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 11px;
}

/* ── learning toggle ──────────────────────────────────────── */

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }
.toggle:hover { color: var(--ink); }

/* ── quiz panel (built by quiz.js) ────────────────────────── */

/*
 * Anchored to the top of the viewport rather than the centre: the action that
 * triggers a question happens on the board, so this keeps it visible.
 */
#quiz-panel {
  position: fixed;
  top: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: none;
  background: var(--surface);
  border: 3px solid var(--accent);
  border-radius: 20px;
  padding: 18px 26px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
#quiz-panel.is-correct { border-color: var(--success); }
#quiz-panel.is-wrong   { border-color: var(--warm); }

.quiz-prompt   { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.quiz-question { font-size: 28px; font-weight: 800; margin-bottom: 14px; }
.quiz-choices  { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.quiz-choice   { min-width: 58px; font-size: 17px; font-weight: 800; padding: 11px 16px; }
.quiz-choice:hover { background: var(--accent); border-color: var(--accent-dark); color: #fff; }

.quiz-result { font-size: 19px; font-weight: 800; margin-bottom: 6px; }
.quiz-note   { font-size: 13px; color: var(--muted); }

/* ── how to play (shown on the start overlay) ─────────────── */

.howto { text-align: left; max-width: 350px; margin: 6px auto 18px; }

.howto-step {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.howto-step:first-child { border-top: none; padding-top: 4px; }

.howto-num {
  flex: none;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.howto-text { flex: 1; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.howto-text b { color: var(--ink); }
.howto-demo { flex: none; display: flex; align-items: center; gap: 3px; }
.howto-arrow { color: var(--muted); font-size: 12px; margin: 0 1px; }

/* Demo tiles, matching the real ones on the board. */
.t {
  width: 25px; height: 25px;
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
  color: rgba(40,40,55,0.82);
}
.t1 { background: var(--d1); } .t2 { background: var(--d2); } .t3 { background: var(--d3); }
.t4 { background: var(--d4); } .t5 { background: var(--d5); } .t6 { background: var(--d6); }
.t7 { background: var(--d7); } .t8 { background: var(--d8); } .t9 { background: var(--d9); }

.t-stack { display: flex; flex-direction: column; gap: 3px; }

.chain-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px; font-weight: 800;
  border-radius: 6px;
  padding: 4px 7px;
}

/* Loops so it reads as "these vanish" without needing a caption. */
.vanish { animation: vanish-loop 2.8s ease-in-out infinite; }
@keyframes vanish-loop {
  0%, 38%   { opacity: 1; transform: scale(1); }
  52%       { opacity: 0; transform: scale(1.3); }
  68%       { opacity: 0; transform: scale(0.75); }
  82%, 100% { opacity: 1; transform: scale(1); }
}

/* ── start / game-over overlay (built by shell.js) ────────── */

#overlay {
  position: fixed; inset: 0;
  display: flex; justify-content: center; align-items: center;
  background: rgba(45,49,66,0.45);
  z-index: 10;
}
#overlay-box {
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
#overlay-box h2 { margin: 0 0 10px; font-size: 24px; font-weight: 800; }
#overlay-box p  { margin: 0 0 14px; color: var(--muted); }
#overlay-box .best { color: var(--gold); font-weight: 800; }

/* ── footer (built by shell.js) ───────────────────────────── */

#site-footer {
  position: fixed; bottom: 12px; left: 0; right: 0;
  text-align: center; font-size: 12px; color: var(--muted);
}
#site-footer a { color: var(--muted); text-decoration: none; margin: 0 8px; font-weight: 600; }
#site-footer a:hover { color: var(--accent); text-decoration: underline; }

/* ── hub page ─────────────────────────────────────────────── */

.hub { max-width: 760px; margin: 0 auto; padding: 56px 24px 80px; }
.hub h1 { font-size: 32px; font-weight: 800; margin: 0 0 12px; }
.hub .tagline { color: var(--muted); margin: 0 0 36px; line-height: 1.7; font-size: 15px; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}
.game-card {
  display: block;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  border-top: 5px solid var(--accent);
}
.game-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.game-card.is-nature { border-top-color: var(--success); }
.game-card .emoji { font-size: 30px; display: block; margin-bottom: 8px; }
.game-card h2 { margin: 0 0 10px; font-size: 18px; font-weight: 800; }
.game-card .tag { margin-bottom: 12px; }
.game-card p { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }

/* ── reading list on the hub ──────────────────────────────── */

.section-head {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 40px 0 14px;
}

.guide-list { display: flex; flex-direction: column; gap: 10px; }
.guide-list a {
  display: block;
  background: var(--surface);
  border-radius: 12px;
  padding: 15px 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
}
.guide-list a:hover { box-shadow: var(--shadow-lg); }
.guide-list b    { display: block; font-size: 14.5px; margin-bottom: 3px; }
.guide-list span { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* ── content pages (about / privacy) ──────────────────────── */

.content {
  max-width: 680px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  line-height: 1.75;
}
.content h1 { font-size: 26px; font-weight: 800; margin: 0 0 28px; }
.content h2 { font-size: 14px; color: var(--muted); margin: 36px 0 10px; text-transform: uppercase; letter-spacing: 0.6px; }
.content p  { margin: 0 0 16px; }
.content ul { margin: 0 0 16px; padding-left: 22px; }
.content li { margin-bottom: 8px; }
.content a  { color: var(--accent-dark); }
.content hr { border: none; border-top: 1px solid var(--line); margin: 44px 0; }
.content .back { display: inline-block; margin-bottom: 28px; color: var(--muted); text-decoration: none; font-weight: 700; }
.content .back:hover { color: var(--accent); }
.content .updated { color: var(--muted); font-size: 12px; }

/* ── phones and small tablets ─────────────────────────────── */

/*
 * Side-by-side board and sidebar need ~490px for Make10 and ~590px for Snake,
 * so below 700px everything stacks: board on top, scaled to fit, controls under
 * it where a thumb can reach them.
 */
@media (max-width: 700px) {
  /*
   * One screen: board on top, D-pad pinned to the bottom where a thumb rests.
   *
   * Height is dvh, not vh. On Android Chrome 100vh includes the strip behind
   * the collapsing URL bar, so a vh-sized layout pushes its own controls off
   * the bottom of the screen. dvh measures what's actually visible.
   */
  .game-page { align-items: flex-start; padding: 0; }
  .game-wrap { width: 100%; gap: 0; }

  #game {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 8px 12px;
    border-radius: 0;
    justify-content: space-between;   /* floats the D-pad to the bottom */
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* Scales the rendered bitmap only — drawing coordinates are untouched. */
  canvas { max-width: 100%; max-height: 52dvh; width: auto; height: auto; }

  #info {
    width: 100%;
    padding-top: 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    flex: 1;
  }
  /* Only the D-pad is pushed down; the rest stays tucked under the board. */
  #dpad { margin-top: auto; }

  /* Stats read as a compact row rather than a tall stack. */
  .stats { display: flex; justify-content: center; gap: 20px; }
  #info .stats h2 { font-size: 9.5px; }
  #info .stats p  { font-size: 18px; margin-bottom: 6px; }

  /* Pause and How to play share one short row instead of two full-width bars. */
  .game-actions { display: flex; gap: 8px; justify-content: center; }
  .btn-block { width: auto; margin: 0 0 6px; padding: 6px 12px; font-size: 12px; }

  /*
   * Everything the board and the controls don't strictly need gives up its
   * vertical space. The tag still leads every card on the hub, the footer
   * still carries a Support link, and the number pairs are on the how-to
   * screen — nothing here is lost, only relocated.
   */
  .next-block,
  .bonds,
  #info > h2,
  #info > .tag,
  .btn-support { display: none; }

  /*
   * Fixed, the footer would sit on top of the D-pad. Put it back in normal
   * flow so it lands below the game — still reachable by scrolling, and the
   * "All games" link stays available.
   */
  #site-footer { position: static; padding: 14px 0 20px; }

  .carry-hud { margin-bottom: 6px; }
  .carry-hud h2 { display: none; }
  #carrying { padding: 5px 8px; font-size: 11.5px; }

  .toggle { justify-content: center; margin-bottom: 6px; }

  /* Bigger targets for thumbs. */
  #dpad { margin-top: 0; gap: 6px; }
  .ctrl-btn { width: 54px; height: 54px; font-size: 22px; border-radius: 14px; }
  .ctrl-btn.wide { width: 168px; height: 46px; font-size: 13px; }

  /* The how-to-play list is 350px wide, so the overlay's desktop padding
     would push it past the edge of a phone screen. */
  #overlay-box { padding: 22px 18px; max-width: calc(100vw - 24px); }
  .howto { max-width: 100%; }
  .howto-text { font-size: 12px; }

  #quiz-panel { top: 8px; padding: 14px 16px; width: calc(100% - 24px); max-width: 340px; }
  .quiz-question { font-size: 22px; }
  .quiz-choice { min-width: 60px; padding: 12px 14px; font-size: 15px; }

  .hub { padding: 36px 18px 72px; }
  .hub h1 { font-size: 25px; }
}
