:root {
  --bg: #000000;
  --text: #F9F9F9;
  --gold-dark: #CF9C22;
  --success: #8dd6a8;
  --error: #ff9b9b;
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --panel: #121212;
  --panel-strong: #1d1b17;
  --border: #70685b;
  --muted: #bab6ad;
  --accent: #EBB83E;
  --accent-strong: #F8CA4C;
  --danger: #ff8f8f;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, #221b0c 0, transparent 36rem),
    var(--bg);
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button {
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.6rem;
  color: #171100;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.secondary {
  color: var(--accent-strong);
  background: transparent;
}

button.danger {
  border-color: var(--danger);
  color: #1a0606;
  background: var(--danger);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.6rem;
  color: var(--accent-strong);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

input,
select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  outline: none;
  background: #101010;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  color: #d5d1c9;
  font-size: 0.86rem;
  font-weight: 650;
}

code {
  color: var(--accent-strong);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 1.9rem);
}

h2 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-title-row h2 {
  margin-bottom: 0;
}

.eyebrow {
  margin-bottom: 0.25rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.small {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
}

.error {
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 1rem 3rem rgb(0 0 0 / 18%);
}

.narrow {
  max-width: 680px;
  margin: 8vh auto 0;
  padding: 1.5rem;
}

.inline-field,
.stacked-field {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.45rem;
}

.stacked-field {
  flex-direction: column;
}

.narrow > label:not(:first-of-type) {
  display: block;
  margin-top: 1rem;
}

.session-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
}

.stage {
  align-self: start;
  padding: 1rem;
}

.stage-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.video-shell {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid #22342e;
  border-radius: 0.65rem;
  background: #020504;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.4rem;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.video-placeholder strong {
  color: #F9F9F9;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.full-width {
  width: 100%;
  margin-top: 0.85rem;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 1rem;
}

.sidebar .panel {
  padding: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  align-items: center;
  gap: 0.65rem;
}

.quality-summary {
  margin: 0.8rem 0 0;
  color: #F9F9F9;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
}

.compact-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin: 0.9rem 0 0;
}

.compact-stats div {
  min-width: 0;
}

