/*
 * arcade/engine/engine.css
 * Shared stylesheet loaded by every Arcademy game.
 * Loaded via: <link rel="stylesheet" href="../../engine/engine.css">
 *
 * --theme-primary and --theme-accent are set at runtime by GameEngine
 * from each game's config object.  The defaults below act as a safe
 * fallback so the HUD is never unstyled before JS executes.
 *
 * Design target: ages 5–16, kid-friendly, arcade aesthetic.
 * Accessibility: WCAG 2.1 AA touch targets (≥44px), high-contrast mode,
 * reduced-motion mode, screen-reader utilities.
 */

/* ═══════════════════════════════════════════════════════════════════
   GOOGLE FONTS — Fredoka One (headings/arcade) + Nunito (body)
   Loaded here so games don't need to repeat the import.
   ═══════════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;700;800;900&display=swap');

/* ═══════════════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES — theme defaults
   Overridden per-game by GameEngine via document.body.style.setProperty()
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --theme-primary: #4fc3f7;   /* sky blue — safe default */
  --theme-accent:  #FFD700;   /* gold */

  --hud-height: 52px;
  --hud-bg: rgba(10, 8, 28, 0.82);
  --hud-border: rgba(255, 255, 255, 0.10);

  --overlay-bg: rgba(0, 0, 0, 0.72);
  --panel-bg:   rgba(18, 14, 40, 0.96);

  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  24px;
  --radius-pill: 999px;

  --shadow-btn: 0 4px 16px rgba(0, 0, 0, 0.40);
  --shadow-modal: 0 12px 48px rgba(0, 0, 0, 0.60);

  --font-arcade: 'Fredoka One', 'Comic Sans MS', cursive;
  --font-body:   'Nunito', 'Segoe UI', Arial, sans-serif;
}

/* ═══════════════════════════════════════════════════════════════════
   BASE RESET (scoped to engine elements only — avoids conflicts)
   ═══════════════════════════════════════════════════════════════════ */
#game-hud,
#game-hud *,
.pause-overlay,
.pause-overlay *,
.settings-panel,
.settings-panel *,
.modal-overlay,
.modal-overlay *,
#error-screen,
#error-screen * {
  box-sizing: border-box;
}

/* ═══════════════════════════════════════════════════════════════════
   1. #game-hud — Fixed top bar
   ═══════════════════════════════════════════════════════════════════ */
#game-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 400;
  height: var(--hud-height);
  padding: 0 12px;

  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;

  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);

  /* Use theme variables for a coloured left accent line */
  border-left: 3px solid var(--theme-primary);

  font-family: var(--font-body);
}

/* ═══════════════════════════════════════════════════════════════════
   2. .hud-btn — Common button base (all HUD controls inherit this)
   Minimum 44×44px tap target for accessibility (WCAG 2.5.5)
   ═══════════════════════════════════════════════════════════════════ */
.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 10px;

  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-pill);
  color: #ffffff;

  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;

  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.20);
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn);
}

