:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef4ee;
  --text: #16231c;
  --muted: #647067;
  --border: #d9e2dc;
  --brand: #0f5132;
  --brand-2: #1b744b;
  --danger: #9f1d1d;
  --warning: #f3ce49;
  --shadow: 0 12px 32px rgba(22, 35, 28, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 81, 50, .15), transparent 30rem),
    linear-gradient(180deg, var(--bg), #edf3ee 55%, #f9faf8);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  padding: .76rem 1rem;
  background: var(--brand);
  color: white;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(15, 81, 50, .18);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 10px 20px rgba(15, 81, 50, .22); }
button:active { transform: translateY(0); box-shadow: 0 5px 12px rgba(15, 81, 50, .18); }
button.secondary { background: var(--surface); color: var(--brand); border: 1px solid var(--border); box-shadow: none; }
button.danger { background: var(--danger); }
button.small { padding: .55rem .75rem; font-size: .88rem; }



.app-header {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2.5rem) 1rem 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.hero-copy { min-width: 0; }
.event-visual {
  flex: 0 0 auto;
  width: min(13rem, 32vw);
  min-height: 9rem;
  border-radius: 1.4rem;
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: .65rem;
  isolation: isolate;
}
.event-year { font-size: clamp(2.15rem, 7vw, 4.8rem); line-height: .9; font-weight: 950; letter-spacing: -.08em; }
.host-strip { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: center; }
.host-strip span { font-size: .72rem; font-weight: 950; letter-spacing: .08em; border-radius: 999px; padding: .28rem .48rem; }
.event-orbit { position: absolute; inset: 0; pointer-events: none; z-index: -1; }
.event-orbit span { position: absolute; border-radius: 999px; border: 2px solid currentColor; opacity: .28; }
.event-orbit span:nth-child(1) { width: 9rem; height: 9rem; top: -2.5rem; right: -2.8rem; }
.event-orbit span:nth-child(2) { width: 6.5rem; height: 6.5rem; bottom: -2.4rem; left: -1.7rem; }
.event-orbit span:nth-child(3) { width: 3.4rem; height: 3.4rem; right: 1.25rem; bottom: 1.1rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--brand); font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(1.75rem, 5vw, 3rem); line-height: 1; }
.subtitle { margin: .5rem 0 0; color: var(--muted); max-width: 56rem; }
.hidden { display: none !important; }

main { max-width: 1180px; margin: 0 auto; padding: 0 1rem 4rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin: .75rem 0;
}
.stat-card {
  background: rgba(255,255,255,.82);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat-card span { display: block; font-size: clamp(1.45rem, 4vw, 2.1rem); font-weight: 850; }
.stat-card small { color: var(--muted); font-weight: 750; }
.progress-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: .9rem 1rem;
  margin-bottom: .75rem;
  box-shadow: var(--shadow);
}
.progress-top { display: flex; justify-content: space-between; margin-bottom: .55rem; color: var(--muted); }
.progress-top strong { color: var(--text); }
.progress-bar { height: .75rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
#progressFill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: inherit; transition: width .2s ease; }

.panel {
  background: rgba(255,255,255,.78);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}
.controls-panel { padding: .75rem; margin: .75rem 0; }
.toolbar, .actions {
  display: grid;
  gap: .75rem;
  margin: .75rem 0;
}
.toolbar { grid-template-columns: 2fr 1fr 1fr; margin: 0; }
.actions { grid-template-columns: repeat(7, auto); justify-content: start; align-items: end; }
label span { display: block; color: var(--muted); font-size: .8rem; font-weight: 800; margin: 0 0 .25rem .25rem; }
.inline-select { min-width: 12rem; }
.inline-select select { min-height: 2.8rem; }
input[type="search"], select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .78rem 1rem;
  background: var(--surface);
  color: var(--text);
  outline-color: var(--brand);
}
.view-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
}
.view-tools strong { display: block; }
.view-tools small { display: block; color: var(--muted); font-weight: 700; margin-top: .1rem; }
.view-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; }
.switch-control {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 2.35rem;
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
.switch-control input { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); }
.switch-control span { margin: 0; color: var(--text); font-size: .88rem; }
.status { min-height: 1.25rem; color: var(--muted); font-weight: 700; }

.section-eyebrow {
  margin: 0 0 .25rem;
  color: var(--brand);
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: .72rem;
}

