:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d9dde3;
  --text: #1c1f24;
  --text-2: #4b525c;
  --muted: #646b75;
  --accent: #2f5f98;
  --focus: #2f5f98;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --surface: #111418;
    --surface-2: #171b21;
    --border: #252a33;
    --text: #e6e8eb;
    --text-2: #b4bac3;
    --muted: #8a919c;
    --accent: #8fa8c8;
    --focus: #8fa8c8;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.5 'Segoe UI',
    -apple-system,
    BlinkMacSystemFont,
    Helvetica,
    Arial,
    sans-serif;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Header ── */
.top {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.top .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding-top: 18px;
  padding-bottom: 18px;
}
.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.tagline {
  margin: 0;
  color: var(--muted);
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding-top: 24px;
}
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── Form ── */
.field {
  margin: 0 0 20px;
  padding: 0;
  border: 0;
  min-width: 0;
}
.field:last-child {
  margin-bottom: 0;
}
legend,
div.field > label {
  display: block;
  padding: 0;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text);
}
fieldset label {
  color: var(--text-2);
}
.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input:focus-visible,
select:focus-visible,
button:focus-visible,
.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.input-prefix {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}
.input-prefix span {
  padding-left: 10px;
  color: var(--muted);
}
.input-prefix input {
  border: 0;
  padding-left: 4px;
  background: transparent;
}
.input-prefix:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.input-prefix input:focus-visible {
  outline: none;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 8px;
}
.options-grid label:not(.check) {
  display: grid;
  gap: 4px;
  font-size: 12px;
}
.options-grid .wide {
  grid-column: 1 / -1;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  cursor: pointer;
}
.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.segmented label {
  position: relative;
}
.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-2);
  cursor: pointer;
}
.segmented label:hover span {
  border-color: var(--muted);
}
.segmented input:checked + span {
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ── Preview & snippets ── */
.output {
  display: grid;
  gap: 16px;
}
.preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 24px 16px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.preview img {
  display: block;
  max-width: 100%;
  height: auto;
}
.preview img:not([src]) {
  display: none;
}
.status {
  margin: 0;
  color: var(--muted);
}
.preview.has-status img {
  opacity: 0.35;
}
.preview.has-status .status {
  position: absolute;
}

.snippet {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.snippet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.copy {
  min-width: 72px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.copy:hover {
  border-color: var(--muted);
}
pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  background: var(--surface-2);
}
code {
  font:
    12px/1.6 ui-monospace,
    'JetBrains Mono',
    'SF Mono',
    Menlo,
    Consolas,
    monospace;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Gallery ── */
.gallery-wrap {
  padding-top: 40px;
  padding-bottom: 48px;
}
.gallery-wrap h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.group h3 {
  margin: 24px 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.tile {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tile:hover {
  border-color: var(--muted);
}
.tile[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--text);
}
.tile img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 80px;
  border-radius: 4px;
}
.tile-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}
.swatch {
  display: inline-flex;
  border-radius: 3px;
  overflow: hidden;
  outline: 1px solid var(--border);
}
.swatch span {
  width: 10px;
  height: 10px;
}

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