:root {
  --bg: #0d1117;
  --panel: rgba(16, 20, 28, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --txt: #f2f5f9;
  --dim: #9aa6b8;
  --sun: #ffd23f;
  --shade: #5ee0a0;
  --warn: #ff8f4d;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

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

/* ---------- scena: la fotocamera occupa tutto lo schermo ---------- */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #05070b;
}

#cam, #ar, #map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cam { object-fit: cover; }
#ar { touch-action: none; }
#map[hidden] { display: none; }

#hud {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
}

.chip {
  pointer-events: auto;
  background: rgba(10, 14, 20, 0.62);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--txt);
  white-space: nowrap;
}

.chip.warn {
  background: rgba(255, 143, 77, 0.85);
  color: #201000;
}

.chip.ghost {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.14);
}

.verdict {
  position: absolute;
  pointer-events: none;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--panel-h, 120px) + 12px);
  background: rgba(10, 14, 20, 0.72);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  max-width: 92%;
}

.hint {
  position: absolute;
  pointer-events: none;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--safe-t) + 52px);
  background: var(--sun);
  color: #201a00;
  border-radius: 999px;
  padding: 7px 15px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.hidden { display: none; }

/* ---------- pannello: sovrapposto alla scena, richiudibile ---------- */
#panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: linear-gradient(to top, rgba(9, 12, 18, 0.97) 60%, rgba(9, 12, 18, 0.72));
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 0 12px calc(8px + var(--safe-b));
  max-height: 46vh;
  overflow-y: auto;
}

#panel.collapsed #strip,
#panel.collapsed .legend,
#panel.collapsed #settings { display: none; }

.grab {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 9px 0 7px;
  cursor: pointer;
}
.grab::before {
  content: "";
  display: block;
  width: 44px;
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  margin: 0 auto;
}

.row { display: flex; align-items: center; gap: 8px; }
.time-row output {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 52px;
  text-align: right;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--sun);
  height: 26px;
}

#strip {
  width: 100%;
  height: 46px;
  margin: 8px 0 4px;
  border-radius: 8px;
  display: block;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--dim);
  flex-wrap: wrap;
}
.legend .sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}
.sw.sun { background: var(--sun); }
.sw.part { background: #b58cff; }
.sw.shade { background: #3f6fd8; }
#nextChange { margin-left: auto; color: var(--txt); font-weight: 600; }

.actions { margin: 10px 0 4px; gap: 8px; }

.act {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--txt);
  font: inherit;
  cursor: pointer;
}
.act b { font-size: 13.5px; }
.act small { font-size: 10px; color: var(--dim); white-space: nowrap; }
.act.armed {
  background: var(--sun);
  border-color: var(--sun);
  color: #201a00;
}
.act.armed small { color: rgba(32, 26, 0, 0.7); }
.act.danger b { color: var(--warn); }

.mini {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--txt);
  border-radius: 9px;
  padding: 6px 11px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.mini.wide { width: 100%; margin-top: 10px; }

details#settings { margin-top: 10px; }
details#settings summary {
  cursor: pointer;
  color: var(--dim);
  font-size: 13px;
  padding: 6px 0;
}
.field { margin: 10px 0; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--dim);
  margin-bottom: 2px;
}
.field label b { color: var(--txt); float: right; }
.note { font-size: 11px; color: var(--dim); margin: 2px 0 0; }

.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.presets button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--dim);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

input[type="number"] {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 9px;
  padding: 7px 9px;
  font: inherit;
}

/* ---------- gate ---------- */
#gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(120% 80% at 50% 0%, #1b2740, #05070b 70%);
  display: grid;
  place-items: center;
  padding: 22px;
}
#gate.gone { display: none; }

.gate-card { max-width: 380px; text-align: center; }
.gate-card .logo { font-size: 46px; }
.gate-card h1 { font-size: 25px; margin: 6px 0 10px; }
.gate-card p { color: var(--dim); font-size: 14px; }
.gate-card .small { font-size: 12px; margin-top: 14px; }
.gate-card .err { color: var(--warn); font-weight: 600; }

#btnStart {
  margin-top: 18px;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--sun);
  color: #201a00;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}

@media (min-height: 780px) {
  #panel { max-height: 50vh; }
}
