:root {
  --paper: #f4f0e7;
  --paper-2: #ebe2d3;
  --ink: #111318;
  --muted: #5d6270;
  --navy: #143257;
  --navy-2: #1e416d;
  --red: #b90e24;
  --red-dark: #760b17;
  --gold: #d0924c;
  --gold-2: #f0c174;
  --steel: #d9dde0;
  --line: #242832;
  --white: #fffdf7;
  --grid: rgba(17, 19, 24, 0.14);
  --shadow: 0 24px 60px rgba(27, 25, 20, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 85% 10%, rgba(208, 146, 76, 0.26), transparent 28rem),
    radial-gradient(circle at 5% 75%, rgba(185, 14, 36, 0.15), transparent 22rem),
    var(--paper);
  overflow-x: clip;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: "IBM Plex Mono", "Courier New", monospace;
  background:
    linear-gradient(90deg, rgba(20, 50, 87, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(20, 50, 87, 0.045) 1px, transparent 1px);
  background-size: 48px 48px;
  overflow-x: clip;
}

button,
input {
  font: inherit;
}

.mission-shell {
  width: min(1480px, calc(100% - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(8px, 1.5dvh, 12px) 0;
  display: grid;
  grid-template-rows: 64px auto auto;
  gap: 12px;
}

.compact-header {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  overflow: hidden;
}

.compact-header h1 {
  min-width: 0;
  flex: 0 1 auto;
  margin: 0;
  font-family: "Russo One", "Arial Black", sans-serif;
  font-size: clamp(24px, 3.2vw, 44px);
  line-height: 1;
  font-weight: 400;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow:
    2px 2px 0 var(--white),
    4px 4px 0 rgba(17, 19, 24, 0.16);
}

.compact-logo {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  object-fit: contain;
  filter: drop-shadow(3px 4px 0 rgba(17, 19, 24, 0.22));
}

.header-footnote {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 7px;
}

.header-footnote .abbr-help {
  width: 18px;
  height: 18px;
  margin-left: 0;
  font-size: 11px;
  line-height: 11px;
  vertical-align: top;
}

.eyebrow,
.panel-kicker,
.decision-label {
  margin: 0;
  color: var(--red);
  font-weight: 700;
  text-transform: uppercase;
}

.eyebrow {
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  font-family: "Russo One", "Arial Black", sans-serif;
  font-weight: 400;
}

h1 {
  max-width: 900px;
  font-size: clamp(44px, 8vw, 112px);
  line-height: 0.88;
  color: var(--ink);
  text-shadow:
    4px 4px 0 var(--white),
    8px 8px 0 rgba(17, 19, 24, 0.16);
}

.subtitle {
  max-width: 780px;
  margin: 20px 0 0;
  font-size: 17px;
  line-height: 1.55;
  color: #3a3d45;
}

.dashboard {
  min-height: min(720px, max(500px, calc(100dvh - 360px)));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 430px);
  gap: 18px;
  align-items: stretch;
}

.chart-panel,
.event-panel {
  border: 4px solid var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
}

.chart-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.panel-header {
  min-width: 0;
  min-height: clamp(70px, 10dvh, 92px);
  padding: 20px 22px 14px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 4px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(208, 146, 76, 0.28), transparent 40%),
    var(--paper);
}

.panel-header h2,
.event-panel h2 {
  margin-top: 6px;
  font-size: 24px;
}

.panel-kicker,
.decision-label {
  font-size: 12px;
}

.source-badge {
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  background: var(--navy);
  color: var(--white);
  padding: 8px 10px;
  font-size: 11px;
  box-shadow: 4px 4px 0 var(--gold);
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 74% 20%, rgba(20, 50, 87, 0.12), transparent 20rem),
    linear-gradient(180deg, #fffaf0 0%, #efe2ca 100%);
}

#flightChart {
  width: 100%;
  height: 100%;
  display: block;
}

.axis-label,
.tick-label,
.event-label,
.chart-note {
  font-family: "IBM Plex Mono", "Courier New", monospace;
  fill: var(--ink);
}

.axis-label {
  font-size: 16px;
  font-weight: 700;
}

.tick-label {
  font-size: 12px;
  fill: #4d515a;
}

.grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-line {
  stroke: var(--ink);
  stroke-width: 4;
}

.flight-path-base {
  fill: none;
  stroke: rgba(17, 19, 24, 0.22);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flight-path {
  fill: none;
  stroke: var(--red);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 14 12;
}

.flight-path-progress {
  fill: none;
  stroke: var(--gold);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.event-point {
  cursor: pointer;
}

.event-point .outer {
  fill: var(--white);
  stroke: var(--ink);
  stroke-width: 4;
}

.event-point .inner {
  fill: var(--navy);
  stroke: var(--white);
  stroke-width: 2;
}

.event-point.active .inner {
  fill: var(--red);
}

.event-point:hover .outer,
.event-point.active .outer {
  stroke-width: 6;
}

.event-point:hover .inner,
.event-point.active .inner {
  r: 8;
}

.event-label {
  font-size: 11px;
  font-weight: 700;
}

.buran-marker {
  filter: drop-shadow(4px 8px 5px rgba(17, 19, 24, 0.28));
}

.buran-marker path {
  stroke: var(--ink);
  stroke-width: 2.6;
  stroke-linejoin: round;
}

.buran-body {
  fill: #f8f6ed;
}

.buran-wing {
  fill: #c8c9ca;
}

.buran-window {
  fill: var(--navy);
}

.controls {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: 50px 50px 50px minmax(120px, 1fr) 96px;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 4px solid var(--ink);
  background: var(--paper);
}

.icon-button {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.icon-button:hover {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--ink);
}

.icon-button.primary {
  background: var(--red);
  color: var(--white);
}

.control-icon {
  width: 26px;
  height: 26px;
  display: block;
}

.control-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.play-shape path {
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1;
}

.scrubber {
  width: 100%;
  accent-color: var(--red);
}

.time-readout {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.event-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(20, 50, 87, 0.06), transparent 36%),
    var(--white);
}

.event-topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#eventIndex {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--white);
  background: var(--navy);
  font-size: 16px;
}

