:root {
  color-scheme: dark;
  --bg: #14161a;
  --panel: #1d2026;
  --border: #2a2e36;
  --text: #e8eaed;
  --muted: #9aa0a8;
  --accent: #3ddc84;
  --accent-orange: #ff8a3d;
  --warn: #f2b84b;
  --danger: #ef6a6a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  padding: 16px 32px 32px;
  align-items: start;
  max-width: 1400px;
  margin: 0 auto;
}

/* Video stays a single tall block on the left, stretched to flush with the
   combined height of the config box + live readouts stacked in the
   narrower right column beside it (see .video-wrap's height:100% below).
   The merged results panel runs full-width along the bottom. */
.video-panel { grid-column: 1; grid-row: 1 / span 2; align-self: stretch; }
.controls { grid-column: 2; grid-row: 1; }
.live-readouts-panel { grid-column: 2; grid-row: 2; }
.resultados-panel { grid-column: 1 / span 2; grid-row: 3; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }

input, textarea, select, button {
  background: #14161a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
input, textarea { width: 100%; }
textarea { resize: vertical; }

.video-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.video-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 300px;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.video-wrap video,
.video-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 10, 0.55);
  color: #fff;
  font-size: 96px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.countdown-overlay[hidden] { display: none; }

.initial-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: rgba(10, 10, 10, 0.45);
  color: #fff;
}
.initial-overlay[hidden] { display: none; }
.initial-title { margin: 0 0 8px; font-size: 26px; font-weight: 700; }
.initial-subtitle { margin: 0; font-size: 14px; color: rgba(255,255,255,0.75); }

.recording-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 10, 10, 0.75);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.recording-overlay[hidden] { display: none; }
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.readouts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
}

.readout {
  background: #14161a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
}
.readout span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.readout strong { font-size: 20px; color: var(--accent-orange); }

#chart {
  width: 100%;
  height: 100px;
  margin-top: 12px;
  background: #14161a;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group.span-2 { grid-column: 1 / span 2; }
.control-group label {
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* Reserves room for a two-line label (e.g. "Lado que mira a la cámara")
     and bottom-aligns the text, so a select next to a shorter one-line
     label (e.g. "Estilo de manejo objetivo") still starts at the same
     height instead of drifting up. */
  min-height: 2.6em;
  display: flex;
  align-items: flex-end;
}

.buttons { flex-direction: row; gap: 8px; }
button { cursor: pointer; flex: 1; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
#startBtn { background: var(--accent); color: #0a0a0a; border-color: var(--accent); font-weight: 600; }

.cycle-count { font-size: 12px; color: var(--muted); font-weight: normal; }

.tabla-biomecanica {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tabla-biomecanica th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.tabla-biomecanica td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.tabla-biomecanica tr.fila-alerta td:first-child { border-left: 3px solid var(--warn); }
.tabla-biomecanica tr.fila-info td:first-child { border-left: 3px solid #6ea8ff; }
.tabla-biomecanica tr.fila-ok td:first-child { border-left: 3px solid var(--accent); }
.tabla-biomecanica td:nth-child(2) { color: var(--accent-orange); font-weight: 600; }
.tabla-biomecanica td:nth-child(3) { color: var(--muted); }
.tabla-biomecanica td:nth-child(4) { color: var(--text); }

#resumenBiomecanico { overflow-x: auto; }

.info-icon {
  cursor: pointer;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.info-icon:hover, .info-icon:focus-visible { color: var(--text); border-color: var(--accent-orange); }

.info-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 260px;
  background: #14161a;
  color: var(--text);
  border: 1px solid var(--accent-orange);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.muted { color: var(--muted); font-size: 13px; }

footer {
  padding: 0 32px 32px;
  color: var(--muted);
  font-size: 12px;
  max-width: 900px;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .video-panel, .controls, .live-readouts-panel, .resultados-panel {
    grid-column: 1;
    grid-row: auto;
  }
  /* Single-column stacking: nothing left to stretch to match, so fall back
     to a fixed aspect ratio instead of height:100% (which would collapse). */
  .video-panel { align-self: auto; }
  .video-wrap { height: auto; aspect-ratio: 16 / 9; min-height: 0; }
}