.hud-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.hud-btn:focus-visible {
  outline: 3px solid var(--theme-accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════
   3. .hud-back — Back button (left-aligned, larger font)
   ═══════════════════════════════════════════════════════════════════ */
.hud-back {
  font-family: var(--font-arcade);
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  gap: 6px;
  padding: 6px 14px;
  border-color: rgba(255, 255, 255, 0.22);
}

/* Arrow glyph spacing when used inside the button */
.hud-back::before {
  content: '‹';
  font-size: 1.3em;
  line-height: 1;
  margin-right: 2px;
}

/* ═══════════════════════════════════════════════════════════════════
   4. .hud-player-name — Centered player name
   ═══════════════════════════════════════════════════════════════════ */
.hud-player-name {
  flex: 1;
  text-align: center;
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* subtle accent underline using theme colour */
  padding-bottom: 2px;
  border-bottom: 2px solid var(--theme-accent);
}

/* ═══════════════════════════════════════════════════════════════════
   5. .hud-mute / .hud-settings — Right-aligned icon buttons
   ═══════════════════════════════════════════════════════════════════ */
.hud-mute,
.hud-settings {
  font-size: 1.2rem;
  padding: 6px;
  width: 44px;
  height: 44px;
}

.hud-mute:hover {
  background: rgba(79, 195, 247, 0.25);
  border-color: var(--theme-primary);
}

.hud-settings:hover {
  background: rgba(255, 215, 0, 0.18);
  border-color: var(--theme-accent);
}

/* Right-side cluster */
.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   6. .pause-overlay — Full-screen semi-transparent overlay
   ═══════════════════════════════════════════════════════════════════ */
.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);

  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════════
   7. .pause-content — Centered content within pause overlay
   ═══════════════════════════════════════════════════════════════════ */
.pause-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;

  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  text-align: center;

  box-shadow: var(--shadow-modal);
  animation: scaleIn 0.20s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
  from { transform: scale(0.88); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.pause-content h2 {
  font-family: var(--font-arcade);
  font-size: 2.4rem;
  color: var(--theme-accent);
  letter-spacing: 2px;
  margin: 0;
  text-shadow: 0 2px 12px rgba(255, 215, 0, 0.35);
}

/* Resume button inside pause overlay */
.pause-content .resume-btn {
  min-width: 160px;
  min-height: 52px;
  padding: 12px 32px;
  background: linear-gradient(135deg, var(--theme-primary), color-mix(in srgb, var(--theme-primary) 60%, #000));
  border: none;
  border-radius: var(--radius-pill);
  color: #ffffff;
  font-family: var(--font-arcade);
  font-size: 1.2rem;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79, 195, 247, 0.35);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.pause-content .resume-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(79, 195, 247, 0.50);
}

.pause-content .resume-btn:active {
  transform: translateY(0);
}

.pause-content .resume-btn:focus-visible {
  outline: 3px solid var(--theme-accent);
  outline-offset: 3px;
}

/* ═══════════════════════════════════════════════════════════════════
   8. .settings-panel — Slide-out panel from top-right
   ═══════════════════════════════════════════════════════════════════ */
.settings-panel {
  position: fixed;
  top: calc(var(--hud-height) + 6px);
  right: 12px;
  z-index: 500;

  min-width: 240px;
  max-width: 300px;

  background: var(--panel-bg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  padding: 18px 16px 16px;

  box-shadow: var(--shadow-modal);

  display: flex;
  flex-direction: column;
  gap: 14px;

  animation: slideDown 0.20s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes slideDown {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════════
   9. .settings-label — Small section label text
   ═══════════════════════════════════════════════════════════════════ */
.settings-label {
  display: block;
  font-family: var(--font-body);
  font-size: 0.70rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 6px;
}

/* ═══════════════════════════════════════════════════════════════════
   10. .settings-btn — Settings control buttons
   ═══════════════════════════════════════════════════════════════════ */
.settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 16px;

  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
  color: #ffffff;

  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.30);
}

.settings-btn:focus-visible {
  outline: 3px solid var(--theme-accent);
  outline-offset: 2px;
}

/* Active / selected state — uses theme primary */
.settings-btn.active {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  color: #000000;
  font-weight: 900;
  box-shadow: 0 2px 12px rgba(79, 195, 247, 0.40);
}

/* Row of settings buttons */
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Toggle button (full-width) for contrast / motion */
.settings-toggle {
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  justify-content: space-between;
  font-size: 0.85rem;
}

/* ═══════════════════════════════════════════════════════════════════
   11. .modal-overlay — Full-screen backdrop for modals
   ═══════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;

  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;

  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);

  animation: fadeIn 0.16s ease;
}

/* ═══════════════════════════════════════════════════════════════════
   12. .modal — Centered white card
   ═══════════════════════════════════════════════════════════════════ */
.modal {
  background: #ffffff;
  color: #1a1a2e;
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  max-width: 400px;
  width: 100%;

  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;

  box-shadow: var(--shadow-modal);
  animation: scaleIn 0.20s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal h2,
.modal h3 {
  font-family: var(--font-arcade);
  font-size: 1.6rem;
  color: #1a1a2e;
  margin: 0;
}

.modal p {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: #333;
  margin: 0;
}

/* Button row inside modal */
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════════
   13. .modal-btn — Modal action buttons
   ═══════════════════════════════════════════════════════════════════ */
.modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 120px;
  padding: 10px 24px;

  background: #e5e7eb;
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  color: #1a1a2e;

  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.modal-btn:hover {
  background: #d1d5db;
  transform: translateY(-1px);
}

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

.modal-btn:focus-visible {
  outline: 3px solid var(--theme-primary);
  outline-offset: 2px;
}

/* Primary variant — uses theme primary background */
.modal-btn.primary {
  background: var(--theme-primary);
  color: #000000;
  font-weight: 900;
  box-shadow: 0 4px 18px rgba(79, 195, 247, 0.40);
}

.modal-btn.primary:hover {
  filter: brightness(1.10);
  transform: translateY(-2px);
}

/* Danger variant (e.g. "Quit" confirm) */
.modal-btn.danger {
  background: #ef4444;
  color: #ffffff;
}

.modal-btn.danger:hover {
  background: #dc2626;
}

/* ═══════════════════════════════════════════════════════════════════
   14. #error-screen — Friendly error display
   ═══════════════════════════════════════════════════════════════════ */
#error-screen {
  position: fixed;
  inset: 0;
  z-index: 900;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;

  background: #0c0a1e;
  color: #ffffff;
  font-family: var(--font-body);
}

#error-screen .error-icon {
  font-size: 4rem;
  margin-bottom: 12px;
}

#error-screen h2 {
  font-family: var(--font-arcade);
  font-size: 2rem;
  color: var(--theme-accent);
  margin-bottom: 10px;
}

#error-screen p {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.70);
  max-width: 360px;
  line-height: 1.55;
  margin-bottom: 28px;
}

#error-screen .error-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Retry and back buttons inside error screen */
#error-screen .error-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  min-width: 140px;
  padding: 12px 28px;

  border: 2px solid rgba(255, 255, 255, 0.20);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;

  font-family: var(--font-arcade);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

#error-screen .error-btn:hover {
  background: rgba(255, 255, 255, 0.20);
  transform: translateY(-2px);
}

