/* ============================================================
   EARth · Estilos
   Filosofía: modo oscuro por defecto, contraste alto, tipografía
   ultra-legible y objetivos táctiles grandes para uso con guantes
   en entornos exteriores de alto estrés. Sin frameworks.
   ============================================================ */

:root {
  --bg:        #0d1117;
  --bg-2:      #161b22;
  --bg-3:      #21262d;
  --line:      #30363d;
  --text:      #f0f6fc;
  --text-dim:  #9da7b3;
  --amber:     #ffb000;
  --green:     #2ea043;
  --red:       #ff3b30;
  --blue:      #4aa3ff;
  --violet:    #b56bff;
  /* Insets seguros para notch / barra de gestos. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Sin selección/zoom accidental durante una operación. */
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 8px) 12px calc(var(--safe-b) + 8px);
}
[hidden] { display: none !important; }

/* ===================== PANTALLA DE ARRANQUE ===================== */
#start-screen { justify-content: center; align-items: center; text-align: center; }
.start-inner { width: 100%; max-width: 440px; }
.logo {
  font-size: clamp(48px, 16vw, 96px);
  font-weight: 900;
  letter-spacing: -2px;
  margin: 0;
  color: var(--text);
}
.logo span { color: var(--amber); }
.tagline { color: var(--text-dim); font-size: 17px; line-height: 1.4; margin: 8px 0 32px; }

.start-btn {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 320px;
  margin: 0 auto;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #2ea043, #1a7431);
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 0 0 6px rgba(46,160,67,.25), 0 0 60px rgba(46,160,67,.35);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease;
  animation: pulse 2.4s ease-in-out infinite;
}
.start-btn:active { transform: scale(.97); }
.start-btn__icon { font-size: 44px; line-height: 1; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 6px rgba(46,160,67,.25), 0 0 40px rgba(46,160,67,.30); }
  50%     { box-shadow: 0 0 0 12px rgba(46,160,67,.10), 0 0 80px rgba(46,160,67,.45); }
}
.device-hint { color: var(--text-dim); font-size: 14px; margin-top: 28px; line-height: 1.4; }
.start-error { color: var(--red); font-weight: 700; margin-top: 16px; }

/* Recursos complementarios (enlaces) en la pantalla de inicio. */
.resources { margin: 22px auto 0; max-width: 440px; display: flex; flex-direction: column; gap: 8px; }
.resources-title {
  margin: 0 2px 2px; font-size: 12px; font-weight: 800; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-dim); text-align: left;
}
.resource-link {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; min-height: 56px; text-decoration: none; color: var(--text);
}
.resource-link:active { background: var(--bg-3); }
.resource-icon { font-size: 24px; line-height: 1; flex: 0 0 auto; }
.resource-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.resource-text strong { font-size: 15px; font-weight: 800; color: var(--blue); }
.resource-text small { font-size: 12px; color: var(--text-dim); }
.resource-arrow { flex: 0 0 auto; color: var(--text-dim); font-size: 16px; font-weight: 700; }

