@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;600;700;900&family=Inconsolata:wght@400;600;700&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

:root {
  --ink: #1a1209;
  --paper: #f5f0e8;
  --paper-warm: #ede5d0;
  --red: #c0392b;
  --red-light: #e74c3c;
  --gold: #b8860b;
  --gold-light: #d4a017;
  --green: #1e6b3c;
  --blue: #1a3a5c;
  --gray: #6b5e4e;
  --gray-light: #a09080;
  --border: #c8b89a;
  --shadow: rgba(26,18,9,0.12);
  --dpp: #1B75BB;
  --kmt: #000095;
  --pfp: #FF6600;
  --npp: #FBBE01;
  --other: #888;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans TC', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 10% 20%, rgba(184,134,11,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 90% 80%, rgba(192,57,43,0.04) 0%, transparent 60%);
}

/* ── HEADER ── */
.site-header {
  background: var(--ink);
  color: var(--paper);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}

.logo {
  font-family: 'Noto Serif TC', serif;
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: 0.05em;
  color: var(--paper);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-badge {
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-family: 'Inconsolata', monospace;
  padding: 2px 8px;
  border-radius: 2px;
  letter-spacing: 0.08em;
}

.header-nav {
  display: flex;
  gap: 24px;
  align-items: center;
}

.header-nav a {
  color: var(--gray-light);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: color 0.2s;
}
.header-nav a:hover { color: var(--paper); }

/* ── HERO / SEARCH ── */
.hero {
  background: var(--ink);
  color: var(--paper);
  padding: 60px 24px 80px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '立法委員';
  position: absolute;
  font-family: 'Noto Serif TC', serif;
  font-size: 18rem;
  font-weight: 900;
  opacity: 0.03;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  pointer-events: none;
}

.hero-year {
  font-family: 'Inconsolata', monospace;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--gold-light);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.hero h1 {
  font-family: 'Noto Serif TC', serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 900;
  margin-bottom: 10px;
  line-height: 1.2;
}

.hero h1 em {
  color: var(--gold-light);
  font-style: normal;
}

.hero-sub {
  color: var(--gray-light);
  font-size: 0.95rem;
  margin-bottom: 36px;
  line-height: 1.6;
}

.search-box {
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

.search-input-wrap {
  display: flex;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--paper);
  transition: border-color 0.2s;
}

.search-input-wrap:focus-within {
  border-color: var(--gold-light);
}

.search-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 1rem;
  font-family: 'Noto Sans TC', sans-serif;
  border: none;
  background: transparent;
  color: var(--ink);
  outline: none;
}

.search-btn {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 0 28px;
  font-size: 0.9rem;
  font-family: 'Noto Sans TC', sans-serif;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.2s;
}
.search-btn:hover { background: var(--red-light); }

.search-hint {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--gray-light);
}

/* ── STATS SECTION ── */
.section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 56px 24px;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.section-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
}

.section-num {
  font-family: 'Inconsolata', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--gray-light);
  text-transform: uppercase;
}

/* ── PARTY STATS ── */
.party-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.party-card {
  border: 1px solid var(--border);
  background: white;
  padding: 20px;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.party-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow);
}

.party-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.party-card.dpp::before { background: var(--dpp); }
.party-card.kmt::before { background: var(--kmt); }
.party-card.pfp::before { background: var(--pfp); }
.party-card.npp::before { background: var(--npp); }
.party-card.other::before { background: var(--other); }

.party-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 4px;
}

.party-count {
  font-family: 'Inconsolata', monospace;
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 14px;
}

.party-total {
  font-family: 'Inconsolata', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--red);
}

.party-label {
  font-size: 0.72rem;
  color: var(--gray-light);
  margin-top: 2px;
}

.party-bar-wrap {
  margin-top: 12px;
  height: 4px;
  background: var(--paper-warm);
  border-radius: 2px;
  overflow: hidden;
}
.party-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.8s ease;
}
.party-card.dpp .party-bar { background: var(--dpp); }
.party-card.kmt .party-bar { background: var(--kmt); }
.party-card.pfp .party-bar { background: var(--pfp); }
.party-card.npp .party-bar { background: var(--npp); }
.party-card.other .party-bar { background: var(--other); }

/* ── COUNTY STATS ── */
.county-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.county-card {
  border: 1px solid var(--border);
  background: white;
  padding: 16px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.county-card:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.county-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.county-total {
  font-family: 'Inconsolata', monospace;
  font-size: 0.88rem;
  color: var(--red);
}
.county-card:hover .county-total { color: var(--gold-light); }

.county-candidates {
  font-size: 0.72rem;
  color: var(--gray-light);
  margin-top: 2px;
}
.county-card:hover .county-candidates { color: var(--gray-light); }

/* ── RANKING ── */
.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.ranking-table th {
  font-family: 'Noto Serif TC', serif;
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--gray);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
}

.ranking-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ranking-table tr:hover td { background: rgba(184,134,11,0.05); }

