:root {
  color-scheme: dark;
  --bg: #0f1412;
  --panel: #161e1b;
  --panel-2: #1d2925;
  --panel-3: #243430;
  --ink: #edf5e7;
  --muted: #92a499;
  --green: #7fd690;
  --green-deep: #4e9d5d;
  --amber: #efc36c;
  --amber-deep: #b9893f;
  --red: #ee7466;
  --blue: #7fb6d6;
  --violet: #b89edd;
  --line: #2a3a35;
  --line-bright: #3f5751;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(circle at 12% -6%, #1f2d28 0, transparent 38rem),
    radial-gradient(circle at 110% 100%, #1a2a31 0, transparent 42rem),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: 48px;
}
.shell { width: min(1180px, calc(100vw - 24px)); margin: 0 auto; padding: 28px 0 32px; }

.eyebrow, .label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: .72rem;
  font-weight: 800;
}
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }

h1 { font-size: clamp(2.4rem, 6vw, 4.6rem); line-height: .92; margin: 6px 0 14px; }
h2 { margin: 0 0 8px; }
h3 { margin: 0 0 10px; font-size: .92rem; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }

/* ----- intro ----- */
.hero {
  background: linear-gradient(155deg, rgba(36,52,48,.94), rgba(20,28,26,.94));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
}
.promise { max-width: 720px; color: #d2dfd4; font-size: 1.08rem; }
.intro-letter {
  margin: 22px 0 18px;
  border-left: 3px solid var(--amber-deep);
  padding: 4px 16px;
  background: rgba(0,0,0,.18);
  border-radius: 0 12px 12px 0;
  font-family: "Newsreader", "Georgia", serif;
  color: #dbe6dc;
  max-width: 720px;
}
.intro-letter .from, .intro-letter .to { font-family: inherit; margin: 4px 0; color: var(--muted); font-size: .92rem; }
.intro-letter p { margin: 8px 0; line-height: 1.55; }
.intro-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.share-input {
  margin-top: 12px;
  width: min(520px, 100%);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: #0c1411;
  color: var(--ink);
  font-family: ui-monospace, "JetBrains Mono", "Menlo", monospace;
}

button {
  font-family: inherit;
  background: #e5f6d3;
  border: 0;
  color: #132016;
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .08s, background .12s;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary {
  background: #2c3d36;
  color: var(--ink);
  border: 1px solid var(--line-bright);
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 7px 12px;
  font-size: .82rem;
}
button.primary { background: #cfeec0; color: #102016; }
button.small { padding: 6px 12px; font-size: .8rem; }

/* ----- game shell ----- */
.game {
  display: none;
  background: rgba(22, 30, 27, .92);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
  margin-top: 18px;
}
.game.active { display: block; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.shift strong { font-size: 1.55rem; display: block; }
.shift .muted { font-size: .9rem; }
.progress strong { display: block; font-size: 1.05rem; }
.topbar .ghost { margin-left: auto; }

.readout {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.readout > div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}
.readout strong { display: block; font-size: 1.3rem; margin-top: 3px; }
.readout .unit { font-size: .82rem; color: var(--muted); margin-left: 2px; }
.delta-cell strong { color: var(--green); }
.delta-cell.short strong { color: var(--red); }
.delta-cell.met strong { color: var(--green); }

.floor {
  display: grid;
  grid-template-columns: minmax(0,1fr) 340px;
  gap: 16px;
  align-items: start;
}
.graph-pane { display: flex; flex-direction: column; gap: 10px; }

.factory {
  position: relative;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(180deg, #131c19, #101714);
  background-size: 36px 36px;
  overflow: hidden;
}
.factory::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 60px rgba(0,0,0,.55);
  border-radius: 18px;
}

.node {
  position: absolute;
  width: 138px;
  min-height: 88px;
  transform: translate(-50%, -50%);
  background: linear-gradient(150deg, #243530, #1a2622);
  border: 2px solid var(--line-bright);
  border-radius: 14px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  font-family: inherit;
  z-index: 3;
  transition: transform .1s, border-color .1s, box-shadow .12s;
}
.node:hover { transform: translate(-50%, -50%) scale(1.03); border-color: var(--amber); }
.node.selected { border-color: var(--amber); box-shadow: 0 0 0 4px rgba(239,195,108,.18); transform: translate(-50%, -50%) scale(1.03); }
.node.starter {
  border-color: var(--amber);
  box-shadow: 0 0 0 4px rgba(239,195,108,.22), 0 0 24px rgba(239,195,108,.34);
}
.node.starter::after {
  content: "open me";
  position: absolute;
  right: 8px;
  top: -13px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--amber);
  color: #1b1508;
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.node h4 { margin: 0 0 4px; font-size: .92rem; }
.node .kind { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; margin-bottom: 4px; display: block; }
.node .rate { font-weight: 800; color: var(--green); font-size: 1.02rem; }
.node.starved .rate { color: var(--red); }
.node.idle .rate { color: var(--muted); }
.node.source { background: linear-gradient(150deg, #2c3a32, #1c2722); border-color: #3f5750; }
.node.sink { background: linear-gradient(150deg, #2c3a40, #1a2429); border-color: #3e5762; }
.node.buffer { background: linear-gradient(150deg, #322c3a, #1f1a26); border-color: #534162; }
.node.splitter { background: linear-gradient(150deg, #3a322c, #251c18); border-color: #6a5341; }

/* ratio puzzle / mixer nodes have a yellow accent stripe */
.node.mixer::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--amber);
  border-radius: 14px 0 0 14px;
}

.edge {
  position: absolute;
  height: 4px;
  background: #2f4541;
  transform-origin: 0 50%;
  z-index: 1;
  opacity: .55;
  border-radius: 4px;
}
.edge.active { background: var(--green); opacity: .92; box-shadow: 0 0 10px rgba(127,214,144,.35); }
.edge.inactive { background: #2a3835; opacity: .35; }
.edge.starved { background: var(--red); opacity: .65; }
.edge .label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,20,18,.85);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: .68rem;
  color: var(--muted);
  white-space: nowrap;
}

.ratio-bar {
  min-height: 38px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: .86rem;
  color: var(--muted);
}
.ratio-bar .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #1a2521;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
}
.ratio-bar .chip.ok { border-color: var(--green-deep); color: var(--green); }
.ratio-bar .chip.bad { border-color: #6a3e3a; color: var(--red); }

/* ----- panel ----- */
.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.op-card {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.op-eyebrow { margin: 0; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.op-name { margin: 4px 0 6px; font-size: 1rem; }
.op-name strong { color: var(--amber); }
.op-voice { margin: 0; color: #d6e0d8; font-family: "Newsreader", "Georgia", serif; font-style: italic; font-size: .94rem; line-height: 1.45; }
.op-note { margin: 0; padding: 8px 10px; background: rgba(0,0,0,.18); border-left: 2px solid var(--amber-deep); border-radius: 0 8px 8px 0; font-family: "Newsreader", "Georgia", serif; font-style: italic; color: #dbe6dc; font-size: .9rem; }
.stats { display: grid; gap: 4px; color: var(--muted); font-size: .88rem; }
.stats span strong { color: var(--ink); }
.actions { display: grid; gap: 8px; }
.actions button { text-align: left; padding: 9px 12px; }
.hint { color: var(--muted); font-size: .82rem; padding: 6px 0 0; }

/* ----- log + share ----- */
.log-row {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  margin-top: 18px;
}
.log, .share, .cell-end, .finale {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.log ol { margin: 0; padding-left: 22px; color: #d8e0d8; max-height: 160px; overflow-y: auto; }
.log li { margin: 5px 0; font-size: .9rem; }
.share code {
  display: block;
  padding: 8px 10px;
  background: #0d1411;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, "JetBrains Mono", "Menlo", monospace;
  color: var(--green);
  word-break: break-all;
  font-size: .82rem;
  margin: 4px 0 10px;
}

/* ----- cell end ----- */
.cell-end { margin-top: 16px; border-color: var(--amber); }
.cell-end blockquote {
  margin: 12px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--amber);
  font-family: "Newsreader", "Georgia", serif;
  font-style: italic;
  font-size: 1.06rem;
  color: #e4ecdf;
  background: rgba(0,0,0,.18);
  border-radius: 0 10px 10px 0;
}

/* ----- finale ----- */
.finale {
  margin-top: 18px;
  border-color: var(--green-deep);
}
.finale h2 { font-family: "Newsreader", "Georgia", serif; font-size: 1.8rem; }
.finale-summary { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.finale-summary li {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.finale-summary .cell-tag { color: var(--amber); font-weight: 800; }
.finale-summary .lift-tag { color: var(--green); font-weight: 800; }
.finale-summary .lift-tag.short { color: var(--red); }
.finale-epitaph {
  font-family: "Newsreader", "Georgia", serif;
  font-style: italic;
  font-size: 1.12rem;
  padding: 14px 18px;
  border-left: 3px solid var(--green-deep);
  margin: 14px 0;
  background: rgba(0,0,0,.18);
  border-radius: 0 10px 10px 0;
}
.finale-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ----- responsive ----- */
@media (max-width: 940px) {
  .readout { grid-template-columns: repeat(2, 1fr); }
  .floor { grid-template-columns: 1fr; }
  .factory { min-height: 640px; }
  .log-row { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  h1 { font-size: 2.2rem; }
  .node { width: 116px; min-height: 78px; padding: 7px 8px; }
  .node h4 { font-size: .82rem; }
  .node .rate { font-size: .92rem; }
  .topbar { gap: 10px; }
  .topbar .ghost { margin-left: 0; }
  .readout { grid-template-columns: repeat(2, 1fr); }
  .factory { min-height: 720px; }
}
