:root {
  --bg: #FAF9F7;
  --surface: #FFFFFF;
  --surface-2: #F3F0EB;
  --ink: #1B1917;
  --muted: #6B655E;
  --line: #E6E1D9;
  --accent: #2E5B88;
  --add: #1F6E4A;
  --add-bg: #EAF5EF;
  --note: #9A5B13;
  --note-bg: #FDF4E6;
  --kill: #9E3333;
  --kill-bg: #FBECEC;
  --excl: #6C4A1D;
  --excl-bg: #F7EFE2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27,25,23,.05), 0 6px 20px rgba(27,25,23,.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* Sticky Topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(250, 249, 247, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1480px; margin: 0 auto;
  padding: 12px 20px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.brand h1 {
  margin: 0; font-family: 'Instrument Serif', Georgia, serif;
  font-size: 28px; font-weight: 400; letter-spacing: -0.01em; line-height: 1.05;
}
.brand h1 span { color: var(--muted); font-style: italic; }
.brand .sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sync-pill {
  font-size: 12px; color: var(--muted); padding: 5px 10px;
  border-radius: 999px; background: var(--surface-2);
}
.sync-pill.saving { color: var(--note); background: var(--note-bg); }
.btn-send {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink); color: #fff; border: none;
  padding: 9px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  transition: transform .12s ease, opacity .12s ease;
}
.btn-send:active { transform: scale(.97); }
.badge-count {
  background: var(--add); color: #fff; font-size: 11.5px;
  padding: 2px 7px; border-radius: 999px; font-variant-numeric: tabular-nums;
}

