/* ==========================================================================
   frontend/styles.css
   Breakout — BM 1.08
   Uses design tokens from design/design-tokens.css + design/design-system.css
   Implements light/dark theme switch via [data-theme="dark"] / .dark
   ========================================================================== */

:root {
  --bo-radius: var(--radius-md, 10px);
  --bo-radius-lg: var(--radius-lg, 16px);
  --bo-gap: var(--space-4, 1rem);
  --bo-gap-sm: var(--space-2, 0.5rem);
  --bo-gap-lg: var(--space-6, 1.5rem);
  --bo-shadow: var(--shadow-md, 0 8px 24px rgba(0,0,0,0.35));
  --bo-transition: 160ms ease;
}

/* Light theme overrides (default tokens are assumed dark-first per design system) */
:root,
[data-theme="light"],
.light {
  --bo-bg: var(--color-bg-light, #f4f5f8);
  --bo-surface: var(--color-surface-light, #ffffff);
  --bo-surface-2: var(--color-surface-2-light, #eceef3);
  --bo-surface-3: var(--color-surface-3-light, #dde0e8);
  --bo-text: var(--color-text-light, #11131a);
  --bo-text-muted: var(--color-text-muted-light, #555b6b);
  --bo-accent: var(--color-accent, #5b8cff);
  --bo-danger: var(--color-danger, #ff5d6c);
  --bo-success: var(--color-success, #37d67a);
  --bo-border: var(--color-border-light, #d0d4e0);
}

[data-theme="dark"],
.dark {
  --bo-bg: var(--color-bg, #0B0D14);
  --bo-surface: var(--color-surface, #13161F);
  --bo-surface-2: var(--color-surface-2, #1A1E2A);
  --bo-surface-3: var(--color-surface-3, #232833);
  --bo-text: var(--color-text, #f1f2f6);
  --bo-text-muted: var(--color-text-muted, #9aa0b4);
  --bo-accent: var(--color-accent, #5b8cff);
  --bo-danger: var(--color-danger, #ff5d6c);
  --bo-success: var(--color-success, #37d67a);
  --bo-border: var(--color-border, #2a2f3d);
}

/* Default to dark theme when no attribute set (matches design system tone) */
html:not([data-theme="light"]):not(.light) {
  --bo-bg: var(--color-bg, #0B0D14);
  --bo-surface: var(--color-surface, #13161F);
  --bo-surface-2: var(--color-surface-2, #1A1E2A);
  --bo-surface-3: var(--color-surface-3, #232833);
  --bo-text: var(--color-text, #f1f2f6);
  --bo-text-muted: var(--color-text-muted, #9aa0b4);
  --bo-border: var(--color-border, #2a2f3d);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bo-bg);
  color: var(--bo-text);
  font-family: var(--font-body, 'Segoe UI', system-ui, sans-serif);
  min-height: 100vh;
}

/* ---- App shell ---- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--bo-gap);
  gap: var(--bo-gap);
}

/* ---- Header / HUD ---- */
.game-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--bo-gap);
  background: var(--bo-surface);
  border: 1px solid var(--bo-border);
  border-radius: var(--bo-radius-lg);
  padding: var(--bo-gap-sm) var(--bo-gap);
  box-shadow: var(--bo-shadow);
}

.game-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--bo-text);
  letter-spacing: 0.02em;
}

.hud-labels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bo-gap-lg);
  align-items: center;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 64px;
}

.hud-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bo-text-muted);
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--bo-accent);
}

.lives-display {
  display: flex;
  align-items: center;
  gap: var(--bo-gap-sm);
}

.lives-hearts {
  font-size: 1.1rem;
  letter-spacing: 2px;
}

.status-label {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bo-surface-3);
  color: var(--bo-text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* ---- Main layout ---- */
.game-main {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--bo-gap);
  align-items: start;
}

.game-board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bo-surface);
  border: 1px solid var(--bo-border);
  border-radius: var(--bo-radius-lg);
  padding: var(--bo-gap-sm);
  box-shadow: var(--bo-shadow);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  max-width: 720px;
  height: auto;
  aspect-ratio: 720 / 520;
  background: var(--bo-bg);
  border-radius: var(--bo-radius);
  border: 1px solid var(--bo-border);
  touch-action: none;
  cursor: crosshair;
}

/* ---- Control panel ---- */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: var(--bo-gap);
  background: var(--bo-surface);
  border: 1px solid var(--bo-border);
  border-radius: var(--bo-radius-lg);
  padding: var(--bo-gap);
  box-shadow: var(--bo-shadow);
  align-self: start;
}

.panel-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--bo-text);
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bo-gap-sm);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bo-text-muted);
}

.select-input {
  background: var(--bo-surface-2);
  color: var(--bo-text);
  border: 1px solid var(--bo-border);
  border-radius: var(--bo-radius);
  padding: 8px 10px;
  font-size: 0.9rem;
}

.select-input:focus-visible {
  outline: 2px solid var(--bo-accent);
  outline-offset: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--bo-accent);
}

.range-value {
  font-size: 0.85rem;
  color: var(--bo-text-muted);
  margin-left: 6px;
}

.touch-controls {
  display: flex;
  gap: var(--bo-gap-sm);
}

.help-text {
  font-size: 0.8rem;
  color: var(--bo-text-muted);
  line-height: 1.4;
  margin: 0;
}

.inline-error {
  background: color-mix(in srgb, var(--bo-danger) 15%, transparent);
  border: 1px solid var(--bo-danger);
  color: var(--bo-danger);
  border-radius: var(--bo-radius);
  padding: 8px 10px;
  font-size: 0.85rem;
}

/* ---- Buttons ---- */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--bo-radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--bo-transition), transform var(--bo-transition), border-color var(--bo-transition);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--bo-accent);
  color: #ffffff;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bo-surface-2);
  color: var(--bo-text);
  border-color: var(--bo-border);
}

.btn-secondary:hover {
  background: var(--bo-surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--bo-text);
  border-color: var(--bo-border);
}

.btn-ghost:hover {
  background: var(--bo-surface-2);
}

.btn:focus-visible,
.select-input:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--bo-accent);
  outline-offset: 2px;
}

/* ---- Overlays / Modals ---- */
.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.pause-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bo-surface);
  border: 1px solid var(--bo-border);
  border-radius: var(--bo-radius-lg);
  padding: var(--bo-gap-lg);
  width: min(90vw, 360px);
  box-shadow: var(--bo-shadow);
  text-align: center;
}

.modal h2 {
  margin-top: 0;
  font-size: 1.2rem;
  color: var(--bo-text);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  color: var(--bo-text-muted);
  margin: var(--bo-gap-sm) 0;
}

.modal-footer {
  display: flex;
  gap: var(--bo-gap-sm);
  justify-content: center;
  margin-top: var(--bo-gap);
  flex-wrap: wrap;
}

/* ---- Footer ---- */
.game-footer {
  text-align: center;
  color: var(--bo-text-muted);
  font-size: 0.8rem;
  padding: var(--bo-gap-sm) 0;
}

.hidden {
  display: none !important;
}

/* ---- Responsive breakpoints ---- */
@media (max-width: 860px) {
  .game-main {
    grid-template-columns: 1fr;
  }
  .control-panel {
    order: 2;
  }
  .game-board-wrap {
    order: 1;
  }
}

@media (max-width: 520px) {
  .game-title {
    font-size: 1.2rem;
  }
  .hud-labels {
    gap: var(--bo-gap-sm);
  }
  .hud-item {
    min-width: 50px;
  }
  .control-buttons {
    flex-direction: column;
  }
  .touch-controls {
    flex-direction: column;
  }
  .modal {
    padding: var(--bo-gap);
  }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}