/* Self-hosted fonts (SIL Open Font License 1.1, see fonts/LICENSE-*.txt) */
@font-face { font-family: "Bangers"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/bangers-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Archivo"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("../fonts/archivo-latin-wght-normal.woff2") format("woff2"); }
/* Base reset */
:root { color-scheme: light; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
/* Layout: comic workbench. Sticky preview panel on the left (top on phones), trait picker on the right. */
:root {
  --ink: #141018;          /* line art, borders, text on paper */
  --paper: #fbfcff;        /* panels */
  --tile: #dfe5f6;         /* thumbnail ground */
  --muted: #535a7a;        /* secondary text on paper */
  --hero-blue: #1f4fd6;    /* suit */
  --cape-red: #e0202e;     /* cape */
  --gold: #ffc933;         /* emblem */
  --page: #e6ebfa;         /* page ground */
  --page-ink: #141018;
  --page-muted: #4b5272;
  --dot: rgba(31, 79, 214, 0.11);
  --card-shadow: #141018;
  --checker-a: #f3f5fb;
  --checker-b: #dde2f0;
  --f-display: "Bangers", "Impact", "Arial Black", system-ui, sans-serif;
  --f-body: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0f2a; --page-ink: #eef1ff; --page-muted: #a9b0d6;
    --dot: rgba(255, 255, 255, 0.055); --card-shadow: #1f4fd6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0f2a; --page-ink: #eef1ff; --page-muted: #a9b0d6;
  --dot: rgba(255, 255, 255, 0.055); --card-shadow: #1f4fd6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  background-color: var(--page);
  background-image: radial-gradient(var(--dot) 1.3px, transparent 1.5px);
  background-size: 14px 14px;
  color: var(--page-ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 40px;
}
button { font: inherit; color: inherit; }
.app { max-width: 1160px; margin: 0 auto; }

/* ---------- header */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 24px; padding-block: 22px 18px; }
.logo { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: clamp(38px, 6.4vw, 66px); line-height: 0.92; letter-spacing: 0.02em; text-wrap: balance; }
.logo .si { display: inline-grid; place-items: center; width: 1.16em; height: 1.16em; vertical-align: -0.12em; background: var(--gold); color: var(--ink); border: 3px solid var(--ink); border-radius: 50%; margin-right: 0.14em; font-size: 0.82em; padding-top: 0.06em; transform: rotate(-6deg); box-shadow: 3px 3px 0 var(--card-shadow); }
.logo .word { color: var(--page-ink); text-shadow: 3px 3px 0 var(--cape-red); }
.tagline { margin: 6px 0 0; color: var(--page-muted); font-size: 15px; max-width: 44ch; }
.count { font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--page-muted); font-variant-numeric: tabular-nums; }
.count b { color: var(--page-ink); font-size: 15px; }

/* ---------- layout */
.forge { display: grid; grid-template-columns: minmax(380px, 540px) minmax(0, 1fr); gap: 24px; align-items: start; }
.left { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 6px 6px 0 var(--card-shadow); }

/* ---------- stage */
.stage { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.frame { position: relative; width: 100%; aspect-ratio: 1 / 1; max-width: 100%; border: 3px solid var(--ink); border-radius: 8px; overflow: hidden;
  background-color: var(--checker-a);
  background-image: linear-gradient(45deg, var(--checker-b) 25%, transparent 25%, transparent 75%, var(--checker-b) 75%), linear-gradient(45deg, var(--checker-b) 25%, transparent 25%, transparent 75%, var(--checker-b) 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px; }
.frame canvas { display: block; width: 100%; height: 100%; }
.frame.pop canvas { animation: pop 260ms ease-out; }
@keyframes pop { 0% { transform: scale(0.985); } 60% { transform: scale(1.006); } 100% { transform: scale(1); } }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 16, 24, 0.35); color: #fff; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 13px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 8px 14px; border: 3px solid var(--ink); border-radius: 10px; cursor: pointer;
  font-weight: 800; font-size: 15px; letter-spacing: 0.03em; box-shadow: 4px 4px 0 var(--ink); transition: transform 80ms ease, box-shadow 80ms ease; }
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-shuffle { background: var(--cape-red); color: #fff; font-family: var(--f-display); font-weight: 400; font-size: 24px; letter-spacing: 0.06em; }
.btn-save { background: var(--hero-blue); color: #fff; }
.btn[disabled] { opacity: 0.6; cursor: progress; }

/* ---------- controls under the stage */
.controls { display: flex; flex-direction: column; gap: 12px; padding: 12px 14px 14px; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; }
.seg { display: inline-flex; border: 2.5px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 7px 14px; font-weight: 700; font-size: 13px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.seg button + button { border-left: 2.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.textbtn { border: 0; background: none; padding: 6px 2px; font-weight: 700; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; color: var(--ink); }
.loadout { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; border: 2px solid var(--ink); border-radius: 999px; padding: 4px 10px; background: var(--tile); cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink); }
.chip span { font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.chip:hover { background: var(--gold); }

/* ---------- picker */
.picker { padding: 0; min-width: 0; overflow: hidden; }
.tabs { display: flex; gap: 0; overflow-x: auto; border-bottom: 3px solid var(--ink); background: var(--tile); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-right: 2.5px solid var(--ink); background: transparent; padding: 13px 16px 11px; cursor: pointer;
  font-weight: 800; font-size: 13px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink); white-space: nowrap; }
.tab:last-child { border-right: 0; }
.tab[aria-selected="true"] { background: var(--gold); }
.tab .lockmark { width: 13px; height: 13px; }
.panelhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 16px 18px 6px; }
.panelhead h2 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 32px; letter-spacing: 0.04em; line-height: 1; text-wrap: balance; }
.panelhead p { margin: 4px 0 0; color: var(--muted); font-size: 14px; max-width: 52ch; }
.lock { display: inline-flex; align-items: center; gap: 8px; border: 2.5px solid var(--ink); border-radius: 999px; padding: 6px 12px 6px 10px; background: var(--paper); cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink); }
.lock svg { width: 16px; height: 16px; }
.lock[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 12px 18px 20px; }
.opt { display: flex; flex-direction: column; gap: 0; padding: 0; border: 2.5px solid var(--ink); border-radius: 10px; overflow: hidden; background: var(--paper); cursor: pointer; text-align: left;
  transition: transform 90ms ease, box-shadow 90ms ease; box-shadow: 0 0 0 var(--ink); }
.opt:hover { transform: translate(-2px, -2px); box-shadow: 3px 3px 0 var(--ink); }
.opt img { display: block; width: 100%; aspect-ratio: 1 / 1; height: auto; background: var(--tile); object-fit: cover; }
.opt .nm { display: block; padding: 7px 8px 8px; font-size: 12.5px; font-weight: 700; line-height: 1.2; color: var(--ink); border-top: 2.5px solid var(--ink); min-height: 2.6em; }
.opt[aria-checked="true"] { box-shadow: 4px 4px 0 var(--ink); transform: translate(-2px, -2px); }
.opt[aria-checked="true"] .nm { background: var(--gold); }
.opt .badge { display: none; }
.tip { margin: 0; padding: 0 18px 18px; color: var(--muted); font-size: 13px; }
.short { display: none; }

/* ---------- focus + toast + sheet */
:focus-visible { outline: 3px solid var(--hero-blue); outline-offset: 2px; }
.btn:focus-visible, .opt:focus-visible, .tab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--ink); color: #fff;
  border: 2.5px solid var(--gold); border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 14px; transition: opacity 160ms ease, transform 160ms ease; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; overflow-y: auto; overscroll-behavior: contain; background: rgba(13, 15, 42, 0.72);
  padding: calc(env(safe-area-inset-top, 0px) + 16px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px)); }
