:root {
  --paper: #e4ddd0;
  --paper-2: #efe8dc;
  --ink: #1c1916;
  --muted: #8a8175;
  --side: #1a1714;
  --side-2: #26211c;
  --line: rgba(255, 244, 230, 0.08);
  --text: #f3eee6;
  --terra: #d85a32;
  --terra-deep: #9a3412;
  --dim: #9a3412;
  --block-60: #7a5138;
  --block-40: #8d6246;
  --block-20: #a07452;
  --pillar: #3f342c;
  --shadow: 0 18px 50px rgba(40, 28, 18, 0.18);
  font-family: "Outfit", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app {
  height: 100vh;
  display: grid;
  grid-template-columns: 308px 1fr;
  min-height: 0;
}

#side {
  min-width: 0;
  background:
    radial-gradient(1200px 400px at -10% -20%, rgba(216, 90, 50, 0.16), transparent 50%),
    var(--side);
  color: var(--text);
  overflow: auto;
  padding: 18px 16px 28px;
  border-right: 1px solid #000;
}
#side h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #c9b8a4;
  font-weight: 600;
}
#side section {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 14px;
}
.brand h1 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 650;
  font-size: 32px;
  margin: 0;
  letter-spacing: -0.03em;
  line-height: 0.9;
}
.brand p { margin: 4px 0 0; color: #c9b8a4; font-size: 13px; }
.mark {
  width: 42px;
  height: 42px;
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.7fr;
  gap: 3px;
  padding: 7px;
  background: #2c241e;
  border-radius: 8px;
  border: 1px solid rgba(255, 236, 214, 0.14);
}
.mark span:nth-child(1) { background: var(--block-60); }
.mark span:nth-child(2) { background: var(--block-40); }
.mark span:nth-child(3) { background: var(--block-20); }

.tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tools button {
  background: var(--side-2);
  color: var(--text);
  border: 1px solid rgba(255, 244, 230, 0.1);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 500;
}
.tools button.on {
  border-color: var(--terra);
  background: #3a261e;
  color: #ffd7c8;
  box-shadow: inset 0 0 0 1px var(--terra);
}
.tools .swatch {
  height: 58px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 16px;
  font-weight: 550;
  letter-spacing: -0.04em;
}
.s60 { background: linear-gradient(#8d6248, var(--block-60)) !important; color: #fff8f2 !important; }
.s40 { background: linear-gradient(#a07858, var(--block-40)) !important; color: #fff8f2 !important; }
.s20 { background: linear-gradient(#b48a68, var(--block-20)) !important; color: #2a1c14 !important; }
.s30 { background: linear-gradient(#c4a07c, #9a6a48) !important; color: #2a1c14 !important; }
.s10 { background: linear-gradient(#e4cbb4, #c4a484) !important; color: #2a1c14 !important; }
.scap { background: linear-gradient(#8ea097, #3e4a44) !important; color: #f4efe6 !important; }
.stup { background: linear-gradient(#5c4e44, var(--pillar)) !important; color: #f3eee6 !important; }
.tools .swatch.on { box-shadow: inset 0 0 0 2px #fff3e6, 0 0 0 1px var(--terra); }

.keys, .note { color: #b3a394; font-size: 12px; line-height: 1.45; margin: 8px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #d9cbbd; position: relative; }
input[type="number"], select {
  background: #100e0c;
  border: 1px solid rgba(255, 244, 230, 0.12);
  border-radius: 7px;
  padding: 7px 8px;
  color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13px;
}
input[type="number"] { width: 100%; padding-right: 28px; }
select { width: 100%; }
#inspectWrap[hidden] { display: none !important; }
.unit {
  position: absolute;
  right: 8px;
  bottom: 8px;
  color: #8d8276;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  pointer-events: none;
}
.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 8px; color: var(--text); font-size: 13px; }
.check input { accent-color: var(--terra); }
.slider { margin-bottom: 8px; }
.slider input[type="range"] { width: 100%; accent-color: var(--terra); }
.slider b {
  font-weight: 550;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  color: #f0d2c4;
}

.seg {
  background: #241f1b;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid rgba(255, 244, 230, 0.06);
}
.seg.head { display: flex; }
.seg .top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.seg .idx {
  font-family: "Fraunces", Georgia, serif;
  font-size: 16px;
}
.seg .meta { color: #e7b2a2; font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 11px; }
.seg .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segDel {
  background: transparent;
  color: #ffb4a8;
  border: 1px solid rgba(255, 140, 120, 0.35);
  border-radius: 7px;
  padding: 2px 8px;
  font-size: 11px;
}
#elevSegs { display: inline-flex; gap: 4px; }

button.ghost, button.danger, .actions button, .paneBar button, .headerBtn {
  border-radius: 8px;
  border: 1px solid rgba(255, 244, 230, 0.14);
  background: #2a241f;
  color: var(--text);
  padding: 8px 10px;
}
.actions { display: flex; flex-direction: column; gap: 6px; }
.actions button { text-align: left; }
#btnFill { background: var(--terra); border-color: #a84324; color: white; font-weight: 600; }
button.danger { background: transparent; color: #ffb4a8; border-color: rgba(255, 140, 120, 0.35); }
button.ghost { width: 100%; margin-top: 4px; background: transparent; }
button:hover { filter: brightness(1.08); }

.mat { background: #141210; margin: 0 -16px; padding: 14px 16px 16px; border-top: 1px solid var(--line); }
#mats, #inspect { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 12.5px; line-height: 1.55; }
.rowline { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed rgba(255,244,230,0.08); padding: 3px 0; }
.rowline b { font-weight: 550; color: #fff; }
.total { margin-top: 8px; color: #ffd0c2; }
.warn { color: #ffb089; margin-top: 6px; }
#inspect .mini { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
#inspect button { margin-top: 6px; }

#work {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}
#elementBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #1a1714;
  color: var(--text);
  border-bottom: 1px solid #000;
}
#elementBar .barLabel {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c9b8a4;
  margin-left: 6px;
}
#toggleSide, #elementBar .histBtn {
  background: #2a241f;
  color: var(--text);
  border: 1px solid rgba(255, 244, 230, 0.16);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
#elementBar .histBtn:disabled {
  opacity: 0.35;
  cursor: default;
}
#elementBar { flex-wrap: wrap; }
#elementBar .swatch {
  width: 52px;
  height: 40px;
  border: 1px solid rgba(255, 244, 230, 0.12);
  border-radius: 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 16px;
  font-weight: 550;
}
#elementBar .swatch.on {
  box-shadow: inset 0 0 0 2px #fff3e6, 0 0 0 1px var(--terra);
}
#elementBar .scap { width: auto; min-width: 64px; padding: 0 12px; }
.subhead { margin: 10px 0 2px; color: #c9b8a4; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.caps { margin-top: 3px; color: #f0e6da; font-size: 12px; }
#app.side-hidden {
  grid-template-columns: 0 1fr;
}
#app.side-hidden #side {
  width: 0;
  visibility: hidden;
  overflow: hidden;
  padding: 0;
  border: 0;
}

#stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(180px, 1.05fr) 8px minmax(220px, 1fr) 34px;
  background: var(--paper);
}
.pane { position: relative; min-height: 0; }
.pane canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#split {
  background: linear-gradient(#d9d0c2, #cfc4b4);
  cursor: row-resize;
  position: relative;
}
#split::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px;
  width: 42px;
  height: 4px;
  transform: translateX(-50%);
  border-radius: 4px;
  background: #8a8175;
}
.paneBar {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  background: rgba(28, 25, 22, 0.88);
  color: var(--text);
  padding: 6px 8px 6px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.paneBar strong { font-family: "Fraunces", Georgia, serif; font-weight: 650; font-size: 16px; }
.paneBar .sub { color: #d9cbbd; font-size: 12px; margin-right: 4px; }
.paneBar button {
  background: transparent;
  border: 1px solid rgba(255,244,230,0.2);
  color: white;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.zoom { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 11px; color: #f0d2c4; min-width: 88px; }
#hint {
  background: #1c1916;
  color: #f0e6da;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 13px;
  letter-spacing: 0.01em;
}
#hint b { color: #ffb089; font-weight: 600; margin-right: 6px; }

@media (max-width: 980px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  #app.side-hidden { grid-template-columns: 1fr; grid-template-rows: 0 1fr; }
  #side { max-height: none; }
  #stage { height: 100vh; }
}
