/* ============================================================
   Arkanoid — Stylesheet
   ============================================================ */
 
/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
 
/* ── CSS custom properties (light theme defaults) ───────────── */
:root {
  color-scheme: light dark;
 
  /* Surfaces */
  --color-bg:         #e8eaf0;
  --color-surface:    #ffffff;
  --color-surface-2:  #f0f2f7;
  --color-border:     #c8ccd8;
 
  /* Text */
  --color-text:       #1a1c23;
  --color-text-muted: #5a5f72;
 
  /* Accent */
  --color-accent:     #3d5afe;
  --color-accent-fg:  #ffffff;
 
  /* Focus ring */
  --color-focus:      #3d5afe;
 
  /* HUD */
  --color-hud-bg:     #dde0ea;
 
  /* Overlay */
  --color-overlay-bg: rgba(30, 32, 44, 0.82);
  --color-overlay-fg: #ffffff;
 
  /* Settings */
  --color-modal-bg:   #ffffff;
  --color-modal-shadow: rgba(0,0,0,0.25);
 
  /* Controls */
  --color-ctrl-bg:    #dde0ea;
  --color-ctrl-fg:    #1a1c23;
  --color-ctrl-hover: #c8ccd8;
 
  /* Game canvas background */
  --color-canvas-bg:  #eef5ff;
  --color-canvas-top: #f9fbff;
  --color-canvas-bottom: #dbe8ff;
  --color-canvas-grid: rgba(76, 114, 173, 0.12);
  --color-paddle:     #3558b8;
  --color-ball:       #ff6b6b;
  --color-shadow:     rgba(12, 18, 36, 0.18);
  --color-brick-stroke: rgba(255, 255, 255, 0.66);

  /* Brick row colours (6 rows) */
  --brick-r0: #e05263;
  --brick-r1: #f08b49;
  --brick-r2: #d59b00;
  --brick-r3: #25985a;
  --brick-r4: #2d6cdf;
  --brick-r5: #7b57d1;
 
  /* Spacing & sizing */
  --header-h:  56px;
  --hud-h:     44px;
  --ctrl-h:    72px;
  --radius:    8px;
  --radius-sm: 4px;
}

body[data-theme="auto"] {
  color-scheme: light dark;
}
 
/* ── Dark theme (system default) ───────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:         #10121a;
    --color-surface:    #1c1f2e;
    --color-surface-2:  #252836;
    --color-border:     #3a3d50;
    --color-text:       #e8eaf0;
    --color-text-muted: #8b90a8;
    --color-hud-bg:     #1c1f2e;
    --color-ctrl-bg:    #252836;
    --color-ctrl-fg:    #e8eaf0;
    --color-ctrl-hover: #3a3d50;
    --color-modal-bg:   #1c1f2e;
    --color-modal-shadow: rgba(0,0,0,0.6);
    --color-canvas-bg:  #0a0c12;
    --color-canvas-top: #101827;
    --color-canvas-bottom: #06090f;
    --color-canvas-grid: rgba(255, 255, 255, 0.06);
    --color-paddle:     #c8ccd8;
    --color-shadow:     rgba(0, 0, 0, 0.45);
    --color-brick-stroke: rgba(255, 255, 255, 0.16);
  }
}
 
/* ── Explicit theme overrides (set via JS / localStorage) ──── */
[data-theme="light"] {
  --color-bg:         #e8eaf0;
  --color-surface:    #ffffff;
  --color-surface-2:  #f0f2f7;
  --color-border:     #c8ccd8;
  --color-text:       #1a1c23;
  --color-text-muted: #5a5f72;
  --color-hud-bg:     #dde0ea;
  --color-ctrl-bg:    #dde0ea;
  --color-ctrl-fg:    #1a1c23;
  --color-ctrl-hover: #c8ccd8;
  --color-modal-bg:   #ffffff;
  --color-modal-shadow: rgba(0,0,0,0.25);
  --color-canvas-bg:  #eef5ff;
  --color-canvas-top: #f9fbff;
  --color-canvas-bottom: #dbe8ff;
  --color-canvas-grid: rgba(76, 114, 173, 0.12);
  --color-paddle:     #3558b8;
  --color-shadow:     rgba(12, 18, 36, 0.18);
  --color-brick-stroke: rgba(255, 255, 255, 0.66);
  --brick-r0: #e05263;
  --brick-r1: #f08b49;
  --brick-r2: #d59b00;
  --brick-r3: #25985a;
  --brick-r4: #2d6cdf;
  --brick-r5: #7b57d1;
  color-scheme: light;
}
 
[data-theme="dark"] {
  --color-bg:         #10121a;
  --color-surface:    #1c1f2e;
  --color-surface-2:  #252836;
  --color-border:     #3a3d50;
  --color-text:       #e8eaf0;
  --color-text-muted: #8b90a8;
  --color-hud-bg:     #1c1f2e;
  --color-ctrl-bg:    #252836;
  --color-ctrl-fg:    #e8eaf0;
  --color-ctrl-hover: #3a3d50;
  --color-modal-bg:   #1c1f2e;
  --color-modal-shadow: rgba(0,0,0,0.6);
  --color-canvas-bg:  #0a0c12;
  --color-canvas-top: #101827;
  --color-canvas-bottom: #06090f;
  --color-canvas-grid: rgba(255, 255, 255, 0.06);
  --color-paddle:     #c8ccd8;
  --color-shadow:     rgba(0, 0, 0, 0.45);
  --color-brick-stroke: rgba(255, 255, 255, 0.16);
  color-scheme: dark;
}
 
/* ── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
 
/* ── Accessibility utilities ────────────────────────────────── */
.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;
}
 
/* Skip link */
.skip-link {
  position: fixed;
  top: -100%;
  left: 8px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}
 
.skip-link:focus {
  top: 8px;
}
 
/* Focus ring for all interactive elements */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
 
/* ── Base typography & body ─────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}
 
/* ── App shell ──────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding-bottom: 6px;
}
 
/* ── Header ─────────────────────────────────────────────────── */
header {
  width: 100%;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
 
header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text);
}
 
/* ── Icon button ────────────────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s;
}
 
.icon-btn:hover {
  background: var(--color-surface-2);
}
 
/* ── HUD ────────────────────────────────────────────────────── */
#hud {
  width: 100%;
  height: var(--hud-h);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--color-hud-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
 
.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
 
.hud-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}
 
.hud-item > span:last-child {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
 
/* Lives hearts */
#lives {
  display: flex;
  gap: 3px;
}
 
.life-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  fill: var(--brick-r0);
}
 
/* ── Main / canvas area ─────────────────────────────────────── */
main {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 8px;
  min-height: 0;
}
 
#canvas-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--color-canvas-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 14px 40px var(--color-shadow);
}
 
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* prevent scroll interference */
  cursor: none;       /* hide cursor over canvas */
}
 
#game-canvas:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: -3px;
}
 
/* ── Game overlay ───────────────────────────────────────────── */
#game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}
 
#game-overlay.hidden {
  display: none;
}
 
#overlay-content {
  text-align: center;
  color: var(--color-overlay-fg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
 
.overlay-title {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
}
 
.overlay-sub {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: rgba(255,255,255,0.75);
  max-width: 28ch;
}
 
/* ── Buttons ────────────────────────────────────────────────── */
[hidden] {
  display: none !important;
}
 
/* ── Mobile controls ────────────────────────────────────────── */
#mobile-controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px 4px;
  gap: 8px;
  flex-shrink: 0;
}
 
.ctrl-btn {
  flex: 1 1 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-ctrl-bg);
  color: var(--color-ctrl-fg);
  font-size: 1.4rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

#btn-pause {
  flex: 0 0 52px;
  height: 38px;
  border-radius: 999px;
}

#btn-pause svg {
  width: 18px;
  height: 18px;
}
 
.ctrl-btn:active,
.ctrl-btn[aria-pressed="true"] {
  background: var(--color-ctrl-hover);
}
 
/* Show mobile controls only on devices without fine pointer (touch) */
@media (hover: hover) and (pointer: fine) {
  #mobile-controls {
    display: none;
  }
}
 
/* ── Keyboard hint ──────────────────────────────────────────── */
#keyboard-hint {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  text-align: center;
  padding: 2px 8px 6px;
}
 
/* Hide keyboard hint on touch-primary devices */
@media (hover: none) {
  #keyboard-hint {
    display: none;
  }
}
 
/* ── Settings modal ─────────────────────────────────────────── */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
 
#settings-overlay[hidden] {
  display: none;
}
 
#settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  background: var(--color-modal-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(360px, calc(100vw - 32px));
  box-shadow: 0 8px 32px var(--color-modal-shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
 
#settings-panel[hidden] {
  display: none;
}
 
#settings-panel h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
}
 
#settings-panel fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
 
#settings-panel legend {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 0 4px;
}
 
.radio-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--color-text);
  font-size: 0.95rem;
}
 
.radio-label input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
  cursor: pointer;
  flex-shrink: 0;
}
 
/* ── Power-up badge colours (drawn on canvas, also used in CSS) */
.pu-life    { color: #ff4757; }
.pu-wide    { color: #ffd32a; }
.pu-slow    { color: #2ed573; }
.pu-multi   { color: #1e90ff; }
 
/* ── Responsive tweaks ──────────────────────────────────────── */
@media (max-width: 400px) {
  header h1 {
    font-size: 1.1rem;
  }
  .ctrl-btn {
    height: 44px;
  }
  #btn-pause {
    flex-basis: 46px;
    height: 34px;
  }
}
 
/* Landscape on small screens: shrink header */
@media (max-height: 500px) and (orientation: landscape) {
  header {
    height: 40px;
  }
  header h1 {
    font-size: 1rem;
  }
  #hud {
    height: 36px;
  }
  .hud-label {
    font-size: 0.6rem;
  }
  .hud-item > span:last-child {
    font-size: 0.95rem;
  }
  #mobile-controls {
    padding: 4px 12px 2px;
  }
  .ctrl-btn {
    height: 40px;
  }
  #btn-pause {
    flex-basis: 42px;
    height: 30px;
  }
}
/* ── Footer ─────────────────────────────────────────────────── */
#footer {
  text-align: center;
  padding: 12px 8px;
  font-size: 0.75rem;
}

#footer a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

#footer a:hover,
#footer a:focus-visible {
  color: var(--color-accent);
  text-decoration: underline;
}