:root {
  --sky-top: #5c94fc;
  --sky-bottom: #a8d8ff;
  --ink: #1d1d2b;
  --muted: #5a5f73;
  --card: #fffdf6;
  --card-edge: #1d1d2b;
  --accent: #e52521;
  --gold: #ffd23f;
  --gold-dark: #c9900c;
  --grass: #4caf3c;
  --brick: #c8602a;
  --shadow: 4px 4px 0 rgba(29, 29, 43, 0.85);
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(var(--sky-top), var(--sky-bottom) 520px, #d9f0ff 900px);
  background-color: #d9f0ff;
  line-height: 1.5;
}

a { color: #1747b5; font-weight: 700; }

h1, h2, h3 { font-family: var(--pixel); font-weight: 400; line-height: 1.4; margin: 0 0 12px; }
h2 { font-size: 13px; }
h3 { font-size: 11px; }
.small, small { font-size: 12.5px; color: var(--muted); }
.hidden { display: none !important; }

/* ------------------------------------------------------------ header */
.sky {
  position: relative;
  overflow: hidden;
  padding: 44px 16px 28px;
  text-align: center;
  color: #fff;
}
.hero { position: relative; max-width: 860px; margin: 0 auto; }
.hero h1 {
  font-size: clamp(18px, 4vw, 34px);
  text-shadow: 3px 3px 0 #1d1d2b;
  letter-spacing: 1px;
}
.tagline { font-size: 17px; margin: 0 auto 8px; text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35); }
.hint {
  display: inline-block;
  margin: 6px 0 0;
  padding: 6px 12px;
  background: rgba(29, 29, 43, 0.35);
  border-radius: 6px;
  font-weight: 700;
}

.cloud {
  position: absolute;
  width: 120px; height: 36px;
  background: #fff;
  border-radius: 40px;
  opacity: 0.9;
  animation: drift 60s linear infinite;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 54px; height: 54px; top: -26px; left: 18px; }
.cloud::after { width: 40px; height: 40px; top: -18px; left: 60px; }
.c1 { top: 30px; left: -140px; }
.c2 { top: 110px; left: -140px; animation-delay: -25s; transform: scale(0.7); }
.c3 { top: 60px; left: -140px; animation-delay: -45s; transform: scale(1.2); }
@keyframes drift { to { left: 110%; } }
@media (prefers-reduced-motion: reduce) { .cloud { animation: none; display: none; } }

/* ------------------------------------------------------------ layout */
main { max-width: 1560px; margin: 0 auto; padding: 0 16px 32px; }

.card {
  background: var(--card);
  border: 3px solid var(--card-edge);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.sim {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 1260px) {
  .sim { grid-template-columns: 250px minmax(0, 1fr); }
  .stats { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .sim { grid-template-columns: minmax(0, 1fr); }
  .stage { order: -1; }
}

/* ------------------------------------------------------------ controls */
.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: 14px; }
.field > span { display: flex; justify-content: space-between; margin-bottom: 2px; }
.field output { font-family: var(--pixel); font-size: 10px; background: var(--ink); color: var(--gold); padding: 3px 6px; border-radius: 4px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.seed { display: flex; align-items: center; gap: 8px; }
.seed label { flex: 0 0 auto; }
.seed input { flex: 1; min-width: 0; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 6px; font: inherit; }

.segmented { display: flex; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 6px 4px; cursor: pointer; font-size: 13px; }
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: -3px; }

details { margin: 4px 0 14px; font-size: 14px; }
summary { cursor: pointer; font-weight: 700; margin-bottom: 8px; }

/* ------------------------------------------------------------ buttons */
.btn, .tool {
  font: 700 14px var(--body);
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.05s;
}
.btn:hover, .tool:hover { background: #fff6d6; }
.btn:active, .tool:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn:focus-visible, .tool:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary {
  background: var(--gold);
  border-color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink), inset -3px -3px 0 var(--gold-dark);
}
.btn.primary:hover { background: #ffe066; }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.btn.small { padding: 4px 8px; }
.btn.icon { width: 42px; padding: 7px 0; font-size: 16px; }

/* ------------------------------------------------------------ stage */
.stage { padding: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.speed { display: flex; align-items: center; gap: 8px; margin-left: auto; font-weight: 700; font-size: 14px; }
.speed input { width: 130px; }
.speed output { font-family: var(--pixel); font-size: 10px; min-width: 38px; }

.tools { padding: 8px; background: #eef7ff; border: 2px dashed #8fb8e0; border-radius: 8px; }
.tools-label { font-weight: 700; font-size: 13px; color: var(--muted); }
.tool { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; font-size: 13px; }
.tool.active { background: var(--ink); color: #fff; }
.tool.once { background: #ffe1e1; }
.tool.once:hover { background: #ffc9c9; }

.map-wrap { position: relative; border: 3px solid var(--ink); border-radius: 6px; overflow: hidden; background: #7fcf5c; }
#map { display: block; width: 100%; height: auto; image-rendering: pixelated; cursor: pointer; }
#map.placing { cursor: crosshair; }

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(29, 29, 43, 0.72);
  color: #fff;
  text-align: center;
  padding: 16px;
}
.overlay .small { color: #d8dcef; max-width: 420px; }
#loading-text { font-family: var(--pixel); font-size: 12px; line-height: 1.8; }
.bounce { animation: bounce 0.6s ease-in-out infinite alternate; }
@keyframes bounce { to { transform: translateY(-14px); } }

.summary-card {
  background: var(--card);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 18px;
  max-width: 560px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
}
.summary-card h3 { font-size: 13px; }
.summary-card .small { color: var(--muted); }
.summary-card table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 8px; }
.summary-card th, .summary-card td { padding: 5px 8px; border-bottom: 1px solid #e3dccb; text-align: right; }
.summary-card th:first-child, .summary-card td:first-child { text-align: left; }
.summary-card th { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.toast {
  position: absolute; left: 50%; bottom: 14px;
  transform: translate(-50%, 20px);
  background: var(--ink); color: #fff;
  padding: 8px 14px; border-radius: 8px;
  font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: 12px 0 6px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.toggles { display: flex; flex-wrap: wrap; gap: 16px; font-size: 14px; font-weight: 600; }

.ico { display: inline-block; width: 20px; height: 20px; flex: 0 0 auto; }
.ico canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.ico.big { width: 48px; height: 48px; }

.swatch { display: inline-block; width: 20px; height: 20px; border-radius: 50%; }
.swatch.sparkle { border: 3px solid #ffdd00; box-shadow: 0 0 6px #ffdd00; }
.swatch.aura { background: conic-gradient(#ff3d3d, #ffd23f, #3ddc84, #4cc9f0, #ff3d3d); opacity: 0.8; }
.swatch.line { height: 0; border-radius: 0; border-top: 3px solid; }
.swatch.line.plan { border-top: 3px dashed #8a8a8a; }
.swatch.line.yield { border-color: #ff9f1c; }
.swatch.line.bid { border-color: #9b5de5; }
.swatch.line.down { border-color: #ff3b3b; }

/* ------------------------------------------------------------ stats */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 10px; }
.kpis div { background: #f1ede1; border-radius: 8px; padding: 6px 10px; }
.kpis dt { font-size: 12px; color: var(--muted); font-weight: 700; }
.kpis dd { margin: 0; font-family: var(--pixel); font-size: 13px; }

.progress { height: 12px; border: 2px solid var(--ink); border-radius: 6px; overflow: hidden; background: #fff; margin-bottom: 12px; }
#progress-bar { height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--gold), var(--gold) 6px, #ffc21a 6px, #ffc21a 12px); transition: width 0.2s; }

.impact { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.impact div { display: flex; flex-direction: column; align-items: flex-start; font-size: 12px; color: var(--muted); font-weight: 700; line-height: 1.3; }
.big-num { font-family: var(--pixel); font-size: 18px; color: var(--accent); margin-bottom: 6px; }

.robot-info { display: flex; gap: 10px; align-items: flex-start; background: #eef7ff; border: 2px solid #8fb8e0; border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; font-size: 14px; }
.robot-info .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); margin-top: 3px; flex: 0 0 auto; }

.events { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow-y: auto; font-size: 13.5px; }
.events li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 2px; border-bottom: 1px dashed #d8d0bb; }
.events li small { display: block; }
.events li.quiet { opacity: 0.6; }
.events li.empty { color: var(--muted); }
.tag { font-size: 11px; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 4px; font-weight: 800; }

/* ------------------------------------------------------------ tabs */
.tabs {
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  max-width: 1560px; margin: 0 auto 20px; padding: 0 16px;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  font: 400 12px var(--pixel);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}
.tab:hover { background: #fff6d6; }
.tab.active { background: var(--gold); box-shadow: 3px 3px 0 var(--ink), inset -3px -3px 0 var(--gold-dark); }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tab .ico { width: 22px; height: 22px; }
.cta-row { text-align: center; margin: 28px 0 0; }

/* ------------------------------------------------------------ ours / baseline labels */
.badge {
  display: inline-block;
  font: 800 10.5px var(--body);
  font-style: normal;
  letter-spacing: 0.3px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: 1px;
}
.badge.ours { background: var(--gold); color: var(--ink); border: 1.5px solid var(--ink); }
.badge.base { background: #dfe3ec; color: #3d4356; border: 1.5px solid #8b92a8; }
.planner span { display: flex; flex-direction: column; align-items: center; gap: 3px; line-height: 1.2; }
.planner .badge { margin-left: 0; }
.segmented input:checked + span .badge.base { background: #fff; }
.planner-note { display: block; margin-top: 6px; line-height: 1.35; }

.mode-badge {
  font-weight: 800; font-size: 13px;
  padding: 6px 10px; border-radius: 8px; border: 2px solid var(--ink);
}
.mode-badge.ours { background: var(--gold); }
.mode-badge.base { background: #dfe3ec; color: #3d4356; border-color: #8b92a8; }
@media (max-width: 1260px) { .mode-badge { order: 10; } }

/* ------------------------------------------------------------ approach tab */
.approach h2 { font-size: 13px; }
.section-title { font-size: 15px !important; margin: 36px 0 14px; }
.approach p { margin: 0 0 10px; }
.approach p:last-child { margin-bottom: 0; }
.lead { max-width: 900px; }
.small-lead { margin-top: 12px !important; color: var(--muted); }

.intro { display: flex; gap: 18px; align-items: flex-start; font-size: 16px; }
.intro .ico.big { width: 64px; height: 64px; }

.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: stretch; }
.side { position: relative; padding-top: 22px; }
.side h3 { font-size: 13px; }
.ours-card { border-color: var(--ink); background: #fff8d9; box-shadow: 4px 4px 0 var(--gold-dark); }
.base-card { background: #f3f4f8; }
.big-badge { position: absolute; top: -14px; left: 14px; margin: 0; font-size: 12px; padding: 3px 10px; }
.vs { align-self: center; font: 400 18px var(--pixel); color: #fff; text-shadow: 3px 3px 0 var(--ink); }
.ticks, .crosses { list-style: none; padding: 0; margin: 0 0 12px; }
.ticks li, .crosses li { position: relative; padding-left: 26px; margin-bottom: 6px; }
.ticks li::before { content: "✔"; position: absolute; left: 0; color: #1f8a2e; font-weight: 800; }
.crosses li::before { content: "✖"; position: absolute; left: 0; color: #b3261e; font-weight: 800; }
.verdict { font-weight: 800; padding: 8px 10px; border-radius: 8px; background: #e6e8ef; }
.verdict.good { background: var(--gold); }
@media (max-width: 820px) {
  .versus { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
  .intro { flex-direction: column; }
}

.pipeline {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px;
}
.pipeline li { position: relative; text-align: center; padding-top: 22px; }
.pipeline li:not(:last-child)::after {
  content: "▶"; position: absolute; right: -14px; top: 50%;
  transform: translate(50%, -50%); color: var(--ink); font-size: 14px; z-index: 1;
}
.pipeline .num {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; border: 2px solid var(--ink);
  font: 400 11px/24px var(--pixel);
}
.pipeline h3 { margin-top: 6px; }
.pipeline p { font-size: 14px; }
@media (max-width: 1000px) {
  .pipeline { grid-template-columns: 1fr 1fr; row-gap: 26px; }
  .pipeline li::after { display: none; }
}
@media (max-width: 520px) { .pipeline { grid-template-columns: 1fr; } }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 36px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.bdi { margin: 0 0 10px; }
.bdi div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px dashed #d8d0bb; }
.bdi dt { font-family: var(--pixel); font-size: 10px; padding-top: 4px; color: var(--accent); }
.bdi dd { margin: 0; }

.flaws { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.flaw p { font-size: 14.5px; }

.ladder { display: grid; gap: 14px; }
.rung { display: flex; gap: 16px; align-items: flex-start; }
.rung.r2 { margin-left: 6%; }
.rung.r3 { margin-left: 12%; }
.rung-num {
  flex: 0 0 auto; width: 48px; height: 48px;
  display: grid; place-items: center;
  font: 400 18px var(--pixel); color: var(--ink);
  background: var(--gold); border: 3px solid var(--ink); border-radius: 6px;
  box-shadow: inset -4px -4px 0 var(--gold-dark);
}
.r2 .rung-num { background: #ffb347; box-shadow: inset -4px -4px 0 #c97a10; }
.r3 .rung-num { background: #ff7a6b; box-shadow: inset -4px -4px 0 #c0392b; }
.cost { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 0 !important; }
.cost span { font-size: 12.5px; font-weight: 800; background: #f1ede1; border-radius: 6px; padding: 3px 8px; }
@media (max-width: 700px) { .rung.r2, .rung.r3 { margin-left: 0; } }

.priority { list-style: none; counter-reset: p; padding: 0; margin: 0 0 12px; }
.priority li {
  display: grid; grid-template-columns: 28px 24px auto 1fr; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px dashed #d8d0bb;
}
.priority li::before {
  counter-increment: p; content: counter(p);
  font: 400 10px var(--pixel); color: #fff; background: var(--ink);
  width: 22px; height: 22px; border-radius: 4px; display: grid; place-items: center;
}
.priority small { justify-self: start; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-top: 16px; }
.kpi { display: flex; flex-direction: column; gap: 4px; font-weight: 700; color: var(--muted); }
.table-card { overflow-x: auto; padding: 8px; }
.results { width: 100%; border-collapse: collapse; font-size: 15px; min-width: 520px; }
.results th, .results td { padding: 8px 12px; text-align: center; border-bottom: 1px solid #e3dccb; }
.results th { font-size: 14px; }
.results b { color: #1747b5; }

/* ------------------------------------------------------------ team */
.team { margin-top: 12px; }
.team-grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px;
}
.member { display: flex; align-items: center; gap: 14px; }
.member .ico.big { width: 56px; height: 56px; }
.member b { display: block; font-size: 17px; }
.roll { font: 400 11px var(--pixel); color: var(--accent); letter-spacing: 0.5px; }

/* ------------------------------------------------------------ footer */
.ground {
  margin-top: 40px;
  padding: 56px 16px 24px;
  color: #fff;
  text-align: center;
  background:
    linear-gradient(#4caf3c 0 14px, transparent 14px),
    repeating-linear-gradient(90deg, transparent 0 46px, #5a2a10 46px 48px),
    repeating-linear-gradient(0deg, #c8602a 0 22px, #5a2a10 22px 24px);
}
.ground p { margin: 4px auto; max-width: 900px; text-shadow: 1px 1px 0 #3a1a08; font-weight: 600; }
.ground a { color: var(--gold); }
.ground .small { color: #ffe9d6; }