.event-panel h2 {
  margin-top: 22px;
  font-size: 34px;
  line-height: 1.04;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 24px 0 0;
}

.telemetry-grid div {
  min-height: 78px;
  padding: 10px;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.telemetry-grid dt {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.telemetry-grid dd {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.abbr-tip {
  position: relative;
  display: inline-block;
  white-space: nowrap;
}

.abbr-help {
  width: 14px;
  height: 14px;
  margin-left: 2px;
  padding: 0;
  vertical-align: super;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--gold-2);
  color: var(--ink);
  font-size: 9px;
  line-height: 9px;
  font-weight: 700;
  cursor: help;
}

.abbr-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 200;
  width: min(320px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 3px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  box-shadow: 6px 6px 0 var(--red);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 500;
  text-transform: none;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(var(--tooltip-x, 0), var(--tooltip-y, 0), 0);
  transition: opacity 120ms ease, transform 120ms ease;
}

.abbr-tooltip::after {
  content: "";
  position: absolute;
  left: var(--tooltip-arrow-x, 14px);
  top: var(--tooltip-arrow-y, auto);
  bottom: var(--tooltip-arrow-bottom, -9px);
  width: 14px;
  height: 14px;
  background: var(--white);
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(var(--tooltip-arrow-rotate, 45deg));
}

.abbr-tooltip strong {
  display: block;
  margin-bottom: 5px;
  color: var(--red);
  font-size: 13px;
  text-transform: uppercase;
}

.abbr-tooltip.is-open {
  opacity: 1;
}

.decision-block .abbr-tooltip {
  background: var(--paper);
  color: var(--ink);
}

.decision-block {
  margin-top: 20px;
  padding: 18px;
  border: 3px solid var(--ink);
  background: var(--navy);
  color: var(--white);
  box-shadow: 6px 6px 0 var(--gold);
}

.decision-block p:last-child {
  margin: 10px 0 0;
  font-size: 16px;
  line-height: 1.5;
}

.systems-strip {
  align-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.system-pill {
  border: 2px solid var(--ink);
  background: var(--gold-2);
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 700;
}

.waypoint-rail {
  min-height: 0;
  border: 4px solid var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.waypoints {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: minmax(88px, 1fr);
}

.waypoints::after {
  content: "";
  grid-column: span 3;
  border-bottom: 0;
  background: var(--white);
}

.waypoint {
  min-height: 88px;
  border: 0;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  background: var(--white);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.waypoint:nth-child(6n) {
  border-right: 0;
}

.waypoint:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.waypoint.active,
.waypoint:hover {
  background: var(--red);
  color: var(--white);
}

.waypoint strong {
  display: block;
  font-family: "Russo One", "Arial Black", sans-serif;
  font-weight: 400;
  font-size: 18px;
}

.waypoint span {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.25;
}

@media (max-width: 1120px) {
  .mission-shell {
    grid-template-rows: 64px auto auto;
  }

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

  .event-panel {
    margin-top: 14px;
  }

  .chart-panel {
    min-height: min(720px, max(560px, calc(100dvh - 98px)));
  }

  .waypoints {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .waypoints::after {
    grid-column: span 1;
  }

  .waypoint:nth-child(6n) {
    border-right: 2px solid var(--ink);
  }

  .waypoint:nth-child(4n) {
    border-right: 0;
  }
}

@media (max-width: 760px) {
  .mission-shell {
    width: min(100% - 18px, 1480px);
    grid-template-rows: 58px auto auto;
    gap: 10px;
    padding: 8px 0;
  }

  .compact-header {
    height: 58px;
    gap: 10px;
  }

  .compact-logo {
    width: 54px;
    height: 54px;
    flex-basis: 54px;
  }

  .compact-header h1 {
    font-size: clamp(22px, 8vw, 32px);
  }

  h1 {
    font-size: 46px;
  }

  .subtitle {
    font-size: 14px;
  }

  .panel-header {
    min-height: 58px;
    display: block;
    padding: 10px 12px 8px;
  }

  .panel-header h2 {
    margin-top: 3px;
    max-width: 100%;
    font-size: clamp(18px, 6.4vw, 26px);
    line-height: 1.08;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .panel-kicker {
    font-size: 10px;
  }

  .chart-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  #flightChart {
    width: max(980px, 230vw);
    min-width: 980px;
    max-width: none;
  }

  .controls {
    min-height: 70px;
    grid-template-columns: 44px 44px 44px minmax(90px, 1fr);
    padding: 10px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .time-readout {
    grid-column: 1 / -1;
    text-align: left;
    font-size: 18px;
  }

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

  .waypoints {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .waypoints::after {
    display: none;
  }

  .waypoint:nth-child(4n),
  .waypoint:nth-child(6n) {
    border-right: 2px solid var(--ink);
  }

  .waypoint:nth-child(2n) {
    border-right: 0;
  }

  .waypoint:nth-last-child(-n + 3) {
    border-bottom: 2px solid var(--ink);
  }

  .waypoint:last-child {
    border-bottom: 0;
  }
}

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