:root {
  --ink: #0f0c08;
  --bg: #17130d;
  --panel: #201a11;
  --panel-2: #271f14;
  --text: #ece1ca;
  --muted: #a39274;
  --bronze: #b08d57;
  --bronze-2: #d4b079;
  --hairline: rgba(176, 141, 87, 0.16);
  --side-w: 318px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Albert Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100dvh; }

/* ---------------- Sidebar ---------------- */
.side {
  width: var(--side-w);
  flex: none;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 100%);
  border-right: 1px solid var(--hairline);
  padding: 26px 22px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(176, 141, 87, 0.3) transparent;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-family: 'Marcellus', serif;
  font-size: 22px;
  line-height: 1;
  padding-bottom: 4px;
  color: var(--bronze-2);
  border: 1px solid rgba(176, 141, 87, 0.45);
  outline: 1px solid rgba(176, 141, 87, 0.14);
  outline-offset: 3px;
  border-radius: 2px;
  background: rgba(176, 141, 87, 0.06);
}

.brand-text h1 {
  font-family: 'Marcellus', serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0.32em;
  color: var(--text);
  line-height: 1;
}
.brand-text p {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.group h2 {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bronze);
  padding-bottom: 9px;
  margin-bottom: 13px;
  border-bottom: 1px solid var(--hairline);
}

/* engine cards */
.engine-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }

