:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #eef2ea;
  background: #10161a;
  --line: #34434a;
  --panel: #192227;
  --muted: #a6b8b9;
  --gold: #ffd276;
  --mint: #8df2be;
}

* { box-sizing: border-box; }
body { max-width: 1600px; margin: auto; padding: 0 clamp(12px, 3vw, 44px) 24px; }
button { color: inherit; background: #242f35; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-weight: 650; font-size: .79rem; min-width: 44px; min-height: 44px; padding: 6px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: #35444c; border-color: #67808a; }
button:focus-visible, select:focus-visible, canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button[aria-pressed="true"] { color: var(--gold); border-color: #a3854c; background: #382e20; }
button:disabled { color: #a2acad; cursor: default; opacity: .64; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: .92rem; letter-spacing: .02em; }
[hidden] { display: none !important; }

.topbar { display: flex; gap: clamp(12px, 3vw, 38px); min-height: 78px; align-items: center; flex-wrap: wrap; padding: 12px 0; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: #e8b553; border: 1px solid #ffd98a; color: #1c251e; font-size: 1.2rem; box-shadow: inset 0 -4px #b78035; }
h1 { font-size: clamp(1.25rem, 3vw, 2rem); letter-spacing: -.045em; }
.metrics { display: flex; gap: 18px; margin-left: auto; font-variant-numeric: tabular-nums; }
.metrics > div { display: grid; gap: 2px; align-content: center; min-width: 68px; }
.metrics span, .small { color: var(--muted); font-size: .71rem; font-weight: 600; }
.metrics strong { color: var(--mint); font-size: 1.18rem; line-height: 1; }
.run-controls, .view-controls, .edit-controls, .inspect-controls { display: flex; gap: 5px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 288px; align-items: start; gap: 15px; }
.workshop, .panel { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; }
.stage-head, .build-head { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.stage-head { padding: 8px 11px 8px 14px; font-size: .85rem; }
.floor-size { color: var(--muted); font-size: .72rem; margin-left: 6px; white-space: nowrap; }
.running-dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 8px #8df2be77; }
.running-dot.paused { background: var(--gold); box-shadow: none; }
.expansion-controls { display: flex; gap: 5px; flex-wrap: wrap; padding: 0 11px 8px; }
#demo { border-color: #547b73; color: var(--mint); }
.expansion-help { display: grid; gap: 7px; margin: 0 11px 8px; padding: 9px; border: 1px solid #547b73; border-radius: 6px; background: #182b2b; }
.expansion-help p { color: #d7e8df; font-size: .8rem; line-height: 1.45; }
.expansion-help div { display: flex; gap: 5px; justify-content: flex-end; }
.stage { position: relative; min-width: 0; overflow: hidden; border-block: 1px solid var(--line); background: #10191e; }
#floor { display: block; width: 100%; height: clamp(360px, 59vh, 695px); touch-action: none; cursor: crosshair; }
#floor.panning { cursor: grab; }
#floor.dragging { cursor: grabbing; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; position: absolute; left: 8px; bottom: 8px; padding: 5px 8px; background: #11191ef0; border: 1px solid #34434a; border-radius: 5px; color: #c8d3d3; font-size: .68rem; pointer-events: none; }
.legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 2px; }
.iron { background: #b7c5cf; }.copper { background: #f89a68; }.starved { background: #76c7ec; }.blocked { background: #ff9973; }
.toast { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 16px); text-align: center; pointer-events: none; background: #27363d; color: #fff4d9; border: 1px solid #718189; border-radius: 6px; padding: 7px 11px; font-size: .8rem; }
.toast:empty { display: none; }

.build-panel { padding: 10px 11px; }
.build-head { margin-bottom: 8px; }
.edit-controls b { color: var(--gold); }
.tools { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.tool { display: grid; justify-items: center; gap: 1px; padding: 5px 3px; white-space: nowrap; }
.tool canvas { width: 32px; height: 30px; }
.tool span { white-space: normal; overflow-wrap: anywhere; }
.tool small { color: #bdccca; font-size: .68rem; }
.tool.locked small { color: var(--gold); }
.tool-help { font-size: .76rem; color: #c4cfcc; line-height: 1.4; padding: 0 14px 8px; min-height: 1.4em; }
.guide-help { color: var(--gold); font-weight: 650; }

.sidebar { display: grid; gap: 10px; }
.panel { padding: 12px; }
.panel h2 { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 9px; }
.orders { border-top: 2px solid #c0a15f; }
.orders ol { display: grid; gap: 3px; list-style: none; padding: 0; margin: 0; }
.orders li { display: grid; grid-template-columns: 13px minmax(0, 1fr) auto; gap: 6px; align-items: center; min-height: 25px; color: #bfcdcc; font-size: .78rem; }
.orders li.current { color: var(--gold); font-weight: 700; }
.orders li.done .goal-mark { color: var(--mint); }
.goal-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.orders p, .contracts p, .restart p, .bottleneck, .inspection-info { color: var(--muted); font-size: .76rem; line-height: 1.42; }
.orders p { margin: 7px 0; }
.orders h3 { border-top: 1px solid var(--line); padding-top: 9px; margin: 9px 0 5px; color: #d8e4dc; font-size: .79rem; }
.research { border-top: 2px solid #82b7a1; }
.rates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-bottom: 8px; }
.rate { display: grid; gap: 2px; padding: 5px 7px; background: #121b20; border: 1px solid #2e3c43; border-radius: 5px; font-size: .69rem; color: var(--muted); }
.rate strong { font-size: .9rem; color: #e4efeb; font-variant-numeric: tabular-nums; }
.rate span { overflow-wrap: anywhere; }
.inspector { display: grid; gap: 6px; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; font-size: .78rem; }
.purchase-list { display: grid; gap: 5px; }
.purchase-list button { display: flex; justify-content: space-between; align-items: center; text-align: left; }
.purchase-list b { color: var(--gold); font-variant-numeric: tabular-nums; margin-left: 6px; white-space: nowrap; }
.purchase-list button.complete b { color: var(--mint); }
.contracts p, .restart p { margin-bottom: 8px; }
.offer-label { display: grid; gap: 2px; }
.offer-label small { font-size: .7rem; color: var(--muted); font-weight: 500; }
#sort-filter { font: inherit; min-width: 44px; min-height: 44px; max-width: 100%; }
#active-contract { font-size: .8rem; }
#contract-progress { padding-left: 18px; margin: 6px 0 9px; color: var(--muted); }
.restart { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
.save-controls { display: flex; gap: 5px; }
.save-controls button { flex: 1; }
.save-status { font-size: .74rem; color: var(--muted); }
.save-status:empty { display: none; }
dialog { width: min(390px, calc(100% - 28px)); border: 1px solid #52626a; border-radius: 10px; background: #192227; color: inherit; padding: 18px; }
dialog::backdrop { background: #080d11bf; }
dialog p { margin: 10px 0 16px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 7px; }
.danger { border-color: #b47a63; color: #ffc3ac; }
.noscript { margin-top: 10px; }

@media (max-width: 870px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  #floor { height: clamp(320px, 55vh, 530px); }
}
@media (max-width: 510px) {
  .topbar { gap: 8px; }
  .metrics { gap: 8px; }
  .metrics > div { min-width: auto; }
  .brand { gap: 6px; }
  .brand-mark { width: 27px; height: 29px; }
  .run-controls { width: 100%; }
  .run-controls button { flex: 1; }
  .sidebar { grid-template-columns: minmax(0, 1fr); }
  .stage-head { padding-inline: 7px; flex-wrap: wrap; }
  .view-controls { margin-left: auto; }
  #floor { height: clamp(232px, 43vh, 330px); }
  .tools { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .legend { gap: 6px; }
  .edit-controls button { padding-inline: 6px; }
}
