:root {
  color-scheme: dark;
  --bg: #0f1216;
  --surface: #171c22;
  --surface-strong: #202832;
  --line: #303945;
  --line-soft: rgba(215, 225, 236, 0.12);
  --text: #f3f6f8;
  --muted: #a8b5c2;
  --subtle: #768696;
  --accent: #65b7d8;
  --accent-strong: #9fdaf0;
  --green: #78c7a0;
  --danger: #f07579;
  --track: #d9e5ed;
  --shadow: rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  background:
    radial-gradient(circle at 74% 8%, rgba(101, 183, 216, 0.12), transparent 28%),
    linear-gradient(90deg, rgba(55, 84, 110, 0.16), transparent 40%),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 18vw) 1fr;
  min-height: calc(100svh - 78px);
}

.event-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 18px 98px;
  border-right: 1px solid var(--line);
  background: rgba(13, 16, 20, 0.92);
}

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

.eyebrow,
.kicker,
.panel-heading span,
.evidence-strip span,
.compact-list span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5.8vw, 4rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  max-width: 980px;
  font-size: clamp(2rem, 3.1vw, 4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.event-title {
  max-width: 720px;
  margin-top: 12px;
  color: var(--muted);
  font-size: clamp(1rem, 1.2vw, 1.18rem);
  line-height: 1.4;
}

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

.filter-chip,
.transport-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.filter-chip {
  padding: 0 12px;
  color: var(--muted);
}

.filter-chip.is-active,
.transport-button {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-button {
  display: grid;
  width: 100%;
  gap: 8px;
  padding: 14px 0;
  border: 0;
  border-top: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.event-button strong {
  font-size: 1rem;
  line-height: 1.2;
}

.event-button span {
  color: var(--muted);
  font-size: 0.85rem;
}

.event-button.is-active strong,
.event-button:hover strong {
  color: var(--accent-strong);
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 28px 30px 112px;
}

.workspace-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  min-height: 128px;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 430px;
}

.event-meta span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.82rem;
}

.video-strip {
  display: grid;
}

.network-impact-grid {
  --prediction-table-width: 392px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--prediction-table-width);
  gap: 14px;
  align-items: start;
}

.media-panel,
.network-panel,
.crossing-panel,
.timeline-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 22px 60px var(--shadow);
}

.media-panel {
  display: grid;
  min-height: clamp(255px, 30vh, 360px);
}

.video-grid,
.media-fallback {
  width: 100%;
  height: 100%;
  min-height: clamp(255px, 30vh, 360px);
}

.video-grid {
  /* Single clip on the left, narrow side stats panel on the right. Using flex
     instead of grid here so the clip keeps its natural 16:9 size while the
     stats panel stays at a fixed compact width -- the strip can be wider than
     the two together and the leftover space is fine. */
  display: flex;
  align-items: stretch;
  gap: 14px;
  background: transparent;
}

.video-grid[hidden] {
  display: none;
}

.video-grid > .media-window {
  /* Height is the primary control; width follows the 16:9 aspect ratio.
     The 50% bump from clamp(170, 20vh, 240) takes the clip to clamp(255, 30vh, 360).
     Borders mirror the network/crossing/timeline panels for visual parity. */
  flex: 0 0 auto;
  aspect-ratio: 16 / 9;
  height: clamp(255px, 30vh, 360px);
  width: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 22px 60px var(--shadow);
}

.video-side-stats {
  /* Stacking is vertical with a thin divider between rows. The panel grows
     with the remaining horizontal space in the strip (flex: 1 1 ...) so on
     wide browsers the cells expand with the frame -- without grow, the panel
     would stay at its base width and leave empty space to the right of the
     content inside the frame. */
  flex: 1 1 220px;
  min-width: 180px;
  display: grid;
  grid-auto-rows: 1fr;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 22px 60px var(--shadow);
  overflow: hidden;
}

.video-side-stats > div {
  display: grid;
  gap: 2px;
  align-content: center;
  padding: 14px 18px;
  background: var(--surface);
  min-width: 0;
}

.video-side-stats > div + div {
  border-top: 1px solid var(--line-soft);
}

.video-side-stats span {
  color: var(--subtle);
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  line-height: 1;
}

