:root {
  --birch: #e7dcc6;        /* panel surface */
  --birch-hi: #f1e9d9;     /* inputs, raised surfaces */
  --birch-lo: #d6c7aa;     /* ply core layer */
  --kerf: #6b4a2e;         /* burnt laser edge: borders, focus */
  --ink: #26231f;
  --ink-soft: #5d554a;
  --cut: #e8412c;          /* LightBurn cut layer */
  --engrave: #2f5bd8;      /* LightBurn engrave layer */
  --night: #2a2e35;        /* the wall in a dark room */
  --night-lo: #1d2026;
  --led: #ffc56b;
  --ok: #3f7d4f;
  --rail-w: 344px;
  --radius-s: 4px;
  --radius-m: 8px;
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background: var(--birch);
  font-size: 15px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--birch); display: flex; flex-direction: column; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--kerf); outline-offset: 2px; }
code { font-size: .92em; background: var(--birch-hi); padding: 0 .3em; border-radius: 3px; }

/* --- the plywood edge: thin laminations, used as the one divider motif ---- */
.ply {
  height: 6px;
  background: repeating-linear-gradient(180deg,
    var(--birch-lo) 0 1px, var(--birch-hi) 1px 2px, #cdbb98 2px 3px);
}

/* --- top bar --------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--birch-lo);
  box-shadow: 0 1px 0 var(--birch-hi) inset;
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-word {
  position: relative; font-weight: 800; font-size: 22px; letter-spacing: -.02em;
}
/* the wordmark throws its own projected shadow, like the lamp does */
.brand-word::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0; z-index: -1;
  color: rgba(38, 35, 31, .28);
  transform-origin: 50% 100%;
  transform: translate(10px, 3px) skewX(-38deg) scaleY(.62);
  filter: blur(.6px);
}
.brand-sub { font-weight: 500; color: var(--ink-soft); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status { color: var(--ink-soft); font-size: 14px; }

.btn {
  border: 1px solid var(--kerf); background: var(--birch-hi);
  padding: 7px 14px; border-radius: var(--radius-s); cursor: pointer; font-weight: 600;
}
.btn:hover:not(:disabled) { background: #fff8ec; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--birch-hi); border-color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: #3a352e; }
.btn-primary.dirty { box-shadow: 0 0 0 3px rgba(255, 197, 107, .9); }

.download { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 250px;
  background: var(--birch-hi); border: 1px solid var(--kerf); border-radius: var(--radius-m);
  padding: 6px; box-shadow: 0 10px 30px rgba(38, 35, 31, .18);
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: var(--radius-s); cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--birch); }
.menu small { display: block; color: var(--ink-soft); }

/* --- workspace --------------------------------------------------------------- */
.workspace {
  flex: 1; display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 0;
  height: calc(100vh - 57px);
}
.rail {
  overflow-y: auto; padding: 14px 16px 30px; border-right: 1px solid var(--birch-lo);
}
.rail-foot { color: var(--ink-soft); font-size: 13px; margin: 18px 2px 0; }

.group { margin-bottom: 4px; }
.group h2 { margin: 0; font-size: 15px; }
.group-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: none; border: 0; padding: 12px 2px 10px; cursor: pointer; font-weight: 600;
  font-size: 15px;
}
.group-head::after {
  content: ""; width: 8px; height: 8px; border-right: 2px solid var(--kerf);
  border-bottom: 2px solid var(--kerf); transform: rotate(45deg) translateY(-2px);
  transition: transform .15s;
}
.group-head[aria-expanded="false"]::after { transform: rotate(-45deg); }
.group + .group::before, #groups .group::before {
  content: ""; display: block; height: 6px;
  background: repeating-linear-gradient(180deg,
    var(--birch-lo) 0 1px, var(--birch-hi) 1px 2px, #cdbb98 2px 3px);
  border-radius: 1px; opacity: .8;
}
.group-body { padding: 2px 2px 12px; display: grid; gap: 12px; }
.group-body[hidden] { display: none; }

.field { display: grid; gap: 4px; }
.field-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field label, .field .label { font-weight: 500; font-size: 14px; }
.field .help { color: var(--ink-soft); font-size: 12.5px; line-height: 1.35; }
.field .err { color: #a3261a; font-size: 12.5px; }
.num-row { display: grid; grid-template-columns: 1fr 92px; gap: 10px; align-items: center; }
.num {
  display: flex; align-items: center; border: 1px solid var(--birch-lo); border-radius: var(--radius-s);
  background: var(--birch-hi); padding-right: 8px;
}
.num input { font-variant-numeric: tabular-nums; }
.num input {
  width: 100%; border: 0; background: none; padding: 5px 4px 5px 8px; text-align: right;
}
.num input:focus { outline: none; }
.num:focus-within { border-color: var(--kerf); box-shadow: 0 0 0 1px var(--kerf); }
.num span { color: var(--ink-soft); font-size: 12.5px; padding-left: 2px; }
input[type="range"] { width: 100%; accent-color: var(--kerf); }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair .num-row { grid-template-columns: 1fr; }
.pair input[type="range"] { display: none; }

.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { appearance: none; width: 36px; height: 20px; border-radius: 10px;
  background: var(--birch-lo); position: relative; cursor: pointer; flex: none; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--birch-hi); transition: left .15s; }
