:root {
  color-scheme: light;
  --bg: #efeae4;
  --ink: #1d1a17;
  --muted: #6d655c;
  --panel: rgba(247, 244, 239, 0.96);
  --panel-solid: #f7f4ef;
  --line: rgba(29, 26, 23, 0.12);
  --accent: #8e3b32;
  --on-accent: #fffaf7;
  --link: #8e3b32;
  --shadow: 0 18px 50px rgba(40, 24, 16, 0.16);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141311;
  --ink: #f3efe8;
  --muted: #b7aea3;
  --panel: rgba(28, 26, 24, 0.96);
  --panel-solid: #1c1a18;
  --line: rgba(243, 239, 232, 0.14);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --link: #e7b2a8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141311;
    --ink: #f3efe8;
    --muted: #b7aea3;
    --panel: rgba(28, 26, 24, 0.96);
    --panel-solid: #1c1a18;
    --line: rgba(243, 239, 232, 0.14);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    --link: #e7b2a8;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

button, input, textarea, a {
  font: inherit;
  color: inherit;
}

button, .preset, .step, .grip, .handle, input, textarea {
  min-height: 44px;
}

.stage {
  position: fixed;
  inset: 0;
}

#cloth {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px 16px;
  pointer-events: none;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 82%, transparent), transparent);
}

.top > div:first-child {
  min-width: 0;
  flex: 1;
}

.top button { pointer-events: auto; }

.mark {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

h1 {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 420px) {
  h1 { font-size: 17px; }
  .top { gap: 8px; padding: 10px 12px 12px; }
  .top button { padding: 0 12px; }
}

.top-actions { display: flex; gap: 8px; align-items: flex-start; }

.top button, .text-button, .preset {
  border: 1px solid var(--line);
  background: var(--panel-solid);
  border-radius: 999px;
  padding: 0 14px;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  max-height: 86dvh;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  color: var(--ink);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(calc(100% - 56px));
  transition: transform 0.28s ease;
}

.sheet.is-open { transform: translateY(0); }

@media (max-width: 959px) {
  .sheet.is-open {
    top: var(--header-block, 72px);
    max-height: calc(100dvh - var(--header-block, 72px));
  }
}

.handle {
  width: 100%;
  height: 56px;
  min-height: 56px;
  flex: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 620;
}

.handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 99px;
  background: var(--muted);
}

.sheet-body {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom));
  max-height: calc(86dvh - 56px);
  overscroll-behavior: contain;
}

h2 {
  margin: 18px 0 8px;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}

.presets, .actions { display: flex; flex-wrap: wrap; gap: 8px; }

.preset.is-active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
}

.missing {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.missing li {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.missing-name { color: var(--ink); font-weight: 620; }
.missing-story { display: block; margin-top: 2px; }

textarea, input[type="number"], input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
}

textarea { min-height: 88px; resize: vertical; }

.swatches, .stripes {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.swatch-row, .stripe {
  position: relative;
  display: grid;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.swatch-row { grid-template-columns: 44px 1fr; }

.stripe {
  grid-template-columns: 44px 44px minmax(0, 1fr) 44px 56px 44px;
  gap: 6px;
}

.stripe input[type="number"] {
  padding: 0 2px;
  text-align: center;
}

.chip {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}

.chip-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.swatch-copy, .code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swatch-copy { display: flex; flex-direction: column; line-height: 1.2; }
.code { font-weight: 680; }
.swatch-meta { color: var(--muted); font-size: 14px; }

.step, .grip {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  cursor: pointer;
  padding: 0;
}

.grip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  touch-action: none;
}

.grip span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 99px;
  background: var(--muted);
}

.stripe.is-dragging { opacity: 0.7; }

.zoom-row, .check-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.field-label,
.pair label,
.sheet-body > label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  margin: 8px 0;
  font-size: 14px;
  color: var(--muted);
}

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pair label { margin: 0; }

.actions button, .compare {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  padding: 0 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.actions .primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
}

.totals { margin: 8px 0; font-weight: 620; }

.hints { list-style: none; margin: 8px 0 0; padding: 0; }
.hints li {
  margin: 0 0 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-solid));
  font-size: 14px;
}

.story p { margin: 0 0 8px; line-height: 1.45; }
.story-name { font-weight: 680; }
.story-note { color: var(--muted); font-size: 14px; }
.story-links a,
.missing a {
  display: block;
  min-height: 44px;
  padding: 10px 0;
  line-height: 1.35;
  color: var(--link);
}

#texture[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
}

.field-range,
.field-note {
  font-size: 14px;
  line-height: 1.3;
  color: var(--muted);
}

.field-note:empty { display: none; }
.field-note { color: var(--ink); }

details { border-top: 1px solid var(--line); margin-top: 8px; }
summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 680;
}
.about p { line-height: 1.5; }
.about code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

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

@media (min-width: 960px) {
  .stage { right: min(420px, 38vw); }
  .sheet,
  .sheet.is-open {
    left: auto;
    width: min(420px, 38vw);
    top: 0;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    transform: none;
  }
  .handle { display: none; }
  .sheet-body {
    max-height: none;
    height: 100%;
    padding-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, button, .preset { transition: none; }
}
