:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #121a26;
  --muted: #586374;
  --border: #dbe1ea;
  --accent: #1b4f9c;
  --accent-soft: #e3ecfa;
  --on-accent: #ffffff;
  --owned: #17794a;
  --owned-soft: #e2f4ea;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(16 24 40 / 8%);
  --tabbar: 60px;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c121b;
    --surface: #151e2b;
    --text: #e9eef5;
    --muted: #9ba8ba;
    --border: #27344a;
    --accent: #7fb0f7;
    --accent-soft: #1b2c47;
    --on-accent: #0b1220;
    --owned: #4ccb8d;
    --owned-soft: #143424;
    --danger: #ff8a80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 760px; margin: 0 auto; padding: 0 12px 24px; }
h1 { font-size: 1.5rem; margin: 20px 4px 12px; }
h2 { font-size: 1.1rem; margin: 24px 4px 10px; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- header */
.top {
  max-width: 760px; margin: 0 auto; padding: 10px 16px 6px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); flex: none; }
.brand svg path { stroke: var(--surface); }
.guide-link { font-size: .92rem; font-weight: 600; padding: 10px 4px; white-space: nowrap; }
.guide-link::after, .foot [data-guide]::after { content: " ↗"; }

/* ---------- overall progress */
.overall { padding: 4px 4px 10px; }
.overall p { margin: 0 0 6px; }
.overall strong { font-size: 1.05rem; }
.note { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }
.sync { color: var(--danger); font-size: .85rem; margin-left: 6px; }
progress {
  appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 8px;
  border: 0; border-radius: 99px; overflow: hidden; background: var(--border); color: var(--owned);
}
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--owned); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--owned); border-radius: 99px; }

/* ---------- search bar */
.searchbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 8px;
  padding: 8px 0; background: var(--bg);
}
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px; min-height: 48px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
.searchbar input { flex: 1; min-width: 0; }
.btn {
  font: inherit; font-weight: 650; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px; min-height: 48px; padding: 10px 16px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; }
.btn.link { border-color: transparent; background: none; color: var(--accent); padding-inline: 8px; }
.badge {
  background: var(--accent); color: var(--on-accent); border-radius: 99px;
  min-width: 22px; height: 22px; padding: 0 6px; font-size: .8rem; display: inline-grid; place-items: center;
}

