/* ==========================================
   CSS CUSTOM PROPERTIES (Variables)
   Light Mode Theme - Default
   ========================================== */

:root {
  /* Brand Colors */
  --color-primary-orange: #ff9d5c;
  --color-primary-orange-dark: #ff8142;
  --color-primary-blue: #1976d2;
  --color-primary-blue-dark: #1565c0;
  --color-primary-blue-light: #bbdefb;
  --color-primary-blue-lighter: #e3f2fd;

  /* Background Colors */
  --bg-body: #f5f5f5;
  --bg-container: #ffffff;
  --bg-card: #fafafa;
  --bg-card-alt: #f8f9fa;
  --bg-modal: #ffffff;
  --bg-modal-overlay: rgba(0, 0, 0, 0.7);

  /* Text Colors */
  --text-primary: #333333;
  --text-heading: #2c3e50;
  --text-secondary: #6c757d;
  --text-tertiary: #495057;
  --text-on-dark: #ffffff;

  /* Border Colors */
  --border-light: #e0e0e0;
  --border-medium: #dee2e6;
  --border-dark: #ced4da;
  --border-darker: #495057;

  /* Interactive Elements */
  --button-primary-bg: #1976d2;
  --button-primary-hover: #1565c0;
  --button-secondary-bg: #95a5a6;
  --button-secondary-hover: #7f8c8d;
  --button-success-bg: #28a745;
  --button-success-hover: #218838;
  --button-warning-bg: #ffc107;
  --button-warning-hover: #ffb300;
  --button-disabled-bg: #6c757d;
  --button-disabled-text: #999999;

  /* State Colors */
  --state-correct-bg: #d4edda;
  --state-correct-border: #28a745;
  --state-correct-text: #155724;
  --state-incorrect-bg: #f8d7da;
  --state-incorrect-border: #dc3545;
  --state-incorrect-text: #721c24;
  --state-incomplete-bg: #fff3cd;
  --state-incomplete-border: #ffc107;
  --state-warning-text: #856404;
  --state-empty-text: #495057; /* Submit mark: unfinished (neutral, not yellow) */
  --state-empty-border: #868e96;

  /* Hint & Selection Colors */
  --hint-revealed-bg: #fff3cd;
  --hint-revealed-border: #ffc107;
  --hint-revealed-text: #856404;
  --selection-bg: #e3f2fd;
  --selection-border: #0d47a1;
  --selection-shadow: rgba(25, 118, 210, 0.3);
  --focus-ring: #0d47a1; /* Keyboard focus outline; 3:1 or better on white and the card greys */

  /* Puzzle Select Colors */
  --puzzle-select-bg: #e8f4f8;
  --puzzle-select-border: #1976d2;
  --puzzle-select-hover: #bbdefb;

  /* Assigned Difficulty */
  --assigned-diff-bg: #f0f7ff;
  --assigned-diff-text: #666666;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-xl: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Dark Mode Theme Overrides */
[data-theme='dark'] {
  /* Brand Colors - adjusted for dark backgrounds */
  --color-primary-blue: #64b5f6;
  --color-primary-blue-light: #1e3a5f;
  --color-primary-blue-lighter: #0d1b2a;
  --color-secondary-orange: #ff9800;
  --color-secondary-orange-light: #ffb74d;
  --color-secondary-gray: #424242;

  /* Background Colors - dark surfaces */
  --bg-body: #121212;
  --bg-container: #1e1e1e;
  --bg-card: #2d2d2d;
  --bg-card-alt: #252525;
  --bg-modal: #1e1e1e;
  --bg-modal-overlay: rgba(0, 0, 0, 0.8);

  /* Text Colors - light text on dark */
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-tertiary: #888888;
  --text-heading: #ffffff;
  --text-muted: #666666;

  /* Border Colors - subtle borders */
  --border-light: #3a3a3a;
  --border-medium: #4a4a4a;
  --border-dark: #5a5a5a;
  --border-focus: #64b5f6;

  /* Interactive Elements - buttons and controls */
  --button-primary-bg: #ff9800;
  --button-primary-hover: #fb8c00;
  --button-primary-text: #000000;
  --button-secondary-bg: #3a3a3a;
  --button-secondary-hover: #4a4a4a;
  --button-secondary-text: #e0e0e0;
  --button-success-bg: #66bb6a;
  --button-success-hover: #57a65a;
  --button-warning-bg: #ffa726;
  --button-warning-hover: #fb8c00;
  --button-disabled-text: #666666;

  /* State Colors - validation states */
  --state-correct-bg: #1b5e20;
  --state-correct-border: #66bb6a;
  --state-correct-text: #a5d6a7;
  --state-incorrect-bg: #b71c1c;
  --state-incorrect-border: #ef5350;
  --state-incorrect-text: #ef9a9a;
  --state-incomplete-bg: #e65100;
  --state-incomplete-border: #ffa726;
  --state-incomplete-text: #ffcc80;
  --state-empty-text: #ced4da;
  --state-empty-border: #868e96;

  /* Hint & Selection - game-specific */
  --selection-bg: #1e3a5f;
  --selection-border: #64b5f6;
  --selection-shadow: 0 0 0 3px rgba(100, 181, 246, 0.3);
  --focus-ring: #ffb74d; /* Keyboard focus outline; 3:1 or better on the dark surfaces */
  --hint-revealed-bg: #4a148c;
  --hint-revealed-border: #9c27b0;
  --hint-revealed-text: #e1bee7;

  /* Puzzle Select - dropdown styling */
  --puzzle-select-bg: #2d2d2d;
  --puzzle-select-border: #4a4a4a;
  --puzzle-select-hover: #3a3a3a;

  /* Assigned Difficulty - label styling */
  --assigned-diff-bg: #1e3a5f;
  --assigned-diff-text: #64b5f6;

  /* Shadows - adjusted for dark mode */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 10px 15px rgba(0, 0, 0, 0.5);
}

/* Theme Toggle Button */
#theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid var(--border-medium);
  background-color: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: all 0.3s ease;
}