/* Theme tabs */
.theme-bar {
  max-width: 1480px; margin: 0 auto;
  padding: 6px 20px 8px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.theme-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 7px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, color .12s;
}
.tab-btn .cnt { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tab-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab-btn.active .cnt { color: rgba(255,255,255,.72); }
.tab-btn.excl { border-color: #DECAA9; background: var(--excl-bg); color: var(--excl); }
.tab-btn.excl.active { background: var(--excl); color: #fff; border-color: var(--excl); }

/* Secondary filter bar */
.filter-bar {
  max-width: 1480px; margin: 0 auto;
  padding: 6px 20px 10px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  border-top: 1px solid rgba(230,225,217,.65);
}
.filter-group { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.filter-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill {
  border: 1px solid transparent; background: transparent;
  color: var(--muted); padding: 5px 10px; border-radius: 8px;
  font-size: 12.5px; font-weight: 500;
}
.pill.active { background: var(--surface); border-color: var(--line); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.pill.add-pill.active { background: var(--add-bg); border-color: #B7DFC9; color: var(--add); }
.pill.note-pill.active { background: var(--note-bg); border-color: #ECD2A8; color: var(--note); }
.pill.kill-pill.active { background: var(--kill-bg); border-color: #EBC3C3; color: var(--kill); }

.search-wrap input {
  width: 210px; max-width: 100%;
  padding: 6px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; /* prevents iOS zoom */
}
@media (min-width: 720px) { .search-wrap input { font-size: 13px; } }
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Main area */
.main {
  max-width: 1480px; margin: 0 auto;
  padding: 16px 20px 96px;
}
.excl-banner {
  background: var(--excl-bg); border: 1px solid #DECAA9; color: var(--excl);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 3px; font-size: 13px;
}
.excl-banner strong { font-size: 13.5px; }
.section-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; font-size: 13px; color: var(--muted);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 16px;
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .topbar-inner { padding: 10px 12px 6px; }
  .theme-bar, .filter-bar { padding-left: 12px; padding-right: 12px; }
  .main { padding: 12px 12px 88px; }
  .brand h1 { font-size: 22px; }
  .top-actions .btn-send { display: none; }
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  transition: border-color .15s, opacity .15s, box-shadow .15s;
}
.card.st-add { border-color: var(--add); box-shadow: 0 0 0 1.5px var(--add), var(--shadow); }
.card.st-kill { opacity: 0.46; border-color: #E2C6C6; }
.card.st-kill:hover { opacity: 0.78; }

.photo-box {
  position: relative; aspect-ratio: 2 / 3;
  background: var(--surface-2); overflow: hidden; cursor: zoom-in;
}
.photo-box img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.badge-row {
  position: absolute; top: 8px; left: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 6px;
  pointer-events: none;
}
.tag {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  padding: 3px 7px; border-radius: 999px;
  background: rgba(255,255,255,.92); color: var(--ink);
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.tag.new { background: var(--accent); color: #fff; }
.tag.excl { background: var(--excl); color: #fff; }
.tag.added { background: var(--add); color: #fff; }
.tag.killed { background: var(--kill); color: #fff; }

.side-toggle {
  position: absolute; bottom: 8px; right: 8px;
  border: none; border-radius: 999px;
  background: rgba(27,25,23,.78); color: #fff;
  font-size: 11px; font-weight: 600; padding: 4px 9px;
  backdrop-filter: blur(6px);
}

.card-body {
  padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 8px; flex: 1;
}
.card-title {
  margin: 0; font-size: 13.5px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-sub {
  font-size: 11.5px; color: var(--muted); line-height: 1.3;
  display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center;
}
.card-sub .dot { opacity: .45; }
.card-excl-note {
  font-size: 11px; color: var(--excl); background: var(--excl-bg);
  padding: 4px 7px; border-radius: 7px; line-height: 1.3;
}

.card-btns {
  margin-top: auto;
  display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 5px;
}
.act-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 9px; padding: 8px 4px;
  font-size: 12px; font-weight: 600; min-height: 36px;
  transition: background .12s, color .12s, border-color .12s, transform .1s;
}
.act-btn:active { transform: scale(.96); }
.act-btn.add.on { background: var(--add); border-color: var(--add); color: #fff; }
.act-btn.note.on { background: var(--note-bg); border-color: #DDA960; color: var(--note); }
.act-btn.kill.on { background: var(--kill); border-color: var(--kill); color: #fff; }

.note-box { display: none; }
.note-box.open { display: block; }
.note-box input {
  width: 100%; padding: 7px 9px; border-radius: 8px;
  border: 1px solid #E3C79B; background: var(--note-bg);
  font-size: 16px; color: var(--ink);
}
@media (min-width: 720px) { .note-box input { font-size: 12.5px; } }
.note-box input:focus { outline: 2px solid var(--note); outline-offset: -1px; }

.load-more-wrap { display: flex; justify-content: center; margin-top: 24px; }
.btn-more {
  background: var(--surface); border: 1px solid var(--line);
  padding: 11px 24px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
}

/* Mobile sticky footer */
.mobile-bar {
  display: none;
}
@media (max-width: 560px) {
  .mobile-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.95); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .m-stats { font-size: 12.5px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
  .btn-send.sm { padding: 8px 14px; font-size: 12.5px; }
}

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 18, 16, 0.65); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }

.lb-sheet, .send-sheet {
  background: var(--surface); border-radius: 18px; width: 100%;
  max-height: 92dvh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.lb-sheet { max-width: 980px; }
.send-sheet { max-width: 640px; }

.lb-head, .send-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.lb-title-wrap h2, .send-head h2 { margin: 2px 0; font-size: 18px; font-weight: 600; }
.lb-code { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.lb-meta, .send-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.lb-nav { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 18px; line-height: 1; display: grid; place-items: center;
}
.lb-excl {
  background: var(--excl-bg); color: var(--excl); font-size: 12.5px; font-weight: 500;
  padding: 8px 18px; border-bottom: 1px solid #DECAA9;
}
.lb-photos {
  flex: 1; overflow-y: auto; padding: 16px; background: var(--bg);
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
}
.lb-photos img {
  max-height: 60dvh; max-width: 100%; width: auto; border-radius: 12px;
  box-shadow: var(--shadow); object-fit: contain;
}
.lb-actions {
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 10px;
}
.lb-btns { max-width: 420px; }
.lb-note-row input {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 14px;
}

.send-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.send-name-row { display: flex; align-items: center; gap: 10px; }
.send-name-row label { font-size: 13px; font-weight: 600; }
.send-name-row input {
  flex: 1; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line); font-size: 14px;
}
.send-body textarea {
  width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.45;
  resize: vertical;
}
.send-foot {
  padding: 12px 18px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 10px;
}
.btn-ghost {
  background: var(--surface); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.btn-primary {
  background: var(--add); color: #fff; border: none;
  padding: 9px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; z-index: 200;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty {
  grid-column: 1 / -1; text-align: center; padding: 64px 20px; color: var(--muted);
}
