:root {
  --ink: #c8d0c0;
  --ink-dim: #7d8878;
  --ink-bright: #eef2e6;
  --bg: #05060a;
  --panel: #0a0e0c;
  --panel-elevated: #101612;
  --border: #47513f;
  --border-soft: #2a3228;
  --accent: #c9a227;
  --accent-dim: #8a7020;
  --danger: #a33b2e;
  --ok: #6a9a5a;
  --mono: "Courier New", ui-monospace, monospace;

  color-scheme: dark;
  font-family: var(--mono);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: none;
  font-smooth: never;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr minmax(240px, 300px);
  height: 100vh;
  min-height: 0;
}

/* --- panels --------------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 2px solid var(--border);
  overflow: hidden;
}

.panel--right {
  border-right: none;
  border-left: 2px solid var(--border);
}

.panel__header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.panel__header h1,
.panel__header h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-bright);
}

.panel__sub {
  margin: 0.35rem 0 0;
  font-size: 0.7rem;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}

.panel--left {
  overflow-y: auto;
  overflow-x: hidden;
}

.section {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-soft);
}

.section h2 {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.section--actions {
  padding-bottom: 1.25rem;
}

.hint {
  margin: 0 0 0.65rem;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--ink-dim);
  letter-spacing: 0.03em;
}

.tex-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.tex-card {
  margin: 0;
  padding: 0.35rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border-soft);
}

.tex-card figcaption {
  margin-bottom: 0.3rem;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.tex-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #111;
  image-rendering: pixelated;
}

.tex-card a {
  display: block;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

/* --- form controls -------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.65rem;
  font-size: 0.75rem;
  color: var(--ink-dim);
}

.field span em {
  font-style: normal;
  color: var(--ink-bright);
  float: right;
}

.body-style {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.6rem 0.45rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border-soft);
}

.field--slider {
  margin-bottom: 0.4rem;
}

.slider-ends {
  display: flex;
  justify-content: space-between;
  margin: 0 0 0.1rem;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  opacity: 0.75;
}

.slider-ends i {
  font-style: normal;
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--ink-dim);
}

.btn--ghost:hover {
  border-color: var(--border);
  color: var(--ink);
}

.btn--small {
  align-self: flex-start;
  padding: 0.25rem 0.55rem;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field.grow {
  flex: 1;
  min-width: 0;
}

.row {
  display: flex;
  gap: 0.5rem;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  color: var(--ink-bright);
  font: inherit;
  font-size: 0.8rem;
  outline: none;
}

input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.seg__btn {
  padding: 0.45rem 0.5rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  color: var(--ink-dim);
  font: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.seg__btn:hover {
  color: var(--ink-bright);
  border-color: var(--ink-dim);
}

.seg__btn.is-active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

.part-slot {
  margin-bottom: 0.75rem;
}

.part-slot__label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  padding: 0.28rem 0.45rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border-soft);
  color: var(--ink);
  font: inherit;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--border);
  color: var(--ink-bright);
}

.chip.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(201, 162, 39, 0.1);
}

.chip:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.7rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.color-field input[type="color"] {
  width: 2rem;
  height: 1.6rem;
  padding: 0;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
}

.swatches {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.swatch {
  width: 1.55rem;
  height: 1.55rem;
  border: 2px solid var(--border-soft);
  cursor: pointer;
  padding: 0;
}

.swatch.is-active {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
}

/* --- actions -------------------------------------------------------------- */

.actions {
  display: grid;
  gap: 0.4rem;
}

.btn {
  padding: 0.5rem 0.65rem;
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  color: var(--ink-bright);
  font: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--ink-dim);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: bold;
}

.btn--primary:hover {
  background: #d4b03a;
  border-color: #d4b03a;
}

.btn--accent {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.status {
  min-height: 1.2rem;
  margin: 0.55rem 0 0;
  font-size: 0.68rem;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

.status.is-ok {
  color: var(--ok);
}

.status.is-err {
  color: var(--danger);
}

/* --- stage ---------------------------------------------------------------- */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  /* Fallback while WebGL boots — matches outdoor fog palette. */
  background: linear-gradient(180deg, #6a7a72 0%, #a8a890 42%, #3d4a32 100%);
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.stage__hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  padding: 0.85rem 1rem;
  pointer-events: none;
  background: linear-gradient(transparent, rgba(5, 6, 10, 0.85));
}

.stage__stats {
  font-size: 0.7rem;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
  white-space: pre-line;
  line-height: 1.45;
}

.stage__controls {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  pointer-events: auto;
}

.inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inline select {
  width: auto;
  min-width: 7rem;
}

.checkbox input {
  accent-color: var(--accent);
}

/* --- recipe json ---------------------------------------------------------- */

.panel--right .panel__header {
  flex-shrink: 0;
}

.code {
  flex: 1;
  margin: 0;
  padding: 0.85rem 1rem;
  overflow: auto;
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 1100px) {
  #app {
    grid-template-columns: minmax(260px, 300px) 1fr;
  }

  .panel--right {
    display: none;
  }
}

@media (max-width: 760px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
  }

  .panel--left {
    order: 2;
    border-right: none;
    border-top: 2px solid var(--border);
  }

  .stage {
    order: 1;
  }
}
