:root {
  /* Surfaces */
  --bg: #fbf9f8;
  --bg-strong: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f5f3f3;
  --surface-muted: #efeded;
  --surface-strong: #e7e4e3;

  /* Text */
  --ink: #1b1c1c;
  --muted: #575d66;
  --text-soft: #737883;
  --line: rgba(27, 28, 28, 0.1);

  /* Brand accent (blue) */
  --accent: #0051ac;
  --accent-strong: #1469d5;
  --accent-soft: #d8e2ff;

  /* Status */
  --lime: #31905f;
  --amber: #d59b22;
  --red: #d55257;

  /* Dark neutrals */
  --navy: #1b1c1c;
  --navy-soft: #2a2c2e;

  /* Shape and depth */
  --radius-sm: 0.75rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;
  --shadow: 0 12px 32px rgba(27, 28, 28, 0.06);
  --shadow-float: 0 20px 48px rgba(27, 28, 28, 0.1);
  --page-width: 1320px;

  /* Type */
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-label: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.55;
  background:
    radial-gradient(circle at top right, rgba(20, 105, 213, 0.08), transparent 26%),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 14%, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid rgba(20, 105, 213, 0.55);
  outline-offset: 2px;
}

.page-shell {
  min-height: 100vh;
  padding-bottom: 3.5rem;
}

