:root {
  --color-bg: #eef1fb;
  --color-surface: #ffffff;
  --color-text: #22293a;
  --color-text-muted: #5b6472;
  --color-accent: #4f6ef7;
  --color-accent-dark: #3a54d6;
  --color-danger: #eb5757;
  --color-particle: #4f6ef7;
  --color-border: #d7dcec;
  --color-overlay: rgba(255, 255, 255, 0.92);
  --shadow-soft: 0 4px 16px rgba(15, 23, 42, 0.1);
  /* Frío → cálido → rojo: se usa en las barras de cantidad de puntos y dificultad,
     para que la posición del slider transmita "más suave" a "más intenso". */
  --gradient-scale: linear-gradient(to right, #4f6ef7, #34d1c5, #f5d547, #f2994a, #eb5757);
}

/* Modo oscuro automático: sigue la preferencia del sistema operativo/navegador, sin
   agregar ningún botón ni lógica — las reglas de abajo ya usan estas variables. */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #12141f;
    --color-surface: #1c1f2e;
    --color-text: #e7e9f2;
    --color-text-muted: #9aa1b4;
    --color-accent: #6f8bff;
    --color-accent-dark: #8fa3ff;
    --color-border: #2c3145;
    --color-overlay: rgba(18, 20, 31, 0.92);
    --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 16px 40px;
  font-family: system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

h1 {
  margin: 0;
  font-size: 28px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.controls,
.record-info,
.hud,
.canvas-wrap,
.instrucciones {
  width: 100%;
  max-width: 800px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.controls label {
  font-size: 15px;
  white-space: nowrap;
}

.controls input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 32px; /* área de toque generosa (celular), aunque la barra visible sea más fina */
  cursor: pointer;
}

.controls input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--gradient-scale);
}

.controls input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--gradient-scale);
}

.controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px; /* centra el thumb (22px) sobre la barra (8px) en navegadores WebKit/Blink */
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--color-accent-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.controls input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--color-accent-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.controls input[type="range"]:focus-visible {
  outline: 2px solid var(--color-accent-dark);
  outline-offset: 4px;
}

.controls > button {
  align-self: flex-start;
}

.controls button,
.end-overlay button,
.record-form button {
  font-size: 15px;
  font-weight: 600;
  padding: 10px 20px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--color-accent);
  color: white;
  cursor: pointer;
}

.controls button:hover,
.end-overlay button:hover,
.record-form button:hover {
  background: var(--color-accent-dark);
}

.record-info {
  font-size: 14px;
  color: var(--color-text-muted);
  text-align: center;
}

.hud {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 18px;
  font-weight: 600;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--color-border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  border-radius: 999px;
  transition: width 0.15s linear;
}

.progress-fill-timer.low {
  background: var(--color-danger);
  animation: pulse 0.6s ease-in-out infinite;
}

#timer.urgent {
  color: var(--color-danger);
  animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.canvas-wrap {
  position: relative;
  aspect-ratio: 800 / 400;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
  touch-action: none; /* evita que arrastrar el dedo scrollee la página al jugar */
}

.end-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--color-overlay);
  border-radius: 12px;
  text-align: center;
  padding: 16px;
}

.end-overlay p {
  margin: 0;
}

#end-message {
  font-size: clamp(18px, 5vw, 22px);
  font-weight: 700;
}

.end-overlay-hint {
  font-size: 14px;
  color: var(--color-text-muted);
}

.record-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.record-form-title {
  font-size: 15px;
  font-weight: 600;
}

.record-form input {
  font-size: 15px;
  padding: 8px 10px;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-align: center;
}

.instrucciones {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 14px;
}

@media (max-width: 480px) {
  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .controls > button {
    align-self: stretch;
  }

  .hud {
    font-size: 16px;
    gap: 16px;
  }
}
