:root {
  --bg: #020502;
  --bg-2: #061108;
  --panel: rgba(4, 18, 7, 0.88);
  --panel-strong: rgba(2, 10, 4, 0.96);
  --line: rgba(86, 255, 143, 0.18);
  --text: #c8ffd6;
  --muted: #72b27b;
  --accent: #5cff87;
  --accent-soft: rgba(92, 255, 135, 0.12);
  --shadow: 0 0 0 1px rgba(92, 255, 135, 0.12), 0 0 26px rgba(35, 209, 88, 0.12);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(circle at top, rgba(92, 255, 135, 0.08), transparent 24%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-family: 'Courier New', Consolas, Monaco, monospace;
}

body {
  min-height: 100vh;
  position: relative;
}

body.stream-active {
  height: 100vh;
  overflow: hidden;
}

body.stream-active .page-shell {
  height: 100vh;
  padding-bottom: 16px;
}

body.stream-active .stream-screen {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.stream-active main {
  overflow: hidden;
}

body.stream-active .layout {
  height: 100%;
  min-height: 0;
}

body.stream-active .video-panel,
body.stream-active .chat-panel {
  overflow: hidden;
}

body.stream-active .player-frame {
  height: auto;
  max-height: 100%;
}

body.stream-active .chat-feed {
  min-height: 0;
}

body.stream-active .scanlines,
body.stream-active::before {
  pointer-events: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(rgba(255, 255, 255, 0.015) 50%, transparent 50%);
  background-size: 100% 4px;
  opacity: 0.22;
}

button,
input {
  font: inherit;
}

code {
  color: var(--accent);
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0) 2px,
    rgba(92, 255, 135, 0.02) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  opacity: 0.4;
}

.page-shell {
  width: min(1440px, calc(100% - 24px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 0 24px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stream-screen {
  flex: 1 1 auto;
  min-height: 0;
}

.panel {
  background: linear-gradient(180deg, rgba(4, 18, 7, 0.94), rgba(2, 10, 4, 0.94));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.brand-block {
  display: grid;
  gap: 6px;
}

.brand-glow,
.section-title {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  text-shadow: 0 0 8px rgba(92, 255, 135, 0.45), 0 0 18px rgba(92, 255, 135, 0.22);
}

.brand-glow {
  font-size: clamp(1.5rem, 3vw, 2.35rem);
  font-weight: 700;
}

.terminal-line,
.overlay-text,
.chat-empty,
.field-label,
.chat-time {
  color: var(--muted);
}

.terminal-line {
  font-size: 0.92rem;
}

.status-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill,
.ghost-button,
.send-button,
.text-input,
.chat-feed,
.chat-message,
.overlay-card,
.player-controls {
  border: 1px solid var(--line);
  border-radius: 12px;
}

.status-pill {
  background: rgba(92, 255, 135, 0.06);
  padding: 9px 12px;
  font-size: 0.82rem;
}

.login-screen {
  min-height: calc(100vh - 130px);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  position: relative;
}

.matrix-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(92, 255, 135, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(92, 255, 135, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 48%, transparent 100%);
  opacity: 0.4;
}

.login-card {
  position: relative;
  width: min(560px, 100%);
  padding: 24px;
  background: linear-gradient(180deg, rgba(4, 18, 7, 0.96), rgba(1, 7, 3, 0.98));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-copy {
  margin: 12px 0 18px;
  line-height: 1.6;
}

.login-form,
.chat-meta,
.chat-meta-grid {
  display: grid;
  gap: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.95fr);
  gap: 16px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.video-panel,
.chat-panel {
  min-height: 0;
  height: 100%;
  padding: 16px;
}

.video-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.player-frame {
  position: relative;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #010401;
  aspect-ratio: 16 / 9;
}

.player-footer-actions {
  display: flex;
  justify-content: flex-end;
}

.player-reload-button {
  min-width: 0;
  padding: 8px 12px;
  font-size: 0.78rem;
}

.player-frame iframe,
.player-frame video {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #010401;
}

.player-frame video {
  object-fit: contain;
}

.player-frame video:fullscreen,
.player-frame video:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
}

.player-frame.is-fullscreen,
.player-frame.is-fullscreen video {
  border-radius: 0;
}

.player-frame.is-fullscreen {
  aspect-ratio: auto;
  border-color: transparent;
}

.player-frame.is-rotating,
.player-frame.is-rotating video {
  min-height: 0;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
  z-index: 3;
}

.player-overlay.hidden,
.hidden {
  display: none;
}

.overlay-card {
  max-width: 460px;
  padding: 18px;
  background: rgba(2, 10, 4, 0.94);
  text-align: center;
}

.overlay-title {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.player-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(4, 18, 7, 0.86), rgba(2, 10, 4, 0.94));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.34);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  pointer-events: none;
  z-index: 2;
}

.player-frame.controls-visible .player-controls,
.player-frame:hover .player-controls,
.player-frame:focus-within .player-controls {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.player-controls-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.player-controls-row-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-button {
  min-width: 0;
}

.volume-slider {
  width: 100%;
  height: 38px;
  margin: 0;
  accent-color: var(--accent);
  background: rgba(92, 255, 135, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
}

.volume-slider:hover {
  border-color: rgba(92, 255, 135, 0.45);
}

.volume-slider:focus {
  outline: none;
  border-color: rgba(92, 255, 135, 0.5);
  box-shadow: 0 0 0 3px rgba(92, 255, 135, 0.08);
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.stream-screen {
  height: 100%;
  min-height: 0;
}

.field-label {
  font-size: 0.84rem;
}

.text-input,
.ghost-button,
.send-button {
  background: rgba(92, 255, 135, 0.04);
  color: var(--text);
  padding: 11px 13px;
  outline: none;
}

.text-input::placeholder {
  color: rgba(200, 255, 214, 0.46);
}

.text-input:focus {
  border-color: rgba(92, 255, 135, 0.5);
  box-shadow: 0 0 0 3px rgba(92, 255, 135, 0.08);
}

.ghost-button,
.send-button {
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.ghost-button:hover,
.send-button:hover {
  border-color: rgba(92, 255, 135, 0.45);
  background: rgba(92, 255, 135, 0.08);
}

.send-button {
  color: var(--accent);
}

.chat-feed {
  min-height: 0;
  height: 100%;
  padding: 12px;
  overflow: auto;
  background: rgba(1, 7, 3, 0.88);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-feed > * {
  flex-shrink: 0;
}

.chat-message {
  padding: 10px 12px;
  background: rgba(92, 255, 135, 0.04);
}

.chat-message.system {
  background: rgba(92, 255, 135, 0.08);
}

.chat-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: baseline;
}

.chat-author {
  color: var(--accent);
  font-weight: 700;
}

.chat-text {
  margin-top: 6px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.chat-meta-actions {
  display: flex;
  justify-content: flex-start;
  align-items: end;
}

.chat-empty {
  margin: auto;
  text-align: center;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .video-panel,
  .chat-panel {
    min-height: auto;
    height: auto;
  }

  .chat-panel {
    overflow: visible;
  }

  .chat-feed {
    min-height: 260px;
    height: auto;
  }
}

@media (max-width: 640px), (pointer: coarse) and (orientation: landscape) {
  body.stream-active {
    height: auto;
    overflow: auto;
  }

  body.stream-active .page-shell,
  body.stream-active .stream-screen,
  body.stream-active main,
  body.stream-active .layout,
  body.stream-active .video-panel,
  body.stream-active .chat-panel {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .page-shell {
    width: min(100% - 16px, 1440px);
    padding: 10px 0 16px;
    min-height: auto;
  }

  .topbar {
    gap: 10px;
    padding: 12px;
    margin-bottom: 12px;
  }

  .status-row {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
    overflow: visible;
    height: auto;
  }

  .video-panel,
  .chat-panel,
  .login-card {
    height: auto;
    padding: 12px;
  }

  .video-panel {
    grid-template-rows: auto auto auto;
    gap: 10px;
  }

  .panel-header {
    justify-content: flex-start;
  }

  .player-frame {
    border-radius: 16px;
    position: static;
    top: auto;
    z-index: auto;
    aspect-ratio: 16 / 9;
  }

  .player-footer-actions {
    justify-content: flex-start;
  }

  .chat-panel {
    grid-template-rows: minmax(180px, auto) auto auto;
    gap: 10px;
  }

  .chat-feed {
    min-height: 180px;
    height: min(42svh, 320px);
    max-height: min(42svh, 320px);
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-meta-grid {
    gap: 10px;
  }
}
