:root {
  --bg: #F3FAF5;
  --paper: #FFFFFF;
  --mint: #9BDCBE;
  --mint-2: #DDF3E6;
  --mint-3: #C4EBD7;
  --ink: #1E2230;
  --ink-2: #4A5163;
  --pink: #FFB2CB;
  --yellow: #FFD84D;
  --green: #45C97B;
  --r: 20px;
  --b: 3px;
  --lift: 0 4px 0 var(--ink);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12px 12px, var(--mint-2) 3px, transparent 3.5px) 0 0 / 34px 34px,
    var(--bg);
  min-height: 100vh;
  line-height: 1.4;
}
button { font: inherit; color: inherit; }
img, canvas, svg { display: block; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 12px; text-decoration: none; font-weight: 800;
}
.skip:focus { top: 12px; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; box-shadow: 0 0 0 6px var(--yellow); }

/* ---------------------------------------------------------------- header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px;
  max-width: 1180px; margin: 0 auto; padding: 14px 16px 6px;
}
.logo { display: block; border-radius: 14px; }
.logo svg { width: 150px; height: auto; }
.tag { margin: 0; font-weight: 800; font-size: 15px; color: var(--ink-2); flex: 1 1 auto; }
.ca {
  display: inline-flex; align-items: center; gap: 8px;
  border: var(--b) solid var(--ink); border-radius: 999px; background: var(--yellow);
  padding: 5px 12px; font-weight: 800; font-size: 13px; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
}
.ca[hidden] { display: none; }
.ca:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.ca code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }

/* ---------------------------------------------------------------- layout */
.app {
  display: grid; gap: 18px;
  max-width: 1180px; margin: 0 auto; padding: 8px 16px 8px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 900px) {
  .app { grid-template-columns: minmax(360px, 480px) minmax(0, 1fr); align-items: start; gap: 28px; padding-top: 12px; }
  .stage { position: sticky; top: 16px; }
  .logo svg { width: 176px; }
  .tag { font-size: 17px; }
}

