:root {
  --bg: #0b0b0b;
  --surface: #121212;
  --surface-2: #1a1a1a;
  --stage: #2b2b2b; /* behind totems: light enough that dark skins stay visible */
  --border: #242424;
  --border-strong: #363636;
  --text: #ececec;
  --text-muted: #8a8a8a;
  --text-faint: #5c5c5c;
  --invert-bg: #ececec;
  --invert-text: #0b0b0b;
  --danger: #ff7a70;
  --success: #9fd8a8;
  --radius: 4px;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { flex: 1; }

a { color: inherit; }

h1, h2 { font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */

.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 0.9rem;
  text-decoration: none;
}

/* The static favicon until js/logo.js swaps in the spinning totem. */
.brand img,
.brand-logo {
  flex: none;
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

/* Labels and small print */

.eyebrow,
legend,
.field > span,
.field-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

legend, .field > span, .field-label { margin-bottom: 8px; }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) { background: #222; border-color: #444; }

.btn-primary {
  background: var(--invert-bg);
  border-color: var(--invert-bg);
  color: var(--invert-text);
}

.btn-primary:hover:not(:disabled) { background: #fff; border-color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-large { height: 48px; padding: 0 26px; font-size: 1rem; }

/* Inputs */

input[type="text"] {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input[type="text"]::placeholder { color: var(--text-faint); }
input[type="text"]:focus { border-color: #5a5a5a; outline: none; }

/* Custom select (see js/select.js) */

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

.select { position: relative; }

.select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.select-button:hover { border-color: #4a4a4a; }
.select.is-open .select-button { border-color: #5a5a5a; }

.select-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-chevron {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.select.is-open .select-chevron { transform: rotate(180deg); }

.select-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.5);
}

.select-list:focus { outline: none; }

.select-option {
  position: relative;
  padding: 8px 10px 8px 28px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-muted);
}

.select-option.is-active { background: #262626; color: var(--text); }
.select-option[aria-selected="true"] { color: var(--text); }

.select-option[aria-selected="true"]::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  background: var(--text);
}

/* Segmented control */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented label { position: relative; }
.segmented label + label { border-left: 1px solid var(--border-strong); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: block;
  padding: 9px 10px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}

.segmented span:hover { color: var(--text); }
.segmented input:checked + span { background: var(--invert-bg); color: var(--invert-text); font-weight: 500; }
.segmented input:focus-visible + span { outline: 1px solid var(--text); outline-offset: -3px; }

/* Checkbox */

.check {
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  color: var(--text-muted);
}

.check:hover { color: var(--text); }

.check input {
  appearance: none;
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1px solid #4a4a4a;
  border-radius: 2px;
  background: var(--bg);
  display: grid;
  place-content: center;
  cursor: pointer;
}

.check input::before {
  content: "";
  width: 10px;
  height: 8px;
  background: var(--invert-text);
  clip-path: polygon(0 50%, 14% 36%, 38% 60%, 86% 0, 100% 14%, 38% 88%);
  transform: scale(0);
  transition: transform 0.1s;
}

.check input:checked { background: var(--invert-bg); border-color: var(--invert-bg); }
.check input:checked::before { transform: scale(1); }
.check input:checked + span { color: var(--text); }

/* Footer */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 64px;
}

.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 20px;
  padding-bottom: 20px;
  font-size: 0.8rem;
  color: var(--text-faint);
}

/* ---------- Start page ---------- */

.hero {
  padding-top: 88px;
  padding-bottom: 48px;
}

.hero h1 {
  margin: 14px 0 16px;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  max-width: 20ch;
}

.hero p {
  margin: 0;
  max-width: 52ch;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.showcase {
  --fade-width: clamp(56px, 9vw, 200px);
  position: relative;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

/* Fade the cards (not the section's background or borders) out at both edges, using
   the section's own color and an eased curve so there are no visible bands. */
.showcase::before,
.showcase::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  width: var(--fade-width);
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgb(18 18 18 / 1) 0%,
    rgb(18 18 18 / 0.97) 12%,
    rgb(18 18 18 / 0.9) 24%,
    rgb(18 18 18 / 0.78) 36%,
    rgb(18 18 18 / 0.62) 48%,
    rgb(18 18 18 / 0.45) 60%,
    rgb(18 18 18 / 0.28) 72%,
    rgb(18 18 18 / 0.14) 84%,
    rgb(18 18 18 / 0.04) 94%,
    rgb(18 18 18 / 0) 100%
  );
}

.showcase::before { left: 0; }
.showcase::after { right: 0; transform: scaleX(-1); }

.showcase-track {
  display: flex;
  gap: 16px;
  width: max-content;
  padding: 32px 0;
  animation: marquee var(--marquee-duration, 40s) linear infinite;
}

.showcase:hover .showcase-track { animation-play-state: paused; }

.showcase-track:has(.showcase-status) {
  width: 100%;
  justify-content: center;
  animation: none;
}

@keyframes marquee {
  to { transform: translateX(calc(-50% - 8px)); }
}

.totem-card {
  flex: none;
  width: 204px;
  margin: 0;
}

.totem-card canvas {
  display: block;
  width: 204px;
  height: 204px;
  background: var(--stage);
  border-radius: var(--radius);
  image-rendering: pixelated;
}

.totem-card figcaption { padding: 10px 2px 0; }

.totem-card strong { display: block; font-weight: 500; }

.totem-card span {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-faint);
}

.showcase-status {
  padding: 96px 16px;
  text-align: center;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.cta {
  padding-top: 48px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
}

.cta p {
  margin: 0;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 0.8rem;
}

@media (prefers-reduced-motion: reduce) {
  .showcase-track { animation: none; }
}

/* ---------- Generator ---------- */

.page-title {
  padding: 48px 0 28px;
}

.page-title h1 {
  margin: 10px 0 0;
  font-size: clamp(1.7rem, 4vw, 2.3rem);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.layout > section { padding: 24px; }
.layout > section + section { border-left: 1px solid var(--border); }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > section + section { border-left: 0; border-top: 1px solid var(--border); }
}

.step {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 16px;
  font-size: 1rem;
}

.step::before {
  content: attr(data-step);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-faint);
}

.step:not(:first-child) { margin-top: 32px; }

.tabs {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  margin-bottom: -1px;
  padding: 0 0 10px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}

.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }

.name-form { display: flex; gap: 8px; }

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 16px;
  border: 1px dashed #3a3a3a;
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}