#theme-toggle:hover {
  background-color: var(--bg-card-alt);
  transform: scale(1.05);
  box-shadow: var(--shadow-lg);
}

#theme-toggle:active {
  transform: scale(0.95);
}

/* Sun and Moon Icons */
#theme-toggle .sun-icon,
#theme-toggle .moon-icon {
  position: absolute;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Light mode: show moon, hide sun */
#theme-toggle .sun-icon {
  transform: rotate(0deg);
  opacity: 0;
}

#theme-toggle .moon-icon {
  transform: rotate(0deg);
  opacity: 1;
}

/* Dark mode: show sun, hide moon */
[data-theme='dark'] #theme-toggle .sun-icon {
  transform: rotate(180deg);
  opacity: 1;
}

[data-theme='dark'] #theme-toggle .moon-icon {
  transform: rotate(180deg);
  opacity: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  #theme-toggle {
    /* Scrolls with the page here: a fixed toggle would cover the sticky targets */
    position: absolute;
    width: 45px;
    height: 45px;
    top: 15px;
    right: 15px;
  }

  #theme-toggle svg {
    width: 18px;
    height: 18px;
  }
}

/* ===================================
   RESET & BASE STYLES
   =================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  /* Smooth transitions for theme switching */
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===================================
   GAME CONTAINER
   =================================== */

.game-container {
  --gutter: 16px; /* Side padding; the sticky strips use it to span the full width */
  max-width: 600px;
  margin: 0 auto;
  padding: var(--gutter);
  background-color: var(--bg-container);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Smooth transitions for theme switching */
  transition: background-color 0.3s ease;
}

/* ===================================
   HEADER
   =================================== */

.game-header {
  text-align: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border-light);
  transition: border-color 0.3s ease;
}

/* Game Logo */
.game-logo {
  max-width: 280px;
  width: 100%;
  height: auto;
  margin: 0 auto 16px auto;
  display: block;
}

/* Remove the h1 styles since we replaced it with logo */
.game-header h1 {
  font-size: 2rem;
  margin: 0 0 16px 0;
  color: var(--text-heading);
  font-weight: 700;
}

.puzzle-info {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  font-size: 14px;
}