.engine-card {
  display: flex; flex-direction: column; align-items: stretch; gap: 5px;
  padding: 4px 4px 6px;
  background: rgba(255, 244, 220, 0.025);
  border: 1px solid rgba(176, 141, 87, 0.14);
  border-radius: 6px;
  color: var(--muted);
  font: 500 9.5px 'Albert Sans', sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: center;
}
.engine-card canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  background: #2a2317;
  display: block;
}
.engine-card span {
  display: block;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.engine-card:hover { color: var(--text); border-color: rgba(176, 141, 87, 0.4); }
.engine-card.active {
  color: var(--bronze-2);
  background: rgba(176, 141, 87, 0.12);
  border-color: rgba(176, 141, 87, 0.6);
  box-shadow: inset 0 0 22px rgba(176, 141, 87, 0.07);
}

/* material chips */
.style-row { display: flex; flex-direction: column; gap: 6px; }

.style-chip {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font: 500 12.5px 'Albert Sans', sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: left;
}
.style-chip .swatch {
  width: 22px; height: 22px; flex: none;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: inset -2px -3px 5px rgba(0, 0, 0, 0.25), inset 2px 3px 5px rgba(255, 255, 255, 0.3);
}
.style-chip:hover { color: var(--text); background: rgba(255, 244, 220, 0.03); }
.style-chip.active {
  color: var(--text);
  background: rgba(176, 141, 87, 0.1);
  border-color: rgba(176, 141, 87, 0.4);
}
.style-chip.active::after {
  content: '';
  margin-left: auto;
  width: 5px; height: 5px;
  background: var(--bronze-2);
  transform: rotate(45deg);
}

/* segmented */
.seg {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border: 1px solid rgba(176, 141, 87, 0.22);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 16px;
}
.seg button {
  padding: 8px 0;
  background: transparent;
  border: none;
  border-right: 1px solid rgba(176, 141, 87, 0.14);
  color: var(--muted);
  font: 500 13px 'Marcellus', serif;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg button:last-child { border-right: none; }
.seg button:hover { color: var(--text); }
.seg button.active { background: rgba(176, 141, 87, 0.18); color: var(--bronze-2); }

/* sliders */
.ctl {
  display: grid;
  grid-template-columns: 88px 1fr 30px;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 12.5px;
  color: var(--muted);
}
.ctl output {
  font: 500 11.5px 'Marcellus', serif;
  color: var(--bronze-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, rgba(176, 141, 87, 0.55), rgba(176, 141, 87, 0.18));
  border-radius: 1px;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  margin-top: -5.5px;
  background: var(--panel);
  border: 1.5px solid var(--bronze);
  transform: rotate(45deg);
  border-radius: 2px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
input[type='range']:hover::-webkit-slider-thumb,
input[type='range']:active::-webkit-slider-thumb {
  background: var(--bronze);
  box-shadow: 0 0 9px rgba(176, 141, 87, 0.6);
}
input[type='range']::-moz-range-track {
  height: 2px;
  background: linear-gradient(90deg, rgba(176, 141, 87, 0.55), rgba(176, 141, 87, 0.18));
}
input[type='range']::-moz-range-thumb {
  width: 11px; height: 11px;
  background: var(--panel);
  border: 1.5px solid var(--bronze);
  transform: rotate(45deg);
  border-radius: 2px;
}

/* seed */
.seed-row { display: flex; gap: 8px; }
#seedInput {
  flex: 1;
  min-width: 0;
  background: rgba(255, 244, 220, 0.035);
  border: 1px solid rgba(176, 141, 87, 0.22);
  border-radius: 5px;
  padding: 9px 12px;
  color: var(--bronze-2);
  font: 500 14px 'Marcellus', serif;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}
#seedInput:focus { outline: none; border-color: var(--bronze); }

.hint { margin-top: 9px; font-size: 11px; line-height: 1.5; color: rgba(163, 146, 116, 0.75); }

/* buttons */
.icon-btn {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: rgba(255, 244, 220, 0.035);
  border: 1px solid rgba(176, 141, 87, 0.22);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:hover { color: var(--bronze-2); border-color: rgba(176, 141, 87, 0.5); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.icon-btn svg .f { fill: currentColor; stroke: none; }

.side-actions {
  margin-top: auto;
  padding-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px;
  border-radius: 5px;
  font: 600 12px 'Albert Sans', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.btn svg .f { fill: currentColor; stroke: none; }
.btn.ghost {
  background: transparent;
  border: 1px solid rgba(176, 141, 87, 0.35);
  color: var(--bronze-2);
}
.btn.ghost:hover { background: rgba(176, 141, 87, 0.1); border-color: var(--bronze); }
.btn.solid {
  background: linear-gradient(160deg, #c39c63, #9a7743);
  border: 1px solid rgba(255, 230, 190, 0.25);
  color: #1c150c;
  box-shadow: 0 2px 14px rgba(176, 141, 87, 0.25);
}
.btn.solid:hover { filter: brightness(1.08); box-shadow: 0 3px 20px rgba(176, 141, 87, 0.4); }

/* ---------------- Stage ---------------- */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(110% 90% at 50% 0%, rgba(176, 141, 87, 0.07), transparent 55%),
    radial-gradient(120% 120% at 50% 110%, rgba(0, 0, 0, 0.5), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid rgba(176, 141, 87, 0.1);
}
.menu { display: none; }

.readout {
  display: flex; align-items: center; gap: 12px;
  font-family: 'Marcellus', serif;
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--text);
}
.readout .dot { width: 4px; height: 4px; background: var(--bronze); transform: rotate(45deg); }
.seed-chip {
  font-size: 12.5px;
  letter-spacing: 0.3em;
  color: var(--bronze-2);
  border: 1px solid rgba(176, 141, 87, 0.3);
  border-radius: 4px;
  padding: 4px 9px 3px 12px;
}
.top-rand { margin-left: auto; }

.frame {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3.5vmin, 44px);
}

#panel {
  display: block;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(176, 141, 87, 0.35),
    0 0 0 7px #100d08,
    0 0 0 8px rgba(176, 141, 87, 0.18),
    0 22px 70px rgba(0, 0, 0, 0.65),
    0 6px 22px rgba(0, 0, 0, 0.5);
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.55);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ---------------- Mobile ---------------- */
@media (max-width: 880px) {
  .side {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 72dvh;
    z-index: 50;
    border-right: none;
    border-top: 1px solid rgba(176, 141, 87, 0.3);
    border-radius: 14px 14px 0 0;
    transform: translateY(102%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0.25, 1);
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.6);
  }
  body.drawer-open .side { transform: translateY(0); }
  body.drawer-open .backdrop { display: block; opacity: 1; }

  .side-actions { margin-top: 6px; }
  .menu { display: grid; }
  .readout { font-size: 13.5px; gap: 9px; }
  .top-rand span { display: none; }
  .topbar { padding: 10px 14px; }
  .btn.top-rand { padding: 10px 12px; }
  .brand-mark { width: 44px; height: 44px; font-size: 17px; }
  .brand-text h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
