:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --border: #ddd9d0;
  --accent: #bf2626;
  --accent-hover: #a01e1e;
  --accent-light: #e03030;
  --text: #1a1a1a;
  --text-muted: #6b6560;
  --header-bg: #111111;
  --nav-bg: #bf2626;
  --table-head-bg: #1a1a1a;
  --row-alt: #f0ece4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Source Sans 3', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── Header ──────────────────────────────────── */
#site-header {
  background: var(--header-bg);
  color: white;
  text-align: center;
  padding: 56px 24px 48px;
}

.header-icon {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 12px;
  display: block;
}

#site-header h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(2.8rem, 10vw, 7rem);
  letter-spacing: 0.06em;
  color: white;
  line-height: 1;
}

#site-header p {
  margin-top: 14px;
  color: #b0a9a0;
  font-size: 1.05rem;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

#site-header a {
  color: #e87070;
  text-decoration: none;
}

#site-header a:hover {
  text-decoration: underline;
}

/* ── Nav ─────────────────────────────────────── */
#main-nav {
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  padding: 0 16px;
}

#main-nav ul {
  list-style: none;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto;
  flex: 1;
}

#main-nav a {
  display: block;
  padding: 13px 22px;
  color: rgba(255,255,255,0.92);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
}

#main-nav a:hover {
  background: rgba(255,255,255,0.18);
  color: white;
}

/* ── Main Container ──────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

section {
  padding: 52px 0;
  border-bottom: 1px solid var(--border);
}

section:last-child {
  border-bottom: none;
}

section > h2 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.4rem;
  letter-spacing: 0.07em;
  color: var(--header-bg);
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
}

section > h2::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border);
}

/* ── Stats ───────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px 18px;
  text-align: center;
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.stat-value {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 3rem;
  color: var(--accent);
  line-height: 1;
  letter-spacing: 0.03em;
}

.stat-value.gold  { color: #b8860b; }
.stat-value.green { color: #2d7a3a; }

.stat-label {
  margin-top: 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-note {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Controls ────────────────────────────────── */
.controls-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap::before {
  content: '🔍';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus {
  border-color: var(--accent);
}

#type-filter {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

#type-filter:focus {
  border-color: var(--accent);
}

.result-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ── Table ───────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--table-head-bg);
  color: white;
  padding: 11px 13px;
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

thead th:hover       { background: #2a2a2a; }
thead th.sort-active { background: #2e2e2e; }

.sort-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.65rem;
  opacity: 0.35;
  vertical-align: middle;
}

thead th.sort-active .sort-arrow {
  opacity: 1;
  color: #ff9080;
}

tbody tr {
  transition: background 0.1s;
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: #ffe8e3 !important;
}

tbody td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Number cell */
.td-num {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

/* Sausage type */
.td-type {
  font-weight: 600;
  min-width: 160px;
}

/* Rating badge */
.rating {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
  background: #888;
  color: white;
}
.rating.r-perfect { background: #c8a000; color: #fff; }
.rating.r-great   { background: #2d7a3a; color: #fff; }
.rating.r-good    { background: #3a7a9a; color: #fff; }
.rating.r-meh     { background: #7a6a2a; color: #fff; }
.rating.r-bad     { background: #a04020; color: #fff; }
.rating.r-zero    { background: #8a2020; color: #fff; }
.rating.r-dq      { background: #555;    color: #ddd; }

/* Burst cell */
.burst-yes { color: var(--accent); font-weight: 700; }
.burst-no  { color: #999; }

/* Episode link */
.ep-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.ep-link:hover {
  text-decoration: underline;
}

/* Episode type pill */
.ep-type {
  background: #eee9e0;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--text-muted);
}

/* Song */
.td-song {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.83rem;
  max-width: 220px;
}

/* ── Loading / Empty ─────────────────────────── */
.loading-msg, .no-results {
  text-align: center;
  padding: 52px 20px;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.loading-spinner {
  display: inline-block;
  font-size: 2rem;
  animation: spin 1.2s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.error-msg {
  background: #fff3f3;
  border: 1px solid #f5c0c0;
  border-radius: 8px;
  padding: 20px;
  color: #a02020;
}

/* ── Data section ────────────────────────────── */
.prose p {
  margin-bottom: 14px;
  max-width: 680px;
  line-height: 1.7;
}

.prose a {
  color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 22px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.825rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary           { background: var(--accent);     color: white; }
.btn-primary:hover     { background: var(--accent-hover); }
.btn-dark              { background: var(--header-bg);  color: white; }
.btn-dark:hover        { background: #333; }

/* ── Footer ──────────────────────────────────── */
footer {
  background: var(--header-bg);
  color: #888;
  text-align: center;
  padding: 28px 20px;
  font-size: 0.875rem;
}

footer a       { color: #e87070; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 600px) {
  section      { padding: 36px 0; }
  .stats-grid  { grid-template-columns: repeat(2, 1fr); }
}

/* ── Dark Mode Toggle Button ─────────────────── */
#theme-toggle {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.55);
  color: white;
  padding: 5px 13px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
  margin-left: auto;
  flex-shrink: 0;
}
#theme-toggle:hover {
  background: rgba(255,255,255,0.15);
  border-color: white;
}

/* ── Dark Mode ───────────────────────────────── */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --surface: #242424;
  --border: #3a3a3a;
  --accent: #e04040;
  --accent-hover: #c43030;
  --accent-light: #e04040;
  --text: #e8e4de;
  --text-muted: #9a9490;
  --header-bg: #0d0d0d;
  --nav-bg: #9e1f1f;
  --table-head-bg: #0d0d0d;
  --row-alt: #1e1e1e;
}

[data-theme="dark"] #site-header p  { color: #8a8480; }
[data-theme="dark"] #site-header a  { color: #e87070; }
[data-theme="dark"] .stat-card       { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .stat-note       { color: var(--text-muted); }
[data-theme="dark"] .search-wrap input { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .search-wrap input::placeholder { color: var(--text-muted); }
[data-theme="dark"] select            { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .prose a          { color: #e87070; }
[data-theme="dark"] .prose a:hover    { color: #ff9090; }
[data-theme="dark"] footer            { background: var(--header-bg); color: #6a6460; }
