:root {
  --red: #e5141f;
  --red-dark: #8f0b12;
  --cyan: #58e6ff;
  --amber: #ffb547;
  --panel: rgba(4, 7, 14, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #f2f5f8;
  --muted: #9aa5b5;
  --sans: "Helvetica Neue", Helvetica, Arial, "Liberation Sans", sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --pipw: 18.5vw;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: var(--sans);
}

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  user-select: none;
  font-size: clamp(9px, 0.95vw, 16px);
  letter-spacing: 0.02em;
}

#hud .panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--red);
  backdrop-filter: blur(3px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* ---------- EAS strip ---------- */
#eas {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2.6vh;
  min-height: 16px;
  display: flex;
  align-items: center;
  background: repeating-linear-gradient(135deg, #7a0a10 0 12px, #4a0409 12px 24px);
  border-bottom: 1px solid rgba(255, 90, 90, 0.5);
  font-family: var(--mono);
  font-size: 0.85em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}
#eas .eas-tag {
  position: relative;
  z-index: 2;
  background: var(--red);
  color: #fff;
  padding: 0 1.2em;
  height: 100%;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.5);
}
#eas .eas-tag::before {
  content: '';
  width: 0.6em; height: 0.6em; border-radius: 50%;
  background: #fff; margin-right: 0.6em;
  animation: blink 1.4s steps(1) infinite;
}
#eas .eas-text {
  padding-left: 1.5em;
  color: #ffd7d7;
  text-shadow: 0 1px 0 #000;
  animation: easScroll 32s linear infinite;
}
@keyframes easScroll {
  0% { transform: translateX(100vw); }
  100% { transform: translateX(-120%); }
}
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.25; } }

/* ---------- Logo ---------- */
#logo {
  position: absolute;
  top: calc(2.6vh + 1.6vh);
  left: 1.2vw;
  display: flex;
  align-items: stretch;
  gap: 0.6em;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.7));
}
#logo .logo-box {
  display: flex;
  align-items: center;
  background: #0b1020;
  border: 2px solid #fff;
  padding: 0.15em 0.4em;
  font-weight: 900;
  font-size: 2.6em;
  letter-spacing: -0.02em;
  line-height: 1;
  transform: skewX(-8deg);
}
#logo .logo-box .knx { color: #fff; padding-right: 0.15em; }
#logo .logo-box .seven {
  background: var(--red);
  color: #fff;
  padding: 0 0.22em;
  margin-right: -0.4em;
  margin-top: -0.15em;
  margin-bottom: -0.15em;
  display: flex;
  align-items: center;
}
#logo .logo-sub {
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 0.95em;
  line-height: 1.05;
  letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 1px 3px #000;
}

/* ---------- Telemetry ---------- */
#telemetry {
  position: absolute;
  top: calc(2.6vh + 9.6vh);
  left: 1.2vw;
  padding: 0.5em 0.9em 0.6em 0.8em;
  font-family: var(--mono);
  font-size: 0.9em;
  min-width: 13em;
}
#telemetry .tele-title {
  color: var(--cyan);
  font-weight: 700;
  font-size: 0.8em;
  letter-spacing: 0.15em;
  margin-bottom: 0.4em;
  border-bottom: 1px solid rgba(88, 230, 255, 0.25);
  padding-bottom: 0.3em;
}
#telemetry .tele-row {
  display: flex;
  justify-content: space-between;
  gap: 1.4em;
  line-height: 1.45;
}
#telemetry .tele-row span { color: var(--muted); }
#telemetry .tele-row b { color: #fff; font-weight: 600; }

/* ---------- Feed label (top center) ---------- */
#feedlabel {
  position: absolute;
  top: calc(2.6vh + 1.8vh);
  left: 50%;
  transform: translateX(-60%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 0.35em 1em 0.35em 0.8em;
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 1em;
  display: flex;
  align-items: center;
  gap: 0.6em;
  text-shadow: 0 1px 2px #000;
}
#feedlabel .dot {
  width: 0.7em; height: 0.7em; border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  animation: blink 1s steps(1) infinite;
}