/* ---------- category strip + chips */
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; margin: 0 -12px; padding-inline: 12px; }
.strip::-webkit-scrollbar { display: none; }
.cat, .chip {
  font: inherit; font-size: .93rem; font-weight: 600; white-space: nowrap; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 99px; min-height: 44px; padding: 8px 14px;
}
.cat small { font-weight: 500; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.cat.sub { border-style: dashed; }
.cat.done small { color: var(--owned); font-weight: 700; }
.cat.on, .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.cat.on small { color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
#active { padding-bottom: 10px; }
#active .chip { min-height: 40px; padding: 6px 12px; }
.chip.clear { border-color: transparent; background: none; color: var(--accent); text-decoration: underline; }

.resultbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 4px 8px; color: var(--muted); font-size: .92rem; }
.sort select { min-height: 40px; padding: 6px 10px; width: auto; max-width: 46vw; font-size: .92rem; }

/* ---------- item rows */
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: stretch; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  content-visibility: auto; contain-intrinsic-size: auto 82px;
}
.item-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 8px 4px 8px 8px; color: inherit; text-decoration: none; }
.item-main img, .item-main .nophoto { width: 64px; height: 64px; flex: none; border-radius: 10px; object-fit: contain; background: var(--bg); }
.item-text { min-width: 0; display: grid; gap: 2px; }
.item-name { font-weight: 650; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-meta { color: var(--muted); font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tick {
  flex: none; width: 68px; border: 0; border-left: 1.5px solid var(--border); background: none; cursor: pointer;
  display: grid; place-items: center; color: transparent;
}
.tick svg, .own-btn svg {
  width: 34px; height: 34px; padding: 5px; border-radius: 50%; border: 2px solid var(--muted);
  fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
}
.item.owned { border-color: var(--owned); background: var(--owned-soft); }
.item.owned .tick { border-left-color: var(--owned); }
.item.owned .tick svg { background: var(--owned); border-color: var(--owned); color: var(--surface); }
.tick:active svg { transform: scale(.88); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

/* ---------- cards + forms */
.card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.form { display: grid; gap: 14px; }
.form p { margin: 0; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .93rem; }
label.sub { font-weight: 500; color: var(--muted); margin-top: 10px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: .93rem; padding: 0; margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details { border-top: 1.5px solid var(--border); padding-top: 12px; }
details .form { padding-top: 8px; }
summary { font-weight: 650; cursor: pointer; min-height: 40px; display: flex; align-items: center; }
.error { color: var(--danger); font-weight: 600; }
.code { font-size: 1.7rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.preview { max-width: 100%; max-height: 260px; border-radius: 12px; justify-self: start; }
.turnstile:empty { display: none; }
.prose ul { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.danger { margin-top: 24px; border-color: var(--danger); }
.danger h2 { margin: 0 0 6px; }
.danger-btn { border-color: var(--danger); color: var(--danger); }

.progress-table { padding: 6px 16px; }
.pt-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; color: inherit; text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.pt-row:last-child { border-bottom: 0; }
.pt-row.sub { padding-left: 18px; }
.pt-row progress { grid-column: 1 / -1; }
.pt-num { color: var(--muted); font-variant-numeric: tabular-nums; }

.foot { display: flex; flex-wrap: wrap; gap: 6px 20px; justify-content: center; padding: 28px 0 8px; font-size: .92rem; }
.foot a { padding: 10px 2px; }

/* ---------- bottom tab bar (thumb reach) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; justify-content: center;
  background: var(--surface); border-top: 1.5px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 220px; height: var(--tabbar); display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 650;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current] { color: var(--accent); }

/* ---------- sheets (filters, item detail, merge) */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 88dvh;
  background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0; overflow: auto;
  overscroll-behavior: contain;
}
dialog.sheet.tall { height: 94dvh; max-height: 94dvh; }
dialog.sheet::backdrop { background: rgb(8 12 20 / 55%); }
.sheet-body { display: grid; gap: 16px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); position: relative; }
.sheet.tall .sheet-body { min-height: 100%; grid-template-rows: 1fr auto; padding-top: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 1.25rem; }
.sheet p { margin: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.seg legend { grid-column: 1 / -1; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; min-height: 48px; border: 1.5px solid var(--border); margin-left: -1.5px;
  font-weight: 650; cursor: pointer; background: var(--surface);
}
.seg label:first-of-type span { border-radius: 12px 0 0 12px; margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 12px 12px 0; }
.seg input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); position: relative; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.sticky-action {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  margin: 0 -16px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

.close {
  position: absolute; top: 14px; right: 14px; z-index: 2; width: 44px; height: 44px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.6rem; line-height: 1; cursor: pointer;
}
#detail-content { display: grid; gap: 14px; align-content: start; }
.detail-photo { width: 100%; max-height: 52dvh; aspect-ratio: 1; object-fit: contain; background: var(--bg); border-radius: 14px; }
.description { white-space: pre-line; }
.nophoto-note { padding: 28px 56px 28px 0; }
dl { margin: 0; display: grid; gap: 0; }
dl div { display: grid; grid-template-columns: 8em 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
dt { color: var(--muted); font-size: .92rem; }
dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.own-btn svg { width: 26px; height: 26px; padding: 3px; border-color: currentColor; }
.own-btn.owned { background: var(--owned); border-color: var(--owned); color: var(--surface); }
.own-btn:not(.owned) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 100; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-size: .92rem; font-weight: 600; max-width: calc(100vw - 32px); text-align: center;
}

@media (min-width: 700px) {
  .items { grid-template-columns: 1fr 1fr; }
  dialog.sheet { margin: auto; border-radius: 20px; }
  dialog.sheet.tall { height: auto; }
}