.trade-panel {
  padding: .95rem;
  margin: .75rem 0 1rem;
}
.trade-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .85rem;
}
.trade-header h2 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.7rem);
}
.trade-header p:not(.section-eyebrow) {
  margin: .3rem 0 0;
  color: var(--muted);
  max-width: 48rem;
}
.trade-actions, .card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: flex-end;
}
.trade-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
}
.trade-card {
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: .75rem;
  min-width: 0;
}
.trade-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .55rem;
}
.trade-card header strong { font-size: 1rem; }
.trade-card header span { color: var(--muted); font-size: .8rem; font-weight: 850; white-space: nowrap; }
.trade-card textarea {
  width: 100%;
  min-height: 14rem;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: .85rem;
  padding: .7rem;
  background: #fbfdfb;
  color: var(--text);
  font: .85rem/1.35 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.card-actions { margin-top: .55rem; }
.hint {
  margin-top: .55rem;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.sticker-list { display: grid; gap: 1rem; }
.group {
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.group-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(110deg, var(--group-accent-1, var(--brand)), var(--group-accent-2, var(--brand-2)));
  color: var(--group-header-text, white);
  padding: .35rem .55rem;
}
.group-heading { margin: 0; min-width: 0; }
.group-toggle {
  width: 100%;
  min-height: 3.3rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .55rem;
  text-align: left;
  border-radius: .95rem;
  padding: .4rem .55rem;
  background: transparent;
  color: white;
  box-shadow: none;
}
.group-toggle:hover { background: rgba(255,255,255,.08); box-shadow: none; }
.chevron {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  transition: transform .16s ease;
}
.group.is-collapsed .chevron { transform: rotate(-90deg); }
.group-title-text { display: block; font-size: 1rem; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-subtitle { display: block; margin-top: .15rem; font-size: .78rem; font-weight: 700; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-count {
  min-width: 3.2rem;
  text-align: center;
  font-size: .82rem;
  font-weight: 900;
  opacity: .95;
  white-space: nowrap;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: .38rem .55rem;
}
.group-progress { height: .34rem; background: rgba(15,81,50,.14); }
.group-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--group-accent-2, var(--warning)), var(--group-accent-3, var(--warning))); transition: width .2s ease; }
.group-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.group-items[hidden] { display: none; }
.sticker-row {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .7rem;
  padding: .66rem .75rem;
  border-top: 1px solid var(--border);
}
.sticker-row:nth-child(odd) { background: rgba(238,244,238,.42); }
.sticker-row.is-owned { background: rgba(15,81,50,.06); }
.sticker-row.has-duplicates .dupes output { color: var(--brand); }
.owned-check { display: grid; place-items: center; margin: 0; }
.owned-check input { position: absolute; opacity: 0; pointer-events: none; }
.checkmark {
  width: 1.45rem;
  height: 1.45rem;
  border: 2px solid #93a199;
  border-radius: .42rem;
  display: inline-grid;
  place-items: center;
  background: #fff;
}
.owned-check input:focus-visible + .checkmark { outline: 3px solid rgba(15,81,50,.24); outline-offset: 2px; }
.owned-check input:checked + .checkmark { border-color: var(--brand); background: var(--brand); }
.owned-check input:checked + .checkmark::after { content: "✓"; color: white; font-weight: 900; }
.sticker-main { min-width: 0; }
.sticker-title {
  display: flex;
  align-items: baseline;
  gap: .38rem;
  min-width: 0;
  line-height: 1.25;
}
.code { font-variant-numeric: tabular-nums; letter-spacing: .01em; white-space: nowrap; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foil-badge {
  display: none;
  border: 1px solid #d0a916;
  color: #6b5300;
  background: #fff8d7;
  border-radius: 999px;
  padding: .05rem .35rem;
  font-size: .68rem;
  font-weight: 900;
  flex: 0 0 auto;
}
.sticker-row.is-foil .foil-badge { display: inline-block; }
.meta { color: var(--muted); font-size: .75rem; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dupes {
  display: grid;
  grid-template-columns: auto 1.75rem auto;
  align-items: center;
  gap: .25rem;
}
.dupes button {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  display: grid;
  place-items: center;
  box-shadow: none;
}
.dupes output { text-align: center; font-weight: 850; font-variant-numeric: tabular-nums; }
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  color: var(--muted);
  border-radius: 1.25rem;
  padding: 2rem;
  text-align: center;
  font-weight: 800;
}

.compact-mode .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-mode .stat-card { padding: .72rem .85rem; }
.compact-mode .progress-wrap { padding: .72rem .85rem; }
.compact-mode .sticker-list { gap: .65rem; }
.compact-mode .group-toggle { min-height: 2.7rem; }
.compact-mode .group-subtitle { display: none; }
.compact-mode .group-items { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-mode .sticker-row { padding: .45rem .55rem; gap: .48rem; }
.compact-mode .checkmark { width: 1.25rem; height: 1.25rem; border-radius: .34rem; }
.compact-mode .dupes { grid-template-columns: auto 1.45rem auto; }
.compact-mode .dupes button { width: 1.55rem; height: 1.55rem; font-size: .9rem; }
.compact-mode .meta { display: none; }
.compact-mode .trade-card textarea { min-height: 10rem; font-size: .78rem; }
.compact-mode .trade-panel { padding: .7rem; }

@media (max-width: 1000px) {
  .compact-mode .group-items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr; }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions button { width: 100%; }
  .group-items, .compact-mode .group-items { grid-template-columns: 1fr; }
  .app-header { align-items: stretch; flex-direction: column; }
  .view-tools { align-items: stretch; flex-direction: column; }
  .trade-header { flex-direction: column; align-items: stretch; }
  .trade-actions { justify-content: stretch; }
  .trade-actions button { flex: 1 1 auto; }
  .trade-grid { grid-template-columns: 1fr; }
  .view-actions { justify-content: stretch; }
  .view-actions > * { flex: 1 1 auto; }
}

@media (max-width: 520px) {
  main, .app-header { padding-left: .75rem; padding-right: .75rem; }
  .actions { grid-template-columns: 1fr; }
  .group-header { grid-template-columns: minmax(0, 1fr); }
  .group-count { justify-self: start; margin-left: 2.1rem; margin-bottom: .25rem; }
  .sticker-row { grid-template-columns: auto minmax(0, 1fr); }
  .dupes { grid-column: 2; justify-content: start; }
  .view-actions { flex-direction: column; }
  .view-actions > * { width: 100%; justify-content: center; }
  .trade-card textarea { min-height: 11rem; }
  .trade-actions { flex-direction: column; }
  .trade-actions button, .card-actions button { width: 100%; }
}

@media print {
  .toolbar, .view-tools, .actions, .status, .dupes, .owned-check, .trade-panel { display: none !important; }
  body { background: white; }
  main, .app-header { max-width: none; padding: 0; }
  .stats-grid, .progress-wrap, .panel { box-shadow: none; }
  .group { break-inside: avoid; box-shadow: none; }
  .group-header { position: static; background: #eee; color: #111; }
  .group-toggle { color: #111; }
  .chevron, .group-count, .group-progress { display: none; }
  .group-items { display: grid !important; grid-template-columns: repeat(3, 1fr); }
  .sticker-row { grid-template-columns: 1fr; padding: .25rem .45rem; }
}

.summary-panel,
.data-panel {
  padding: .95rem;
  margin: .75rem 0;
}

.panel-heading,
.mini-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-heading h2 {
  margin: 0;
  font-size: clamp(1.2rem, 3vw, 1.65rem);
}

.panel-summary {
  margin: .28rem 0 0;
  color: var(--muted);
  font-weight: 750;
}

.panel-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  white-space: nowrap;
}

.toggle-icon {
  display: inline-grid;
  place-items: center;
  width: 1.1rem;
  font-size: 1.1rem;
  line-height: 1;
}

.collapsible-body[hidden] {
  display: none !important;
}

.is-panel-collapsed {
  background: rgba(255,255,255,.62);
}

.summary-panel .progress-wrap {
  margin: .85rem 0 0;
  box-shadow: none;
}

.summary-panel .stats-grid {
  margin: .85rem 0 0;
}

.data-panel .actions {
  margin: 0;
}

.panel-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .55rem;
  flex-wrap: wrap;
}

#backupBody {
  margin-top: .85rem;
  padding-top: .85rem;
  border-top: 1px solid var(--border);
}

.data-panel.is-panel-collapsed {
  padding-bottom: .8rem;
}

.mini-panel-heading strong {
  display: block;
}

.mini-panel-heading small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-top: .18rem;
}