/* ---------- Live + clock ---------- */
#topright {
  position: absolute;
  top: calc(2.6vh + 1.6vh);
  right: 1.2vw;
  display: flex;
  align-items: stretch;
  gap: 0.5em;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.7));
}
#live {
  background: var(--red);
  color: #fff;
  font-weight: 900;
  font-size: 1.5em;
  letter-spacing: 0.12em;
  padding: 0.15em 0.6em 0.15em 0.5em;
  display: flex;
  align-items: center;
  gap: 0.4em;
}
#live .live-dot {
  width: 0.55em; height: 0.55em; border-radius: 50%;
  background: #fff;
  animation: blink 1s steps(1) infinite;
}
#clock {
  background: #0b1020;
  border: 1px solid var(--panel-border);
  color: #fff;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.5em;
  padding: 0.15em 0.6em;
  display: flex;
  align-items: center;
  letter-spacing: 0.05em;
}

/* ---------- PiP feeds ---------- */
#pips {
  position: absolute;
  top: calc(2.6vh + 9.4vh);
  right: 1.2vw;
  display: flex;
  flex-direction: column;
  gap: 0.9vw;
  pointer-events: auto;
}
.pip {
  position: relative;
  width: var(--pipw);
  height: calc(var(--pipw) * 0.5625);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  background: transparent; /* the feed itself is drawn by WebGL underneath */
  overflow: hidden;
}
.pip:hover { border-color: var(--cyan); }
.pip .pip-view {
  position: absolute;
  inset: 0;
}
.pip .pip-label {
  position: absolute;
  left: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.45em;
  background: rgba(0, 0, 0, 0.72);
  padding: 0.25em 0.7em 0.25em 0.5em;
  font-family: var(--mono);
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  border-right: 1px solid rgba(255, 255, 255, 0.25);
}
.pip .pip-glitch {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.35) 0 2px, rgba(0,0,0,0.5) 2px 5px, rgba(120,200,255,0.25) 5px 7px);
  mix-blend-mode: screen;
}
.pip.glitching .pip-glitch { opacity: 1; animation: glitchJitter 0.12s steps(2) infinite; }
.pip.glitching .pip-view { filter: contrast(1.5) saturate(0.2); }

.rec {
  width: 0.65em; height: 0.65em; border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  display: inline-block;
  animation: blink 1.2s steps(1) infinite;
}

/* ---------- Event log ---------- */
#eventlog {
  position: absolute;
  left: 1.2vw;
  bottom: calc(5vh + 9.2vh + 1.2vh);
  width: 31vw;
  max-width: 560px;
  padding: 0.5em 0.8em 0.6em;
  font-family: var(--mono);
  font-size: 0.86em;
}
#eventlog .log-title {
  display: flex;
  justify-content: space-between;
  color: var(--cyan);
  font-weight: 700;
  font-size: 0.82em;
  letter-spacing: 0.15em;
  border-bottom: 1px solid rgba(88, 230, 255, 0.25);
  padding-bottom: 0.3em;
  margin-bottom: 0.35em;
}
#log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.22em;
}
#log-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.7em;
  line-height: 1.3;
  color: #dfe6ee;
  animation: logIn 0.35s ease-out;
  opacity: 0.55;
}
#log-list li:nth-child(-n+3) { opacity: 1; }
#log-list li .ts { color: var(--muted); }
#log-list li .msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#log-list li.warn .msg { color: var(--amber); }
#log-list li.crit .msg { color: #ff6b6b; font-weight: 700; }
#log-list li.info .msg { color: var(--cyan); }
#log-list li:first-child .msg { text-shadow: 0 0 8px rgba(255, 255, 255, 0.35); }
@keyframes logIn {
  from { transform: translateX(-12px); opacity: 0; background: rgba(255,255,255,0.25); }
  to { transform: none; }
}

