/*
 * Base styles for every game page (games/{slug}/play.html).
 * A game's own style.css only sets the theme variables below and its own play field.
 */

:root {
  --game-bg: linear-gradient(180deg, #e3f2fd 0%, #bbdefb 100%);
  --game-ink: #1e3a4c;           /* main text */
  --game-accent: #2e7d32;        /* headings, stats, success */
  --game-banner-bg: rgba(255, 255, 255, 0.75);
  --game-focus: #ffb300;
  --game-header-h: 64px;
  --btn-size: 50px;
  --btn-home: #1e88e5;
  --btn-lang: #0277bd;
  --btn-speech: #00897b;
  --btn-sound: #8e24aa;
  --btn-restart: #ef6c00;
  --toast-bg: rgba(27, 94, 32, 0.95);
  --toast-warning-bg: rgba(191, 54, 12, 0.95);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background: var(--game-bg);
  color: var(--game-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* No double-tap zoom / text selection inside games (TZ 5.4); pinch-zoom stays available. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Layout ------------------------------------------------------------- */

.game-container {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.game-header {
  flex: 0 0 auto;
  min-height: var(--game-header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  z-index: 10;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 16px;
  border-radius: 30px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--game-accent);
  font-variant-numeric: tabular-nums;
}

.instruction-banner {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 16px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--game-ink);
  background: var(--game-banner-bg);
}

/* --- Buttons ------------------------------------------------------------ */

.toddler-btn {
  position: relative;
  width: var(--btn-size);
  height: var(--btn-size);
  flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid #ffffff;
  color: #ffffff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s ease;
  touch-action: none;
}

.toddler-btn:active {
  transform: scale(0.92);
}

.toddler-btn:focus-visible,
.action-btn:focus-visible,
[role="button"]:focus-visible {
  outline: 4px solid var(--game-focus);
  outline-offset: 3px;
}

.home-btn { background: var(--btn-home); }
.lang-btn { background: var(--btn-lang); gap: 1px; flex-direction: column; }
.lang-btn .btn-icon { font-size: calc(var(--btn-size) * 0.32); line-height: 1; }
.lang-btn .lang-code { font-size: calc(var(--btn-size) * 0.22); font-weight: 800; line-height: 1; letter-spacing: 0.02em; }
.speech-btn { background: var(--btn-speech); }
.sound-btn { background: var(--btn-sound); }
.restart-btn { background: var(--btn-restart); }
.btn-muted { filter: grayscale(0.7) opacity(0.8); }

.home-progress-svg {
  position: absolute;
  inset: -3px;
  width: calc(100% + 6px);
  height: calc(100% + 6px);
  pointer-events: none;
}

.home-progress-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 3;
}

.home-progress-bar {
  fill: none;
  stroke: #ffeb3b;
  stroke-width: 3;
  stroke-linecap: round;
}

.action-btn {
  background: var(--game-accent);
  color: #ffffff;
  border: none;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 14px 32px;
  min-height: 52px;
  border-radius: 40px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.action-btn:hover {
  transform: scale(1.04);
}

/* --- Toast / modal / loading ------------------------------------------- */

.feedback-toast {
  position: absolute;
  top: calc(var(--game-header-h) + 12px);
  left: 50%;
  max-width: min(90vw, 520px);
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #ffffff;
  padding: 8px 22px;
  border-radius: 24px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

.feedback-toast[data-tone="warning"] {
  background: var(--toast-warning-bg);
}

.feedback-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

.game-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.game-modal.show {
  opacity: 1;
}

.modal-content {
  background: #ffffff;
  padding: 32px 36px;
  border-radius: 32px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 440px;
  width: 100%;
  animation: game-pop-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-icon {
  font-size: 2.6rem;
  line-height: 1.2;
}

.modal-title {
  margin: 8px 0 12px;
  font-size: 1.9rem;
  color: var(--game-accent);
}

.modal-message {
  margin: 0 0 24px;
  font-size: 1.15rem;
  color: #455a64;
}

.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--game-bg);
  z-index: 300;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-icon {
  font-size: 3.5rem;
  animation: game-float 1.4s ease-in-out infinite alternate;
}

@keyframes game-pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes game-float {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}

@keyframes game-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.shake {
  animation: game-shake 0.3s ease;
}

/* --- Small screens ------------------------------------------------------ */

@media (max-width: 600px) {
  :root {
    --game-header-h: 56px;
    --btn-size: 42px;
  }

  .game-header {
    padding-left: 6px;
    padding-right: 6px;
  }

  .header-left,
  .header-right {
    gap: 6px;
  }

  .header-center {
    gap: 8px;
    padding: 4px 10px;
  }

  .stat-badge {
    font-size: 1rem;
  }

  .toddler-btn {
    font-size: 1.15rem;
  }

  .instruction-banner {
    font-size: 0.95rem;
  }
}

/* Narrow phones: stats move to their own row so the buttons never overflow. */
@media (max-width: 480px) {
  .game-header {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .header-center {
    order: 3;
    flex: 1 0 100%;
    justify-content: center;
  }

  .feedback-toast {
    top: calc(var(--game-header-h) + 52px);
  }
}

@media (max-width: 360px) {
  :root {
    --btn-size: 38px;
  }
}

/* --- Reduced motion (TZ 6.4, 11) ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