/* Hero */
.hero {
  width: min(calc(100% - 2rem), var(--page-width));
  margin: 1rem auto 0;
  padding: 1.5rem clamp(1.1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero__copy {
  display: grid;
  gap: 0.5rem;
  max-width: 62rem;
}

.hero__eyebrow,
.panel__eyebrow {
  margin: 0;
  font-family: var(--font-label);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-head);
  font-size: clamp(1.7rem, 3.4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.hero__lede {
  margin: 0;
  max-width: 52rem;
  color: var(--muted);
  font-size: 1.02rem;
}

.hero__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.hero__chips span {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

/* Layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 1rem;
  align-items: start;
  width: min(calc(100% - 2rem), var(--page-width));
  margin: 1rem auto 0;
}

.controls {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel {
  padding: 1.15rem 1.3rem;
}

.panel + .panel {
  border-top: 1px solid var(--line);
}

.panel__header {
  margin-bottom: 1rem;
}

.panel__header h2 {
  margin: 0;
  font-family: var(--font-head);
  font-size: 1.55rem;
  line-height: 1.1;
}

.panel__hint,
.panel__status {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.panel__status {
  color: var(--ink);
  font-weight: 600;
}

.panel__status.is-error {
  color: #a33c43;
}

/* Drop zone */
.dropzone {
  display: grid;
  place-items: center;
  gap: 0.35rem;
  min-height: 150px;
  padding: 1.2rem;
  border: 2px dashed rgba(27, 28, 28, 0.18);
  border-radius: calc(var(--radius-lg) - 8px);
  background:
    radial-gradient(circle at top left, rgba(20, 105, 213, 0.12), transparent 26%),
    radial-gradient(circle at bottom right, rgba(20, 105, 213, 0.12), transparent 28%),
    var(--bg-strong);
  text-align: center;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
  transform: translateY(-2px);
  border-color: rgba(20, 105, 213, 0.58);
  box-shadow: 0 14px 32px rgba(27, 28, 28, 0.1);
}

.dropzone__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.dropzone__subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.78rem 1.1rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(0, 81, 172, 0.22);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
  box-shadow: none;
}

.button--secondary {
  background: var(--surface-muted);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.button--secondary:hover,
.button--secondary:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--line);
}

.button--secondary:disabled:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.button--small {
  min-height: 2.4rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.86rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

/* Part list */
.part-list {
  display: grid;
  gap: 0.5rem;
}

.part {
  display: grid;
  grid-template-columns: 0.8rem minmax(0, 1fr) auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.part:hover {
  background: var(--accent-soft);
}

.part.is-selected {
  border-color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-strong);
}

.part__swatch {
  width: 0.8rem;
  height: 2rem;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(27, 28, 28, 0.18);
}

.part__name {
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part__meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part__eye {
  min-width: 2.2rem;
  min-height: 2.2rem;
  border: none;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--line);
}

.part__eye[aria-pressed="false"] {
  color: var(--text-soft);
  background: transparent;
}

/* Selected part */
.sel-name {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 800;
}

.group {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.group h3 {
  margin: 0;
  font-family: var(--font-label);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.group .panel__hint,
.group .button-row {
  margin-top: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.field-grid--triple {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.field > span {
  font-size: 0.9rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  min-height: 3rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid rgba(27, 28, 28, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input[type="color"] {
  padding: 0.25rem;
  cursor: pointer;
}

.field input:focus,
.field select:focus {
  border-color: rgba(20, 105, 213, 0.58);
  outline: none;
  box-shadow: 0 0 0 4px rgba(20, 105, 213, 0.14);
}

.range-field {
  display: grid;
  gap: 0.5rem;
}

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

.step-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
}

.step-grid .button {
  padding-inline: 0.4rem;
}

/* Toggle */
.toggle {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  align-items: center;
  align-self: end;
  min-height: 3rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid rgba(27, 28, 28, 0.14);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

.toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.toggle__track {
  position: relative;
  width: 3rem;
  height: 1.7rem;
  border-radius: 999px;
  background: rgba(27, 28, 28, 0.16);
  transition: background 180ms ease;
}

.toggle__track::after {
  content: "";
  position: absolute;
  top: 0.18rem;
  left: 0.18rem;
  width: 1.34rem;
  height: 1.34rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 10px rgba(27, 28, 28, 0.18);
  transition: transform 180ms ease;
}

.toggle input:checked + .toggle__track {
  background: rgba(20, 105, 213, 0.75);
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(1.3rem);
}

.toggle input:focus-visible + .toggle__track {
  outline: 3px solid rgba(20, 105, 213, 0.55);
  outline-offset: 2px;
}

.toggle__label {
  color: var(--muted);
  font-size: 0.94rem;
}

.notice {
  margin-top: 1rem;
  padding: 0.95rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(27, 28, 28, 0.08);
  background: rgba(27, 28, 28, 0.06);
  font-size: 0.92rem;
  line-height: 1.5;
}

.notice--info {
  background: rgba(20, 105, 213, 0.08);
}

/* Stage */
.stage {
  position: sticky;
  top: 1rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: calc(100vh - 2rem);
  min-height: 460px;
  max-height: 860px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.stage__bed {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.stage__bed select {
  min-height: 2.4rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(27, 28, 28, 0.14);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

.button[aria-pressed="true"]:not(.is-plain) {
  background: var(--accent-soft);
  color: var(--accent);
}

.stage__viewer {
  position: relative;
  min-height: 0;
  background:
    radial-gradient(ellipse at 50% 30%, #ffffff 0%, var(--surface-soft) 62%, var(--surface-muted) 100%);
}

.stage__viewer canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.stage__viewer.is-dragover {
  box-shadow: inset 0 0 0 3px rgba(20, 105, 213, 0.58);
}

.stage__empty {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 1.5rem;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.stage__empty p {
  margin: 0;
}

.stage__empty-title {
  margin-bottom: 0.3rem !important;
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 800;
}

.stage__bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.stage__bar #viewStatus {
  color: var(--ink);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 3.75rem;
  z-index: 20;
  max-width: min(90vw, 32rem);
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  background: var(--navy);
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: var(--shadow-float);
  transform: translateX(-50%);
}

.noscript {
  width: min(calc(100% - 2rem), var(--page-width));
  margin: 1rem auto;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: rgba(213, 82, 87, 0.13);
  color: #a33c43;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage {
    position: relative;
    top: 0;
    order: -1;
    height: 70vh;
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  .button-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage__bed {
    margin-left: 0;
  }

  .stage__hint {
    display: none;
  }
}

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