:root {
  --ink: #17233a;
  --navy: #142f63;
  --navy-soft: #52688f;
  --amber: #c57a24;
  --paper: #f3efe5;
  --paper-deep: #e9e1d2;
  --grey: #a8a8a1;
  --hairline: rgba(23, 35, 58, 0.12);
  --sans: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", Baskerville, "Palatino Linotype", Palatino, serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: #edf1f7;
  background:
    radial-gradient(circle at 15% -10%, rgba(72, 97, 145, 0.32), transparent 34rem),
    linear-gradient(145deg, #0d172b 0%, #101c33 58%, #0a1427 100%);
  font-family: var(--sans);
}

button, input, select { font: inherit; }

.prototype-shell {
  width: min(1800px, 100%);
  margin: 0 auto;
  padding: 34px clamp(18px, 4vw, 64px) 44px;
}

.prototype-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin: 0 auto 18px;
  max-width: 1280px;
}

.prototype-kicker,
.prototype-note {
  margin: 0;
  color: #91a1bf;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.prototype-header h1 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(27px, 3vw, 42px);
  font-weight: 400;
}

.prototype-note { padding-bottom: 7px; text-align: right; }

.film {
  position: relative;
  width: min(1720px, 100%);
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.85), transparent 33%),
    linear-gradient(135deg, #f7f3ea 0%, var(--paper) 55%, #efe8dc 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 34px 90px rgba(1, 8, 22, 0.45), 0 4px 18px rgba(1, 8, 22, 0.28);
  isolation: isolate;
}

.paper-grain {
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.26;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(24, 45, 82, 0.018) 3px 4px),
    repeating-linear-gradient(90deg, transparent 0 5px, rgba(101, 74, 39, 0.014) 5px 6px);
  mix-blend-mode: multiply;
}

.film::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  background: var(--navy);
  z-index: 3;
}

.clock-date {
  fill: var(--navy);
  stroke: rgba(247, 243, 234, 0.96);
  stroke-width: 4px;
  paint-order: stroke;
  stroke-linejoin: round;
  font-family: var(--sans);
  font-size: 26px;
  font-weight: 560;
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
}