.dropzone:hover, .dropzone.dragover { border-color: #6a6a6a; background: var(--surface-2); }
.dropzone:focus-within { border-color: var(--text); }
.dropzone strong { color: var(--text); font-weight: 500; }
.dropzone small { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); }
.dropzone input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.status {
  min-height: 1.55em;
  margin: 12px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.status.error { color: var(--danger); }
.status.ok { color: var(--success); }

.options { display: grid; gap: 20px; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

.field { display: block; }

.field-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.preview {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: var(--stage);
  border-radius: var(--radius);
}

.preview canvas, .preview-sizes canvas { image-rendering: pixelated; }

.preview canvas {
  width: 82%;
  height: 82%;
  touch-action: pan-y; /* horizontal drags rotate, vertical ones still scroll the page */
}

.preview.is-ready canvas { cursor: grab; }
.preview.is-dragging canvas { cursor: grabbing; }
.preview canvas:focus-visible { outline: 1px solid var(--text); outline-offset: 4px; }

.preview-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: #8f8f8f;
  pointer-events: none;
}

.preview-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: #8f8f8f;
  pointer-events: none;
}

.preview-reset {
  pointer-events: auto;
  height: 26px;
  padding: 0 10px;
  border: 1px solid #454545;
  border-radius: 3px;
  background: rgb(0 0 0 / 0.35);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.preview-reset:hover { border-color: #6a6a6a; }

.preview-empty {
  position: absolute;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: #777;
}

.preview-sizes {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  margin: 12px 0 24px;
}

.preview-sizes canvas {
  background: var(--stage);
  border-radius: 3px;
  padding: 4px;
}

#skin-thumb { width: 64px; height: 64px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.actions .btn-primary { flex: 1 1 220px; }

.hint { font-size: 0.85rem; color: var(--text-faint); margin: 16px 0 0; }
