:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --line: #2a323d;
  --ink: #e6edf3;
  --muted: #9aa7b4;
  --accent: #f5a623;
  --accent-2: #4ea1ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: 100vh;
  gap: 0;
}

/* ---- left: stage ---- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: radial-gradient(1200px 600px at 40% 0%, #182029 0%, var(--bg) 70%);
}

.stage header {
  padding: 14px 20px 8px;
}
.stage h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.2px;
}
.stage h1 span { color: var(--accent); }
.stage .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

#canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
canvas { display: block; width: 100%; height: 100%; }

/* zone strip under the 3D view */
.strip-wrap { padding: 6px 20px 4px; }
.strip-label {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 11px; margin-bottom: 4px;
}
.strip {
  height: 26px; border-radius: 6px; overflow: hidden;
  display: flex; flex-direction: row-reverse; border: 1px solid var(--line);
  background: repeating-linear-gradient(90deg, #11151b 0 9px, #141a21 9px 10px);
}
.strip .seg {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #0e1116; font-weight: 600;
  white-space: nowrap; overflow: hidden;
}

/* readouts */
.readouts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px 20px 14px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stat .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat .v { font-size: 20px; font-weight: 650; margin-top: 2px; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 500; }

/* feasibility flags */
.flags { padding: 0 20px 16px; display: flex; flex-wrap: wrap; gap: 6px; }
.flag {
  font-size: 11.5px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; gap: 6px;
}
.flag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.flag.good::before { background: var(--good); }
.flag.warn::before { background: var(--warn); }
.flag.bad::before  { background: var(--bad); }
.flag.good { color: #b9f0c4; }
.flag.warn { color: #f0d9a0; }
.flag.bad  { color: #ffc4bf; }

/* ---- right: controls ---- */
.controls {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px;
}
.group { margin-bottom: 18px; }
.group > h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); margin: 0 0 8px;
}

.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.shape-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 8px 4px; cursor: pointer; text-align: center;
  font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: border-color .12s, background .12s;
}
.shape-btn svg { width: 46px; height: 20px; }
.shape-btn:hover { border-color: var(--accent-2); }
.shape-btn.active { border-color: var(--accent); background: #22242099; }
.shape-btn.active svg path { fill: var(--accent); }
.shape-btn svg path { fill: #8aa0b4; }

.field { margin-bottom: 10px; }
.field .row { display: flex; justify-content: space-between; align-items: baseline; }
.field label { font-size: 12.5px; color: var(--ink); }
.field .val { font-size: 12.5px; color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
input[type="range"]:disabled { opacity: .4; }

select, input[type="text"], input[type="number"] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--ink); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}

.seg-control { display: flex; gap: 6px; }
.seg-control button {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  padding: 7px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.seg-control button.active { border-color: var(--accent); color: var(--ink); background: #23241f; }

.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* grip zones */
.zone {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  margin-bottom: 8px; background: var(--panel-2);
}
.zone .zhead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.zone .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.zone .zhead select { flex: 1; }
.zone .del {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px;
  padding: 0 2px; line-height: 1;
}
.zone .del:hover { color: var(--bad); }
.add-zone {
  width: 100%; background: transparent; border: 1px dashed var(--line);
  color: var(--muted); padding: 8px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.add-zone:hover { border-color: var(--accent-2); color: var(--ink); }

.save-bar { position: sticky; bottom: -16px; background: var(--panel); padding: 12px 0 0; margin-top: 8px; }
.btn-primary {
  width: 100%; background: var(--accent); color: #1a1204; border: none;
  padding: 11px; border-radius: 9px; font-weight: 650; font-size: 14px; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.saved-list { margin-top: 10px; }
.saved-item {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px;
  margin-bottom: 5px; font-size: 12px; background: var(--panel-2); cursor: pointer;
}
.saved-item:hover { border-color: var(--accent-2); }
.saved-item .meta { color: var(--muted); }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #1f2937; border: 1px solid var(--line); color: var(--ink);
  padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.bad { border-color: var(--bad); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  #canvas-wrap { min-height: 30vh; }
  .controls { border-left: none; border-top: 1px solid var(--line); }
}