.toggle input:checked { background: var(--kerf); }
.toggle input:checked::after { left: 18px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border: 1px solid var(--kerf); border-radius: var(--radius-s); overflow: hidden; }
.segmented button { border: 0; background: var(--birch-hi); padding: 7px 6px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--kerf); }
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--birch-hi); font-weight: 600; }

.drop {
  display: grid; gap: 4px; padding: 18px 14px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--kerf); border-radius: var(--radius-m); background: var(--birch-hi);
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within { box-shadow: 0 0 0 2px var(--kerf); }
.drop.over { background: #fff8ec; }
.drop-title { font-weight: 600; overflow-wrap: anywhere; }
.drop-hint { color: var(--ink-soft); font-size: 12.5px; }
.examples { margin: 0; font-size: 13.5px; color: var(--ink-soft); }
.examples button { border: 0; background: none; color: var(--ink); text-decoration: underline;
  text-underline-offset: 2px; cursor: pointer; padding: 0 2px; }

/* --- stage: the wall in a dark room ------------------------------------------ */
.stage-wrap { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0;
  background: var(--night-lo); }
.tabs { display: flex; gap: 2px; padding: 10px 16px 0; background: var(--night-lo); }
.tab { border: 0; background: none; color: #b9b2a6; padding: 9px 14px; cursor: pointer;
  border-radius: var(--radius-s) var(--radius-s) 0 0; font-weight: 500; }
.tab[aria-selected="true"] { background: var(--night); color: #f3ebdc; }
.tab:hover { color: #f3ebdc; }
.stage {
  position: relative; min-height: 0; overflow: auto; padding: 16px;
  background: radial-gradient(ellipse at 50% 45%, #3a3a3a 0, var(--night) 55%, var(--night-lo) 100%);
  color: #e9e1d2;
}
.view { height: 100%; display: flex; flex-direction: column; gap: 12px; }
.view[hidden] { display: none; }
.wall-fig, .panels-fig { margin: 0; flex: 1; min-height: 0; display: grid; place-items: center; }
.wall-fig img { max-width: 100%; max-height: calc(100vh - 290px); border-radius: var(--radius-s);
  image-rendering: auto; }
.wall-fig figcaption { color: #b9b2a6; font-size: 13px; margin-top: 8px; max-width: 70ch; text-align: center; }
.panels-fig img { max-width: 100%; background: #fff; border-radius: var(--radius-s); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid #5c574f; background: transparent; color: #d8d0c2; padding: 5px 12px;
  border-radius: 999px; cursor: pointer; font-size: 13.5px; }
.seg button[aria-checked="true"] { background: var(--led); border-color: var(--led); color: var(--ink); font-weight: 600; }
.three { flex: 1; min-height: 420px; border-radius: var(--radius-s); overflow: hidden; }
.hint { margin: 0; color: #b9b2a6; font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; list-style: none; margin: 0; padding: 0;
  font-size: 13px; color: #d8d0c2; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; background: var(--c);
  margin-right: 6px; vertical-align: -1px; }
.sheets { display: grid; gap: 16px; }
.sheets .sheet { background: #fff; border-radius: var(--radius-s); padding: 8px; }
.sheets .sheet svg { width: 100%; height: auto; display: block; max-height: calc(100vh - 280px); }
.sheets h3 { margin: 0 0 6px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }

.empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 18px;
  text-align: center; color: #cfc7b8; }
.empty p { margin: 0; max-width: 34ch; font-size: 16px; }
.empty-lamp { width: 78px; height: 78px; border-radius: 6px; background: #4a4136; position: relative;
  box-shadow: 0 0 0 1px #6b5a45 inset, 0 0 90px 30px rgba(255, 197, 107, .18); }
.empty-lamp::after { content: ""; position: absolute; inset: 33px; border-radius: 50%; background: var(--led);
  box-shadow: 0 0 18px 6px rgba(255, 197, 107, .8); }

.busy { position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(29, 32, 38, .55); backdrop-filter: blur(1px); }
.busy span { background: var(--night-lo); color: #f3ebdc; padding: 10px 18px; border-radius: 999px;
  border: 1px solid #5c574f; }
.busy span::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 10px;
  border-radius: 50%; background: var(--led); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* --- results strip -------------------------------------------------------- */
.results { background: var(--birch); color: var(--ink); padding: 12px 20px 14px;
  border-top: 1px solid var(--birch-lo); display: grid; gap: 8px; }
.metrics { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.metrics div { display: grid; }
.metrics dt { font-size: 12.5px; color: var(--ink-soft); }
.metrics dd { margin: 0; font-weight: 600; font-size: 17px; }
.metrics dd small { font-weight: 400; font-size: 12.5px; color: var(--ink-soft); }
.warnings { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 13.5px; }
.warnings li { padding-left: 18px; position: relative; }
.warnings li::before { content: ""; position: absolute; left: 3px; top: .5em; width: 8px; height: 8px;
  border-radius: 50%; background: var(--cut); }
.warnings li.good::before { background: var(--ok); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--birch-hi); padding: 10px 16px; border-radius: var(--radius-m);
  max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(0,0,0,.3); }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .rail { border-right: 0; border-bottom: 1px solid var(--birch-lo); max-height: none; }
  .stage { min-height: 70vh; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .wall-fig img { max-height: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
