:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta cromática retro electromecánica */
  --bg-primary: #0a0d14;
  --bg-card: #131823;
  --bg-card-secondary: #1a2232;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-amber: rgba(245, 158, 11, 0.35);

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-gold: #f59e0b;
  --accent-amber: #d97706;
  --accent-wood: #78350f;
  --accent-cyan: #06b6d4;
  --accent-red: #ef4444;
  --accent-green: #10b981;

  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-secondary: #f1f5f9;
  --border-color: rgba(0, 0, 0, 0.1);
  --border-amber: rgba(217, 119, 6, 0.4);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

/* Reset y estructura canónica */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.hero-title {
  font-family: var(--font-heading);
}

.mono {
  font-family: var(--font-mono);
}

/* Layout canónico */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Cabecera de la mesa y HUD */
.pinball-header-panel {
  background: linear-gradient(135deg, #181d29 0%, #10141f 100%);
  border: 1px solid var(--border-amber);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
}

.pinball-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.pinball-hero-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.pinball-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  border: 1px solid rgba(245, 158, 11, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pinball-header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Botones retro de control */
.btn-pinball {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease-in-out;
  min-height: 40px;
}

.btn-primary-retro {
  background: linear-gradient(180deg, #f59e0b 0%, #b45309 100%);
  color: #0f172a;
  border-color: #fcd34d;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.35);
}

.btn-primary-retro:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn-secondary-retro {
  background: var(--bg-card-secondary);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary-retro:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.btn-icon-retro {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-card-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}

.btn-icon-retro:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Marcador electromecánico analógico (Reel HUD) */
.score-reels-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #090c12;
  border: 3px solid #78350f;
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.8);
}

.reels-wrapper {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.score-reel-box {
  display: flex;
  gap: 4px;
  background: #141720;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid #332415;
}

.score-reel-digit {
  width: 32px;
  height: 44px;
  background: #fbf7ee;
  color: #1a1a1a;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
}

.score-reel-digit::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0, 0, 0, 0.12);
}

.hud-pulse {
  animation: hudPulse 0.15s ease;
}

@keyframes hudPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.015); border-color: #facc15; }
  100% { transform: scale(1); }
}

.hud-metrics {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.hud-metric-item {
  display: flex;
  flex-direction: column;
}

.hud-metric-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.hud-metric-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.hud-badge-tilt {
  background-color: var(--accent-red);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  animation: blinkTilt 0.4s infinite alternate;
}

@keyframes blinkTilt {
  from { opacity: 1; }
  to { opacity: 0.2; }
}

/* Contenedor del visor 3D con atmósfera sobria de salón recreativo en penumbra */
.pinball-viewport-card {
  position: relative;
  width: 100%;
  height: clamp(740px, 80vh, 960px);
  min-height: 680px;
  background: radial-gradient(circle at 50% 32%, #141c2c 0%, #090d16 65%, #030407 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  margin-bottom: 1.25rem;
}

@media (min-width: 1400px) {
  .pinball-viewport-card {
    height: clamp(800px, 84vh, 1020px);
  }
}

#pinball-canvas-container {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}

#pinball-canvas-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Toast de avisos sobre el lienzo 3D */
.pinball-status-toast {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border-amber);
  color: #fef08a;
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s ease-out;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
  white-space: nowrap;
}

.pinball-status-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Controles táctiles móviles en pantalla */
.pinball-touch-controls {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 15;
}

/* Ocultar mandos táctiles en escritorio donde se juega con teclado y ratón */
@media (hover: hover) and (pointer: fine) {
  .pinball-touch-controls {
    display: none !important;
  }
}

.touch-col-left,
.touch-col-right {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  pointer-events: auto;
}

.btn-touch-flipper {
  width: 80px;
  height: 64px;
  background: rgba(245, 158, 11, 0.25);
  border: 2px solid #f59e0b;
  border-radius: 12px;
  color: #fef08a;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.btn-touch-flipper:active {
  background: rgba(245, 158, 11, 0.7);
  transform: scale(0.96);
}

.btn-touch-plunger {
  width: 74px;
  height: 64px;
  background: rgba(6, 182, 212, 0.25);
  border: 2px solid #06b6d4;
  border-radius: 12px;
  color: #a5f3fc;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.btn-touch-plunger:active {
  background: rgba(6, 182, 212, 0.7);
  transform: scale(0.96);
}

.btn-touch-nudge {
  width: 52px;
  height: 52px;
  background: rgba(239, 68, 68, 0.25);
  border: 2px solid #ef4444;
  border-radius: 10px;
  color: #fca5a5;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.btn-touch-nudge:active {
  background: rgba(239, 68, 68, 0.65);
  transform: scale(0.94);
}

/* Barra de ayuda con atajos de teclado */
.pinball-shortcuts-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.shortcut-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

kbd {
  display: inline-block;
  padding: 0.2rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-main);
  background-color: var(--bg-card-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

/* Modales personalizados accesibles */
.pinball-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(4px);
}

.pinball-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.pinball-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-amber);
  border-radius: var(--radius-lg);
  max-width: 540px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

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

/* Tabla de récords arcade */
.records-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.records-table th,
.records-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.records-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.text-amber {
  color: var(--accent-gold);
}

.text-sm {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.font-bold {
  font-weight: 700;
}

/* Formulario para registrar nuevo récord */
.record-input-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.input-initials {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  min-height: 40px;
  background: var(--bg-card-secondary);
  border: 2px solid var(--border-amber);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.input-initials:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}

/* Adaptación responsive en pantallas pequeñas */
@media (max-width: 768px) {
  .pinball-viewport-card {
    height: 540px;
    min-height: unset;
  }

  .pinball-hero-title {
    font-size: 1.35rem;
  }

  .score-reels-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .score-reel-digit {
    width: 26px;
    height: 38px;
    font-size: 1.4rem;
  }

  .pinball-shortcuts-bar {
    display: none; /* En móvil se usan los controles táctiles directos */
  }

  .btn-touch-flipper {
    width: 68px;
    height: 56px;
  }

  .btn-touch-plunger {
    width: 62px;
    height: 56px;
  }
}
