:root {
  color-scheme: dark;
  --bg: #070a12;
  --panel: rgba(18, 24, 42, 0.82);
  --panel-solid: #11182a;
  --line: rgba(143, 163, 205, 0.18);
  --text: #f4f7ff;
  --muted: #98a6c5;
  --cyan: #62e8ff;
  --violet: #a78bfa;
  --green: #57e6a5;
  --red: #ff6f91;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 8% -10%, rgba(98, 232, 255, 0.17), transparent 34rem),
    radial-gradient(circle at 95% 4%, rgba(167, 139, 250, 0.2), transparent 32rem),
    linear-gradient(145deg, #070a12 0%, #090d18 48%, #080b14 100%);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.22;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

button, a { font: inherit; }
button { color: inherit; }

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 54px;
}

.topbar, .section-heading, .controls {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; margin-bottom: 18px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 4vw, 2.55rem); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.15rem; }

.eyebrow {
  margin-bottom: 5px;
  color: var(--cyan);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .2em;
}

.live-state {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(7, 10, 18, .62);
  font-size: .86rem;
  font-weight: 700;
}

.state-dot { width: 9px; height: 9px; border-radius: 50%; background: #f4b95f; box-shadow: 0 0 14px currentColor; }
.live-state[data-state="live"] { color: var(--green); border-color: rgba(87,230,165,.32); }
.live-state[data-state="live"] .state-dot { background: var(--green); animation: pulse 1.7s infinite; }
.live-state[data-state="error"] { color: var(--red); }
.live-state[data-state="error"] .state-dot { background: var(--red); }

.player-card, .stats-card, .help-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.player-card { overflow: hidden; }
.video-wrap { position: relative; aspect-ratio: 16 / 9; background: #02040a; }
video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }

.video-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  background: radial-gradient(circle, rgba(21,32,57,.5), rgba(2,4,10,.94));
  transition: opacity .25s ease, visibility .25s ease;
}
.video-overlay[hidden] { display: grid; opacity: 0; visibility: hidden; pointer-events: none; }
.video-overlay p { margin: 16px 0 4px; font-weight: 800; font-size: 1.1rem; }
.video-overlay small { color: var(--muted); }

.spinner { width: 38px; height: 38px; border: 3px solid rgba(98,232,255,.16); border-top-color: var(--cyan); border-radius: 50%; animation: spin .9s linear infinite; }

.latency-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: rgba(3,6,12,.72);
  color: var(--muted);
  font-size: .72rem;
  backdrop-filter: blur(10px);
}
.latency-badge b { margin-left: 5px; color: var(--cyan); }

.controls { gap: 9px; flex-wrap: wrap; padding: 14px; border-top: 1px solid var(--line); }
button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.045);
  cursor: pointer;
  font-weight: 750;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
button:hover { transform: translateY(-1px); border-color: rgba(98,232,255,.45); background: rgba(98,232,255,.08); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
button.primary { color: #06111a; border-color: transparent; background: linear-gradient(135deg, var(--cyan), #9bf3ff); }
button.primary[data-enabled="true"] { color: var(--text); border-color: rgba(255,111,145,.5); background: rgba(255,111,145,.12); }
.preset-group { display: flex; gap: 5px; padding: 4px; border: 1px solid var(--line); border-radius: 13px; background: rgba(0,0,0,.16); }
.preset { min-height: 34px; padding: 5px 10px; border: 0; font-size: .78rem; color: var(--muted); }
.preset.active { color: var(--text); background: rgba(98,232,255,.14); box-shadow: inset 0 0 0 1px rgba(98,232,255,.25); }
.ghost { margin-left: auto; }
.ghost + .ghost { margin-left: 0; }

.audio-note { margin: 0; padding: 0 15px 14px; color: var(--muted); font-size: .78rem; }

.stats-card, .help-card { margin-top: 16px; padding: 20px; }
.section-heading { justify-content: space-between; margin-bottom: 15px; }
.route-pill { padding: 7px 10px; border-radius: 999px; color: var(--green); background: rgba(87,230,165,.09); border: 1px solid rgba(87,230,165,.2); font-size: .72rem; font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.stats-grid article { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(4,8,16,.42); }
.stats-grid span, .stats-grid small { display: block; color: var(--muted); font-size: .72rem; }
.stats-grid strong { display: block; overflow: hidden; margin: 7px 0 4px; font-size: 1.03rem; text-overflow: ellipsis; white-space: nowrap; }
.measurement-note { margin: 14px 0 0; color: var(--muted); font-size: .75rem; line-height: 1.7; }
.diagnostic-actions { display: flex; align-items: center; gap: 12px; margin-top: 13px; }
.diagnostic-actions small { color: var(--muted); font-size: .72rem; line-height: 1.55; }
.diagnostic { flex: 0 0 auto; min-height: 36px; padding: 7px 11px; font-size: .75rem; }
.diagnostic:disabled { cursor: not-allowed; opacity: .48; transform: none; }

.help-card { box-shadow: none; }
.help-card ol { margin: 12px 0 0; padding-left: 1.35rem; color: var(--muted); line-height: 1.8; font-size: .86rem; }
.portal-link { display: inline-block; margin-top: 12px; color: var(--cyan); text-underline-offset: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .46; box-shadow: 0 0 5px currentColor; } }

@media (max-width: 850px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .ghost { margin-left: 0; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 18px, 1240px); padding-top: 18px; }
  .player-card, .stats-card, .help-card { border-radius: 16px; }
  .controls { align-items: stretch; }
  .controls > button, .preset-group { flex: 1 1 auto; }
  .preset-group { overflow-x: auto; }
  .preset { white-space: nowrap; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .diagnostic-actions { align-items: stretch; flex-direction: column; }
  .diagnostic { width: 100%; }
  .route-pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