.trade-panel.is-panel-collapsed {
  padding-bottom: .8rem;
}

.trade-panel.is-panel-collapsed .trade-header {
  margin-bottom: 0;
}

.trade-intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin: .85rem 0;
  padding-top: .85rem;
  border-top: 1px solid var(--border);
}

.trade-intro p {
  margin: 0;
  color: var(--muted);
  max-width: 48rem;
}

.compact-mode .summary-panel,
.compact-mode .data-panel {
  padding: .7rem;
}

.compact-mode .panel-heading h2 {
  font-size: 1.12rem;
}

@media (max-width: 900px) {
  .panel-heading,
  .mini-panel-heading,
  .trade-intro {
    flex-direction: column;
    align-items: stretch;
  }
  .panel-toggle {
    width: 100%;
  }
}

@media print {
  .data-panel,
  .panel-toggle,
  .trade-panel {
    display: none !important;
  }
  .summary-panel {
    box-shadow: none;
    padding: 0;
    border: 0;
  }
}

.backup-pill {
  display: inline-flex;
  align-items: center;
  min-height: 2.05rem;
  padding: .25rem .7rem;
  border-radius: 999px;
  background: rgba(179, 54, 54, .1);
  border: 1px solid rgba(179, 54, 54, .18);
  color: var(--danger);
  font-size: .78rem;
  font-weight: 850;
  white-space: nowrap;
}
.backup-pill.is-ok {
  background: rgba(15, 81, 50, .1);
  border-color: rgba(15, 81, 50, .18);
  color: var(--brand);
}
.group-header::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255,255,255,.18), transparent 34%, rgba(0,0,0,.12));
}
.group-header > * {
  position: relative;
  z-index: 1;
}
@media (max-width: 900px) {
  .inline-select { width: 100%; }
}
