:root {
  color-scheme: dark;
  --ink: #ece9df;
  --muted: #9a9d91;
  --line: rgba(236, 233, 223, 0.1);
  --panel: rgba(24, 27, 23, 0.94);
  --surface: #111410;
  --accent: #e6a45d;
  --accent-soft: rgba(230, 164, 93, 0.14);
  --green: #859c84;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--surface); color: var(--ink); }

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 10%, rgba(107, 125, 100, 0.14), transparent 37%),
    #111410;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: 76px 1fr; }

.topbar {
  height: 76px;
  padding: 0 22px;
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 20, 16, 0.88);
  backdrop-filter: blur(18px);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand strong { display: block; font-family: Georgia, serif; font-size: 20px; letter-spacing: 0.01em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }

.brand-mark { position: relative; width: 42px; height: 30px; display: flex; align-items: end; gap: 2px; }
.brand-mark i { display: block; width: 7px; height: 7px; background: var(--accent); border-radius: 1px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(4) { transform: translateY(-7px); }
.brand-mark i:nth-child(3) { transform: translateY(-13px); }

.view-tabs { justify-self: center; display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 9px; }
.tab, .button, .icon-button, .segmented button, .stepper button, .swatch {
  border: 0;
  cursor: pointer;
}
.tab { padding: 8px 16px; border-radius: 6px; background: transparent; color: var(--muted); font-size: 12px; }
.tab.active { background: rgba(255,255,255,.08); color: var(--ink); }
.top-actions { justify-self: end; display: flex; gap: 8px; }
.button { padding: 10px 15px; border-radius: 7px; font-size: 12px; }
.button.ghost { background: transparent; border: 1px solid var(--line); }
.button.primary { background: var(--accent); color: #271a0d; font-weight: 750; }

main { min-height: 0; display: grid; grid-template-columns: 300px minmax(420px, 1fr) 286px; }
.panel { background: var(--panel); padding: 25px 22px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #42473f transparent; z-index: 4; }
.controls-panel { border-right: 1px solid var(--line); }
.stats-panel { border-left: 1px solid var(--line); }
.panel-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 26px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: Georgia, serif; font-weight: 500; }
h1 { font-size: 25px; }
h2 { font-size: 23px; }
.icon-button { width: 34px; height: 34px; border-radius: 50%; background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 18px; }
.icon-button:hover { color: var(--ink); border-color: rgba(236,233,223,.25); }

.control-group { padding: 17px 0; border-top: 1px solid var(--line); }
.control-group > label, .control-label label { font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.control-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.control-label p { margin: 5px 0 0; max-width: 190px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.control-label output { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 11px; padding: 3px; background: rgba(0,0,0,.25); border-radius: 7px; }
.segmented button { padding: 8px 4px; border-radius: 5px; background: transparent; color: var(--muted); font-size: 10px; }
.segmented button.active { background: #343831; color: var(--ink); }

input[type="range"] { width: 100%; margin: 16px 0 0; accent-color: var(--accent); height: 3px; }
.range-ends { display: flex; justify-content: space-between; margin-top: 5px; color: #666b62; font-size: 9px; }
.two-up { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; border-top: 1px solid var(--line); }
.two-up .control-group { border: 0; }
.compact > label { display: block; margin-bottom: 10px; }
.stepper { display: grid; grid-template-columns: 30px 1fr 30px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; }
.stepper input { min-width: 0; width: 100%; border: 0; background: rgba(0,0,0,.2); color: var(--ink); text-align: center; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { appearance: none; }
.stepper button { height: 31px; background: #2a2e28; color: var(--muted); font-size: 16px; }
.switch input { position: absolute; opacity: 0; }
.switch span { display: block; width: 32px; height: 18px; padding: 3px; background: #3c4139; border-radius: 20px; transition: .2s; }
.switch span::after { content: ""; display: block; width: 12px; height: 12px; background: #aaa; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); background: #20170e; }
.swatches { display: flex; gap: 10px; margin-top: 12px; }
.swatch { width: 27px; height: 27px; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.swatch.active { outline: 2px solid var(--ink); outline-offset: 3px; }
.custom-controls[hidden] { display: none; }
.add-point-button { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 6px; background: #2a2e28; color: var(--ink); font-size: 10px; cursor: pointer; }
.symmetry-row { display: flex; justify-content: space-between; align-items: center; margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.symmetry-row label { font-size: 11px; font-weight: 700; }
.symmetry-row p { margin: 4px 0 0; color: var(--muted); font-size: 9px; }
.button:disabled { opacity: .38; cursor: not-allowed; }
.tip { display: flex; gap: 11px; margin-top: 12px; padding: 13px; border: 1px solid rgba(230,164,93,.18); background: var(--accent-soft); border-radius: 7px; }
.tip > span { color: var(--accent); }
.tip p { margin: 0; color: #b9b4a7; font-size: 10px; line-height: 1.5; }
.tip strong { display: block; color: var(--ink); font-size: 10px; }

.viewport-wrap { position: relative; min-width: 0; overflow: hidden; background: #151914; }
#glCanvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#glCanvas:active { cursor: grabbing; }
.world-handles { position: absolute; inset: 0; z-index: 3; pointer-events: none; touch-action: none; }
.world-handles[hidden] { display: none; }
#curveHandles { position: absolute; inset: 0; pointer-events: none; }
.curve-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 2px solid #151914;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(230,164,93,.75), 0 3px 10px rgba(0,0,0,.5);
  cursor: grab;
  pointer-events: auto;
  z-index: 2;
}
.curve-handle.endpoint { background: #d9d5c9; }
.curve-handle.selected {
  width: 18px;
  height: 18px;
  background: #f3c084;
  box-shadow: 0 0 0 2px rgba(230,164,93,.45), 0 3px 13px rgba(0,0,0,.65);
}
.curve-handle:active { cursor: grabbing; }
.world-axis {
  position: absolute;
  z-index: 1;
  display: block;
  width: 112px;
  height: 18px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  opacity: .82;
}
.world-axis[hidden] { display: none; }
.world-axis::after { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 2px; border-radius: 2px; transition: height .12s, opacity .12s; }
.x-axis::after { background: linear-gradient(90deg, transparent, #b86f60 22%, #b86f60 78%, transparent); }
.y-axis::after { background: linear-gradient(90deg, transparent, #83a17d 22%, #83a17d 78%, transparent); }
.world-axis:hover::after, .world-axis.active::after { height: 4px; opacity: 1; }
.world-axis:active { cursor: grabbing; }
.world-edit-hint {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(17,20,16,.76);
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .04em;
  pointer-events: none;
}
.point-popover {
  position: absolute;
  z-index: 7;
  width: 210px;
  padding: 14px;
  border: 1px solid rgba(236,233,223,.16);
  border-radius: 9px;
  background: rgba(25,28,24,.97);
  box-shadow: 0 18px 45px rgba(0,0,0,.5);
  backdrop-filter: blur(12px);
}
.point-popover[hidden] { display: none; }
.popover-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px; }
.popover-heading small { display: block; color: var(--accent); font-size: 8px; letter-spacing: .14em; text-transform: uppercase; }
.popover-heading strong { display: block; margin-top: 3px; font: 15px Georgia, serif; }
.popover-heading button { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 4px; background: rgba(255,255,255,.06); color: var(--muted); cursor: pointer; }
.point-popover > label { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--muted); font-size: 9px; }
.point-popover label span { display: flex; align-items: center; gap: 5px; }
.point-popover input { width: 68px; padding: 6px; border: 1px solid var(--line); border-radius: 5px; outline: 0; background: #131612; color: var(--ink); font: 10px ui-monospace, monospace; text-align: right; }
.point-popover input:focus { border-color: var(--accent); }
.point-popover input:disabled { opacity: .45; }
.delete-point-button { width: 100%; margin-top: 13px; padding: 8px; border: 1px solid rgba(190,92,72,.28); border-radius: 5px; background: rgba(190,92,72,.1); color: #d78f7e; font-size: 9px; cursor: pointer; }
.delete-point-button:disabled { opacity: .35; cursor: not-allowed; }
.viewport-fade { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 120px rgba(3,5,3,.45); }
.viewport-info { position: absolute; right: 19px; bottom: 16px; display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 9px; }
.axis-key { display: flex; gap: 3px; }
.axis { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 3px; color: #131613; font-weight: 800; }
.axis.x { background: #b66c5f; } .axis.y { background: #7f9e79; } .axis.z { background: #6e89a5; }
.dimension { position: absolute; display: flex; align-items: center; color: rgba(236,233,223,.52); font: 9px ui-monospace, monospace; pointer-events: none; }
.dimension i { position: relative; display: block; width: 46px; height: 1px; background: rgba(236,233,223,.24); }
.dimension i::after { content: ""; position: absolute; top: -3px; width: 1px; height: 7px; background: rgba(236,233,223,.4); }
.dimension i:first-child::after { left: 0; } .dimension i:last-child::after { right: 0; }
.dimension span { margin: 0 8px; }
.span-dimension { left: 50%; bottom: 64px; transform: translateX(-50%); }
.rise-dimension { top: 46%; right: 30px; transform: rotate(-90deg); }
.webgl-error { position: absolute; inset: 0; display: grid; place-items: center; background: #151914; }
.webgl-error[hidden] { display: none; }

.stats-panel > h2 { margin-bottom: 20px; }
.hero-stat { padding: 19px 0 21px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.hero-stat span { display: block; color: var(--accent); font-family: Georgia, serif; font-size: 43px; line-height: 1; }
.hero-stat small { color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; padding: 12px 0; border-bottom: 1px solid var(--line); }
.stat-grid > div { padding: 11px 0; }
.stat-grid > div:nth-child(even) { padding-left: 18px; border-left: 1px solid var(--line); }
.stat-grid span { display: block; font-family: ui-monospace, monospace; font-size: 13px; }
.stat-grid small { color: var(--muted); font-size: 9px; }
.profile-card { margin-top: 18px; padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.16); }
.card-heading { display: flex; justify-content: space-between; align-items: center; font-size: 10px; }
.card-heading small { color: var(--accent); }
#profileCanvas { width: 100%; height: 105px; margin-top: 7px; }
.legend { padding: 14px 0; border-bottom: 1px solid var(--line); }
.legend > div { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 5px 0; font-size: 10px; }
.legend strong { font-family: ui-monospace, monospace; font-weight: 400; }
.legend-block { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); }
.railing-block { background: #8d6848; }
.build-note { display: flex; gap: 12px; padding-top: 17px; }
.build-note span { color: var(--accent); font: 10px ui-monospace, monospace; }
.build-note p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .view-tabs { display: none; }
  main { grid-template-columns: 270px 1fr; }
  .stats-panel { display: none; }
}

@media (max-width: 700px) {
  body { overflow: auto; }
  .app-shell { display: block; }
  .topbar { position: sticky; top: 0; height: 64px; padding: 0 14px; }
  .brand small, .button.ghost { display: none; }
  main { display: flex; flex-direction: column; }
  .viewport-wrap { order: -1; height: 52vh; min-height: 390px; }
  .controls-panel { overflow: visible; border-right: 0; }
  .panel { width: 100%; }
  .rise-dimension { display: none; }
}
