:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #eee8da;
  --ink: #1c2030;
  --muted: #6d6f7b;
  --line: #e2dccd;
  --hero: #1b2140;
  --hero-ink: #f4f1e8;
  --hero-muted: #b9b8cc;
  --yellow: #ffcb05;
  --yellow-ink: #2a2100;
  --yellow-soft: #fff3c4;
  --red: #d93a12;
  --red-soft: #fde3db;
  --green: #17885c;
  --shadow: 0 1px 2px rgba(28, 32, 48, .06), 0 4px 14px rgba(28, 32, 48, .06);
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131a;
    --surface: #1a1d27;
    --surface-2: #252937;
    --ink: #f1ede3;
    --muted: #9d9fae;
    --line: #2e3344;
    --hero: #161a2f;
    --yellow: #ffd23f;
    --yellow-soft: rgba(255, 210, 63, .12);
    --red: #ff6a47;
    --red-soft: rgba(255, 106, 71, .14);
    --green: #3fcf95;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: 80px;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.fill { fill: currentColor; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- Hero ---------- */
.hero { background: var(--hero); color: var(--hero-ink); position: relative; overflow: hidden; }
.hero::after {
  content: ''; position: absolute; right: -90px; top: -110px; width: 320px; height: 320px;
  border-radius: 50%; border: 34px solid rgba(255, 203, 5, .07); pointer-events: none;
}
.hero-top { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; padding-top: 22px; position: relative; z-index: 1; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
  width: 52px; height: 52px; border-radius: 14px; background: var(--yellow); color: #1b2140;
  display: grid; place-items: center; font: 800 1.45rem/1 var(--font-display); flex: none;
  box-shadow: 0 6px 20px rgba(255, 203, 5, .25); transform: rotate(-4deg);
}
.eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--yellow); }
.hero h1 { font: 800 clamp(1.5rem, 4vw, 2.1rem)/1.1 var(--font-display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 700; font-size: .9rem; white-space: nowrap; transition: background .15s, transform .1s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn-primary { background: var(--yellow); color: #2a2100; }
.btn-primary:hover:not(:disabled) { background: #ffd83d; }
.btn-hero { background: rgba(255, 255, 255, .08); color: var(--hero-ink); border-color: rgba(255, 255, 255, .16); }
.btn-hero:hover:not(:disabled) { background: rgba(255, 255, 255, .15); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); }
.btn-ink { background: var(--ink); color: var(--bg); }
.btn-block { width: 100%; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 0 20px; position: relative; z-index: 1; align-items: center; }
.stat {
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px; padding: 8px 14px; display: flex; align-items: baseline; gap: 8px;
}
.stat strong { font: 800 1.35rem/1 var(--font-display); color: var(--yellow); font-variant-numeric: tabular-nums; }
.stat span { font-size: .82rem; color: var(--hero-muted); font-weight: 600; }
.saved { margin-left: auto; font-size: .8rem; color: var(--hero-muted); display: flex; align-items: center; gap: 6px; }
.saved .i { width: 15px; height: 15px; color: #5fd69f; }
.saved.err .i { color: #ff8a6b; }

.ro-banner {
  background: rgba(255, 203, 5, .12); border: 1px solid rgba(255, 203, 5, .35); color: var(--hero-ink);
  border-radius: 12px; padding: 10px 14px; font-size: .9rem; margin-bottom: 18px; display: flex; gap: 10px; align-items: center;
  position: relative; z-index: 1;
}
.ro-banner .i { color: var(--yellow); }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.toolbar-inner { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 12px; padding-bottom: 12px; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font-weight: 700; font-size: .88rem;
  color: var(--muted); display: flex; gap: 7px; align-items: center; white-space: nowrap; flex: 1 0 auto; justify-content: center;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.count { background: var(--yellow); color: #2a2100; border-radius: 999px; font-size: .72rem; font-weight: 800; padding: 1px 7px; min-width: 22px; text-align: center; }
.count.zero { background: var(--line); color: var(--muted); }

.search {
  display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; height: 44px;
}
.search:focus-within { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 203, 5, .25); }
.search .i { color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; width: 100%; min-width: 0; font-size: .95rem; height: 100%; }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear { border: 0; background: var(--surface-2); border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; color: var(--muted); }
.search-clear .i { width: 14px; height: 14px; }
kbd { font: 700 .72rem var(--font-body); color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 0 13px; height: 38px; border-radius: 999px; font-weight: 700; font-size: .84rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .i { width: 15px; height: 15px; }

.hintbar { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center; padding: 14px 0 4px; font-size: .84rem; color: var(--muted); }
.linkbtn { border: 0; background: none; color: var(--muted); font-weight: 700; font-size: .84rem; display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { color: var(--red); }
.linkbtn .i { width: 15px; height: 15px; }

/* ---------- Board ---------- */
.board { padding-top: 10px; }
.group-title { display: flex; align-items: center; gap: 10px; font: 800 1.2rem var(--font-display); margin: 22px 0 12px; }
.group-title span { font: 700 .75rem var(--font-body); background: var(--surface-2); color: var(--muted); padding: 3px 9px; border-radius: 999px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }

.tile {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
  transition: border-color .15s, background .15s;
}
.tile.is-dup { border-color: var(--yellow); background: linear-gradient(180deg, var(--yellow-soft), var(--surface) 75%); }
.tile.is-dup::before { content: ''; position: absolute; left: -1px; right: -1px; top: -1px; height: 5px; background: var(--yellow); border-radius: var(--radius) var(--radius) 0 0; }
.tile.is-wanted:not(.is-dup) { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; min-height: 30px; }
.tile-num { font: 600 .8rem var(--font-display); color: var(--muted); font-variant-numeric: tabular-nums; }
.tile-num b { font-size: 1.05rem; font-weight: 800; color: var(--ink); }
.tile-name { font-weight: 700; font-size: .97rem; line-height: 1.25; min-height: 2.5em; display: flex; align-items: flex-start; gap: 4px; justify-content: space-between; overflow-wrap: anywhere; }
.tile-name.is-unknown .label { color: var(--muted); font-weight: 500; font-style: italic; }
.icon-btn { border: 0; background: transparent; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.edit { opacity: .55; margin: -5px -6px 0 0; }
.icon-btn.edit:hover, .icon-btn.edit:focus-visible { opacity: 1; }
.icon-btn.edit .i { width: 15px; height: 15px; }
.icon-btn.star[aria-pressed="true"], .want-flag { color: var(--red); }
.want-flag { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700; }
.want-flag .i { width: 15px; height: 15px; }
.rename-input { width: 100%; border: 1px solid var(--yellow); background: var(--surface); border-radius: 8px; padding: 4px 8px; font-weight: 700; font-size: .95rem; outline: none; }

.stepper { display: flex; align-items: center; justify-content: space-between; background: var(--surface-2); border-radius: 11px; padding: 4px; }
.stepper button {
  width: 42px; height: 36px; border-radius: 8px; border: 0; background: var(--surface); color: var(--ink);
  font: 700 1.25rem/1 var(--font-body); display: grid; place-items: center; box-shadow: var(--shadow);
}
.stepper button:disabled { opacity: .35; box-shadow: none; }
.stepper button[data-act="inc"] { background: var(--ink); color: var(--bg); }
.tile.is-dup .stepper button[data-act="inc"] { background: var(--yellow); color: #2a2100; }
.qty { font: 800 1.2rem var(--font-display); min-width: 2.5ch; text-align: center; font-variant-numeric: tabular-nums; }
.qty.zero { color: var(--muted); font-weight: 600; }
.qty.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.35); } }
.qty-pill { align-self: flex-start; background: var(--yellow); color: #2a2100; font: 800 .95rem var(--font-display); border-radius: 8px; padding: 2px 10px; }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty strong { display: block; font: 800 1.2rem var(--font-display); color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---------- Dialogs ---------- */
dialog.dialog {
  border: 0; border-radius: 18px; padding: 0; margin: auto; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px);
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
dialog.dialog::backdrop { background: rgba(10, 12, 20, .55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dialog-head { padding: 20px 22px 4px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dialog-head h2 { font: 800 1.35rem var(--font-display); }
.dialog-head p { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.dialog-body { padding: 14px 22px 22px; display: grid; gap: 18px; }
.field label, .field .label { display: flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field label .i { width: 15px; height: 15px; }
.field-row { display: flex; gap: 8px; }
.input {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; font-size: .9rem; outline: none;
}
.input:focus { border-color: var(--yellow); }
.input[readonly] { color: var(--muted); font-size: .82rem; }
.note { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.note.warn { color: var(--red); }
.json-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.json-row .btn { width: 100%; }
.sep { border: 0; border-top: 1px solid var(--line); }

.checks { display: grid; gap: 8px; }
.check {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--bg);
}
.check:has(input:checked) { border-color: var(--yellow); background: var(--yellow-soft); }
.check input { width: 20px; height: 20px; accent-color: #e0a800; flex: none; }
.check b { display: block; font-size: .92rem; }
.check small { color: var(--muted); font-size: .8rem; }

.formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.format {
  border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 14px 10px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; transition: border-color .15s, background .15s;
}
.format:hover:not(:disabled) { border-color: var(--yellow); background: var(--yellow-soft); }
.format .i { width: 26px; height: 26px; color: var(--ink); }
.format b { font-size: .92rem; }
.format small { font-size: .74rem; color: var(--muted); line-height: 1.3; }
.format:disabled { opacity: .5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 10px 10px 16px; border-radius: 12px; font-weight: 700; font-size: .9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); display: flex; align-items: center; gap: 12px; z-index: 100;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.error { background: var(--red); color: #fff; }
.toast button { border: 0; background: var(--yellow); color: #2a2100; font-weight: 800; border-radius: 8px; padding: 6px 12px; }
.toast:not(.has-action) { padding-right: 16px; }

.lbl-short { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 640px) {
  .hero-actions { width: 100%; display: grid; grid-template-columns: auto 1fr 1fr; }
  .hero-actions .btn { padding: 0 12px; }
  .saved { margin-left: 0; width: 100%; }
  .stat { padding: 6px 10px; }
  .stat strong { font-size: 1.15rem; }
  .segmented { width: 100%; }
  .segmented .i { display: none; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { flex-direction: column; gap: 2px; align-items: flex-start; }
  .stat span { font-size: .74rem; }
  .saved { grid-column: 1 / -1; }
  .search { flex-basis: 100%; }
  kbd { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 10px 10px 8px; }
  .stepper button { width: 40px; }
  .formats { grid-template-columns: 1fr; }
  .json-row { grid-template-columns: 1fr; }
  .hero-actions .btn .i { display: none; }
  .format { flex-direction: row; text-align: left; padding: 12px 14px; }
  .format span { display: flex; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
