@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0f1113; --panel: #171a1d; --panel2: #1e2226; --line: #2a2f34;
  --text: #d9d6cc; --muted: #84837c; --amber: #e8a93c; --amber-dim: #6b4e1c; --red: #e05a47; --ok: #8cc56b; --pin: #ff3030;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { height: 100dvh; overflow: hidden; padding: 12px; gap: 10px; display: grid; grid-template-rows: auto 1fr auto;
  background: var(--bg); color: var(--text); font: 14px/1.5 'IBM Plex Mono', ui-monospace, Consolas, monospace; }
/* very faint scanlines */
body::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px); opacity: .5; }

.amber { color: var(--amber); }
.muted { color: var(--muted); }
.cursor::after { content: '▋'; color: var(--amber); animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0 } }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 14px; padding: 4px 2px 10px; border-bottom: 1px solid var(--line); }
.brand { margin: 0; font-size: 18px; font-weight: 600; color: var(--amber); letter-spacing: .08em; }
.chan { color: var(--muted); }
.chan b { color: var(--text); font-weight: 500; }
.right { margin-left: auto; display: flex; gap: 16px; align-items: center; white-space: nowrap; }
.enc { color: var(--ok); }
.enc.off { color: var(--red); }
.enc::before { content: '● '; }

/* ---------- layout ---------- */
.main { display: grid; grid-template-columns: 360px 1fr; gap: 10px; min-height: 0; }
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.card { background: var(--panel); border: 1px solid var(--line); padding: 12px 14px; }
.card h3 { margin: 0 0 8px; font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: .1em; text-transform: uppercase;
  display: flex; justify-content: space-between; }