.rank-num {
  font-family: 'Inconsolata', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--gray-light);
  width: 40px;
}

.rank-1 .rank-num { color: #c0392b; }
.rank-2 .rank-num { color: #7f8c8d; }
.rank-3 .rank-num { color: #b8860b; }

.candidate-name {
  font-weight: 700;
  font-size: 0.95rem;
}
.candidate-name a {
  color: var(--ink);
  text-decoration: none;
}
.candidate-name a:hover { color: var(--red); }

.candidate-district {
  font-size: 0.75rem;
  color: var(--gray-light);
  margin-top: 2px;
}

.money {
  font-family: 'Inconsolata', monospace;
  font-weight: 600;
  color: var(--ink);
}

.elected-badge {
  background: var(--green);
  color: white;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 2px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.party-tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 2px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: white;
}
.tag-dpp { background: var(--dpp); }
.tag-kmt { background: var(--kmt); }
.tag-pfp { background: var(--pfp); }
.tag-npp { background: #a08800; color: white; }
.tag-other { background: var(--other); }

/* ── LOADING ── */
.loading {
  text-align: center;
  padding: 60px;
  color: var(--gray-light);
  font-family: 'Inconsolata', monospace;
  letter-spacing: 0.1em;
}

.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FOOTER ── */
.site-footer {
  background: var(--ink);
  color: var(--gray);
  text-align: center;
  padding: 28px 24px;
  font-size: 0.78rem;
  font-family: 'Inconsolata', monospace;
  letter-spacing: 0.08em;
  margin-top: 40px;
}
.site-footer span { color: var(--gold-light); }

/* ── RESULTS PAGE ── */
.results-hero {
  background: var(--ink);
  color: var(--paper);
  padding: 36px 24px;
}

.results-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.results-breadcrumb {
  font-family: 'Inconsolata', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--gray-light);
  margin-bottom: 14px;
}
.results-breadcrumb a { color: var(--gold-light); text-decoration: none; }

.results-title {
  font-family: 'Noto Serif TC', serif;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 900;
  margin-bottom: 8px;
}

.results-title em { color: var(--gold-light); font-style: normal; }

.results-meta {
  font-size: 0.82rem;
  color: var(--gray-light);
  font-family: 'Inconsolata', monospace;
}

/* ── CONTROLS ── */
.controls-bar {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 57px;
  z-index: 90;
}

.controls-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.sort-label {
  font-size: 0.8rem;
  color: var(--gray);
  font-weight: 600;
  white-space: nowrap;
}

.sort-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sort-btn {
  padding: 5px 14px;
  font-size: 0.78rem;
  font-family: 'Noto Sans TC', sans-serif;
  font-weight: 500;
  border: 1px solid var(--border);
  background: white;
  color: var(--gray);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.sort-btn:hover { border-color: var(--ink); color: var(--ink); }
.sort-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.filter-select {
  padding: 5px 12px;
  font-size: 0.78rem;
  font-family: 'Noto Sans TC', sans-serif;
  border: 1px solid var(--border);
  background: white;
  color: var(--ink);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}

.results-count {
  margin-left: auto;
  font-family: 'Inconsolata', monospace;
  font-size: 0.78rem;
  color: var(--gray-light);
}

/* ── DETAIL TABLE ── */
.full-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.full-table thead {
  position: sticky;
  top: 103px; /* site-header(57px) + controls-bar(46px) */
  z-index: 80;
}

.full-table th {
  font-family: 'Inconsolata', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--gray);
  padding: 10px 12px;
  text-align: right;
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--ink);
}
.full-table th:first-child,
.full-table th:nth-child(2),
.full-table th:nth-child(3) { text-align: left; }
.full-table th:hover { color: var(--ink); }
.full-table th.sort-asc::after { content: ' ▲'; color: var(--red); }
.full-table th.sort-desc::after { content: ' ▼'; color: var(--red); }

.full-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: right;
}
.full-table td:first-child,
.full-table td:nth-child(2),
.full-table td:nth-child(3) { text-align: left; }

.full-table tr:hover td { background: rgba(184,134,11,0.04); }

.row-rank {
  font-family: 'Inconsolata', monospace;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--gray-light);
  min-width: 32px;
}

/* ── DONATE BAR ── */
.donate-bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.donate-mini-bar {
  width: 60px;
  height: 4px;
  background: var(--paper-warm);
  border-radius: 2px;
  overflow: hidden;
}
.donate-mini-fill {
  height: 100%;
  background: var(--red);
  border-radius: 2px;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .party-grid { grid-template-columns: 1fr 1fr; }
  .county-grid { grid-template-columns: repeat(3, 1fr); }
  .ranking-table th:nth-child(n+5),
  .ranking-table td:nth-child(n+5) { display: none; }
  .full-table th:nth-child(n+6),
  .full-table td:nth-child(n+6) { display: none; }
  .header-nav { display: none; }
}

@media (max-width: 480px) {
  .county-grid { grid-template-columns: repeat(2, 1fr); }
  .hero { padding: 36px 16px 52px; }
}
