:root {
  --bg: #f6f2f8;
  --surface: #ffffff;
  --sunk: #efe8f3;
  --fg: #241d2b;
  --muted: #6b6178;
  --line: #e2d8ea;
  --accent: #cf3f6e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3ec;
  --ok: #217a52;
  --ok-soft: #e1f4ea;
  --bad: #b3263e;
  --bad-soft: #fbe4e8;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", system-ui, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131c;
    --surface: #221c29;
    --sunk: #1c1722;
    --fg: #f1ebf6;
    --muted: #aa9fb7;
    --line: #362e40;
    --accent: #ff7aa0;
    --accent-ink: #2a0d18;
    --accent-soft: #3a1d2a;
    --ok: #6fd8a6;
    --ok-soft: #173327;
    --bad: #ff8d9f;
    --bad-soft: #3a1a21;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.55;
}

a { color: var(--accent); }

.bar, .page {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top .bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; font-family: var(--round); font-weight: 700; font-size: 18px; }
.brand svg { color: var(--accent); }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 15px; }
nav a:hover { color: var(--fg); background: var(--sunk); }
nav a[aria-current="page"] { color: var(--fg); background: var(--accent-soft); }

.page { padding-block: 32px 56px; display: grid; gap: 28px; }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.foot .bar { padding-block: 20px; }

h1, h2 { font-family: var(--round); line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(30px, 4.6vw, 44px); font-weight: 800; }
h2 { font-size: 24px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 15px/1 var(--text); color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px;
  text-decoration: none; cursor: pointer; position: relative;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 7px 11px; font-size: 14px; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; align-items: center; }
.hero-text { display: grid; gap: 16px; }
.hero-text p { margin: 0; color: var(--muted); max-width: 58ch; font-size: 17px; }
.hero-ask { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.hero-ask blockquote { margin: 0; font-family: var(--round); font-size: 19px; font-weight: 600; line-height: 1.4; }

.gallery-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px; }
.card {
  display: grid; gap: 8px; justify-items: center; align-content: start; text-decoration: none; color: var(--fg);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 10px 10px; min-width: 0;
}
.card:hover { border-color: var(--accent); }
.thumb {
  width: 80px; height: 128px; image-rendering: pixelated;
  background-repeat: no-repeat; background-size: 512px 256px; background-position: -8px -8px;
  border-radius: 3px; box-shadow: 0 4px 12px rgba(30, 10, 40, 0.18);
}
.card .name { font-weight: 600; font-size: 14px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.card .by { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.card .remove { margin-top: 4px; }
.more { display: flex; justify-content: center; }
.empty { grid-column: 1 / -1; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 28px; text-align: center; }

.notice { border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); }
.notice.ok { background: var(--ok-soft); border-color: transparent; }
.notice.ok strong { color: var(--ok); }
.notice.bad { background: var(--bad-soft); border-color: transparent; }
.notice.bad strong { color: var(--bad); }

.cape-view { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 32px; align-items: start; }
.preview { margin: 0; }
.preview img { width: 100%; height: auto; image-rendering: pixelated; border-radius: 16px; display: block; }
.cape-info { display: grid; gap: 16px; min-width: 0; }
.cape-info p { margin: 0; }
.texture { display: grid; gap: 6px; }
.tex { width: 256px; max-width: 100%; image-rendering: pixelated; background: repeating-conic-gradient(var(--sunk) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; border: 1px solid var(--line); border-radius: 6px; }
.ai-box { background: var(--sunk); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; font-size: 14px; overflow-wrap: anywhere; }

.docs { max-width: 76ch; display: grid; gap: 12px; }
.docs h2 { margin-top: 18px; font-size: 22px; }
.docs p, .docs ul { margin: 0; }
.docs ul { padding-left: 22px; display: grid; gap: 4px; }
.docs .step { padding-left: 4px; }
.docs a { overflow-wrap: anywhere; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--sunk); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }

.editor { display: grid; grid-template-columns: 220px minmax(0, 1fr) 240px; gap: 24px; align-items: start; }
.ed-tools, .ed-side { display: grid; gap: 16px; }
.ed-canvas { display: grid; gap: 8px; justify-items: center; min-width: 0; }
#canvas { touch-action: none; cursor: crosshair; max-width: 100%; border-radius: 6px; box-shadow: 0 6px 20px rgba(30, 10, 40, 0.18); background: var(--surface); }
#preview { width: 220px; max-width: 100%; height: auto; image-rendering: pixelated; border-radius: 12px; background: #201b28; }
.group { display: flex; gap: 6px; flex-wrap: wrap; }
.tool { font: 600 14px/1 var(--text); border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.field { display: grid; gap: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select { font: 400 15px var(--text); color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.field input[type="color"] { padding: 2px; height: 34px; width: 64px; }
details { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface); }
details[open] { display: grid; gap: 10px; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, 30px); gap: 6px; }
.swatch { width: 30px; height: 30px; border-radius: 7px; border: 2px solid var(--line); cursor: pointer; padding: 0; position: relative; }
.swatch[aria-pressed="true"] { border-color: var(--fg); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch span { position: absolute; left: 2px; top: 0; font: 700 10px var(--mono); color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.pal-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sr { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.status { margin: 0; font-size: 14px; min-height: 1.5em; }
.status.bad { color: var(--bad); }
.status.ok { color: var(--ok); }

.admin { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }

@media (max-width: 960px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .ed-canvas { order: -1; }
}

@media (max-width: 760px) {
  .hero, .cape-view { grid-template-columns: minmax(0, 1fr); }
}

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