:root {
  --bg: #1a2125;
  --accent: #3fa7d6;
  --ctl: rgba(255, 255, 255, 0.14);
  --ctl-border: rgba(255, 255, 255, 0.4);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  top: var(--st);
  left: var(--sl);
  width: calc(100% - var(--sl) - var(--sr));
  height: calc(100% - var(--st) - var(--sb));
  border: 0;
  display: block;
  background: var(--bg);
}

/* ---- Controles ---- */

#pad, #toolbar, #install, #rotate {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#pad {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Posiciones y tamaños los calcula touch.js (variables --stick-size, etc.) */
#stick-zone {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}

#stick-base {
  position: absolute;
  width: var(--stick-size, 130px);
  height: var(--stick-size, 130px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--ctl-border);
  background: var(--ctl);
  opacity: calc(var(--ctl-opacity, 0.75) * 0.75);
  pointer-events: none;
  transition: opacity 0.15s;
}
#stick-base.active { opacity: 1; transition: none; }

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--knob-size, 58px);
  height: var(--knob-size, 58px);
  margin: calc(var(--knob-size, 58px) / -2) 0 0 calc(var(--knob-size, 58px) / -2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

#kick {
  position: absolute;
  width: var(--kick-size, 96px);
  height: var(--kick-size, 96px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--ctl-border);
  background: var(--ctl);
  color: rgba(255, 255, 255, 0.85);
  font: 700 calc(var(--kick-size, 96px) * 0.135) / 1 system-ui, sans-serif;
  letter-spacing: 0.06em;
  pointer-events: auto;
  touch-action: none;
  opacity: var(--ctl-opacity, 0.75);
}
#kick.on {
  background: var(--accent);
  border-color: #fff;
  opacity: 1;
  transform: translate(-50%, -50%) scale(0.93);
}

/* Vista previa (con el panel de ajustes abierto): no se puede tocar */
#pad[data-mode="preview"] #stick-zone,
#pad[data-mode="preview"] #kick { pointer-events: none; }

/* Modo mover controles */
#pad[data-mode="edit"] { background: rgba(0, 0, 0, 0.35); pointer-events: auto; }
#pad[data-mode="edit"] #stick-zone { pointer-events: none; }
#pad[data-mode="edit"] #stick-base,
#pad[data-mode="edit"] #kick {
  pointer-events: auto;
  touch-action: none;
  opacity: 1;
  outline: 2px dashed var(--accent);
  outline-offset: 6px;
  cursor: grab;
}
#pad[data-mode="edit"] #stick-base.dragging,
#pad[data-mode="edit"] #kick.dragging { outline-style: solid; }

#edit-bar {
  position: fixed;
  top: calc(var(--st) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  border-radius: 12px;
  background: #0e1417;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  z-index: 25;
}
#edit-bar span { line-height: 1.3; }
#edit-bar button { flex: none; }
#edit-bar button {
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: 600 14px system-ui, sans-serif;
}

/* ---- Panel de ajustes ---- */

#settings {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--st) + 12px) calc(var(--sr) + 16px) calc(var(--sb) + 12px) calc(var(--sl) + 16px);
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.3);
  z-index: 30;
}

#settings .sheet {
  width: min(420px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: #0e1417;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#settings header,
#settings footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px 18px;
  flex: none;
}
#settings header { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
#settings footer {
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
#settings h2 {
  margin: 0;
  flex: 1;
  font-size: 17px;
}

#settings .rows {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 18px;
}

#settings .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
}
#settings .row:last-child { border-bottom: 0; }
#settings .row.range { flex-direction: column; align-items: stretch; }
#settings .row output { float: right; opacity: 0.7; font-variant-numeric: tabular-nums; }
#settings .row small { opacity: 0.55; font-size: 12px; }

#settings input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
}
#settings input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

#settings button {
  border: 0;
  border-radius: 8px;
  font: 600 14px system-ui, sans-serif;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  padding: 9px 14px;
  touch-action: manipulation;
}
#settings button.primary { background: var(--accent); }
#settings footer button { flex: 1; }
#settings .icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  opacity: 0.7;
  font-size: 16px;
}

#settings .seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}
#settings .seg button {
  padding: 6px 12px;
  background: transparent;
  font-weight: 500;
}
#settings .seg button[aria-pressed="true"] {
  background: var(--accent);
  font-weight: 600;
}

/* ---- Barra de herramientas ---- */

/* Vertical en el borde izquierdo; el juego deja ese hueco (--hx-left en
   game-mobile.css) en la lista de salas y en el menú de la sala. */
#toolbar {
  position: fixed;
  top: calc(var(--st) + 8px);
  left: calc(var(--sl) + 7px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 11;
}
/* Los botones de juego solo se muestran durante el partido */
body:not(.hb-playing) #toolbar [data-playing] { display: none; }
body.hx-editing #toolbar { display: none; }

.tb {
  width: 38px;
  height: 38px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.45);
  touch-action: manipulation;
}
.tb svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tb.off { opacity: 0.45; }

/* ---- Avisos ---- */

#rotate {
  display: none;
  position: fixed;
  top: calc(var(--st) + 52px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 12;
}
@media (orientation: portrait) {
  body.hb-playing #rotate { display: block; }
}

.tb.accent {
  background: var(--accent);
  border-color: transparent;
}

/* Instrucciones de instalación (iPhone): globo junto a la barra */
#install {
  position: fixed;
  left: calc(var(--sl) + 56px);
  top: calc(var(--st) + 8px);
  width: max-content;
  max-width: min(360px, calc(100% - 72px));
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  border-radius: 14px;
  background: #0e1417;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  line-height: 1.35;
  z-index: 20;
}
body.hb-playing #install,
body.hx-editing #install,
#settings:not([hidden]) ~ #install { display: none !important; }

#install button {
  flex: none;
  border: 0;
  border-radius: 8px;
  font: inherit;
  color: #fff;
}
#install-btn {
  padding: 8px 14px;
  background: var(--accent);
  font-weight: 600;
}
#install-close {
  width: 32px;
  height: 32px;
  background: transparent;
  opacity: 0.7;
}