/* ---------------------------------------------------------------- stage */
.preview-card {
  position: relative;
  border: var(--b) solid var(--ink); border-radius: calc(var(--r) + 6px);
  background: var(--paper); padding: 8px; box-shadow: 0 6px 0 var(--ink);
}
#preview {
  width: 100%; height: auto; aspect-ratio: 1 / 1;
  border-radius: var(--r); border: var(--b) solid var(--ink);
  background: var(--mint);
}
.styles-quick {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 14px 0 0;
}
.chip {
  border: var(--b) solid var(--ink); border-radius: 999px; background: var(--paper);
  font-weight: 800; font-size: 13px; padding: 7px 4px; cursor: pointer; white-space: nowrap;
  transition: transform .08s ease, background .15s ease;
}
.chip:hover { background: var(--mint-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.chip:active { transform: translateY(1px); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 14px;
  border: var(--b) solid var(--ink); border-radius: 16px; background: var(--paper);
  font-weight: 800; font-size: 15px; cursor: pointer; box-shadow: var(--lift);
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn-dice svg circle { fill: currentColor; stroke: none; }
.btn:hover { background: var(--mint-2); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-primary { background: var(--green); }
.btn-primary:hover { background: #5BD68C; }
.btn-dice { background: var(--yellow); }
.btn-dice:hover { background: #FFE27A; }
.btn-dice.spin svg { animation: spin .45s ease; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.btn-small { min-height: 38px; font-size: 14px; padding: 6px 12px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
.hint { margin: 12px 2px 0; font-size: 13px; color: var(--ink-2); font-weight: 600; }
kbd {
  font-family: inherit; font-weight: 800; font-size: 12px;
  border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 7px; padding: 0 6px; background: var(--paper);
}

/* ---------------------------------------------------------------- editor */
.editor {
  border: var(--b) solid var(--ink); border-radius: calc(var(--r) + 6px);
  background: var(--paper); box-shadow: 0 6px 0 var(--ink); overflow: hidden;
}
.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 10px 0; background: var(--mint-2);
  border-bottom: var(--b) solid var(--ink); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: var(--b) solid var(--ink); border-bottom: 0; border-radius: 14px 14px 0 0;
  background: var(--mint-3); padding: 9px 14px 8px; font-weight: 800; font-size: 14px; cursor: pointer;
  position: relative; top: 0; margin-bottom: 0;
}
.tab:hover { background: #E9F8EF; }
.tab[aria-selected="true"] { background: var(--paper); top: var(--b); padding-bottom: 11px; margin-top: -3px; }
.tab:focus-visible { outline-offset: -6px; box-shadow: none; }

.panel { padding: 14px 14px 18px; min-height: 300px; }
.group + .group { margin-top: 18px; }
.group-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 0 0 8px; font-size: 13px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
}
.group-h small { text-transform: none; letter-spacing: 0; font-weight: 700; color: var(--ink); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.thumbs.big { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.opt {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  border: var(--b) solid var(--ink); border-radius: 16px; background: var(--paper); padding: 4px 4px 5px; cursor: pointer;
  transition: transform .08s ease, box-shadow .12s ease;
}
.opt img, .opt .ph { width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: 11px; background: var(--mint-2); }
.opt span { font-size: 12px; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt:hover { transform: translateY(-2px); box-shadow: 0 3px 0 var(--ink); }
.opt[aria-pressed="true"] { background: var(--yellow); box-shadow: 0 3px 0 var(--ink); }
.opt[aria-pressed="true"] span::before { content: "✓ "; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw {
  width: 40px; height: 40px; border-radius: 50%; border: var(--b) solid var(--ink); cursor: pointer; padding: 0;
  transition: transform .08s ease; position: relative;
}
.sw:hover { transform: scale(1.08); }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
.sw.pair { width: 46px; height: 46px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg .chip { padding: 7px 14px; }

/* ---------------------------------------------------------------- gallery */
.gallery { max-width: 1180px; margin: 22px auto 0; padding: 0 16px; }
.gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.gallery h2 { margin: 0; font-size: 18px; font-weight: 900; }
.strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 10px;
  overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x mandatory;
}
@media (min-width: 900px) { .strip { grid-auto-columns: minmax(0, 1fr); overflow: visible; } }
.strip button {
  border: var(--b) solid var(--ink); border-radius: 18px; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--mint-2); box-shadow: 0 4px 0 var(--ink); scroll-snap-align: start;
  transition: transform .1s ease;
}
.strip button:hover { transform: translateY(-3px) rotate(-1.5deg); }
.strip button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.strip img { width: 100%; height: auto; aspect-ratio: 1 / 1; }

/* ---------------------------------------------------------------- mini preview (mobile, while scrolled into the editor) */
.mini {
  position: fixed; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 15;
  width: 84px; height: 84px; padding: 0; border: var(--b) solid var(--ink); border-radius: 20px; overflow: hidden;
  background: var(--paper); box-shadow: 0 4px 0 var(--ink); cursor: pointer;
}
.mini[hidden] { display: none; }
.mini canvas { width: 100%; height: 100%; }
@media (min-width: 900px) { .mini { display: none; } }
.style-note { margin: 12px 2px 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
@media (hover: none) and (pointer: coarse) { .kb-only { display: none; } }

/* ---------------------------------------------------------------- footer + toast */
.foot { max-width: 1180px; margin: 18px auto 0; padding: 14px 16px 34px; text-align: center; font-size: 14px; color: var(--ink-2); }
.foot p { margin: 4px 0; }
.foot .fine { font-size: 12px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 40px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 14px; padding: 10px 18px; border-radius: 999px;
  transition: transform .2s ease, opacity .2s ease; z-index: 20; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 420px) {
  .btn { font-size: 14px; padding: 10px 8px; gap: 6px; }
  .chip { font-size: 12px; }
  .tag { font-size: 14px; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
