:root {
  color-scheme: dark;
  --bg0: #06040f;
  --bg1: #101626;
  --bg2: #171f37;
  --neon: #00f0ff;
  --neon-soft: rgba(0, 240, 255, 0.3);
  --warn: #f9c74f;
  --danger: #ff4d6d;
  --ok: #7bf1a8;
  --text: #edf2ff;
  --muted: #aeb7cc;
  --panel: rgba(12, 18, 33, 0.82);
  --border: rgba(144, 179, 255, 0.24);
}

* {
  box-sizing: border-box;
}

/* ── Login overlay ───────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 20% -20%, #1c2f66 0%, transparent 55%),
    radial-gradient(1200px 600px at 120% 20%, #4c1d53 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 48%, var(--bg2) 100%);
  padding: 24px;
}

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

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  padding: 32px 28px;
  width: min(380px, 100%);
  text-align: center;
}

.login-title { font-family: Orbitron, Inter, sans-serif; font-size: 1.4rem; margin: 0 0 6px; letter-spacing: 0.04em; }
.login-subtitle { color: var(--muted); margin: 0 0 20px; font-size: 0.88rem; }
.login-input { width: 100%; border-radius: 11px; border: 1px solid rgba(181,214,255,0.27); background: rgba(7,12,24,0.66); color: var(--text); padding: 13px 14px; font-size: 1rem; text-align: center; letter-spacing: 0.08em; margin-bottom: 12px; }
.login-btn { font-size: 1rem; padding: 13px 12px; margin-top: 0; }
.login-error { color: var(--danger); margin: 12px 0 0; font-size: 0.85rem; min-height: 1.2em; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  touch-action: manipulation;
  background: radial-gradient(1200px 600px at 20% -20%, #1c2f66 0%, transparent 55%),
    radial-gradient(1200px 600px at 120% 20%, #4c1d53 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 48%, var(--bg2) 100%);
}

.app-bg {
  position: fixed; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(to right, transparent 0, transparent 24px, rgba(255,255,255,0.015) 24px, rgba(255,255,255,0.015) 25px);
}

.app-shell {
  width: min(980px, 100% - 24px);
  margin: 6px auto 28px;
  position: relative;
  z-index: 1;
}

/* ── Top bar ─────────────────────────────────────────────── */

.top-bar { margin-bottom: 4px; padding: 0 2px; }
.site-title { font-family: Orbitron, Inter, sans-serif; margin: 0; font-size: 0.6rem; letter-spacing: 0.1em; color: rgba(174,183,204,0.5); text-transform: uppercase; }

.mic-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #555;
  margin-right: 4px;
  vertical-align: middle;
}
.mic-dot.mic-listening {
  background: #00ff80;
  box-shadow: 0 0 6px rgba(0,255,100,0.6);
}
.mic-dot.mic-error {
  background: #ff4040;
  box-shadow: 0 0 6px rgba(255,60,60,0.5);
}
.mic-dot.mic-unsupported {
  background: #555;
}

/* ── Help overlay ────────────────────────────────────────── */

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 16, 0.85);
  backdrop-filter: blur(6px);
  padding: 16px;
  overflow-y: auto;
}

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

.help-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.help-title {
  font-family: Orbitron, Inter, sans-serif;
  font-size: 1.1rem;
  margin: 0 0 16px;
  letter-spacing: 0.04em;
  color: #d9feff;
}