/* Tarjeta agrupada (app disponible en varias plataformas). */
.resource-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.resource-card__head { display: flex; align-items: center; gap: 12px; }
.resource-platforms { display: flex; gap: 8px; }
.platform-btn {
  flex: 1; text-align: center; text-decoration: none;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  color: var(--blue); font-size: 13px; font-weight: 800;
  padding: 10px 6px; min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.platform-btn:active { background: var(--line); }

/* Aviso de descargo de responsabilidad en la pantalla de inicio. */
.disclaimer {
  margin: 20px auto 0; max-width: 440px; text-align: left;
  font-size: 13px; line-height: 1.45; color: var(--text);
  background: rgba(255, 59, 48, .10);
  border: 1px solid var(--red); border-radius: 10px;
  padding: 12px 14px;
}
.disclaimer strong { color: var(--red); }

/* Nota mínima persistente en la pantalla operativa. */
.disclaimer-mini {
  margin: 6px 4px 0; text-align: center;
  font-size: 11px; color: var(--text-dim); line-height: 1.3;
}

/* Estado de disponibilidad sin conexión (pantalla de arranque). */
.offline-status {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 18px;
  padding: 8px 14px; border-radius: 20px; font-size: 14px; font-weight: 700;
  border: 1px solid var(--line); background: var(--bg-2);
}
.offline-status.ready    { color: var(--green); border-color: var(--green); }
.offline-status.checking { color: var(--text-dim); }
.offline-status.partial  { color: var(--amber); border-color: var(--amber); }
.recache-btn {
  display: block; margin: 12px auto 0; padding: 12px 18px; min-height: 48px;
  border-radius: 10px; border: 1px solid var(--amber); background: var(--bg-3);
  color: var(--amber); font-size: 15px; font-weight: 800; cursor: pointer;
}

/* Píldora de red en la topbar operativa. */
.net-pill {
  margin-left: 8px; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 900; letter-spacing: .3px;
  border: 1px solid var(--line); color: var(--text-dim); white-space: nowrap;
}
.net-pill.online  { color: var(--green); border-color: var(--green); }
.net-pill.offline { color: var(--amber); border-color: var(--amber); }

/* ===================== TOPBAR ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 10px;
}
.status { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 10px var(--green);
  animation: blink 1.5s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: .35; } }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.device-label { color: var(--text-dim); font-size: 12px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
  font-size: 18px; cursor: pointer;
}
.icon-btn:active { background: var(--red); }

/* ===================== MEDIDORES ===================== */
.meters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.meter-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-dim); margin-bottom: 3px; font-weight: 700; }
.db { font-variant-numeric: tabular-nums; color: var(--text); }
.meter-bar {
  position: relative; height: 18px; border-radius: 5px; overflow: hidden;
  background: var(--bg-3); border: 1px solid var(--line);
}
.meter-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  /* Verde → ámbar → rojo según nivel. */
  background: linear-gradient(90deg, var(--green) 0%, var(--green) 55%, var(--amber) 78%, var(--red) 100%);
  transition: width .04s linear;
}
.meter-peak {
  position: absolute; top: -1px; bottom: -1px; width: 3px;
  background: var(--text); left: 0%;
  box-shadow: 0 0 6px var(--text);
}

/* ===================== ESPECTROGRAMA ===================== */
.spectro-wrap {
  position: relative; flex: 1 1 auto; min-height: 180px;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--line);
  background: #05070a; margin-bottom: 10px;
}
#spectrogram { width: 100%; height: 100%; display: block; }
.spectro-axis {
  position: absolute; right: 0; top: 0; bottom: 0; width: 42px;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 4px 4px; pointer-events: none;
  font-size: 10px; color: var(--text-dim); text-align: right;
  background: linear-gradient(90deg, transparent, rgba(5,7,10,.6));
  font-variant-numeric: tabular-nums;
}
.detect-badges { position: absolute; left: 6px; top: 6px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.badge {
  font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 20px;
  color: #000; opacity: 0; transform: translateX(-6px);
  transition: opacity .15s, transform .15s;
}
.badge.on { opacity: 1; transform: none; }
.badge.bang   { background: var(--red); }
.badge.voice  { background: var(--amber); }
.badge.weak   { background: var(--violet); color: #fff; }
.badge.breath { background: var(--blue); }

/* ===================== LECTURA NUMÉRICA ===================== */
.readout { display: flex; gap: 8px; margin-bottom: 10px; }
.readout-cell {
  flex: 1; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
}
.readout-label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.readout-val { font-size: 28px; font-weight: 900; font-variant-numeric: tabular-nums; }
.readout-val.small { font-size: 16px; font-weight: 700; }

/* ===================== CONTROLES ===================== */
.controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1; min-height: 48px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text-dim); font-size: 15px; font-weight: 800;
  cursor: pointer;
}
.seg-btn.active { background: var(--amber); color: #000; border-color: var(--amber); }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle {
  display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; min-height: 46px;
}
.toggle input { width: 22px; height: 22px; accent-color: var(--green); }
/* Toggle destacado (Modo Impactos): ocupa toda la fila y usa acento rojo. */
.toggle--accent { grid-column: 1 / -1; border-color: var(--red); }
.toggle--accent input { accent-color: var(--red); }