.video-side-stats strong {
  font-size: clamp(1.15rem, 1.6vw, 1.55rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
}

.video-side-stats small {
  color: var(--subtle);
  font-size: 0.72rem;
  line-height: 1.25;
}

.media-window {
  position: relative;
  min-width: 0;
  min-height: clamp(255px, 30vh, 360px);
  margin: 0;
  overflow: hidden;
  background: #050604;
}

.media-window[hidden] {
  display: none;
}

.media-window figcaption {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 4px 7px;
  background: rgba(5, 7, 9, 0.62);
  color: rgba(245, 247, 247, 0.86);
  font-size: 0.66rem;
  font-weight: 760;
  line-height: 1;
  text-transform: uppercase;
}

.event-video {
  width: 100%;
  height: 100%;
  min-height: clamp(255px, 30vh, 360px);
  object-fit: contain;
  background: #050604;
}

.event-video.is-ready {
  display: block;
}

.media-fallback {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  background:
    radial-gradient(circle at 70% 24%, rgba(101, 183, 216, 0.16), transparent 24%),
    linear-gradient(135deg, #151b22 0%, #202833 52%, #101419 100%);
}

.media-fallback.is-hidden {
  display: none;
}

.media-fallback p {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
}

.fallback-route {
  position: relative;
  width: min(62vw, 560px);
  height: 180px;
}

.fallback-route span {
  position: absolute;
  display: block;
  height: 2px;
  background: rgba(245, 243, 234, 0.72);
  transform-origin: left center;
}

.fallback-route span:nth-child(1) {
  top: 122px;
  left: 10%;
  width: 56%;
  transform: rotate(-18deg);
}

.fallback-route span:nth-child(2) {
  top: 89px;
  left: 38%;
  width: 44%;
  transform: rotate(-30deg);
}

.fallback-route span:nth-child(3) {
  top: 95px;
  left: 52%;
  width: 88px;
  height: 10px;
  background: var(--accent);
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(101, 183, 216, 0.44);
  transform: rotate(-30deg);
}

.network-panel,
.crossing-panel,
.timeline-panel {
  padding: 14px;
}

.network-panel {
  display: grid;
  justify-items: center;
  width: 100%;
  min-height: 0;
}

.network-panel .panel-heading {
  width: 100%;
}

.crossing-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  min-height: 0;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-heading strong {
  color: var(--track);
  font-size: 0.9rem;
  font-weight: 650;
}

#networkSvg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--network-aspect-ratio, 1564 / 1669);
  background: #0d141a;
}

.map-track {
  fill: none;
  stroke: var(--track);
  stroke-linecap: round;
  stroke-width: 1.2;
}

.map-track-shadow {
  stroke: rgba(0, 0, 0, 0.5);
  stroke-width: 8;
}

.background-map {
  filter: saturate(0.72) contrast(1.04) brightness(0.72);
}

.sector-line,
.connector-line,
.active-route {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sector-line {
  stroke: rgba(216, 228, 238, 0.55);
  stroke-width: 5;
}

.connector-line {
  stroke: rgba(216, 228, 238, 0.38);
  stroke-dasharray: 14 12;
  stroke-width: 4;
}

.active-route {
  stroke: rgba(235, 244, 250, 0.5);
  stroke-width: 9;
}

.corridor-crossing circle {
  fill: rgba(15, 18, 22, 0.86);
  stroke: var(--muted);
  stroke-width: 3;
}

.corridor-crossing text,
.train-label {
  fill: var(--text);
  paint-order: stroke;
  stroke: rgba(15, 18, 22, 0.9);
  stroke-linejoin: round;
  stroke-width: 5;
  font-weight: 780;
}

.corridor-crossing text {
  font-size: 15px;
}

.train-label {
  font-size: 18px;
}

.corridor-crossing.blocked circle {
  fill: rgba(240, 117, 121, 0.9);
  stroke: #ffd1d2;
}

.corridor-crossing.predicted circle {
  fill: rgba(101, 183, 216, 0.88);
  stroke: var(--accent-strong);
}

.corridor-crossing.cleared circle {
  fill: rgba(120, 199, 160, 0.62);
  stroke: #c5f0d7;
}

.train-glyph {
  color: #e8541e;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.48));
}

.train-body {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 16;
}

.train-arrowhead {
  fill: currentColor;
  stroke: none;
}

.train-glyph.is-untrusted {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
  opacity: 0.78;
}

.train-glyph.is-untrusted .train-body {
  stroke-dasharray: 18 12;
  stroke-width: 12;
}

.train-glyph.is-untrusted .train-arrowhead {
  fill-opacity: 0.78;
}

.media-window {
  position: relative;
}

.wallclock-overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #f3f6f9;
  background: rgba(8, 12, 18, 0.66);
  border-radius: 4px;
  pointer-events: none;
  z-index: 2;
}

.wallclock-overlay:empty {
  display: none;
}

.evidence-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.evidence-strip div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 18px 18px 16px 0;
}