.compact-stats dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.compact-stats dd {
  margin: 0.2rem 0 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 99rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-idle {
  color: var(--muted);
}

.badge-live {
  border-color: #237b56;
  color: var(--accent-strong);
  background: #123c2d;
}

.badge-warning {
  border-color: #7a6730;
  color: #ffe09b;
  background: #382f14;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0;
}

.stats-grid div {
  min-width: 0;
}

.stats-grid dt {
  color: var(--muted);
  font-size: 0.7rem;
}

.stats-grid dd {
  overflow: hidden;
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-shell:fullscreen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  background: #000;
}

.video-shell:fullscreen video {
  object-fit: contain;
}

.log-panel ol {
  display: grid;
  gap: 0.45rem;
  max-height: 11rem;
  margin: 0;
  padding-left: 1.3rem;
  overflow: auto;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

[hidden] {
  display: none !important;
}

/* Player surface: diagnostics continue collecting without occupying the page. */
.viewer-view .session-layout { grid-template-columns: minmax(0, 1fr); }
.viewer-view .sidebar,
.viewer-view #test-panel,
.viewer-view #astro-frame-capture-panel,
.viewer-view .topbar .eyebrow,
.viewer-view #native-control-notice,
.viewer-view #native-fault-marker,
.viewer-view #viewer-control-panel > .eyebrow,
.viewer-view #viewer-input-title,
.viewer-view #viewer-input-detail,
.viewer-view #viewer-control-panel .compact-stats,
.viewer-view #dualsense-features { display: none !important; }
.viewer-view #viewer-control-panel {
  padding: 0;
  margin: 0 0 .85rem;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.viewer-view #viewer-control-panel > .stacked-field {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  margin: 0;
}
.viewer-view #connect-dualsense { order: -1; }
.viewer-view #native-emergency { margin-bottom: .65rem; }
.viewer-view #viewer-control-status { margin: .5rem 0 0; }
.viewer-view .video-shell { max-height: calc(100dvh - 280px); }
button.secondary:hover:not(:disabled) { color: var(--accent-strong); background: #302610; }

.test-panel { grid-column: 1 / -1; padding: 1rem; }
.test-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.test-heading h2 { margin-bottom: .4rem; }
#test-clock { font-size: 1.5rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.test-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.test-controls select { width: min(100%, 320px); }
.test-controls button { padding: .5rem .7rem; font-size: .85rem; }
#test-progress { width: 100%; height: .55rem; accent-color: var(--accent); margin-top: .75rem; }
#test-package-detail { font-size: .8rem; }
.test-overlay { position: absolute; top: .75rem; left: .75rem; right: .75rem; width: fit-content; max-width: calc(100% - 1.5rem); background: #111111ee; border: 1px solid var(--border); border-radius: .5rem; padding: .5rem .75rem; color: #F9F9F9; font: 600 14px/1.5 system-ui; pointer-events: none; white-space: pre-line; }
.viewer-view #test-panel { grid-column: 1 / -1; }
.host-view main, .host-view .topbar { max-width: 1920px; }
.host-view .topbar { padding-top: .65rem; padding-bottom: .65rem; }
.host-view .small { font-size: .82rem; }
.host-view .stats-grid dt, .host-view .compact-stats dt { font-size: .8rem; }
.host-view .stats-grid dd { white-space: normal; overflow-wrap: anywhere; font-size: .95rem; }
.host-view .stage .video-shell { max-height: 200px; }
.host-view #agent-status-detail { max-height: 3.4em; overflow: auto; }
.host-view #invite-panel .stacked-field { flex-direction: row; }
.host-view #invite-panel input { min-width: 0; }
.host-view #invite-panel .small { display: none; }
.host-view #host-control-panel .stacked-field { display: grid; grid-template-columns: 1fr 1fr; }
.host-view #host-control-panel .compact-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.host-view #quality-panel #codec-support, .host-view #quality-panel #audio-codec-support { display: none; }
.host-view .log-panel ol { max-height: 20rem; }

@media (min-width: 1000px) {
  .host-view .session-layout { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; align-items: start; }
  .host-view .sidebar { display: contents; }
  .host-view #test-panel { grid-column: 1 / -1; grid-row: 1; }
  .host-view .stage { grid-column: 1; grid-row: 2; }
  .host-view #telemetry-panel { grid-column: 2 / 4; grid-row: 2; }
  .host-view #telemetry-panel .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .host-view #viewer-presence-panel { grid-column: 4; grid-row: 2; }
  .host-view #quality-panel { grid-column: 1; grid-row: 3; }
  .host-view #host-control-panel { grid-column: 2 / 4; grid-row: 3; }
  .host-view .log-panel { grid-column: 4; grid-row: 3; }
  .host-view #invite-panel { grid-column: 1 / -1; grid-row: 4; }
  .host-view .panel { padding: .8rem; }
  .host-view #test-panel { padding-top: .65rem; padding-bottom: .65rem; }
  .host-view #test-panel .small { margin-top: .4rem; line-height: 1.3; }
  .host-view #test-package-detail { max-height: 2.6em; overflow: auto; }
  .host-view #telemetry-panel .stats-grid { gap: .45rem .8rem; }
  .host-view #telemetry-panel .stats-grid dt { font-size: .75rem; }
  .host-view #telemetry-panel .stats-grid dd { font-size: .9rem; }
  .host-view #telemetry-panel > .small { margin-top: .5rem; }
  .host-view #host-control-panel > .small:last-child { display: none; }
  .host-view #host-control-panel .compact-stats { gap: .4rem; }
  .host-view #host-control-panel h2, .host-view #telemetry-panel h2 { margin-bottom: .6rem; }
  .host-view #agent-status-detail { margin-top: .35rem; }
  .host-view #quality-panel .panel-title-row { margin-bottom: .5rem; }
  .host-view #quality-panel .quality-summary { margin-top: .5rem; }
  .host-view .form-grid { gap: .4rem; }
  .host-view input, .host-view select, .host-view button, .host-view .button-link { min-height: 2.3rem; padding: .45rem .65rem; }
  .host-view .actions { gap: .4rem; }
}

@media (min-width: 1440px) {
  .host-view .stage .video-shell { max-height: 160px; }
  .host-view #test-panel { padding-top: .4rem; padding-bottom: .4rem; }
  .host-view #agent-status-detail { max-height: 1.5em; }
  .host-view #quality-summary { display: none; }
  .host-view #telemetry-panel .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .host-view #host-control-panel .compact-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .host-view .topbar h1 { font-size: 1.5rem; }
  .host-view #quality-panel select { min-height: 1.85rem; padding-top: .25rem; padding-bottom: .25rem; }
}

.test-controls input[type="number"] { width: 5rem; }
.test-controls label { white-space: nowrap; }

.astro-capture-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .65rem;
  margin: .8rem 0;
}

.astro-capture-fields label,
.astro-capture-roi label {
  display: grid;
  gap: .3rem;
}

.astro-capture-action {
  grid-column: 1 / -1;
}

.astro-capture-roi {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .5rem;
  min-width: 0;
  margin: .6rem 0;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
}

.astro-capture-roi legend {
  max-width: 100%;
  padding: 0 .25rem;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1.35;
}

.astro-capture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
}

@media (max-width: 640px) {
  .astro-capture-roi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .astro-capture-actions { flex-direction: column; }
}

@media (max-width: 980px) {
  .session-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .topbar,
  main {
    padding-right: 0.85rem;
    padding-left: 0.85rem;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .log-panel {
    grid-column: auto;
  }

  .inline-field,
  .stacked-field,
  .actions {
    flex-direction: column;
  }

  .action-group {
    flex-direction: column;
  }
}

#dualsense-features {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  gap: 0.35rem;
}
#dualsense-features label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
#dualsense-features input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  min-height: 0;
  margin: 0;
  padding: 0;
  flex: none;
}
#dualsense-features input[type="range"] {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