.puzzle-select {
  padding: 6px 12px;
  border-radius: 12px;
  background-color: var(--puzzle-select-bg);
  color: var(--color-primary-blue);
  font-weight: 500;
  border: 2px solid var(--puzzle-select-border);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.puzzle-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.puzzle-select:hover {
  background-color: var(--puzzle-select-hover);
}

.puzzle-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--selection-shadow);
}

/* Header streak chip: same pill as .puzzle-select, but read-only */
.streak-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid var(--puzzle-select-border);
  background-color: var(--puzzle-select-bg);
  color: var(--color-primary-blue);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
}

.streak-chip.is-zero {
  color: var(--text-secondary);
  border-color: var(--text-secondary);
  background-color: transparent;
}

/* The phone copy (beside the Menu button) is hidden until the 600px rules */
.streak-chip-phone {
  display: none;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.header-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

/* Menu button is only used on small screens (see the 600px rules below) */
.menu-toggle {
  display: none;
}

.btn-header {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-on-dark);
  background-color: var(--button-primary-bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-header:hover {
  background-color: var(--button-primary-hover);
  transform: translateY(-1px);
}

.btn-header:active {
  transform: translateY(0);
}

.btn-header:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Home link specific styling */
.btn-home {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-home:hover {
  background-color: var(--button-primary-hover);
  transform: translateY(-1px);
}

.btn-home:active {
  transform: translateY(0);
}

/* ===================================
   COLUMN TARGETS
   =================================== */

.column-targets {
  /* Sticks to the top of the screen while the equations scroll past it.
     Full width of the container (negative margins cancel its padding) so
     equations do not show in the side gutters. */
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 calc(var(--gutter) * -1) 12px;
  padding: 8px var(--gutter);
  background-color: var(--bg-container);
  border-bottom: 1px solid var(--border-light);
}

.target {
  background-color: var(--bg-card-alt);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  border: 2px solid var(--border-medium);
}

.target .label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

.target .current {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-tertiary);
}

.target .separator {
  font-size: 20px;
  color: #adb5bd;
  margin: 0 4px;
}

.target .goal {
  font-size: 20px;
  font-weight: 600;
  color: var(--state-correct-border);
}

/* Submit mark on a column target (✓ or ✗). Inline with a fixed width so the
   sticky targets never change height when the mark appears or clears */
.target-mark {
  display: inline-block;
  min-width: 1em;
  margin-left: 6px;
  font-size: 18px;
  font-weight: 700;
}

.target-mark.is-correct {
  color: var(--state-correct-text);
}

.target-mark.is-wrong {
  color: var(--state-incorrect-text);
}

/* Column target status colors */
.target.correct {
  border-color: var(--state-correct-border);
  background-color: var(--state-correct-bg);
}

.target.incorrect {
  border-color: var(--state-incorrect-border);
  background-color: var(--state-incorrect-bg);
}

.target.incomplete {
  border-color: var(--state-incomplete-border);
  background-color: var(--state-incomplete-bg);
}

.assigned-difficulty {
  text-align: center;
  font-size: 14px;
  color: var(--assigned-diff-text);
  padding: 8px;
  margin-bottom: 15px;
  font-style: italic;
  background: var(--assigned-diff-bg);
  border-radius: 6px;
}

/* ===================================
   EQUATIONS
   =================================== */

.equations-container {
  flex: 1;
  margin-bottom: 20px;
}

.equation {
  margin-bottom: 20px;
  padding: 16px;
  background-color: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.question {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
  line-height: 1.4;
  padding-bottom: 4px;
}

/* Submit marks: each status is an icon plus a word in .equation-status, and the
   card border is a second signal. Reserved height keeps the card from jumping
   when a mark clears */
.equation-status {
  min-height: 1.4em;
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  color: var(--text-secondary);
}

.equation.is-correct {
  border-color: var(--state-correct-border);
}

.equation.is-correct .equation-status {
  color: var(--state-correct-text);
}

.equation.is-wrong {
  border-color: var(--state-incorrect-border);
}

.equation.is-wrong .equation-status {
  color: var(--state-incorrect-text);
}

.equation.is-empty {
  border-color: var(--state-empty-border);
}

.equation.is-empty .equation-status {
  color: var(--state-empty-text);
}

.equation.hinted {
  border-color: #17a2b8;
  background-color: #e7f7f9;
}

/* Hinted equation marker */
.equation.hinted::after {
  content: '💡';
  margin-left: 8px;
  font-size: 18px;
  opacity: 0.7;
}

.equation-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 24px;
}

/* Question on the left, per-equation Hint button on the right */
.equation-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.equation-header .question {
  flex: 1;
  min-width: 0;
}

/* Small pill; the ::after widens the tap area to 44px without the visual size */
.btn-hint-equation {
  position: relative;
  flex-shrink: 0;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-on-dark);
  background-color: var(--button-warning-bg);
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.btn-hint-equation::after {
  content: '';
  position: absolute;
  inset: -10px -6px;
}

.btn-hint-equation:hover {
  background-color: var(--button-warning-hover);
}

/* Both hints used: grey and still tappable, so the row can offer ✓ Check */
.btn-hint-equation.is-hinted,
.btn-hint-equation.is-hinted:hover {
  background-color: var(--button-disabled-bg);
}

/* Finished daily: the pill is off altogether */
.btn-hint-equation:disabled {
  background-color: var(--button-disabled-bg);
  color: var(--text-on-dark);
  cursor: not-allowed;
}

/* Inline choice row inside the equation card */
.hint-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.hint-choices[hidden] {
  display: none;
}

.btn-hint-choice {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-container);
  border: 2px solid var(--border-dark);
  border-radius: 8px;
  cursor: pointer;
}

.btn-hint-choice:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===================================
   BLANKS (Operands & Solutions)
   =================================== */

.blank {
  width: 60px;
  height: 60px;
  font-size: 24px;
  font-weight: 700;
  border: 2px solid var(--border-dark);
  border-radius: 8px;
  background-color: var(--bg-container);
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Operand blanks (buttons) */
.blank.operand {
  color: var(--text-tertiary);
}

.blank.operand:hover {
  border-color: var(--color-primary-blue);
  background-color: var(--color-primary-blue-lighter);
}

.blank.operand.selected {
  border-color: var(--selection-border);
  background-color: var(--color-primary-blue-light);
  box-shadow: 0 0 0 3px var(--selection-shadow);
}

/* Solution blanks (inputs) */
.blank.solution {
  text-align: center;
  color: var(--text-secondary);
}

.blank.solution:focus {
  outline: none;
  border-color: var(--color-primary-blue);
  background-color: var(--selection-bg);
}

.blank.operand.filled {
  background-color: var(--puzzle-select-bg);
  border-color: var(--color-primary-blue);
}

/* Hint-revealed styling - HIGHER SPECIFICITY to override filled state */
.blank.operand.hint-revealed,
.blank.solution.hint-revealed {
  background-color: var(--hint-revealed-bg) !important;
  border-color: var(--hint-revealed-border) !important;
  font-style: italic;
  color: var(--hint-revealed-text) !important;
}

.solution.hint-revealed {
  background-color: var(--hint-revealed-bg);
  border-color: var(--hint-revealed-border);
  font-style: italic;
  color: var(--hint-revealed-text);
}

/* No spinner removal needed - using text input with numeric keyboard */

/* ===================================
   OPERATORS & EQUALS
   =================================== */

.operator,
.equals {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-secondary);
  user-select: none;
}

/* Operator is plain text on every difficulty */
.operator-container {
  display: inline-block;
  min-width: 40px;
  text-align: center;
}

/* ===================================
   NUMBER POOL
   =================================== */

.number-pool {
  /* Sticks to the bottom of the screen while the equations scroll past it */
  position: sticky;
  bottom: 0;
  z-index: 50;
  background-color: var(--bg-card-alt);
  padding: 16px;
  border-radius: 8px 8px 0 0;
  border: 2px solid var(--border-medium);
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

.pool-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}

.pool-numbers {
  display: grid;
  gap: 8px;
  margin: 0 auto;
}

/* Easy mode: 5×2 grid (10 numbers) */
.pool-numbers[data-difficulty='easy'] {
  grid-template-columns: repeat(5, 1fr);
  max-width: 320px;
}

/* Medium mode: 6×2 grid (12 numbers) */
.pool-numbers[data-difficulty='medium'] {
  grid-template-columns: repeat(6, 1fr);
  max-width: 380px;
}

/* Hard mode: 8×2 grid (16 numbers) */
.pool-numbers[data-difficulty='hard'] {
  grid-template-columns: repeat(8, 1fr);
  max-width: 500px;
}

.pool-number {
  width: 52px;
  height: 52px;
  font-size: 20px;
  font-weight: 700;
  border: 2px solid var(--border-darker);
  border-radius: 8px;
  background-color: var(--bg-container);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pool-number:hover {
  border-color: var(--color-primary-blue);
  background-color: var(--selection-bg);
  transform: translateY(-2px);
}

.pool-number.selected {
  border-color: var(--selection-border);
  background-color: var(--color-primary-blue);
  color: var(--text-on-dark);
  box-shadow: 0 0 0 3px var(--selection-shadow);
}

.pool-number.used {
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border-light);
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.pool-number.used:hover {
  transform: none;
  border-color: var(--border-light);
  background-color: var(--bg-card);
}

/* ===================================
   CONTROLS
   =================================== */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.game-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
}

/* Undo sits beside Submit; Submit takes the rest of the row */
.submit-row {
  display: flex;
  gap: 12px;
}

.submit-row .btn-submit {
  flex: 1;
  width: auto;
}

.btn-undo {
  flex-shrink: 0;
  padding: 16px 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-container);
  border: 2px solid var(--border-dark);
  border-radius: 8px;
  cursor: pointer;
}