#error-screen .error-btn.primary {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  color: #000000;
  font-weight: 900;
}

#error-screen .error-btn.primary:hover {
  filter: brightness(1.10);
}

#error-screen .error-btn:focus-visible {
  outline: 3px solid var(--theme-accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════
   15. .hidden — Display none utility
   ═══════════════════════════════════════════════════════════════════ */
.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════
   16. .sr-only — Visually hidden but screen-reader accessible
   ═══════════════════════════════════════════════════════════════════ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   17. FONT SIZE OVERRIDES — applied by Accessibility module to <body>
   ═══════════════════════════════════════════════════════════════════ */
body.font-large {
  font-size: 1.25rem;
}

body.font-large .hud-btn,
body.font-large .settings-btn,
body.font-large .modal-btn,
body.font-large .error-btn {
  font-size: 1.1rem;
  min-height: 50px;
}

body.font-large .hud-player-name {
  font-size: 1.0rem;
}

body.font-xl {
  font-size: 1.5rem;
}

body.font-xl .hud-btn,
body.font-xl .settings-btn,
body.font-xl .modal-btn,
body.font-xl .error-btn {
  font-size: 1.25rem;
  min-height: 54px;
}

body.font-xl .hud-player-name {
  font-size: 1.1rem;
}

body.font-xl #game-hud {
  height: 60px;
}

/* ═══════════════════════════════════════════════════════════════════
   18. body.high-contrast — Increased text contrast + visible focus
   ═══════════════════════════════════════════════════════════════════ */
body.high-contrast #game-hud {
  background: #000000;
  border-bottom: 2px solid #ffffff;
  border-left-color: #ffff00;
}

body.high-contrast .hud-btn {
  background: #000000;
  border: 2px solid #ffffff;
  color: #ffffff;
}

body.high-contrast .hud-player-name {
  border-bottom-color: #ffff00;
  color: #ffff00;
}

body.high-contrast .settings-panel {
  background: #000000;
  border: 2px solid #ffffff;
}

