:root {
  --bg: #0b0c0d;
  --surface: #141617;
  --line: #26292b;
  --text: #e8e6e1;
  --muted: #8b8e8f;
  --live: #e5483a;
  --ok: #4fae6a;
  --warn: #d9a23b;
  --focus: #e8e6e1;
  --font: "Segoe UI", "Noto Sans Arabic", "Noto Sans", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }

button, input {
  font: inherit;
  color: inherit;
}
input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
}
input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
button {
  background: var(--text);
  color: var(--bg);
  border: 0;
  border-radius: 4px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
button.plain {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
}
button.plain:hover { border-color: var(--muted); }
button.danger { background: transparent; color: var(--live); border: 1px solid #5a2620; font-weight: 500; }
button.danger:hover { border-color: var(--live); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.msg { min-height: 1.5em; margin: 0; color: var(--warn); font-size: 14px; }

/* ---------- Entry form (viewer + admin) ---------- */
.entry {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.entry form { width: 100%; max-width: 320px; display: grid; gap: 12px; }
.entry h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
.entry .code-input {
  font-family: var(--mono);
  font-size: 26px;
  letter-spacing: .25em;
  text-align: center;
  text-transform: uppercase;
  padding: 12px;
}
.entry button { padding: 12px; }

/* ---------- Player ---------- */
.player { height: 100%; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; background: #000; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.notice {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center; padding: 16px;
  color: var(--muted);
  pointer-events: none;
}
.notice p { margin: 0; max-width: 32ch; }
.sound {
  position: absolute; inset-inline-start: 12px; bottom: 12px;
  background: var(--text); color: var(--bg);
}
.overlay-stats {
  position: absolute; inset-inline-end: 8px; top: 8px;
  margin: 0; padding: 8px 10px;
  background: rgba(0, 0, 0, .75);
  font: 12px/1.45 var(--mono);
  white-space: pre;
  border-radius: 3px;
  pointer-events: none;
}
.bar {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}
.bar button { padding: 6px 10px; font-size: 14px; }
.bar .grow { flex: 1; }
.bar .volume { width: 110px; padding: 0; border: 0; background: none; accent-color: var(--text); cursor: pointer; }
.bar .volume:focus { outline: none; }
.bar .volume:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.state { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; padding-inline: 4px; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state[data-s="live"]::before { background: var(--live); }
.state[data-s="bad"]::before { background: var(--warn); }

/* Portrait phones: video at the top at its own aspect ratio, controls right under it. */
@media (orientation: portrait) and (max-width: 700px) {
  .stage { flex: none; aspect-ratio: 16 / 9; }
  .overlay-stats { font-size: 10px; padding: 4px 6px; top: 4px; inset-inline-end: 4px; }
}

/* Landscape phones: give the video the whole screen height. */
@media (max-height: 500px) and (orientation: landscape) {
  .bar { position: absolute; bottom: 0; inset-inline: 0; opacity: 0; transition: opacity .2s; }
  .player:hover .bar, .bar:focus-within { opacity: 1; }
}

/* ---------- Admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 16px; }
.admin header { display: flex; align-items: baseline; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.admin header h1 { font-size: 17px; margin: 0; font-weight: 600; }
.admin header nav { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-inline-start: auto; font-size: 14px; }
.admin header nav a { white-space: nowrap; }
.admin a { color: var(--text); text-underline-offset: 3px; text-decoration-color: var(--line); }
.admin a:hover { text-decoration-color: var(--text); }
.admin section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.admin h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 10px; letter-spacing: .02em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { width: auto; flex: 1; min-width: 140px; max-width: 220px; }
.big-code { font: 600 40px/1 var(--mono); letter-spacing: .12em; direction: ltr; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 24px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; unicode-bidi: plaintext; text-align: right; }
.on { color: var(--ok); }
.off { color: var(--live); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: start; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
td .warn { color: var(--warn); }
tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); padding: 12px 0; }

/* Tool pages */
.tool { max-width: 1100px; margin: 0 auto; padding: 16px; }
.tool h1 { font-size: 17px; margin: 0 0 4px; }
.tool p { margin: 0 0 12px; color: var(--muted); max-width: 75ch; }
.tool label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.tool label input[type="number"] { width: 90px; }
.tool input[type="checkbox"] { width: auto; }
.summary { font-family: var(--mono); font-size: 14px; margin: 12px 0; white-space: pre-wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px; margin-top: 12px; }
.tiles video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; }
canvas.preview { width: 100%; max-width: 640px; aspect-ratio: 16 / 9; background: #000; display: block; margin-top: 12px; }
.row.spaced { margin-top: 12px; }
.probe { position: fixed; width: 2px; height: 2px; opacity: 0; pointer-events: none; inset-inline-start: 0; top: 0; }