.sheet .card { width: min(520px, 100%); margin: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sheet img { display: block; width: min(100%, 56vh); height: auto; aspect-ratio: 1 / 1; margin-inline: auto; border: 3px solid var(--ink); border-radius: 8px; background: var(--tile);
  -webkit-touch-callout: default; user-select: auto; }
.sheetbtns { display: flex; flex-wrap: wrap; gap: 10px; }
.sheetbtns .btn { flex: 1 1 140px; }
.btn-ghost { background: var(--paper); color: var(--ink); }
.btn-allow { background: var(--gold); color: var(--ink); }
.sheet .why { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet .why:empty { display: none; }
.sheet h3 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 28px; letter-spacing: 0.04em; }
.sheet p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- phones and tablets: preview on top, then a single-row strip of options */
@media (max-width: 859px) {
  .forge { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
  .left { display: contents; }
  .stage { order: 1; }
  .picker { order: 2; }
  .controls { order: 3; }
  .frame { width: min(100%, 60vh); width: min(100%, 60svh); margin-inline: auto; }
  .actions { width: min(100%, 60vh); width: min(100%, 60svh); margin-inline: auto; }
  .grid { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 104px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding: 8px 14px 16px; scroll-padding-inline: 14px; }
  .opt { scroll-snap-align: start; }
  .opt:hover { transform: none; box-shadow: none; }
  .opt[aria-checked="true"], .opt[aria-checked="true"]:hover { box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
  .panelhead { padding: 12px 14px 2px; }
  .panelhead p { display: none; }
  .panelhead h2 { font-size: 26px; }
  .tip { display: none; }
}
@media (max-width: 560px) {
  .top { padding-block: 14px 10px; }
  .tagline { font-size: 14px; }
  .stage { padding: 8px; gap: 8px; border-radius: 12px; box-shadow: 4px 4px 0 var(--card-shadow); }
  .btn { min-height: 46px; }
  .btn-shuffle { font-size: 21px; }
  .grid { grid-auto-columns: 96px; gap: 10px; padding: 8px 12px 14px; }
  .tab { padding: 12px 10px 10px; font-size: 12px; letter-spacing: 0.05em; }
  .lock { padding: 5px 10px 5px 8px; font-size: 12px; }
  .long { display: none; }
  .short { display: inline; }
  .count { display: none; }
  .panelhead { flex-wrap: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .frame.pop canvas { animation: none; }
  .btn, .opt, .toast { transition: none; }
}
a.btn { text-decoration: none; }
