:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #141111;
  color: #f7efe2;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: #141111;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid rgba(247, 239, 226, 0.18);
  border-radius: 8px;
  color: #f7efe2;
  background: #231d1d;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: #22d3ee;
  outline: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid rgba(247, 239, 226, 0.12);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid #ffd000;
  border-radius: 8px;
  color: #17110f;
  background: #ffd000;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 2vw, 1.85rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: rgba(247, 239, 226, 0.65);
  font-size: 0.88rem;
}

.exports {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.exports button {
  min-width: 58px;
  padding: 0 14px;
  font-weight: 800;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.25fr) minmax(200px, 1.25fr) auto minmax(150px, 0.8fr) minmax(150px, 0.8fr);
  gap: 12px;
  align-items: end;
  padding: 14px 24px;
  border-bottom: 1px solid rgba(247, 239, 226, 0.12);
  background: #191515;
}

label,
.segments {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

label span,
legend {
  color: rgba(247, 239, 226, 0.66);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

label b {
  color: #f7efe2;
  font-weight: 800;
}

input[type="text"],
input:not([type]) {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(247, 239, 226, 0.16);
  border-radius: 8px;
  padding: 0 12px;
  color: #f7efe2;
  background: #0f0d0d;
  font-weight: 760;
}

input[type="range"] {
  width: 100%;
  accent-color: #22d3ee;
}

.seed-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.seed-row button {
  color: #17110f;
  background: #bef264;
  border-color: #bef264;
  font-size: 1.25rem;
  font-weight: 900;
}

.segments {
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  align-items: end;
}

.segments legend {
  grid-column: 1 / -1;
}

.segments button {
  padding: 0 12px;
}

.segments button.is-active {
  color: #17110f;
  background: #22d3ee;
  border-color: #22d3ee;
  font-weight: 900;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}

.stage {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  background: #f7efe2;
}

#pieceCanvas {
  display: block;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 420px;
  border: 1px solid rgba(20, 17, 17, 0.18);
  border-radius: 8px;
  background: #fff7ed;
}

.inspector {
  display: grid;
  grid-template-rows: auto 220px auto auto auto 1fr;
  gap: 14px;
  min-height: 0;
  padding: 18px;
  border-left: 1px solid rgba(247, 239, 226, 0.12);
  background: #171313;
}

.inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

.badge {
  border: 1px solid rgba(247, 239, 226, 0.14);
  border-radius: 999px;
  padding: 6px 10px;
  color: #17110f;
  background: #bef264;
  font-size: 0.75rem;
  font-weight: 900;
  white-space: nowrap;
}

.badge[data-state="warn"] {
  background: #fb7185;
}

#meshCanvas {
  display: block;
  width: 100%;
  height: 220px;
  border: 1px solid rgba(247, 239, 226, 0.14);
  border-radius: 8px;
  background: #141111;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  border-bottom: 1px solid rgba(247, 239, 226, 0.1);
}

.metric span {
  color: rgba(247, 239, 226, 0.62);
  font-size: 0.82rem;
}

.metric strong {
  text-align: right;
  font-size: 0.9rem;
}

.messages {
  min-height: 0;
  margin: 0;
  padding: 0 0 0 18px;
  color: rgba(247, 239, 226, 0.72);
  font-size: 0.86rem;
  line-height: 1.45;
}

.panel {
  display: grid;
  gap: 8px;
}

h3 {
  color: rgba(247, 239, 226, 0.7);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.variation-rack {
  display: grid;
  gap: 8px;
}

.variation-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  width: 100%;
  min-height: 54px;
  padding: 9px 10px;
  text-align: left;
}

.variation-card strong {
  color: #bef264;
  font-size: 0.9rem;
}

.variation-card span {
  overflow: hidden;
  color: #f7efe2;
  font-size: 0.82rem;
  font-weight: 780;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variation-card small {
  grid-column: 1 / -1;
  color: rgba(247, 239, 226, 0.58);
  font-size: 0.74rem;
}

.variation-card[data-active="true"],
.variation-card:hover {
  border-color: #ffd000;
}

.variation-card[data-state="warn"] strong {
  color: #fb7185;
}

.layer-list {
  display: grid;
  max-height: 144px;
  overflow: auto;
  border: 1px solid rgba(247, 239, 226, 0.1);
  border-radius: 8px;
}

.layer-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 0 9px;
  border-bottom: 1px solid rgba(247, 239, 226, 0.08);
  color: rgba(247, 239, 226, 0.7);
  font-size: 0.78rem;
}

.layer-row:last-child {
  border-bottom: 0;
}

.layer-row strong {
  color: #22d3ee;
  font-size: 0.9rem;
}

@media (max-width: 1040px) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segments {
    grid-column: 1 / -1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .inspector {
    border-top: 1px solid rgba(247, 239, 226, 0.12);
    border-left: 0;
  }

  #pieceCanvas {
    height: 56vh;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    grid-template-columns: 1fr;
    padding-inline: 14px;
  }

  .stage,
  .inspector {
    padding: 14px;
  }

  .segments {
    grid-template-columns: 1fr;
  }
}
