:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #1d1b18;
  --muted: #6d675e;
  --line: #e4ddd1;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.06), 0 8px 24px rgb(40 30 10 / 0.06);
  --radius: 12px;
  --ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --display: Georgia, 'Times New Roman', serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1d1b19;
    --surface-2: #232120;
    --text: #f1ede6;
    --muted: #a39d93;
    --line: #322e2a;
    --accent: #f97316;
    --accent-ink: #1a0f06;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ header */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font: 600 19px/1 var(--display);
  letter-spacing: -0.01em;
}

.brand svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.site-header nav {
  display: flex;
  gap: 18px;
  font-size: 14px;
}

.site-header nav a {
  text-decoration: none;
  color: var(--muted);
}

.site-header nav a:hover {
  color: var(--text);
}

/* --------------------------------------------------------------- workbench */

.workbench {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 28px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 8px 24px 40px;
  align-items: start;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0;
}

.field > span,
.field > label,
.label-row > span {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.field small {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row {
  display: flex;
  gap: 8px;
}

input[type='text'],
select {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[type='text']:focus,
select:focus {
  border-color: var(--focus);
  outline: none;
}

#title {
  font-family: var(--display);
  font-size: 17px;
}

#seed {
  font-family: var(--mono);
  font-size: 14px;
}

button {
  cursor: pointer;
}

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: transform 0.15s ease, border-color 0.15s;
}

.icon-btn.small {
  width: 28px;
  height: 28px;
  font-size: 17px;
}

.icon-btn:hover {
  border-color: var(--muted);
  transform: rotate(-12deg);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.swatch {
  height: 30px;
  padding: 0;
  border: 1px solid rgb(0 0 0 / 0.12);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.15);
  transition: transform 0.12s ease;
}

.swatch:hover {
  transform: translateY(-2px);
}

.swatch.auto {
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--muted);
}

.swatch.active {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.segmented button {
  padding: 7px 4px;
  font-size: 13px;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  transition: filter 0.15s, transform 0.1s;
}

.primary:hover {
  filter: brightness(1.06);
}

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

.primary span {
  font-size: 20px;
  line-height: 1;
}

kbd {
  font: 600 11px/1 var(--mono);
  padding: 3px 5px;
  border-radius: 4px;
  background: rgb(255 255 255 / 0.2);
  border: 1px solid rgb(255 255 255 / 0.3);
}

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

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 16px 8px;
  min-height: 100%;
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse at 50% 35%, rgb(255 255 255 / 0.55), transparent 65%),
    var(--surface-2);
  border: 1px solid var(--line);
}

@media (prefers-color-scheme: dark) {
  .stage {
    background:
      radial-gradient(ellipse at 50% 35%, rgb(255 255 255 / 0.05), transparent 65%),
      var(--surface-2);
  }
}

.book {
  position: relative;
  margin: 0;
  width: min(100%, 420px, calc((100vh - 220px) * 0.6667));
  min-width: 240px;
  aspect-ratio: 2 / 3;
  border-radius: 3px 6px 6px 3px;
  overflow: hidden;
  box-shadow:
    0 2px 4px rgb(0 0 0 / 0.12),
    0 18px 40px -8px rgb(0 0 0 / 0.35),
    0 40px 80px -24px rgb(0 0 0 / 0.25);
  transform: perspective(1400px) rotateY(-4deg);
  transition: transform 0.4s ease;
}

.book:hover {
  transform: perspective(1400px) rotateY(0deg);
}

.book img {
  display: block;
  width: 100%;
  height: 100%;
}

.book::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgb(0 0 0 / 0.28) 0,
    rgb(255 255 255 / 0.18) 1.2%,
    rgb(0 0 0 / 0.08) 2.6%,
    transparent 5%,
    transparent 96%,
    rgb(255 255 255 / 0.08)
  );
}

.meta {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

.meta strong {
  color: var(--text);
}

.meta code {
  font: 12.5px var(--mono);
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
}

.actions > button {
  height: 38px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

.actions > button:hover {
  border-color: var(--muted);
}

#copy-svg {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.scale {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.scale select {
  width: auto;
  height: 38px;
}

/* ----------------------------------------------------------------- gallery */

.gallery-section,
.usage {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px;
}

.section-head h2 {
  margin: 0;
  font: 600 28px/1.2 var(--display);
  letter-spacing: -0.01em;
}

.section-head p {
  margin: 6px 0 22px;
  color: var(--muted);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 22px 18px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  text-align: left;
  background: none;
  border: 0;
}

.tile-img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  margin-bottom: 6px;
  border-radius: 2px 4px 4px 2px;
  overflow: hidden;
  background: var(--line);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.1), 0 8px 18px -6px rgb(0 0 0 / 0.3);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.tile-img img {
  display: block;
  width: 100%;
  height: 100%;
}

.tile:hover .tile-img {
  transform: translateY(-4px);
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.1), 0 16px 28px -8px rgb(0 0 0 / 0.35);
}

.tile.active .tile-img {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.tile-name {
  font-weight: 600;
  font-size: 14px;
}

.tile-desc {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--muted);
}

/* ------------------------------------------------------------------- usage */

.code-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 18px;
}

.code-grid > div {
  min-width: 0;
}

.code-grid h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

pre {
  margin: 0;
  padding: 18px;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 13px/1.6 var(--mono);
}

.site-footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  color: var(--muted);
  font-size: 13px;
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

@media (max-width: 860px) {
  .workbench {
    grid-template-columns: minmax(0, 1fr);
    padding: 4px 16px 24px;
  }

  .stage {
    order: -1;
  }

  .controls {
    position: static;
  }

  .book {
    width: min(100%, 320px);
    min-width: 0;
  }

  .site-header {
    padding: 14px 16px;
  }

  .site-header nav a:not(:last-child) {
    display: none;
  }

  .gallery-section,
  .usage {
    padding: 24px 16px;
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 18px 14px;
  }
}

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