@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --ink: #ecf7f4;
  --muted: #89a7a5;
  --dim: #527270;
  --bg: #071317;
  --panel: #0a1b20;
  --panel-soft: #0c2227;
  --line: rgba(139, 194, 188, .16);
  --line-strong: rgba(139, 194, 188, .3);
  --accent: #51e3c2;
  --accent-strong: #8fffe6;
  --danger: #ff8c79;
  --warning: #f5c96a;
  --mono: 'DM Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: 'Manrope', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 18%, rgba(32, 117, 108, .18), transparent 32rem),
    var(--bg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button, select { cursor: pointer; }

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(24px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark { width: 38px; height: 38px; }
.brand-mark circle, .brand-mark path { fill: none; stroke: var(--accent); stroke-width: 1.4; }
.brand-mark circle:last-child { fill: var(--accent); stroke: none; }

.brand span { display: flex; align-items: baseline; gap: 8px; }
.brand strong { font-size: 17px; letter-spacing: .14em; }
.brand small { color: var(--muted); font: 500 10px/1 var(--mono); letter-spacing: .14em; }

.live-state {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font: 500 11px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(245, 201, 106, .08);
}

.live-state.online .live-dot { background: var(--accent); box-shadow: 0 0 0 5px rgba(81, 227, 194, .08); }
.live-state.offline .live-dot { background: var(--danger); box-shadow: 0 0 0 5px rgba(255, 140, 121, .08); }

.workspace {
  min-height: calc(100vh - 124px);
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
}

.control-rail {
  padding: clamp(42px, 6vh, 74px) clamp(28px, 4vw, 62px);
  border-right: 1px solid var(--line);
  background: rgba(7, 19, 23, .76);
}

.eyebrow {
  margin: 0 0 16px;
  color: var(--accent);
  font: 500 11px/1.2 var(--mono);
  letter-spacing: .16em;
}

.intro h1 {
  margin: 0;
  max-width: 400px;
  font-size: clamp(38px, 4vw, 58px);
  line-height: .98;
  letter-spacing: -.055em;
}

.intro > p:last-child {
  max-width: 410px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

form { margin-top: clamp(36px, 6vh, 62px); }

label { display: block; margin-bottom: 20px; }

label > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: #bcd0cd;
  font: 500 11px/1.2 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
}

label em { color: var(--dim); font-style: normal; font-size: 9px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row.three-up { grid-template-columns: 1fr 1fr 1fr; }

input, select {
  width: 100%;
  height: 48px;
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  outline: none;
  background: rgba(11, 35, 40, .7);
  font-size: 13px;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

input::placeholder { color: #52706f; }
input:focus, select:focus {
  border-color: var(--accent);
  background: rgba(13, 42, 46, .96);
  box-shadow: 0 0 0 3px rgba(81, 227, 194, .08);
}

.form-error {
  margin: -2px 0 18px;
  color: #ffd0c7;
  font-size: 12px;
  line-height: 1.5;
}

.solve-button {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  color: #05241e;
  background: var(--accent);
  border: 0;
  border-radius: 3px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .02em;
  transition: transform .18s ease, background .18s ease;
}

.solve-button:hover { transform: translateY(-2px); background: var(--accent-strong); }
.solve-button:active { transform: translateY(0); }
.solve-button:disabled { cursor: wait; opacity: .55; transform: none; }
.solve-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.run-note {
  margin: 12px 0 0;
  color: var(--dim);
  font: 400 10px/1.5 var(--mono);
}

.route-workspace {
  min-width: 0;
  padding: clamp(32px, 5vw, 72px);
  overflow: hidden;
}

.workspace-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.workspace-heading h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 40px);
  letter-spacing: -.045em;
}

.run-time {
  padding: 8px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  font: 500 10px/1 var(--mono);
  letter-spacing: .1em;
  white-space: nowrap;
}

.empty-state { margin-top: clamp(30px, 6vh, 72px); }

.chart-field {
  position: relative;
  height: clamp(330px, 48vh, 500px);
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background-image:
    linear-gradient(rgba(110, 164, 158, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 164, 158, .06) 1px, transparent 1px);
  background-size: 48px 48px;
}

.chart-field::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 48% 50%, transparent, rgba(7, 19, 23, .72) 82%);
  pointer-events: none;
}

.chart-field svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.coast { fill: none; stroke: rgba(137, 186, 180, .15); stroke-width: 22; stroke-linecap: round; }
.route-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 8 10;
  filter: url(#glow);
  animation: sail 12s linear infinite;
}
.route-node { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.route-node.n2 { animation: beacon 2s ease-in-out infinite; }

.chart-label {
  position: absolute;
  z-index: 1;
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  letter-spacing: .14em;
}
.label-a { left: 10%; top: 72%; }
.label-b { left: 42%; top: 42%; }
.label-c { right: 10%; top: 29%; }

.compass {
  position: absolute;
  z-index: 1;
  right: 18px;
  bottom: 18px;
  width: 50px;
  height: 50px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--muted);
  font: 500 9px/1 var(--mono);
  text-align: center;
}
.compass span { position: absolute; top: 7px; left: 0; right: 0; }
.compass i { position: absolute; width: 1px; height: 20px; left: 24px; top: 16px; background: var(--accent); transform: rotate(18deg); transform-origin: 50% 80%; }

.empty-copy { max-width: 560px; margin-top: 30px; }
.coordinate { color: var(--dim); font: 400 9px/1 var(--mono); letter-spacing: .12em; }
.empty-copy h3, .progress-state h3 { margin: 12px 0 8px; font-size: clamp(24px, 3vw, 38px); letter-spacing: -.04em; }
.empty-copy p, .progress-state > p:not(.eyebrow) { color: var(--muted); line-height: 1.65; font-size: 14px; }

.progress-state {
  min-height: 540px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.radar {
  position: relative;
  width: 210px;
  height: 210px;
  margin-bottom: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 31px, rgba(81, 227, 194, .1) 32px 33px);
}
.radar::before, .radar::after { content: ''; position: absolute; background: var(--line-strong); }
.radar::before { width: 1px; top: 0; bottom: 0; left: 50%; }
.radar::after { height: 1px; left: 0; right: 0; top: 50%; }
.radar i {
  position: absolute;
  inset: 50% 50% 0 50%;
  width: 50%;
  height: 50%;
  background: conic-gradient(from 270deg at 0 0, rgba(81, 227, 194, .38), transparent 36%);
  transform-origin: 0 0;
  animation: sweep 2.4s linear infinite;
}
.radar b, .radar span { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 18px var(--accent); }
.radar b { top: 64px; left: 126px; }
.radar span { top: 129px; left: 55px; animation: beacon 1.5s ease-in-out infinite; }
.progress-state h3 { max-width: 640px; }
.progress-state > p:not(.eyebrow) { margin: 0; }
.progress-track { width: min(380px, 80%); height: 2px; margin-top: 30px; overflow: hidden; background: var(--line); }
.progress-track i { display: block; width: 38%; height: 100%; background: var(--accent); animation: search 1.8s ease-in-out infinite; }
.cancel-run {
  margin-top: 24px;
  padding: 10px 16px;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: transparent;
  font: 600 10px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}
.cancel-run:hover { color: #ffd0c7; border-color: rgba(255, 208, 199, .55); }
.cancel-run:disabled { cursor: wait; opacity: .5; }

.result-state { padding-top: clamp(36px, 6vh, 70px); }

.result-lead {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
  animation: rise .38s ease both;
}
.result-status { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); font: 500 10px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.result-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.result-lead h3 { margin: 13px 0 0; font-size: clamp(28px, 4vw, 50px); line-height: 1.05; letter-spacing: -.055em; }
.result-context { text-align: right; color: var(--muted); font: 400 11px/1.7 var(--mono); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
  animation: rise .38s .08s ease both;
}
.metric { padding: 24px 20px 24px 0; }
.metric + .metric { padding-left: 20px; border-left: 1px solid var(--line); }
.metric span { display: block; color: var(--dim); font: 500 9px/1.3 var(--mono); letter-spacing: .11em; text-transform: uppercase; }
.metric strong { display: block; margin-top: 10px; font-size: clamp(19px, 2vw, 27px); font-variant-numeric: tabular-nums; letter-spacing: -.04em; }

.route-section { padding: 34px 0; border-bottom: 1px solid var(--line); animation: rise .38s .16s ease both; }
.section-kicker { color: var(--dim); font: 500 10px/1 var(--mono); letter-spacing: .12em; }
.route-stop { position: relative; display: grid; grid-template-columns: 160px 1fr; gap: 28px; padding: 28px 0 28px 42px; }
.route-stop::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.route-stop::after { content: ''; position: absolute; left: 3px; top: 34px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--accent); background: var(--bg); }
.stop-meta strong { display: block; font-size: 16px; }
.stop-meta span { display: block; margin-top: 7px; color: var(--dim); font: 400 9px/1.5 var(--mono); }
.cargo-list { min-width: 0; }
.cargo-row { display: grid; grid-template-columns: 70px minmax(120px, 1fr) 80px 110px; gap: 14px; align-items: center; min-height: 36px; border-bottom: 1px solid rgba(139, 194, 188, .08); font-size: 12px; }
.cargo-action { color: var(--accent); font: 500 9px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.cargo-action.unload { color: var(--warning); }
.cargo-number { text-align: right; color: var(--muted); font-family: var(--mono); font-size: 10px; }
.no-cargo { color: var(--dim); font-size: 12px; }

.artifact-section { padding: 34px 0; animation: rise .38s .24s ease both; }
.artifact-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 24px; }
.artifact-link { display: inline-flex; align-items: center; min-height: 42px; padding: 0 15px; border: 1px solid var(--line-strong); border-radius: 3px; color: var(--ink); text-decoration: none; font-size: 11px; transition: border-color .16s ease, color .16s ease, transform .16s ease; }
.artifact-link:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.result-message { padding: 26px 0; color: var(--muted); line-height: 1.65; border-bottom: 1px solid var(--line); }
.suggestions { margin: 12px 0 0; color: var(--warning); font-size: 12px; }

.solver-details { padding: 20px 0; color: var(--muted); }
.solver-details summary { cursor: pointer; font: 500 10px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.solver-details pre { overflow: auto; padding: 20px 0; white-space: pre-wrap; color: #9fb8b5; font: 400 11px/1.75 var(--mono); }

footer {
  min-height: 48px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(24px, 4vw, 64px);
  border-top: 1px solid var(--line);
  color: var(--dim);
  font: 400 9px/1.4 var(--mono);
  letter-spacing: .05em;
}

[hidden] { display: none !important; }

@keyframes sail { to { stroke-dashoffset: -180; } }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes search { 0% { transform: translateX(-110%); } 50% { transform: translateX(165%); } 100% { transform: translateX(-110%); } }
@keyframes beacon { 50% { opacity: .35; transform: scale(.82); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .control-rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .field-row.three-up { grid-template-columns: repeat(3, 1fr); }
  .route-workspace { min-height: 700px; }
}

@media (max-width: 640px) {
  .topbar { height: 66px; padding-inline: 18px; }
  .brand small { display: none; }
  .workspace { min-height: calc(100vh - 114px); }
  .control-rail, .route-workspace { padding: 36px 20px; }
  .intro h1 { font-size: 42px; }
  .field-row, .field-row.three-up { grid-template-columns: 1fr; gap: 0; }
  .chart-field { height: 300px; }
  .result-lead { grid-template-columns: 1fr; }
  .result-context { text-align: left; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(3) { border-left: 0; }
  .route-stop { grid-template-columns: 1fr; gap: 16px; padding-left: 32px; }
  .cargo-row { grid-template-columns: 58px 1fr 66px; }
  .cargo-row .cargo-total { display: none; }
  footer { flex-direction: column; }
}

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