:root {
  --bg: #f4efe6;
  --bg-2: #ece4d6;
  --card: #fffdf8;
  --ink: #1f1814;
  --muted: #7a6f64;
  --line: #e4d9c8;
  --accent: #c44b2b;
  --accent-soft: #f6e4dc;
  --have: #2d7a4f;
  --have-soft: #e3f2e9;
  --want: #c44b2b;
  --want-soft: #f6e4dc;
  --secret: #7a4cc8;
  --secret-soft: #f0e8fb;
  --gold: #b0892e;
  --warn: #8a5a12;
  --warn-soft: #f8edd6;
  --shadow: 0 1px 2px rgba(31, 24, 20, 0.06), 0 8px 24px rgba(31, 24, 20, 0.05);
  --radius: 16px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang TC", "Noto Sans TC", "Source Han Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; position: relative; padding-bottom: calc(var(--nav-h) + var(--safe-bot) + 12px); }

.loading-screen, .error-screen {
  padding: 40vh 24px 0;
  text-align: center;
  color: var(--muted);
}

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: calc(10px + var(--safe-top)) 16px 10px;
  border-bottom: 1px solid transparent;
}
.top-row { display: flex; align-items: center; gap: 8px; }
.top h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 0.02em;
  flex: 1;
  line-height: 1.2;
}
.back-btn, .lang-btn, .icon-btn {
  border: 0;
  background: var(--card);
  box-shadow: var(--shadow);
  border-radius: 999px;
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
}
.back-btn { min-width: 36px; padding: 0 10px; }
.lang-btn[aria-pressed="true"], .lang-btn.active { background: var(--ink); color: #fff; }

.disclaimer {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 10px;
  padding: 8px 10px;
}

.install-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.install-hint button {
  border: 0; background: none; color: var(--muted); margin-left: auto; padding: 0 4px;
}

.search-wrap { margin-top: 10px; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 16px; /* avoid iOS zoom */
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }

.ip-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 10px;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.ip-chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  font-weight: 600;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

main { padding: 12px 16px 8px; }

/* Cards */
.ip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ip-card, .series-card, .stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.ip-card {
  padding: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 110px;
}
.ip-card .count { color: var(--muted); font-size: 12px; }
.ip-card .progress-text { font-weight: 700; font-size: 15px; }
.ip-card h2 { margin: 0; font-size: 16px; }

.series-list { display: flex; flex-direction: column; gap: 10px; }
.series-card {
  padding: 12px;
  text-align: left;
  width: 100%;
  display: block;
}
.series-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.series-card h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.series-card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.series-card .prog { font-weight: 700; font-size: 14px; white-space: nowrap; }
.bar {
  height: 6px;
  background: var(--bg-2);
  border-radius: 99px;
  margin-top: 8px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.meta-line { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-2);
  color: var(--muted);
}
.badge.secret { background: var(--secret-soft); color: var(--secret); }
.badge.unc { background: var(--warn-soft); color: var(--warn); }
.badge.year { background: #ece8f6; color: #4d3f73; }

/* Figure grid */
.fig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.fig-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.fig-card.have { outline: 2px solid var(--have); }
.thumb {
  aspect-ratio: 1;
  background: #efe8dc;
  position: relative;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .ph { width: 100%; height: 100%; object-fit: contain; padding: 16px; opacity: 0.9; }
.fig-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.fig-body .name { font-size: 13px; font-weight: 700; line-height: 1.3; }
.fig-body .en { font-size: 11px; color: var(--muted); line-height: 1.3; }
.actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; }
.actions button {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 700;
}
.actions button.on-have { background: var(--have); color: #fff; border-color: var(--have); }
.actions button.on-want { background: var(--want); color: #fff; border-color: var(--want); }

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
}
.section-head h2 { margin: 0; font-size: 18px; }
.section-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.share-btn, .primary-btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  line-height: 1.6;
}

.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-card { padding: 14px; }
.stat-card .num { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.stat-card .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.more-btn, .ghost-btn {
  width: 100%;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
}

/* Bottom nav */
.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 520px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  height: calc(var(--nav-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  z-index: 30;
}
.nav button {
  border: 0;
  background: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.nav button.active { color: var(--accent); }
.nav .ico { font-size: 18px; line-height: 1; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,14,10,0.5);
  z-index: 50; display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + var(--safe-bot));
  max-height: 90dvh;
  overflow: auto;
}
.modal h3 { margin: 0 0 10px; }
.modal .preview { width: 100%; border-radius: 12px; background: var(--bg-2); }
.modal .row-btns { display: flex; gap: 8px; margin-top: 12px; }
.modal .row-btns button { flex: 1; }

.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