.btn-undo:hover:not(:disabled) {
  background-color: var(--bg-card);
}

.btn-undo:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-submit {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-on-dark);
  background-color: var(--button-success-bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-submit:hover {
  background-color: var(--button-success-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-submit:active {
  transform: translateY(0);
}

.btn-submit:disabled {
  background-color: var(--button-disabled-bg);
  cursor: not-allowed;
  transform: none;
}

.attempts,
.hints {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===================================
   FEEDBACK
   =================================== */

/* Version label at the bottom of the game (uses theme text colour) */
.game-version {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.feedback {
  min-height: 60px;
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  white-space: pre-line; /* The Submit summary has a second "Check equations" line */
  font-size: 14px;
  font-weight: 500;
}

.feedback.success {
  background-color: var(--state-correct-bg);
  color: var(--state-correct-text);
  border: 2px solid var(--state-correct-border);
}

.feedback.error {
  background-color: var(--state-incorrect-bg);
  color: var(--state-incorrect-text);
  border: 2px solid var(--state-incorrect-border);
}

.feedback.warning {
  background-color: var(--state-incomplete-bg);
  color: var(--state-warning-text);
  border: 2px solid var(--state-incomplete-border);
}

/* ===================================
   WIN PANEL & SHARE RESULT
   =================================== */

.win-panel {
  min-height: 60px;
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  background-color: var(--state-correct-bg);
  color: var(--state-correct-text);
  border: 2px solid var(--state-correct-border);
}

.win-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
}

.win-stars {
  margin-right: 6px;
  font-size: 20px;
  letter-spacing: 2px;
}

.win-stats {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 500;
}

.win-next {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 500;
}

.win-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.win-buttons .btn {
  flex: 1 1 140px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.share-fallback {
  margin-top: 12px;
  text-align: left;
}

.share-fallback p {
  margin: 0 0 8px;
  font-size: 13px;
}

.share-fallback-text {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
  background-color: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: 6px;
  resize: vertical;
}

/* ===================================
   TUTORIAL OVERLAY
   =================================== */

.tutorial-content {
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.tutorial-body {
  padding: 0;
}

.tutorial-section {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}

.tutorial-section:last-of-type {
  border-bottom: none;
}

.tutorial-section h3 {
  margin: 0 0 16px 0;
  color: var(--text-heading);
  font-size: 1.1rem;
  font-weight: 600;
}

.tutorial-list {
  margin: 0;
  padding-left: 24px;
  color: var(--text-primary);
  line-height: 1.8;
}

.tutorial-list li {
  margin-bottom: 12px;
}

.tutorial-list li:last-child {
  margin-bottom: 0;
}

.tutorial-list strong {
  color: var(--text-heading);
  font-weight: 600;
}

.tutorial-footer {
  padding: 20px 24px;
  background-color: var(--bg-card-alt);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tutorial-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  user-select: none;
}

.tutorial-checkbox input[type='checkbox'] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  margin: 0;
}

.tutorial-checkbox span {
  line-height: 1;
}

.tutorial-checkbox[hidden] {
  display: none; /* replay mode: .tutorial-checkbox sets display: flex, which would win over [hidden] */
}

#tutorial-close {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  margin-left: auto;
}

/* Keyboard controls: a native disclosure styled like the section headings */
.tutorial-details summary {
  cursor: pointer;
  color: var(--text-heading);
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 4px;
}

.tutorial-details[open] .tutorial-list {
  margin-top: 16px;
}

/* The dialog heading takes focus on open so the title is announced; no ring needed */
#tutorial-title:focus {
  outline: none;
}

/* Mobile header: Home, Stats, New Puzzle and Reset move into a dropdown panel */
@media (max-width: 600px) {
  .header-menu {
    position: relative;
    display: flex;
    justify-content: center;
    margin-top: 12px;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
  }

  /* Streak chip moves from the selects row to beside the Menu button */
  .puzzle-info .streak-chip {
    display: none;
  }

  .streak-chip-phone {
    display: inline-flex;
    min-height: 44px;
    box-sizing: border-box;
  }

  .header-controls {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    margin-top: 6px;
    padding: 8px;
    flex-direction: column;
    gap: 6px;
    background-color: var(--bg-card);
    border: 2px solid var(--border-medium);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
  }

  .header-controls.open {
    display: flex;
  }

  .header-controls .btn-header {
    min-height: 44px;
    text-align: left;
  }

  .header-controls .btn-home {
    justify-content: flex-start;
  }

  /* Targets are sticky on every screen size (see COLUMN TARGETS); smaller here */
  .target {
    padding: 6px 8px;
  }

  .target .current {
    font-size: 20px;
  }

  /* Number pool (sticky on every screen size, see NUMBER POOL): full width and
     compact here so it covers less of the equations */
  .number-pool {
    margin: 0 calc(var(--gutter) * -1) 12px;
    padding: 8px var(--gutter);
    border-radius: 0;
    border-width: 2px 0 0 0;
  }

  /* Label stays for screen readers only */
  .pool-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  /* Tiles per row and tile size for each difficulty (Hard: 16 tiles as 6, 6, 4) */
  .pool-numbers[data-difficulty='easy'] {
    --cols: 5;
    --tile: 44px;
  }

  .pool-numbers[data-difficulty='medium'] {
    --cols: 6;
    --tile: 42px;
  }

  .pool-numbers[data-difficulty='hard'] {
    --cols: 6;
    --tile: 40px;
  }

  /* Flex wrap (not grid) so a short last row is centered. max-width is exactly
     --cols tiles plus their gaps, so rows wrap after --cols tiles. */
  .pool-numbers[data-difficulty] {
    --gap: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
    justify-content: center;
    max-width: calc(var(--cols) * var(--tile) + (var(--cols) - 1) * var(--gap));
  }

  .pool-numbers .pool-number {
    flex: none;
    width: var(--tile);
    height: var(--tile);
    font-size: calc(var(--tile) * 0.42);
  }
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .tutorial-content {
    max-width: 95vw;
  }

  .tutorial-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .tutorial-checkbox {
    justify-content: center;
  }

  #tutorial-close {
    width: 100%;
  }
}

/* ===================================
   RESPONSIVE ADJUSTMENTS
   =================================== */

@media (max-width: 480px) {
  .game-container {
    --gutter: 12px;
  }

  /* Mobile logo sizing */
  .game-logo {
    max-width: 220px;
  }

  .blank {
    width: 52px;
    height: 52px;
    font-size: 20px;
  }

  .equation-row {
    font-size: 20px;
    gap: 6px;
  }

  /* Tighter cards so the Hint button does not cost extra height */
  .equation {
    margin-bottom: 12px;
    padding: 10px 12px;
  }

  .question {
    font-size: 13px;
    margin-bottom: 8px;
    padding-bottom: 0;
  }

  .equation-header {
    gap: 8px;
  }

  .hint-choices {
    gap: 6px;
    margin-bottom: 8px;
  }

  .btn-hint-choice {
    padding: 6px 10px;
    font-size: 13px;
  }

  .operator,
  .equals {
    font-size: 24px;
  }
}

@media (min-width: 768px) {
  .game-container {
    margin-top: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
  }
}

/* ===================================
   CONFETTI ANIMATION
   =================================== */

.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #f0f;
  top: -10px;
  opacity: 0;
  animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

/* Confetti color variations */
.confetti:nth-child(5n + 1) {
  background-color: #ff6b6b;
}

.confetti:nth-child(5n + 2) {
  background-color: #4ecdc4;
}

.confetti:nth-child(5n + 3) {
  background-color: #ffe66d;
}

.confetti:nth-child(5n + 4) {
  background-color: #95e1d3;
}

.confetti:nth-child(5n + 5) {
  background-color: #f38181;
}

/* ===================================
   RESUME MODAL
   =================================== */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-modal-overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-modal);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow-xl);
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.modal-content h2 {
  margin: 0 0 1rem 0;
  color: var(--text-heading);
  font-size: 1.5rem;
}