.card.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* pinned current order */
.pinned { border-left: 3px solid var(--amber); }
.order { font-size: 24px; font-weight: 600; color: #fff; line-height: 1.2; word-break: break-word; }
.facts { display: flex; gap: 22px; margin-top: 10px; }
.facts div { display: grid; }
.facts span { font-size: 11px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.facts b { font-size: 18px; font-weight: 600; color: var(--amber); }

/* message feed */
.feed { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.feed > :first-child { margin-top: auto; }
.msg { background: var(--panel2); padding: 7px 10px; border-left: 2px solid var(--line); animation: in .25s ease-out; }
.msg .meta { font-size: 11px; color: var(--muted); }
.msg.cmd { border-left-color: var(--amber); }
.msg.cmd .meta { color: var(--amber); }
.msg.alert { border-left-color: var(--red); }
.msg.alert .meta { color: var(--red); }
@keyframes in { from { opacity: 0; transform: translateY(4px) } }

/* map: fits free space keeping the image ratio (--ar set from JS) */
.mapcard { display: flex; flex-direction: column; padding: 10px; }
.fit { flex: 1; min-height: 0; display: grid; place-items: center; container-type: size; background: #121518; }
.map { --ar: 1; --x: 50; --y: 50; position: relative;
  width: min(100cqw, calc(100cqh * var(--ar))); height: min(100cqh, calc(100cqw / var(--ar))); }
.map img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; filter: saturate(.55) brightness(.85) contrast(1.05); }
.map::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(232,169,60,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(232,169,60,.08) 1px, transparent 1px);
  background-size: 10% 10%; }
.map.edit { cursor: crosshair; }
.gx, .gy { position: absolute; z-index: 1; pointer-events: none; font-size: 11px; color: rgba(232,169,60,.75); background: rgba(15,17,19,.7); padding: 1px 4px; }
.gx { top: 0; transform: translateX(-50%); }
.gy { right: 0; transform: translateY(-50%); }

.hl, .vl { position: absolute; z-index: 1; pointer-events: none; transition: all .5s; }
.hl { left: 0; right: 0; top: calc(var(--y) * 1%); border-top: 1px dashed rgba(255,48,48,.6); }
.vl { top: 0; bottom: 0; left: calc(var(--x) * 1%); border-left: 1px dashed rgba(255,48,48,.6); }

/* red target: pulsing core + two expanding rings */
.pin { position: absolute; z-index: 2; left: calc(var(--x) * 1%); top: calc(var(--y) * 1%);
  width: 16px; height: 16px; margin: -8px 0 0 -8px; transition: left .5s, top .5s; }
.pin i { position: absolute; inset: 0; border-radius: 50%; background: var(--pin); border: 2px solid #fff;
  box-shadow: 0 0 10px var(--pin), 0 0 24px var(--pin); animation: beat 1s infinite ease-in-out; }
.pin::before, .pin::after { content: ''; position: absolute; inset: -6px; border: 3px solid var(--pin); border-radius: 50%;
  animation: ring 1.5s infinite ease-out; }
.pin::after { animation-delay: .75s; }
@keyframes ring { from { transform: scale(.6); opacity: 1 } to { transform: scale(3.6); opacity: 0 } }
@keyframes beat { 50% { transform: scale(1.3) } }
.pin span { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); white-space: nowrap;
  background: #111; border: 1px solid var(--pin); border-left-width: 3px; color: #fff; padding: 2px 8px; font-size: 13px; font-weight: 500; }
.map.flip .pin span { left: auto; right: 24px; }
.pin span:empty { display: none; }
.pin.ghost { border-radius: 50%; border: 2px dashed #fff; }
.pin.ghost::before, .pin.ghost::after { display: none; }

/* ---------- footer ---------- */
.bottom { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; }

/* ---------- staff controls ---------- */
.ctrl { display: grid; gap: 8px; }
label { font-size: 12px; color: var(--muted); }
input, button { font: inherit; color: var(--text); width: 100%; padding: 8px 10px; border-radius: 0; }
input { background: var(--bg); border: 1px solid var(--line); outline: none; }
input::placeholder { color: #55565a; }
input:focus { border-color: var(--amber); }
button { cursor: pointer; background: var(--amber); border: 0; color: #161106; font-weight: 600; }
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
button.ghost { background: transparent; border: 1px solid var(--red); color: var(--red); }
button.ghost:hover { background: var(--red); color: #fff; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- entry screens ---------- */
.gate { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.gate > * { width: min(380px, 100%); display: grid; gap: 12px; }
.gate pre { margin: 0; font: inherit; color: var(--muted); white-space: pre-wrap; }
.gate pre b { color: var(--ok); font-weight: 500; }
.err { color: var(--red); min-height: 1.4em; margin: 0; }
.hidden { display: none !important; }

/* ---------- broadcast video: fullscreen, YouTube UI cropped & unclickable ---------- */
.video { position: fixed; inset: 0; z-index: 30; background: #000; overflow: hidden; display: none; }
.video.on { display: block; }
/* shown at exactly the screen size (no zoom, no crop), but rendered at 2x then scaled down:
   YouTube picks quality from the player size, so it serves HD */
.video iframe { position: absolute; top: 0; left: 0; width: 200%; height: 200%; transform: scale(.5); transform-origin: 0 0;
  pointer-events: none; border: 0; }

/* volume slider: in the header, floats over the video while it plays */
.vol { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.vol input { width: 90px; padding: 0; border: 0; background: none; accent-color: var(--amber); cursor: pointer; }
body.playing .vol { position: fixed; right: 16px; bottom: 16px; z-index: 36; background: rgba(0,0,0,.7); padding: 8px 12px; color: #fff; }

/* written message broadcast: full screen, big text */
.bcast { position: fixed; inset: 0; z-index: 35; display: grid; place-content: center; gap: 22px; padding: 24px; text-align: center;
  background: rgba(8,9,10,.94); opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }
.bcast.on { opacity: 1; visibility: visible; }
.bmeta { color: var(--pin); font-size: 14px; letter-spacing: .2em; text-transform: uppercase; animation: blink 1s steps(1) infinite; }
.btext { color: #fff; font-size: clamp(28px, 6vw, 76px); font-weight: 600; line-height: 1.15; max-width: 22ch; margin: 0 auto; word-break: break-word; }

/* ---------- small screens: map on top, info below, no page scroll ---------- */
@media (max-width: 820px) {
  body { padding: 8px; gap: 8px; font-size: 13px; }
  .chan, .opt, .clock { display: none; }
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .mapcard { order: -1; padding: 6px; }
  .col .grow { max-height: 22vh; }
  .main:has(.edit) .col .grow, .main:has(.edit) .ctrl label { display: none; }
  .ctrl { gap: 6px; }
  .order { font-size: 20px; }
  .card { padding: 9px 11px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