.help-section { margin-bottom: 14px; }
.help-section h3 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.help-section p {
  margin: 0 0 4px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #c8d8f0;
}
.help-section b { color: #d9feff; }
.help-muted { color: rgba(174,183,204,0.6); font-size: 0.75rem; margin-top: 6px; }

.help-close-btn { margin-top: 8px; }

.help-toggle-row {
  text-align: center;
  margin: 10px 0 4px;
}

.help-toggle-btn {
  font-size: 0.72rem;
  opacity: 0.6;
}

/* ── Screen flash overlay ────────────────────────────────── */

.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.screen-flash.flash-red {
  background: rgba(255, 20, 20, 0.25);
  opacity: 1;
  animation: pulse-flash 0.8s ease-in-out infinite;
}

.screen-flash.flash-green {
  background: rgba(0, 255, 100, 0.2);
  opacity: 1;
  animation: pulse-flash 0.8s ease-in-out infinite;
}

@keyframes pulse-flash {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ── Panels ──────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 14px 36px rgba(0,0,0,0.34), inset 0 0 0 1px rgba(255,255,255,0.05);
}

/* ── Main modules: timer + 2 traps ───────────────────────── */

.main-modules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.timer-panel {
  grid-column: 1 / -1;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.timer-panel:active {
  transform: scale(0.99);
  transition: transform 0.05s;
}

.trap-card-standalone {
  padding: 6px 8px;
  flex: 1;
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.trap-card-standalone:active {
  transform: scale(0.97);
  transition: transform 0.05s;
}

/* ── Round header ─────────────────────────────────────────── */

.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.timer-label-sm {
  margin: 0;
  color: rgba(174,183,204,0.6);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.6rem;
}

.last-round-inline {
  margin: 0;
  color: rgba(174,183,204,0.7);
  font-size: 0.75rem;
}

.last-round-inline span:last-child {
  color: #b0c8e8;
}

/* ── Digital main clock ──────────────────────────────────── */

.digital {
  font-weight: 800;
  font-size: clamp(2.4rem, 14vw, 5.5rem);
  line-height: 1;
  color: #d9feff;
  text-shadow: 0 0 16px rgba(0,240,255,0.35), 0 0 4px rgba(255,255,255,0.45);
  margin: 0 0 8px;
  text-align: center;
}

/* ── Round progress bar ───────────────────────────────────── */

.round-progress-wrap {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
  margin-bottom: 8px;
}

.round-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2bd46a, #7bf1a8);
  transition: width 140ms linear;
}

.game-timer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(167,199,255,0.1);
}

.game-timer-val {
  font-size: 0.9rem;
  color: #b0c8e8;
}

.panel-title { margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.13em; font-size: 0.78rem; }
.panel-top-line { display: flex; justify-content: space-between; align-items: center; }
.mono { font-family: Orbitron, Inter, sans-serif; }

/* ── Buttons ─────────────────────────────────────────────── */

.round-btn {
  font-family: Orbitron, Inter, sans-serif; font-size: clamp(1.3rem, 5vw, 1.7rem);
  letter-spacing: 0.1em; padding: 18px 12px; border-radius: 14px; margin-bottom: 8px;
  background: linear-gradient(180deg, #2a8a78, #1e6e5e); color: #c8f5ec;
}
.secondary-row { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
.secondary-row-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

.btn-sm { border: 1px solid transparent; border-radius: 9px; color: var(--text); background: #24304f; padding: 7px 8px; font-size: 0.76rem; font-weight: 600; cursor: pointer; transition: opacity 0.15s; opacity: 0.85; }
.btn-sm:active { transform: scale(0.97); }
.primary-sm { background: #1e3a3a; color: #88bfb5; border-color: rgba(80,160,140,0.3); }
.warning-sm { background: #3a3320; color: #c9b070; border-color: rgba(160,140,60,0.3); }
.danger-sm { background: #3a1e24; color: #c08088; border-color: rgba(160,70,80,0.3); }

.btn, .link-btn { border: 1px solid transparent; border-radius: 11px; color: var(--text); background: #24304f; padding: 11px 12px; font-size: 0.92rem; font-weight: 700; cursor: pointer; transition: opacity 0.15s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled), .link-btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(180deg, #2a8a78, #1e6e5e); color: #c8f5ec; }
.btn.warning { background: linear-gradient(180deg, #8a7a3a, #6e6230); color: #f0e0a0; }
.btn.danger { background: linear-gradient(180deg, #8a3a4a, #6e2e3a); color: #f0b0b8; }
.btn.ghost, .link-btn { background: rgba(50,70,112,0.52); border-color: rgba(188,216,255,0.25); }
.link-btn { padding: 6px 10px; font-size: 0.8rem; }
.full { width: 100%; margin-top: 10px; }

/* ── Split layout ────────────────────────────────────────── */

.split { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 12px; }
.laps-panel, .trap-panel, .trap-settings-panel { background: rgba(13,19,35,0.6); border: 1px solid rgba(167,199,255,0.14); border-radius: 14px; padding: 12px; }
.voice-lag-row { display: flex; }
.voice-lag-label { font-size: 0.78rem; color: #9ab2d8; flex: 1; }
.voice-lag-label input { max-width: 80px; margin-top: 4px; padding: 6px; font-size: 0.82rem; }
.preset-row { margin-bottom: 10px; }
.preset-label { font-size: 0.78rem; color: #9ab2d8; }
.preset-select { width: 100%; margin-top: 4px; padding: 8px; border-radius: 9px; border: 1px solid rgba(181,214,255,0.27); background: rgba(7,12,24,0.66); color: var(--text); font-size: 0.82rem; }
.cfg-trap-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── Laps ────────────────────────────────────────────────── */

.laps-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: auto; padding-right: 4px; }
.lap-row { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 9px 11px; font-family: Orbitron, Inter, sans-serif; }
.lap-tag { color: #9ac3ff; font-size: 0.85rem; }
.lap-time { font-size: 1rem; }

/* ── Trap cards ──────────────────────────────────────────── */

.trap-title { margin: 0; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: #9ab2d8; }
.trap-timer { font-size: clamp(1.2rem, 6vw, 1.8rem); font-weight: 800; margin: 1px 0 1px; color: #d9feff; text-shadow: 0 0 10px rgba(0,240,255,0.25); line-height: 1.1; }
.trap-state { margin: 1px 0 4px; color: #cfe3ff; font-weight: 600; font-size: 0.75rem; }

/* ── Trap card color states ──────────────────────────────── */

/* idle = ready = green */
.trap-idle { background: rgba(0,255,100,0.14); border-color: rgba(0,255,120,0.5); box-shadow: inset 0 0 30px rgba(0,255,100,0.1), 0 0 20px rgba(0,255,100,0.08); }
.trap-idle .trap-timer { color: #00ff80; text-shadow: 0 0 12px rgba(0,255,100,0.4); }
.trap-idle .trap-state { color: #80ffb0; }

/* active = trap running, amber/neutral */
.trap-active { background: rgba(255,200,50,0.12); border-color: rgba(255,200,80,0.45); box-shadow: inset 0 0 30px rgba(255,200,50,0.08), 0 0 20px rgba(255,200,50,0.06); }
.trap-active .trap-timer { color: #ffd060; text-shadow: 0 0 14px rgba(255,200,50,0.5); }
.trap-active .trap-state { color: #ffe090; }

/* cooldown = not ready = red */
.trap-cooldown { background: rgba(255,40,40,0.16); border-color: rgba(255,60,60,0.55); box-shadow: inset 0 0 40px rgba(255,40,40,0.12), 0 0 30px rgba(255,40,40,0.1); }
.trap-cooldown .trap-timer { color: #ff5050; text-shadow: 0 0 16px rgba(255,50,50,0.5); }
.trap-cooldown .trap-state { color: #ff9090; }

/* done = ready again = green */
.trap-done { background: rgba(0,255,100,0.14); border-color: rgba(0,255,120,0.5); box-shadow: inset 0 0 30px rgba(0,255,100,0.1), 0 0 20px rgba(0,255,100,0.08); }
.trap-done .trap-timer { color: #00ff80; text-shadow: 0 0 12px rgba(0,255,100,0.4); }
.trap-done .trap-state { color: #80ffb0; }

/* ── Trap progress bar ───────────────────────────────────── */

.trap-progress-wrap { width: 100%; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.09); overflow: hidden; }
.trap-progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--ok), #3fd86f); transition: width 140ms linear, background-color 200ms ease; }

/* ── Trap config ─────────────────────────────────────────── */

.cfg-col { display: flex; flex-direction: column; gap: 4px; background: rgba(255,255,255,0.02); border: 1px solid rgba(167,199,255,0.1); border-radius: 8px; padding: 6px 8px; }
.cfg-label { margin: 0; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: #9ab2d8; font-weight: 600; }
.cfg-col input { padding: 6px 6px; font-size: 0.78rem; border-radius: 7px; border: 1px solid rgba(181,214,255,0.27); background: rgba(7,12,24,0.66); color: var(--text); }

/* ── Other form controls ─────────────────────────────────── */

.k { margin: 0; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.v { margin: 4px 0 0; font-family: Orbitron, Inter, sans-serif; font-size: 0.95rem; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: #cfdef9; }
input { width: 100%; border-radius: 9px; border: 1px solid rgba(181,214,255,0.27); background: rgba(7,12,24,0.66); color: var(--text); padding: 9px 10px; font-size: 0.9rem; }

/* ── Footer ──────────────────────────────────────────────── */

.footnote { margin: 14px 4px 0; color: var(--muted); font-size: 0.84rem; }
#shareUrl { color: #d8f6ff; word-break: break-all; }

/* ── Responsive: desktop ─────────────────────────────────── */

@media (min-width: 820px) {
  .split { grid-template-columns: 1fr 1fr; }
}

/* ── Responsive: small portrait ──────────────────────────── */

@media (max-width: 560px) and (orientation: portrait) {
}

/* ── Landscape: timer + 2 player columns fill screen ─────── */

@media (orientation: landscape) and (max-height: 500px) {
  html, body { height: 100%; overflow: hidden; }

  .app-shell {
    width: 100%; max-width: 100%; margin: 0;
    padding: 4px env(safe-area-inset-right, 16px) 4px env(safe-area-inset-left, 16px);
    padding-top: max(4px, env(safe-area-inset-top, 4px));
    padding-bottom: max(4px, env(safe-area-inset-bottom, 4px));
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
  }

  .top-bar { margin-bottom: 2px; flex-shrink: 0; }

  .main-modules {
    display: flex; flex-direction: row;
    align-items: stretch; gap: 5px;
    margin-bottom: 0; flex: 1; min-height: 0;
  }

  .timer-panel {
    flex: 1.2; padding: 5px 8px;
    display: flex; flex-direction: column;
  }

  .trap-card-standalone {
    flex: 1; padding: 4px 6px;
    display: flex; flex-direction: column;
  }

  .round-header { margin-bottom: 0; }
  .timer-label-sm { font-size: 0.45rem; }
  .last-round-inline { font-size: 0.6rem; }
  .digital { font-size: clamp(1.2rem, 5vw, 2rem); margin: 0 0 2px; }
  .round-progress-wrap { height: 4px; margin-bottom: 3px; }
  .secondary-row { gap: 2px; flex-shrink: 0; }
  .btn-sm { padding: 3px 2px; font-size: 0.58rem; }

  .trap-title { font-size: 0.52rem; flex-shrink: 0; }
  .trap-timer { font-size: clamp(0.9rem, 4vw, 1.3rem); margin: 0; flex-shrink: 0; }
  .trap-state { font-size: 0.55rem; margin: 0 0 2px; flex-shrink: 0; }
  .trap-progress-wrap { height: 6px; flex-shrink: 0; }
  .panel { border-radius: 8px; }

  .split, .footnote, .help-toggle-row { display: none; }
}