/* ---------- REC bar ---------- */
#recbar {
  position: absolute;
  right: 1.2vw;
  bottom: calc(5vh + 9.2vh + 1.2vh);
  display: flex;
  align-items: center;
  gap: 0.7em;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95em;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000, 0 0 6px rgba(0,0,0,0.8);
}
#signal { display: inline-flex; align-items: flex-end; gap: 2px; }
#signal i {
  display: inline-block; width: 4px; background: #fff;
  height: 4px;
}
#signal i:nth-child(1) { height: 4px; }
#signal i:nth-child(2) { height: 6px; }
#signal i:nth-child(3) { height: 8px; }
#signal i:nth-child(4) { height: 10px; }
#signal i:nth-child(5) { height: 12px; }
#signal i.off { background: rgba(255,255,255,0.25); }

/* ---------- Lower third ---------- */
#lowerthird {
  position: absolute;
  left: 1.2vw;
  bottom: 5vh;
  width: min(68vw, calc(100vw - 2.4vw - var(--pipw) - 2vw));
  height: 9.2vh;
  display: flex;
  flex-direction: column;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.6));
}
#lowerthird .lt-tag {
  align-self: flex-start;
  background: var(--red);
  color: #fff;
  font-weight: 900;
  font-size: 1.15em;
  letter-spacing: 0.16em;
  padding: 0.2em 1em 0.2em 0.8em;
  clip-path: polygon(0 0, 100% 0, calc(100% - 0.8em) 100%, 0 100%);
}
#lowerthird .lt-text {
  flex: 1;
  background: linear-gradient(90deg, rgba(8, 12, 24, 0.94), rgba(8, 12, 24, 0.86));
  border-top: 2px solid #fff;
  display: flex;
  align-items: center;
  padding: 0 1em;
  overflow: hidden;
}
#headline {
  font-weight: 800;
  font-size: 1.5em;
  line-height: 1.05;
  letter-spacing: 0.01em;
  color: #fff;
  text-transform: uppercase;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  animation: headlineIn 0.5s ease-out;
}
@keyframes headlineIn {
  from { transform: translateY(120%); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Ticker ---------- */
#ticker {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 5vh;
  display: flex;
  align-items: stretch;
  background: #05070d;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 1.25em;
  overflow: hidden;
}
#ticker .ticker-tag {
  flex: 0 0 auto;
  background: var(--red);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.18em;
  display: flex;
  align-items: center;
  padding: 0 1.4em 0 1.2vw;
  z-index: 2;
}
#ticker .ticker-track {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
}
#ticker-text {
  position: absolute;
  white-space: nowrap;
  font-weight: 600;
  color: #fff;
  will-change: transform;
}
#ticker-text .sep { color: var(--red); padding: 0 1.2em; }

/* ---------- Overlays ---------- */
#scanlines {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.13) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
  opacity: 0.8;
}
#vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}
#glitch {
  position: absolute; inset: 0;
  opacity: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.28) 0 3px, rgba(0,0,0,0.55) 3px 9px, rgba(90,200,255,0.2) 9px 12px);
  mix-blend-mode: screen;
}
#glitch.on { opacity: 1; animation: glitchJitter 0.1s steps(2) infinite; }
@keyframes glitchJitter {
  0% { transform: translate(0, 0) scaleY(1); }
  50% { transform: translate(-1.5%, 0.4%) scaleY(1.02); }
  100% { transform: translate(1.2%, -0.3%) scaleY(0.99); }
}
#flash {
  position: absolute; inset: 0;
  background: #fff;
  opacity: 0;
  mix-blend-mode: screen;
}
#errbox {
  position: absolute;
  top: 8vh; left: 30vw; right: 30vw;
  display: none;
  background: rgba(120, 0, 0, 0.85);
  color: #fff;
  font-family: var(--mono);
  padding: 1em;
  white-space: pre-wrap;
  z-index: 10;
}
#help {
  position: absolute;
  left: 50%;
  bottom: calc(5vh + 9.2vh + 1.6vh);
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 0.75em;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.1em;
  text-shadow: 0 1px 3px #000;
  animation: helpFade 1s ease-in 14s forwards;
}
@keyframes helpFade { to { opacity: 0; } }

@media (max-aspect-ratio: 4/3) {
  :root { --pipw: 26vw; }
  #telemetry { display: none; }
}