.modal-content p {
  margin: 0 0 1.5rem 0;
  color: #555;
  font-size: 1rem;
  line-height: 1.5;
}

.modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.modal-buttons .btn {
  flex: 1;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-primary {
  background-color: var(--button-primary-bg);
  color: var(--text-on-dark);
}

.btn-primary:hover {
  background-color: var(--button-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--button-secondary-bg);
  color: var(--text-on-dark);
}

.btn-secondary:hover {
  background-color: var(--button-secondary-hover);
  transform: translateY(-1px);
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .modal-content {
    padding: 1.5rem;
  }

  .modal-buttons {
    flex-direction: column;
  }

  .modal-buttons .btn {
    width: 100%;
  }
}

/* ===================================
   STATISTICS MODAL
   =================================== */

.stats-modal {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h2 {
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--button-secondary-bg);
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: var(--text-heading);
}

.stats-section {
  margin-bottom: 2rem;
}

.stats-section h3 {
  margin: 0 0 1rem 0;
  color: var(--text-heading);
  font-size: 1.2rem;
  border-bottom: 2px solid var(--button-primary-bg);
  padding-bottom: 0.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-item {
  text-align: center;
  padding: 1rem;
  background-color: var(--bg-card-alt);
  border-radius: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--button-primary-bg);
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.85rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stars-earned {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.difficulty-stats {
  background-color: var(--bg-card-alt);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.difficulty-stats h4 {
  margin: 0 0 0.75rem 0;
  color: var(--text-heading);
  font-size: 1rem;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

.stats-row:last-child {
  border-bottom: none;
}

.stats-row span:first-child {
  color: #555;
}

.stats-row span:last-child {
  font-weight: bold;
  color: var(--text-heading);
}

.modal-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
  text-align: center;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .stats-modal {
    max-height: 90vh;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ===================================
   KEYBOARD FOCUS AND ACCESSIBILITY
   =================================== */

/* Visible keyboard focus on every control, in both themes.
   :focus-visible keeps the ring off for mouse and touch. The select and the
   answer boxes are listed because their own :focus styles remove the outline. */
:focus-visible,
.puzzle-select:focus-visible,
.blank.solution:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Selection must not rely on colour alone (it has to survive grayscale):
   a selected blank gets a dashed border, a selected tile an underline */
.blank.operand.selected {
  border-style: dashed;
}

.pool-number.selected {
  text-decoration: underline;
}

/* Keep a focused blank clear of the sticky targets above and number pool below */
.blank.operand {
  scroll-margin-top: 120px;
  scroll-margin-bottom: 240px;
}

/* Visually hidden, still read by screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Players who ask for less motion get no transitions or animations */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