.slider-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 12px; }
.slider-row label { grid-column: 1 / -1; font-size: 13px; color: var(--text-dim); font-weight: 700; }
.slider-row input[type=range] { width: 100%; height: 40px; accent-color: var(--amber); }
.slider-val { font-weight: 900; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }

/* ===================== LEYENDA ===================== */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 8px 4px 0; font-size: 12px; color: var(--text-dim); }
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-bang { background: var(--red); }
.sw-voice { background: var(--amber); }
.sw-weak { background: var(--violet); }
.sw-breath { background: var(--blue); }

/* ===================== BOTÓN DE HISTORIAL ===================== */
.hist-btn { position: relative; font-size: 20px; }
.hist-count {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px;
  padding: 0 4px; border-radius: 9px; background: var(--amber); color: #000;
  font-size: 11px; font-weight: 900; line-height: 18px; text-align: center;
}

/* ===================== PANEL DE HISTORIAL ===================== */
.history-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-height: 85vh; display: flex; flex-direction: column;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 12px 14px calc(var(--safe-b) + 14px);
  box-shadow: 0 -10px 40px rgba(0,0,0,.6);
  animation: slideUp .2s ease-out;
}
.history-panel[hidden] { display: none; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

.hp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.hp-header h2 { margin: 0; font-size: 20px; font-weight: 900; }

.hp-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.hp-count {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 8px;
}
.hp-count span { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.hp-count small { color: var(--text-dim); font-size: 10px; width: 100%; }

.hp-list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto;
  flex: 1 1 auto; min-height: 80px; -webkit-overflow-scrolling: touch;
}
.hp-item {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid var(--line);
}
.hp-dot { width: 14px; height: 14px; border-radius: 4px; }
.hp-dot.bang { background: var(--red); }
.hp-dot.voice { background: var(--amber); }
.hp-dot.weak { background: var(--violet); }
.hp-dot.breath { background: var(--blue); }
.hp-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hp-kind { font-weight: 800; font-size: 15px; }
.hp-detail { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.hp-time { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; text-align: right; }
.hp-xcount {
  display: inline-block; margin-left: 6px; background: var(--bg-3); color: var(--text);
  border-radius: 10px; padding: 1px 7px; font-size: 12px; font-weight: 800;
}
.hp-empty { color: var(--text-dim); text-align: center; padding: 24px 0; font-size: 14px; }

.hp-actions { display: flex; gap: 8px; margin-top: 10px; }
.hp-btn {
  flex: 1; min-height: 48px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text); font-size: 15px; font-weight: 800; cursor: pointer;
}
.hp-btn.danger { color: var(--red); border-color: var(--red); }
.hp-btn:active { filter: brightness(1.3); }

/* ===================== FLASH DE ALERTA ===================== */
.alert-flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: var(--red); opacity: 0;
}
.alert-flash.fire { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }

/* Variante de flash por tipo de detección. */
.alert-flash.voice  { background: var(--amber); }
.alert-flash.weak   { background: var(--violet); }
.alert-flash.breath { background: var(--blue); }

/* ===================== OVERLAY DE REANUDAR ===================== */
.resume-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; background: rgba(5, 7, 10, .92);
  backdrop-filter: blur(2px);
}
.resume-overlay[hidden] { display: none; }
.resume-inner { max-width: 420px; }
.resume-icon { font-size: 56px; display: block; }
.resume-overlay h2 { font-size: 26px; font-weight: 900; margin: 10px 0 4px; color: var(--amber); }
.resume-overlay p { color: var(--text-dim); font-size: 16px; margin: 0 0 22px; line-height: 1.4; }
.resume-btn {
  width: 100%; min-height: 88px; border-radius: 16px; border: none;
  background: radial-gradient(circle at 50% 40%, #2ea043, #1a7431); color: #fff;
  font-size: 24px; font-weight: 900; letter-spacing: .5px; cursor: pointer;
  box-shadow: 0 0 0 5px rgba(46,160,67,.25), 0 0 50px rgba(46,160,67,.4);
  animation: pulse 2s ease-in-out infinite;
}
.resume-btn:active { transform: scale(.98); }

/* Reduce animaciones si el usuario lo pide, salvo el flash crítico. */
@media (prefers-reduced-motion: reduce) {
  .start-btn, .status-dot { animation: none; }
}
