:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --text-muted: #8b91a3;
  --accent: #6ee7b7;
  --danger: #f87171;

  --cat-manga: #6ee7b7;
  --cat-novel: #60a5fa;
  --cat-lit: #a78bfa;
  --cat-art: #f472b6;
  --cat-life: #facc15;
  --cat-album: #22d3ee;
  --cat-vinyl: #fb923c;
  --cat-figure: #f59e0b;

  --st-read: #4caf6d;
  --st-reading: #60a5fa;
  --st-unread: #8b91a3;
  --st-notowned: #6b7280;
  --st-unreleased: #a78bfa;
  --st-shipping: #fb923c;

  --radius: 12px;
  --radius-sm: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  font-synthesis: none;
}

[data-theme="light"] {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f2f1ee;
  --border: #e5e3de;
  --text: #1c1a17;
  --text-muted: #6b6a66;
  --accent: #ea580c;
  --danger: #dc2626;

  --cat-manga: #059669;
  --cat-novel: #2563eb;
  --cat-lit: #7c3aed;
  --cat-art: #db2777;
  --cat-life: #ca8a04;
  --cat-album: #0891b2;
  --cat-vinyl: #ea580c;
  --cat-figure: #d97706;

  --st-read: #16a34a;
  --st-reading: #2563eb;
  --st-unread: #78716c;
  --st-notowned: #a8a29e;
  --st-unreleased: #7c3aed;
  --st-shipping: #ea580c;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-3) 96px;
}

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
header.top h1 { font-size: 20px; font-weight: 700; margin: 0; }

.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

nav.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 10;
}
nav.tabbar a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  font-size: 11px;
  color: var(--text-muted);
}
nav.tabbar a .icon { display: block; font-size: 20px; margin-bottom: 2px; }
nav.tabbar a.active { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 var(--space-2);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #0a1a13;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
[data-theme="light"] .btn { color: #fff; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: var(--space-2); }
.btn.block { width: 100%; }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: var(--space-1); }
.field { margin-bottom: var(--space-3); }
.field-row { display: flex; gap: var(--space-2); }
.field-row .field { flex: 1; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.cat-漫畫 { background: color-mix(in srgb, var(--cat-manga) 20%, transparent); color: var(--cat-manga); }
.badge.cat-小說 { background: color-mix(in srgb, var(--cat-novel) 20%, transparent); color: var(--cat-novel); }
.badge.cat-文學 { background: color-mix(in srgb, var(--cat-lit) 20%, transparent); color: var(--cat-lit); }
.badge.cat-美術集 { background: color-mix(in srgb, var(--cat-art) 20%, transparent); color: var(--cat-art); }
.badge.cat-生活技巧 { background: color-mix(in srgb, var(--cat-life) 20%, transparent); color: var(--cat-life); }
.badge.cat-專輯 { background: color-mix(in srgb, var(--cat-album) 20%, transparent); color: var(--cat-album); }
.badge.cat-黑膠 { background: color-mix(in srgb, var(--cat-vinyl) 20%, transparent); color: var(--cat-vinyl); }
.badge.cat-手辦 { background: color-mix(in srgb, var(--cat-figure) 20%, transparent); color: var(--cat-figure); }

.badge.st-已閱 { background: color-mix(in srgb, var(--st-read) 20%, transparent); color: var(--st-read); }
.badge.st-閱讀中 { background: color-mix(in srgb, var(--st-reading) 20%, transparent); color: var(--st-reading); }
.badge.st-未讀 { background: var(--surface-2); color: var(--st-unread); }
.badge.st-未擁有 { background: var(--surface-2); color: var(--st-notowned); }
.badge.st-未發行 { background: color-mix(in srgb, var(--st-unreleased) 20%, transparent); color: var(--st-unreleased); }
.badge.st-配送中 { background: color-mix(in srgb, var(--st-shipping) 20%, transparent); color: var(--st-shipping); }

.brand-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.brand-logo-wrap { background: #fff; border-radius: 8px; padding: 5px 10px; display: inline-flex; align-items: center; }
.brand-logo { height: 18px; width: auto; display: block; }
.sub-brand { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.sub-brand-icon { height: 18px; width: 18px; border-radius: 5px; object-fit: cover; }

.stat-row { display: flex; gap: var(--space-3); margin-top: var(--space-3); flex-wrap: wrap; }
.stat { flex: 1; min-width: 70px; text-align: center; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 11px; color: var(--text-muted); }

.muted { color: var(--text-muted); }
.empty-state { text-align: center; padding: var(--space-5) var(--space-3); color: var(--text-muted); }

/* Toolbar: search + filter chips */
.toolbar { margin-bottom: var(--space-3); }
.search-input { margin-bottom: var(--space-2); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Spreadsheet-style editable table */
.sheet-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}
table.sheet {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
table.sheet th, table.sheet td {
  border-bottom: 1px solid var(--border);
  padding: 0;
  white-space: nowrap;
}
table.sheet th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
  z-index: 3;
}
table.sheet th .sort-arrow { margin-left: 3px; color: var(--accent); }
table.sheet td:first-child, table.sheet th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  min-width: 200px;
}
table.sheet th:first-child { background: var(--surface-2); z-index: 4; }
table.sheet tr:hover td { background: var(--surface-2); }
table.sheet tr:hover td:first-child { background: var(--surface-2); }
table.sheet input, table.sheet select {
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
  min-width: 90px;
}
table.sheet input:focus, table.sheet select:focus {
  background: var(--surface-2);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
table.sheet .row-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 10px;
  font-size: 14px;
}
table.sheet .row-delete:hover { color: var(--danger); }
table.sheet tr.draft-row td:first-child { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
table.sheet tr.draft-row:hover td:first-child { background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }

.sheet-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 60;
}
.confirm-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); max-width: 340px; width: 100%; }
.confirm-box p { white-space: pre-line; font-size: 14px; margin: 0 0 var(--space-4); }

/* Manga series progress */
.series-card { margin-bottom: var(--space-3); }
.series-card .row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.series-card .name { font-weight: 600; font-size: 14.5px; }
.series-card .count { font-size: 12px; color: var(--text-muted); }
.progress-track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { background: var(--cat-manga); height: 100%; border-radius: 999px; }