/* Room lifecycle (viewer): discreet countdown, transient warning, terminal end screen. */
.session-remaining { position: absolute; top: .6rem; right: .6rem; padding: .15rem .5rem; border-radius: .4rem; background: #111111dd; color: var(--muted); font: 600 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; pointer-events: none; }
.session-warning { position: absolute; top: 2.6rem; right: .6rem; max-width: calc(100% - 1.2rem); padding: .35rem .7rem; border: 1px solid var(--border); border-radius: .5rem; background: #111111ee; color: #F9F9F9; font: 600 14px/1.4 system-ui; pointer-events: none; }
.session-ended { position: absolute; inset: 0; display: grid; place-content: center; gap: .4rem; padding: 1rem; background: #000000f2; color: var(--muted); text-align: center; }
.session-ended strong { color: #F9F9F9; font-size: 1.25rem; }
.viewer-pause-notice { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(36rem, calc(100% - 2rem)); padding: 1rem 1.2rem; border: 1px solid #f5c451; border-radius: .7rem; background: #140f02f0; color: #fff4d6; font: 600 16px/1.45 system-ui; text-align: center; z-index: 3; pointer-events: none; }
/* Operator notice (operator-notice.js): small card at the bottom of the video, over every player screen, never interactive; empty = invisible. */
.operator-notice { position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%); width: max-content; max-width: min(34rem, calc(100% - 2rem)); padding: .45rem .8rem; border: 1px solid var(--border); border-radius: .55rem; background: #111111ee; color: #F9F9F9; font: 600 15px/1.4 system-ui; text-align: center; overflow-wrap: anywhere; z-index: 4; pointer-events: none; user-select: none; }
.operator-notice:empty { padding: 0; border: 0; background: none; }
/* Player screens (player-screen.js): a small card over the video while connecting/reconnecting, a full overlay when the link is blocked. */
.viewer-view .video-placeholder { display: none; }
.player-screen { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: .45rem; width: min(30rem, calc(100% - 2rem)); padding: .9rem 1.1rem; border: 1px solid var(--border); border-radius: .65rem; background: #111111ee; color: var(--muted); font: 500 14px/1.45 system-ui; text-align: center; pointer-events: none; }
.player-screen strong { color: #F9F9F9; font-size: 1rem; }
.player-screen[data-tone="warning"] { border-color: #f5c451; }
.player-screen[data-tone="blocked"] { inset: 0; width: auto; transform: none; place-content: center; border: 0; border-radius: 0; background: #000000f2; pointer-events: auto; }
.player-screen[data-tone="blocked"] strong { font-size: 1.15rem; }
.player-screen [hidden] { display: none; }
.player-screen button { margin-top: .35rem; pointer-events: auto; }

/* Player latency probe (diag=latency). */
.latency-probe-warning {
  margin: .6rem 0;
  padding: .6rem .75rem;
  border: 1px solid #6b5a1f;
  border-radius: .6rem;
  background: #2a240d;
  color: #f3e3a6;
  font-size: .85rem;
}

.latency-roi-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.latency-roi-overlay.marking {
  pointer-events: auto;
  cursor: crosshair;
  background: rgba(0, 0, 0, .2);
}

.latency-roi-box {
  position: absolute;
  border: 2px solid #f5c84c;
  box-sizing: border-box;
  pointer-events: none;
}

/* RemotePlaysBR player entry. The loading screen is the only first paint. */
[hidden] { display: none !important; }
.brand-logo { width: 52px; height: 48px; object-fit: contain; vertical-align: middle; margin-right: .65rem; }
.route-loading { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem; padding: 2rem; background: var(--bg); color: var(--muted); text-align: center; }
.route-loading p { max-width: 30rem; line-height: 1.6; }
.player-page { background: var(--bg); }
.player-page .topbar { max-width: 1440px; padding: .7rem 1.5rem; border-bottom: 1px solid var(--border); }
.player-page h1 { font-size: 1.15rem; letter-spacing: -.025em; }
.player-page main { max-width: 1440px; padding-top: 1rem; }
.player-page .session-layout { display: block; }
.player-page .stage { padding: 0; border: 0; background: transparent; }
.player-page .stage-heading { display: none; }
.player-page .video-shell { aspect-ratio: 16 / 9; max-height: calc(100dvh - 260px); border: 1px solid var(--border); border-radius: .8rem; background: #080808; }
.player-page #viewer-control-panel { border: 0; padding: 0 0 .8rem; margin: 0; background: transparent; }
.player-page #viewer-control-status { color: var(--muted); }
.player-page .actions { justify-content: space-between; }
.player-page .player-screen { border: 0; background: transparent; max-width: 34rem; }
.player-page .player-screen strong { font-size: clamp(1rem, 2vw, 1.3rem); color: var(--text); }
.player-page .player-screen[data-tone="blocked"] { max-width: none; background: #080808; }
.player-page .operator-notice { border-color: var(--gold-dark); color: var(--text); background: #211b0bf2; }
.player-page .session-remaining { color: var(--text); border: 1px solid var(--border); }
.player-diagnostics { margin-top: 1.5rem; }
@media (max-width: 640px) { .player-page .topbar { padding: .6rem 1rem; } .player-page .brand-logo { width: 38px; } .player-page main { padding: 1rem; } .player-page .video-shell { min-height: 240px; max-height: none; } .player-page .action-group { flex-wrap: wrap; } .player-page .action-group button { flex: 1 1 auto; } }
.player-page.viewer-view .player-diagnostics, .player-page.viewer-view .player-diagnostics #astro-frame-capture-panel { display: grid !important; }