.evidence-strip div + div {
  padding-left: 18px;
  border-left: 1px solid var(--line-soft);
}

.evidence-strip strong {
  font-size: clamp(1.45rem, 2vw, 2.3rem);
  line-height: 1;
  letter-spacing: 0;
}

.evidence-strip small {
  color: var(--subtle);
  font-size: 0.78rem;
  line-height: 1.25;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}

.crossing-table-wrap {
  height: var(--crossing-table-height, 530px);
  max-height: var(--crossing-table-height, 530px);
  overflow: auto;
  scrollbar-color: rgba(159, 218, 240, 0.5) rgba(255, 255, 255, 0.08);
  scrollbar-width: thin;
}

.crossing-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.crossing-table th,
.crossing-table td {
  padding: 10px 6px;
  border-top: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.crossing-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 750;
  text-transform: uppercase;
}

.crossing-table td {
  color: var(--text);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.crossing-table td:first-child {
  width: 35%;
}

.crossing-table th:nth-child(2),
.crossing-table td:nth-child(2) {
  width: 26%;
}

.crossing-table th:nth-child(3),
.crossing-table td:nth-child(3) {
  width: 18%;
}

.crossing-table th:nth-child(4),
.crossing-table td:nth-child(4) {
  width: 21%;
}

.crossing-table td strong {
  display: block;
  color: var(--text);
  font-size: 0.82rem;
}

.crossing-table mark {
  display: inline-grid;
  min-width: 72px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.05;
  white-space: nowrap;
}

.crossing-table mark strong {
  display: block;
  margin-top: 2px;
  color: currentColor;
  font-size: 0.78rem;
  font-weight: 780;
}

.crossing-table tr.is-active-impact td {
  background: rgba(101, 183, 216, 0.06);
}

.crossing-table tr.blocked mark {
  border-color: rgba(240, 117, 121, 0.6);
  color: #ffb0b3;
}

.crossing-table tr.predicted mark {
  border-color: rgba(101, 183, 216, 0.62);
  color: var(--accent-strong);
}

.crossing-table tr.cleared mark {
  border-color: rgba(120, 199, 160, 0.56);
  color: #a8e4c1;
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-list div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.compact-list strong {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 620;
}

.transport {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 78px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: rgba(13, 16, 20, 0.96);
  backdrop-filter: blur(18px);
}

.transport-button {
  min-width: 82px;
  padding: 0 18px;
}

#timeSlider {
  width: 100%;
  accent-color: var(--accent);
}

.time-readout {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .event-rail {
    padding: 22px 22px 6px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .event-list {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 12px;
  }

  .event-button {
    min-width: min(78vw, 330px);
  }

  .workspace {
    padding: 22px 22px 112px;
  }
}

@media (max-width: 1220px) {
  .network-impact-grid {
    grid-template-columns: 1fr;
  }

  .network-panel {
    justify-self: stretch;
    width: 100%;
  }

  .crossing-panel {
    justify-self: stretch;
    width: 100%;
  }

  #networkSvg {
    width: 100%;
    height: auto;
  }
}

@media (max-width: 900px) {
  .workspace-header {
    display: grid;
    min-height: 0;
  }

  .event-meta {
    justify-content: flex-start;
  }

  .network-impact-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .media-panel,
  .video-grid,
  .media-window,
  .event-video,
  .media-fallback {
    min-height: 26svh;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }

  .network-panel {
    min-height: 0;
  }

  .evidence-strip {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 2.1rem;
  }

  h2 {
    font-size: clamp(2.1rem, 10vw, 3.35rem);
  }

  .workspace,
  .event-rail {
    padding-right: 16px;
    padding-left: 16px;
  }

  .evidence-strip {
    grid-template-columns: 1fr;
  }

  .evidence-strip div + div,
  .evidence-strip div:nth-child(3) {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .transport {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .time-readout {
    justify-content: space-between;
  }

  .crossing-table thead {
    display: none;
  }

  .crossing-table,
  .crossing-table tbody,
  .crossing-table tr,
  .crossing-table td {
    display: block;
    width: 100%;
  }

  .crossing-table {
    min-width: 0;
    table-layout: auto;
  }

  .crossing-table tr {
    padding: 8px 0;
    border-top: 1px solid var(--line-soft);
  }

  .crossing-table td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 4px 0;
    border-top: 0;
    text-align: right;
    white-space: normal;
  }

  .crossing-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 750;
    text-align: left;
    text-transform: uppercase;
  }

  .crossing-table td:first-child {
    display: block;
    min-width: 0;
    padding-bottom: 8px;
    text-align: left;
  }

  .crossing-table td:first-child::before {
    content: "";
  }
}