.figure-title {
  fill: var(--navy);
  font-family: var(--sans);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

#chart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

.grid-line { stroke: rgba(23, 35, 58, 0.105); stroke-width: 1; }
.grid-line.rail { stroke: rgba(20, 47, 99, 0.34); stroke-dasharray: 5 6; }
.axis-label { fill: #6f706d; font-family: var(--sans); font-size: 16px; font-weight: 560; }
.axis-title { fill: var(--ink); font-family: var(--sans); font-size: 12px; font-weight: 620; letter-spacing: 0.035em; }
.axis-note { fill: #8a8175; font-family: var(--sans); font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }

.frontier-path {
  fill: none;
  stroke: url(#frontier-gradient);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(20, 47, 99, 0.16));
}

.frontier-area {
  fill: url(#frontier-area-gradient);
  opacity: 0;
}

.frontier-haze {
  fill: none;
  stroke: #617da9;
  stroke-width: 30px;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-opacity: 0.16;
  filter: url(#frontier-haze);
  opacity: 0;
}


/* Deepened closing wash: darker hues + stronger stops, crossfaded in during
   the 5s epilogue. Same fade-to-paper structure so the floor stays airy. */
.frontier-area.area-deep { fill: url(#frontier-area-gradient-deep); opacity: 0; }
.frontier-area.area-deep-red { fill: url(#frontier-area-gradient-deep-red); opacity: 0; }
.frontier-haze.haze-deep { stroke: #43608f; stroke-opacity: 0.28; opacity: 0; }
.frontier-haze.haze-deep-red { stroke: #94454f; stroke-opacity: 0.28; opacity: 0; }

.frontier-area.area-red { fill: url(#frontier-area-gradient-red); }
.frontier-haze.haze-red { stroke: #b2606a; }

.flag-badge {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}
.badge-open { fill: #2f7d43; }
.badge-closed { fill: #16181c; }

.key-weights-plot { opacity: 0; transform-box: fill-box; transform-origin: center; }
.key-weights-label {
  fill: #6f706d;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 620;
  letter-spacing: 0.02em;
}

.ape-ghost {
  fill: none;
  stroke: #b3404d;
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
  stroke-opacity: 0.85;
  opacity: 0;
}

.ape-marker-label {
  fill: var(--navy);
  stroke: rgba(247, 243, 234, 0.95);
  stroke-width: 3;
  paint-order: stroke;
  stroke-linejoin: round;
  font-family: var(--sans);
  font-size: 13px;
  font-style: italic;
  font-weight: 640;
  letter-spacing: 0.01em;
  opacity: 0;
}

.point { opacity: 0; transform-box: fill-box; transform-origin: center; }
.point-marker { fill: #aaa9a2; stroke: var(--paper); stroke-width: 1.3; }
.point-marker.marker-navy { fill: var(--navy); opacity: 0; }
.point-pulse { fill: none; stroke: var(--amber); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.point.is-record .point-pulse { stroke: var(--navy); stroke-width: 2.5; }

.record-label {
  fill: var(--ink);
  stroke: rgba(247, 243, 234, 0.95);
  stroke-width: 3;
  paint-order: stroke;
  stroke-linejoin: round;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.01em;
  opacity: 0;
}

.callout { pointer-events: none; }
.callout-line { stroke: rgba(20, 47, 99, 0.45); stroke-width: 1; }
.callout-card { fill: rgba(255, 254, 250, 0.98); stroke: rgba(20, 47, 99, 0.16); stroke-width: 1; rx: 4; }
.callout.is-record .callout-card { stroke: var(--navy); stroke-width: 1.3; }
.callout-name { fill: var(--ink); font-family: var(--sans); font-size: 12px; font-weight: 680; }

.cost-ratio-overlay { opacity: 0; pointer-events: none; }
.cost-ratio-scrim { fill: rgba(247, 243, 234, 0.66); }
.cost-ratio-band { fill: rgba(255, 255, 255, 0.2); }
.cost-ratio-guide {
  stroke: var(--amber);
  stroke-width: 2;
  stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}
.cost-ratio-tag rect,
.cost-ratio-card rect {
  fill: rgba(255, 254, 250, 0.97);
  stroke: rgba(20, 47, 99, 0.2);
  stroke-width: 1;
  filter: url(#card-shadow);
}
.cost-ratio-tag text {
  fill: var(--navy);
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}
.cost-ratio-card text {
  fill: var(--navy);
  font-family: var(--sans);
  font-size: 29px;
  font-weight: 720;
  letter-spacing: -0.02em;
}
.cost-ratio-arrow {
  fill: none;
  stroke: var(--navy);
  stroke-width: 2.2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart-key {
  position: absolute;
  z-index: 5;
  left: 45%;
  bottom: 2.9%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #7b786f;
  font-size: clamp(8px, 1vw, 12.5px);
  font-weight: 620;
  letter-spacing: 0.025em;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
}

.chart-key-row { display: flex; align-items: center; gap: clamp(12px, 1.7vw, 22px); }
.chart-key span { display: inline-flex; align-items: center; gap: 8px; }
.key-circle { width: 10px; height: 10px; border-radius: 50%; background: #aaa9a2; }
.key-dash { width: 25px; height: 2px; border-top: 2px dashed rgba(179, 64, 77, 0.85); }
.key-triangle { width: 16px; height: 14px; flex: none; fill: #aaa9a2; overflow: visible; }
.key-line { width: 25px; height: 3px; background: var(--navy); }

.chart-brand {
  position: absolute;
  z-index: 5;
  right: 5.45%;
  bottom: 2.8%;
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: #918d84;
  font-size: clamp(7px, 0.94vw, 12px);
  font-weight: 560;
  letter-spacing: 0.025em;
  line-height: 1;
  white-space: nowrap;
}

.chart-brand strong {
  color: #6f706d;
  font-size: 0.94em;
  font-weight: 720;
  letter-spacing: 0.07em;
}

.chart-brand i { color: #aaa69d; font-style: normal; }

@media (max-width: 1290px) {
  .chart-key {
    left: 4%;
    transform: none;
  }
}

@media (max-width: 700px) {
  .chart-brand { display: none; }
}

@media (max-width: 520px) {
  .chart-key {
    right: 3%;
    left: 3%;
    width: auto;
    font-size: clamp(4px, 1.25vw, 6.5px);
    letter-spacing: 0;
  }

  .chart-key-row {
    width: 100%;
    justify-content: space-between;
    gap: 3px;
  }

  .chart-key span { gap: 3px; }
  .key-line,
  .key-dash { width: 14px; }
  .key-circle { width: 6px; height: 6px; }
  .key-triangle { width: 8px; height: 7px; }
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(1720px, 100%);
  margin: 18px auto 0;
  padding: 12px 14px;
  border: 1px solid rgba(156, 176, 211, 0.16);
  border-radius: 8px;
  background: rgba(8, 17, 34, 0.52);
}

.controls .control-button {
  display: inline-flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 36px;
  padding: 0;
  color: #f5f6f8;
  background: #345383;
  border: 1px solid #486898;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
}

.controls .control-button:hover { background: #40618f; }
.controls .control-button:focus-visible {
  outline: 2px solid #d6e1f2;
  outline-offset: 2px;
}
.control-icon {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-play,
.icon-pause { fill: currentColor; stroke: none; }
#play-button .control-icon { display: none; }
#play-button[data-state="play"] .icon-play,
#play-button[data-state="pause"] .icon-pause,
#play-button[data-state="replay"] .icon-replay { display: block; }
.download-control { color: #c3cee0; background: rgba(20, 34, 58, 0.74); }

.scrubber-label { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 160px; }
.scrubber-label span { width: 88px; color: #a9b7cf; font-size: 11px; font-variant-numeric: tabular-nums; }
.scrubber-label input { width: 100%; accent-color: #d28a38; }

.speed-label { display: flex; align-items: center; gap: 7px; color: #91a1bf; font-size: 11px; }
.speed-label select { padding: 6px 8px; color: #e9edf4; border: 1px solid #354765; border-radius: 4px; background: #14223a; }

.hint, .error {
  width: min(1280px, 100%);
  margin: 10px auto 0;
  color: #8190aa;
  font-size: 11px;
}

.error { color: #efb6a8; }

@media (max-width: 760px) {
  .prototype-shell { padding-inline: 10px; }
  .prototype-header { align-items: start; }
  .prototype-note { max-width: 190px; }
  .controls { flex-wrap: wrap; }
  .scrubber-label { order: 3; flex-basis: 100%; }
  .chart-key { gap: 10px; }
  .chart-brand { right: 3.5%; }
}

@media (max-width: 600px) {
  .embed-mode .chart-brand { display: none; }
}

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

.embed-mode body { background: #0d172b; }
.embed-mode .prototype-shell { width: 100%; margin: 0; padding: 0; }
.embed-mode .film { width: 100%; margin: 0; border: 0; box-shadow: none; }
.embed-mode .controls {
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 7px 10px;
  border: 0;
  border-top: 1px solid rgba(156, 176, 211, 0.16);
  border-radius: 0;
  background: #0d172b;
}
.embed-mode .controls .control-button { flex-basis: 44px; width: 44px; height: 36px; }
.embed-mode .hint { display: none; }
.embed-mode .error { margin: 0; padding: 0 10px; background: #0d172b; }

@media (min-width: 761px) {
  .embed-mode .controls {
    width: calc(100% - 16px);
    min-height: 44px;
    margin: 4px 8px 0;
    padding: 4px 8px;
    border: 1px solid rgba(156, 176, 211, 0.18);
    border-radius: 7px;
  }
}

.capture-mode body { background: #0d172b; overflow: hidden; }
.capture-mode .prototype-shell { width: 1280px; margin: 0; padding: 0; }
.capture-mode .prototype-header,
.capture-mode .controls,
.capture-mode .hint,
.capture-mode .error { display: none; }
.capture-mode .film { width: 1280px; margin: 0; border: 0; box-shadow: none; }
.capture-mode .paper-grain { display: none; }