body.high-contrast .settings-btn {
  background: #000000;
  border: 2px solid #ffffff;
  color: #ffffff;
}

body.high-contrast .settings-btn.active {
  background: #ffff00;
  border-color: #ffff00;
  color: #000000;
}

body.high-contrast .settings-label {
  color: #cccccc;
}

body.high-contrast .pause-overlay,
body.high-contrast .modal-overlay {
  background: rgba(0, 0, 0, 0.92);
}

body.high-contrast .pause-content {
  background: #000000;
  border: 2px solid #ffffff;
}

body.high-contrast .pause-content h2 {
  color: #ffff00;
}

body.high-contrast .modal {
  background: #ffffff;
  border: 3px solid #000000;
  color: #000000;
}

body.high-contrast .modal-btn {
  border: 2px solid #000000;
}

body.high-contrast .modal-btn.primary {
  background: #005fcc;
  color: #ffffff;
  border-color: #003380;
}

body.high-contrast #error-screen {
  background: #000000;
}

body.high-contrast #error-screen h2 {
  color: #ffff00;
}

body.high-contrast #error-screen p {
  color: #ffffff;
}

/* High-contrast focus outlines — 3px solid on all interactive elements */
body.high-contrast *:focus-visible {
  outline: 3px solid #ffff00 !important;
  outline-offset: 2px !important;
}

/* ═══════════════════════════════════════════════════════════════════
   19. body.reduced-motion — Disable all animations and transitions
   ═══════════════════════════════════════════════════════════════════ */
body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  animation: none !important;
  transition: none !important;
}

/* Also respect the OS-level preference as a fallback */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   20. .shake — Keyframe animation: brief horizontal shake
   Used by Effects.screenShake() on #game-container
   ═══════════════════════════════════════════════════════════════════ */
@keyframes shake {
  0%   { transform: translateX(0); }
  10%  { transform: translateX(-6px); }
  25%  { transform: translateX(6px); }
  40%  { transform: translateX(-5px); }
  55%  { transform: translateX(5px); }
  70%  { transform: translateX(-3px); }
  85%  { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.shake {
  animation: shake 300ms ease-in-out;
}

/* ═══════════════════════════════════════════════════════════════════
   21. RESPONSIVE — Touch-friendly, tablet 768px+, laptop
   ═══════════════════════════════════════════════════════════════════ */

/* Small phones (portrait) */
@media (max-width: 480px) {
  #game-hud {
    padding: 0 8px;
    gap: 4px;
  }

  .hud-back {
    padding: 6px 10px;
    font-size: 0.90rem;
  }

  .hud-player-name {
    font-size: 0.78rem;
  }

  .pause-content {
    padding: 28px 24px;
  }

  .pause-content h2 {
    font-size: 1.8rem;
  }

  .modal {
    padding: 24px 20px;
  }

  .settings-panel {
    right: 8px;
    min-width: 220px;
  }
}

/* Tablets (768px and up) */
@media (min-width: 768px) {
  #game-hud {
    padding: 0 20px;
    gap: 12px;
  }

  .hud-back {
    font-size: 1.1rem;
    padding: 6px 18px;
  }

  .hud-player-name {
    font-size: 0.96rem;
  }

  .settings-panel {
    min-width: 280px;
  }

  .pause-content {
    padding: 48px 64px;
    gap: 24px;
  }

  .pause-content h2 {
    font-size: 2.8rem;
  }
}

/* Laptops / desktops (1024px and up) */
@media (min-width: 1024px) {
  .modal {
    padding: 40px 36px;
  }

  .modal h2 {
    font-size: 1.8rem;
  }

  .hud-mute,
  .hud-settings {
    font-size: 1.3rem;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   22. ADDITIONAL UTILITY / ARCADE POLISH
   ═══════════════════════════════════════════════════════════════════ */

/* Smooth focus ring for keyboard nav (non-high-contrast) */
:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 2px;
}

/* Live region for screen-reader announcements (auto-created by engine) */
#sr-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Ensure game content sits below the HUD */
#game-container {
  padding-top: var(--hud-height);
}
