:root {
  --bg: #070b12;
  --panel: #101826;
  --ink: #eef3f8;
  --muted: #8aa0b8;
  --line: #243044;
  --red: #ff2d55;
  --ok: #34d399;
  --warn: #fbbf24;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: #172033;
  font-weight: 600;
  padding: 0 0.6rem;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary, .gate button:not(.ghost) { background: var(--red); border-color: var(--red); color: #fff; }
button.danger { background: #3a1020; border-color: #6b1a33; color: #ffb3c4; }
button.off { color: var(--muted); }
input, select {
  min-height: 40px;
  border: 1px solid var(--line);
  background: #0c1118;
  border-radius: 0.45rem;
  padding: 0 0.6rem;
  min-width: 0;
}
input[type="color"] { padding: 0.2rem; }
.hint { color: var(--muted); line-height: 1.45; }
.small { font-size: 0.8rem; margin: 0.3rem 0 0.5rem; }
.err { color: #ff8aa0; }
.badge { color: var(--ok); font-weight: 700; }
.status { color: var(--muted); }

/* Gate */
.gate {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.5rem;
  max-width: 26rem;
  margin: 0 auto;
}
.kicker { letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-size: 0.72rem; margin: 0; }
h1 { margin: 0.3rem 0 0.4rem; font-size: 1.8rem; }
.gate label { display: grid; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); margin: 0.7rem 0; }
.gate .code { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; min-height: 56px; }
.btns { display: grid; gap: 0.6rem; margin-top: 0.6rem; }
.btns button { min-height: 50px; font-size: 1rem; }

/* Camera */
.cam { position: fixed; inset: 0; background: #000; }
#camVideo { width: 100%; height: 100%; object-fit: contain; background: #000; }
#camVideo.mirror { transform: scaleX(-1); }
.cam-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: calc(0.4rem + env(safe-area-inset-top)) 0.7rem 0.4rem;
  background: linear-gradient(#000a, #0000);
  font-size: 0.8rem;
}
.cam-top .status { margin-left: auto; }
.tally {
  background: var(--red);
  color: #fff;
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: 0.3rem;
  letter-spacing: 0.08em;
}
.cam:has(.tally:not([hidden])) { box-shadow: inset 0 0 0 4px var(--red); }
.cam-rotate {
  position: absolute;
  top: 45%;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  background: #000a;
  padding: 0.5rem;
  display: none;
}
@media (orientation: portrait) { .cam-rotate { display: block; } }
.cam-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.5rem 0.7rem calc(0.5rem + env(safe-area-inset-bottom));
  background: linear-gradient(#0000, #000c);
}
.cam-bar button { background: #172033cc; }

/* Host */
.host { min-height: 100%; display: flex; flex-direction: column; }
.host-top {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
}
.host-top .status { margin-left: auto; text-align: right; }
.live-badge {
  background: var(--red);
  color: #fff;
  font-weight: 800;
  padding: 0.1rem 0.45rem;
  border-radius: 0.3rem;
}
.live-badge[data-status="starting"] { background: var(--warn); color: #111; }
.live-badge[data-status="failed"], .live-badge[data-status="aborted"] { background: #555; }
.host-main { display: grid; gap: 0.6rem; padding: 0.6rem; }
@media (min-width: 900px) {
  .host-main { grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); align-items: start; }
}
.preview-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  border-radius: 0.4rem;
  box-shadow: 0 0 0 1px var(--line);
}
.preview-box .stage { position: absolute; top: 0; left: 0; pointer-events: none; }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.45rem;
  margin-top: 0.5rem;
}
.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #111;
  border-radius: 0.35rem;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 0 0 2px transparent;
}
.tile.on { box-shadow: 0 0 0 3px var(--red); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-name {
  position: absolute;
  left: 0.3rem;
  bottom: 0.3rem;
  font-size: 0.72rem;
  background: #000a;
  padding: 0.1rem 0.35rem;
  border-radius: 0.2rem;
}
.tile-q {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
}
.tile-q[data-q="excellent"] { background: var(--ok); }
.tile-q[data-q="good"] { background: var(--warn); }
.tile-q[data-q="poor"], .tile-q[data-q="lost"] { background: var(--red); }
.tile-mute {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  min-height: 26px;
  font-size: 0.68rem;
  padding: 0 0.4rem;
  background: #000a;
}

.host-panels { background: var(--panel); border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.5rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.3rem; margin-bottom: 0.5rem; }
.tabs button { font-size: 0.78rem; padding: 0 0.2rem; }
.tabs button.on { background: var(--red); border-color: var(--red); color: #fff; }
.panel { display: grid; gap: 0.5rem; }
.team { display: grid; grid-template-columns: 1fr 48px 56px 48px; gap: 0.35rem; align-items: center; }
.team output { text-align: center; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.team button { font-size: 1.3rem; min-height: 48px; }
.team .plus { background: var(--red); border-color: var(--red); color: #fff; }
.row { display: grid; gap: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.4rem; align-items: center; }
.check { display: flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
.check input { min-height: auto; width: 1.1rem; height: 1.1rem; }
.url-row { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; }
.pad { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; }
.pad button { font-size: 0.8rem; }
.wide { width: 100%; margin-top: 0.3rem; }
