/* ===== RESPONSIVE BREAKPOINTS ===== */

/* ---- DESKTOP > 1024px — fit everything in one screen, no vertical scroll ---- */
@media (min-width: 1025px) {

  html, body { height: 100%; }
  body { overflow-y: auto; }

  /* Board height driven by the viewport so board + chrome always fit */
  .age-5-7,
  .age-8-12 { --board-size: min(calc(100vh - 235px), 620px); }

  /* ── Compact single-row header ── */
  .app-header {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 8px 20px;
  }

  .header-top { flex-shrink: 0; flex-wrap: nowrap; }

  .mode-tabs {
    margin-top: 0;
    flex: 0 0 auto;
    gap: 8px;
  }

  .mode-btn {
    flex: none;
    border-radius: 30px;
    padding: 8px 20px;
  }

  .mode-btn.active {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }

  .session-bar {
    flex: 1;
    padding: 0;
    min-width: 180px;
  }

  /* ── Use the full width — no narrow column ── */
  .app-main {
    max-width: none;
    padding: 12px 24px 16px;
  }

  /* ── Teach: hint card BESIDE the board (fills side space) ── */
  #phase-challenge.active {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 32px;
  }

  #phase-challenge .challenge-top {
    max-width: 300px;
    flex-direction: column;
  }

  .level-path-bar { padding: 8px 8px 4px; }

  /* ── Play: buttons BESIDE the board ── */
  #play-mode .board-wrapper {
    flex-direction: row;
    align-items: center;
    gap: 20px;
  }

  #play-mode .play-buttons {
    flex-direction: column;
    margin-top: 0;
  }

  .turn-indicator {
    max-width: 420px;
    margin: 0 auto 10px;
    padding: 8px 20px;
    font-size: 1.1rem;
  }

  .play-layout {
    flex-direction: row;
    align-items: center;
  }

  /* ── Puzzles: info & controls BESIDE the board ── */
  #pz-board.active {
    display: grid;
    grid-template-columns: 300px auto;
    gap: 12px 32px;
    align-items: start;
    justify-content: center;
  }

  #pz-board .board-wrapper   { grid-column: 2; grid-row: 1 / span 5; }
  #pz-board .pz-topbar,
  #pz-board .pz-turn-badge,
  #pz-board .pz-hint-bar,
  #pz-board .pz-controls,
  #pz-board .pz-attempts     { grid-column: 1; justify-self: stretch; }

  #pz-board .pz-turn-badge   { text-align: center; }
  #pz-board .pz-controls     { flex-direction: column; }
  #pz-board .pz-attempts     { text-align: center; }

  /* Puzzle library: wider grid, fits without scrolling */
  .puzzle-grid { max-width: 1100px; }

  /* ── Setup: palette already beside board; keep it within viewport ── */
  .setup-palette {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }
}

/* ---- TABLET 600px – 1024px ---- */
@media (min-width: 600px) and (max-width: 1024px) {
  .age-8-12 { --board-size: min(56vw, 420px); }
  .age-5-7  { --board-size: min(70vw, 480px); }

  .teach-layout {
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .play-layout {
    flex-direction: row;
    align-items: flex-start;
  }

  .play-sidebar {
    max-width: 180px;
    font-size: 0.85rem;
  }
}

/* ---- MOBILE < 600px ---- */
@media (max-width: 599px) {
  :root { --board-size: min(92vw, 360px); }
  .age-5-7 { --board-size: 92vw; }

  .app-main { padding: 12px 10px 32px; }

  .header-top { flex-direction: column; align-items: flex-start; gap: 8px; }

  .brand-text h1 { font-size: 1.1rem; }
  .mascot        { font-size: 1.8rem; }

  .piece-selector { gap: 6px; }
  .piece-btn      { min-width: 60px; padding: 8px 10px; }
  .piece-btn svg  { width: 36px; height: 36px; }
  .age-5-7 .piece-btn svg { width: 40px; height: 40px; }

  .teach-layout {
    flex-direction: column;
    align-items: center;
  }

  .info-card {
    width: 100%;
    max-width: 100%;
    padding: 16px;
  }

  .info-name  { font-size: 1.6rem; }
  .info-emoji { font-size: 2.5rem; }

  .play-layout { flex-direction: column; align-items: center; }

  /* On mobile, sidebar is hidden even for ages 8-12 to save space */
  .play-sidebar { display: none !important; }

  .play-buttons { flex-direction: column; gap: 8px; }
  .action-btn   { width: 100%; text-align: center; }

  .turn-indicator { font-size: 1.1rem; padding: 10px 14px; }

  .overlay-box    { padding: 28px 20px; }
  .overlay-title  { font-size: 1.6rem; }
  .overlay-trophy { font-size: 3rem; }

  .check-banner    { font-size: 1.1rem; padding: 10px 20px; top: 70px; }
  .encourage-banner { font-size: 1.1rem; right: 10px; }

  .mode-btn { font-size: 0.9rem; padding: 8px; }
}

/* ---- VERY SMALL SCREENS < 360px ---- */
@media (max-width: 359px) {
  :root { --board-size: 98vw; }
  .age-5-7 { --board-size: 98vw; }
  .piece-btn { min-width: 50px; padding: 6px 8px; }
  .piece-btn svg { width: 30px; height: 30px; }
}

/* ===== LANDSCAPE PHONE ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header { padding: 6px 16px 0; }
  .brand-text h1 { font-size: 1rem; }
  .app-main { padding: 8px 10px 16px; }
  :root { --board-size: min(55vh, 340px); }
}

/* ===== SETUP MODE ON MOBILE — board on top, piece strips below ===== */
@media (max-width: 768px) {

  .setup-layout {
    flex-direction: column-reverse;   /* board (2nd child) above palette */
    align-items: center;
    gap: 12px;
    padding: 8px;
  }

  .setup-palette {
    width: 100%;
    max-width: var(--board-size);
    min-width: 0;
    padding: 10px 12px;
    gap: 10px;
  }

  /* Each color group = label + horizontal scrollable strip */
  .palette-group {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .palette-label { flex-shrink: 0; min-width: 52px; }

  .palette-row {
    display: flex;
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    padding-bottom: 2px;
  }

  .palette-piece-btn {
    min-width: 48px;
    min-height: 48px;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
  }

  /* Eraser + clear side by side */
  .palette-actions {
    flex-direction: row;
    gap: 8px;
  }

  .palette-eraser,
  .palette-clear { flex: 1; }

  .setup-turn-row {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 10px;
  }

  .setup-turn-btns { width: auto; }
  .turn-sel-btn    { padding: 7px 16px; }
}

/* ===== TOUCH DEVICES — larger tap targets ===== */
@media (pointer: coarse) {
  .piece-btn { min-width: 70px; }
  .action-btn { padding: 14px 20px; min-height: 50px; }
  .age-btn    { padding: 8px 14px; min-height: 38px; }
  .mode-btn   { min-height: 44px; }
}
