/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ───────────────────────────────────────────────────────────── */
:root {
  --bg:         #090b0f;
  --bg2:        #0d1018;
  --surface:    #111521;
  --surface2:   #161c2d;
  --border:     #1c2235;
  --border2:    #252e45;
  --text:       #d8dde8;
  --text2:      #9aa3b8;
  --muted:      #5a6480;
  --accent:     #4a90e2;
  --accent-dim: rgba(74,144,226,.1);
  --green:      #00c98b;
  --green-dim:  rgba(0,201,139,.1);
  --amber:      #f5a623;
  --amber-dim:  rgba(245,166,35,.1);
  --red:        #e5484d;
  --red-dim:    rgba(229,72,77,.1);
  --radius:     8px;
  --radius-sm:  5px;
  --gap:        14px;
  --mono: 'SF Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
}

/* ── Base ────────────────────────────────────────────────────────────────────── */
html { -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top nav bar ─────────────────────────────────────────────────────────────── */
.topnav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 20px;
}

.topnav-inner {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0;
  height: 48px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  text-decoration: none;
  padding-right: 24px;
  border-right: 1px solid var(--border);
  margin-right: 8px;
  white-space: nowrap;
  letter-spacing: -.01em;
}
.nav-brand:hover { text-decoration: none; color: var(--text); }
.nav-brand-icon { font-size: 1.1rem; }

.nav-links {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: .82rem;
  font-weight: 500;
  text-decoration: none;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-badge {
  background: #7c2d12;
  color: #fde68a;
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 12px;
  text-decoration: none;
  letter-spacing: .02em;
}
.nav-badge:hover { text-decoration: none; opacity: .85; }

/* ── Page wrapper ────────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px 20px 32px;
}

/* ── Page header (title + controls row below nav) ───────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-title h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.page-title-sub {
  font-size: .78rem;
  color: var(--muted);
  font-family: var(--mono);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 13px;
  cursor: pointer;
  transition: opacity .15s, filter .15s;
  line-height: 1;
  white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .35; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--green); color: #0a1a12; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-warning { background: var(--amber); color: #1a0a00; }
.btn-ghost   { background: var(--surface2); color: var(--text2); border: 1px solid var(--border2); }
.btn-ghost:hover { color: var(--text); border-color: var(--border2); opacity: 1; background: var(--surface); }

/* legacy aliases */
#refresh-btn { background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size:.8rem; font-weight:600; padding:6px 13px; cursor:pointer; transition:opacity .15s; }
#refresh-btn:hover { opacity:.85; }
#scrape-btn  { background: var(--green); color: #0a1a12; border: none; border-radius: var(--radius-sm); font-size:.8rem; font-weight:600; padding:6px 13px; cursor:pointer; transition:opacity .15s; }
#scrape-btn:hover { opacity:.85; }
#scrape-btn:disabled { opacity:.35; cursor:default; }
#backup-db-btn, #restore-db-btn, #clear-db-btn { border: none; border-radius: var(--radius-sm); font-size:.78rem; font-weight:600; padding:5px 11px; cursor:pointer; }

/* ── Inputs ──────────────────────────────────────────────────────────────────── */
input[type="date"],
input[type="text"],
select {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .82rem;
  padding: 6px 10px;
  outline: none;
  transition: border-color .15s;
}
input[type="date"]:focus,
input[type="text"]:focus,
select:focus { border-color: var(--accent); }
select { cursor: pointer; }

/* ── Stat cards ──────────────────────────────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 700px) { .stat-row { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  position: relative;
  overflow: hidden;
  transition: border-color .15s;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  opacity: .5;
}
.stat-card.highlight::before { background: var(--green); opacity: 1; }
.stat-card:hover { border-color: var(--border2); }

.stat-val {
  font-family: var(--mono);
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat-card.highlight .stat-val { color: var(--green); }

.stat-label {
  font-size: .68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 6px;
  font-weight: 600;
}

/* ── Grid layouts ────────────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-bottom: var(--gap);
}
.grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  margin-bottom: var(--gap);
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

@media (max-width: 900px)  { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px)  { .grid-3 { grid-template-columns: 1fr; } }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card.tall { min-height: 380px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.card-header h2 {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.card-note {
  font-size: .72rem;
  color: var(--muted);
}

.card-divider {
  height: 1px;
  background: var(--border);
  margin: 0 -16px;
}

/* ── Chart containers ────────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 200px;
}

.chart-wrap.tall { min-height: 380px; }
.chart-wrap.scroll { overflow-y: auto; max-height: 440px; }
.chart-wrap.center { display: flex; align-items: center; justify-content: center; }
.chart-wrap.center canvas { max-width: 260px; max-height: 260px; }

/* ── Legend ──────────────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .75rem;
  color: var(--text2);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Tabs ────────────────────────────────────────────────────────────────────── */
.tab-group {
  display: flex;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.tab {
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--muted);
  cursor: pointer;
  font-size: .76rem;
  font-weight: 600;
  padding: 4px 10px;
  transition: all .15s;
  letter-spacing: .02em;
}

.tab:hover:not(:disabled) { color: var(--text2); }
.tab:disabled { opacity: .35; cursor: default; }
.tab.active {
  background: var(--surface2);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--border2);
}

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 340px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .81rem;
}

thead th {
  background: var(--bg);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .07em;
  padding: 8px 10px;
  text-align: left;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border2);
}

thead th.num { text-align: right; }

tbody tr { transition: background .1s; }
tbody tr:nth-child(even) { background: rgba(255,255,255,.015); }
tbody tr:hover { background: rgba(74,144,226,.07); }

td {
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.num {
  text-align: right;
  color: var(--text2);
  font-family: var(--mono);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
td.num.accent { color: var(--accent); }
td.loading { color: var(--muted); text-align: center; padding: 24px; font-style: italic; }
td.empty   { color: var(--muted); text-align: center; padding: 20px; font-style: italic; }

.rank-num {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .03em;
}
.badge-added   { background: var(--green-dim); color: var(--green); }
.badge-removed { background: var(--red-dim);   color: var(--red);   }
.badge-expired { background: rgba(90,100,128,.15); color: var(--text2); }

/* ── Run ID chip ─────────────────────────────────────────────────────────────── */
.run-id-chip {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.run-id-chip:hover { border-color: var(--accent); color: var(--accent); }

.run-detail-btn {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  cursor: pointer;
  font-size: .72rem;
  padding: 2px 8px;
  transition: all .15s;
}
.run-detail-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Inline editing ──────────────────────────────────────────────────────────── */
.edit-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .7rem;
  margin-left: 4px;
  padding: 1px 4px;
  border-radius: 3px;
  transition: opacity .15s, color .15s;
  vertical-align: middle;
  flex-shrink: 0;
}
tr:hover .edit-btn { opacity: 1; }
.edit-btn:hover { color: var(--accent); }

.inline-edit {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .81rem;
  padding: 4px 7px;
  width: 100%;
  min-width: 120px;
  outline: none;
  box-shadow: 0 0 0 3px rgba(74,144,226,.15);
}

.save-flash {
  color: var(--green);
  font-size: .72rem;
  margin-left: 4px;
  animation: fadeout 1.5s forwards;
}
@keyframes fadeout { 0% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }

.editable-cell { display: flex; align-items: center; gap: 2px; }

/* ── Movie link ──────────────────────────────────────────────────────────────── */
.movie-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 210px;
  transition: color .15s;
}
.movie-link:hover { color: var(--accent); text-decoration: none; }

.lang-link {
  color: var(--text2);
  text-decoration: none;
  border-bottom: 1px dotted var(--border2);
  transition: color .15s, border-color .15s;
  font-size: .78rem;
}
.lang-link:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }

.genre-badge {
  display: inline-block;
  background: rgba(74,144,226,.1);
  color: var(--accent);
  border: 1px solid rgba(74,144,226,.2);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: .02em;
}
.genre-badge:hover { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Run detail modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 22px;
  width: min(720px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 76px;
}
.modal-stat .mval {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.modal-stat .mlbl {
  font-size: .65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 4px;
  font-weight: 600;
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  color: var(--muted);
  font-size: .72rem;
  padding: 16px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: var(--gap);
  font-family: var(--mono);
  letter-spacing: .02em;
}

/* ── Universal search ────────────────────────────────────────────────────────── */
.universal-search {
  position: relative;
  flex: 1; min-width: 200px; max-width: 320px;
}
.universal-search input {
  width: 100%;
  padding: 6px 12px 6px 30px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .8rem;
  transition: border-color .15s;
}
.universal-search input:focus { border-color: var(--accent); }
.universal-search::before {
  content: "⌕";
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  font-size: 1rem; pointer-events: none; color: var(--muted); line-height: 1;
}
.search-results {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  max-height: 440px; overflow-y: auto;
  z-index: 1000; display: none;
}
.search-results.open { display: block; }
.search-section { padding: 6px 0; border-bottom: 1px solid var(--border); }
.search-section:last-child { border-bottom: none; }
.search-section-title {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 4px 12px 5px;
  font-weight: 700;
}
.search-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 12px; text-decoration: none; color: var(--text);
  font-size: .82rem; cursor: pointer;
  transition: background .1s;
}
.search-item:hover, .search-item.active { background: var(--accent-dim); text-decoration: none; }
.search-icon { font-size: .9rem; flex-shrink: 0; width: 18px; text-align: center; }
.search-item-body { flex: 1; min-width: 0; overflow: hidden; }
.search-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item-sub { font-size: .7rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.search-empty, .search-loading { padding: 14px; text-align: center; color: var(--muted); font-size: .8rem; }
.search-keyword-hl { background: rgba(245,166,35,.2); color: var(--amber); padding: 0 2px; border-radius: 2px; }

/* ── Scrape status ───────────────────────────────────────────────────────────── */
#scrape-status {
  font-size: .74rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* ── Inline metric chips (trending, demand, etc.) ────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: .72rem;
  font-weight: 700;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 4px;
}
.chip-up   { background: var(--green-dim); color: var(--green); }
.chip-down { background: var(--red-dim);   color: var(--red);   }
.chip-neu  { background: rgba(90,100,128,.12); color: var(--text2); }

/* ── Scrape run feed table row badges ────────────────────────────────────────── */
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green  { background: var(--green); }
.dot-red    { background: var(--red); }
.dot-amber  { background: var(--amber); }
.dot-accent { background: var(--accent); }

/* ── Section label ───────────────────────────────────────────────────────────── */
.section-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 4px;
}

/* ── Trend mini label (up/down % inline) ────────────────────────────────────── */
.trend-up   { color: var(--green); font-weight: 700; }
.trend-down { color: var(--red);   font-weight: 700; }

/* ── Back link ───────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
  margin-bottom: 14px;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Skeleton loader ─────────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { opacity: .4; }
  50%  { opacity: .8; }
  100% { opacity: .4; }
}
.skeleton {
  background: var(--surface2);
  border-radius: 4px;
  animation: shimmer 1.6s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════════════════════════════
   LIGHT THEME + ANIMATIONS  (added 2026-07)
   Dark stays the default; light is opt-in via the header toggle and remembered
   in localStorage. [data-theme="light"] outranks :root so it wins cleanly.
   ══════════════════════════════════════════════════════════════════════════════ */

/* Chart color tokens (read by theme.js so Chart.js follows the theme). */
:root {
  --chart-grid:  #262d40;
  --chart-tick:  #8b949e;
  --chart-label: #d8dde8;
  --shadow:      0 10px 28px -14px rgba(0,0,0,.6);
}

:root[data-theme="light"] {
  --bg:         #eef1f6;
  --bg2:        #e7ebf3;
  --surface:    #ffffff;
  --surface2:   #f2f5fb;
  --border:     #dde3ee;
  --border2:    #c7d0e0;
  --text:       #1b2333;
  --text2:      #4b566b;
  --muted:      #74809a;
  --accent:     #2f6fd6;
  --accent-dim: rgba(47,111,214,.10);
  --green:      #0a9d6e;
  --green-dim:  rgba(10,157,110,.12);
  --amber:      #a86a00;
  --amber-dim:  rgba(168,106,0,.12);
  --red:        #d1373d;
  --red-dim:    rgba(209,55,61,.12);
  --chart-grid:  #e4e9f2;
  --chart-tick:  #74809a;
  --chart-label: #1b2333;
  --shadow:      0 12px 30px -16px rgba(30,50,90,.30);
}

/* ── Smooth theme crossfade ──────────────────────────────────────────────────── */
body, .topnav, .card, .stat-card, .stat-label, .card-note, .nav-link, .nav-badge,
input, select, textarea, button, .btn, table, td, th, .search-results {
  transition: background-color .28s ease, border-color .28s ease,
              color .28s ease, box-shadow .28s ease;
}

/* ── Entrance / scroll reveal (JS adds .reveal then .in) ─────────────────────── */
.reveal { opacity: 0; transform: translateY(20px); }
.reveal.in {
  opacity: 1; transform: none;
  transition: opacity .55s ease, transform .55s cubic-bezier(.22,.7,.24,1);
}

/* ── Card hover lift ─────────────────────────────────────────────────────────── */
.card {
  transition: transform .22s cubic-bezier(.22,.7,.24,1), box-shadow .22s ease,
              border-color .28s ease, background-color .28s ease;
  will-change: transform;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow), 0 0 0 1px var(--border2);
}
.stat-card { transition: transform .2s cubic-bezier(.22,.7,.24,1), border-color .2s ease, background-color .28s ease; }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

/* ── Button press feedback ───────────────────────────────────────────────────── */
button, .btn, .nav-link, .tab {
  transition: transform .12s cubic-bezier(.22,.7,.24,1), opacity .15s,
              filter .15s, background-color .28s, color .28s, border-color .28s;
}
button:active, .btn:active, .tab:active { transform: scale(.94); }
.nav-link:active { transform: scale(.97); }

/* ── Flowing accent gradient on stat-card top bars ───────────────────────────── */
.stat-card::before {
  background: linear-gradient(90deg, var(--accent), var(--green), var(--accent));
  background-size: 200% 100%;
  opacity: .75;
  animation: slideGrad 6s linear infinite;
}
.stat-card.highlight::before { background: linear-gradient(90deg, var(--green), var(--accent), var(--green)); background-size:200% 100%; opacity:1; }
@keyframes slideGrad { to { background-position: -200% 0; } }

/* ── Count-up flash ──────────────────────────────────────────────────────────── */
.stat-val.counting { color: var(--accent); }
.stat-card.highlight .stat-val.counting { color: var(--green); }

/* ── Theme toggle button (injected by theme.js) ──────────────────────────────── */
.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle .ic { transition: transform .4s cubic-bezier(.22,.7,.24,1); }
.theme-toggle:active .ic { transform: rotate(40deg) scale(.9); }

/* ── Respect reduced-motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
  .card:hover, .stat-card:hover { transform: none !important; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   GLASS SURFACES + DYNAMIC AURORA BACKGROUND  (2026-07)
   Translucent frosted cards (iOS-style) over a slow-drifting colour aurora.
   ══════════════════════════════════════════════════════════════════════════════ */
:root {
  --glass-bg:     rgba(18, 24, 38, 0.55);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-blur:   16px;
  --aurora-1: rgba(74, 144, 226, 0.38);
  --aurora-2: rgba(0, 201, 139, 0.30);
  --aurora-3: rgba(160, 90, 220, 0.34);
  --aurora-4: rgba(245, 120, 90, 0.24);
}
:root[data-theme="light"] {
  --glass-bg:     rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.70);
  --glass-blur:   16px;
  --aurora-1: rgba(74, 144, 226, 0.30);
  --aurora-2: rgba(0, 201, 139, 0.22);
  --aurora-3: rgba(180, 120, 240, 0.26);
  --aurora-4: rgba(255, 150, 120, 0.20);
}

/* Base colour on <html> so the aurora (body::before) is visible above it. */
html { background: var(--bg); }
body { background: transparent; }

/* Slow-drifting aurora behind all content. */
body::before {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38% 38% at 18% 22%, var(--aurora-1), transparent 62%),
    radial-gradient(34% 34% at 82% 26%, var(--aurora-3), transparent 62%),
    radial-gradient(42% 42% at 30% 82%, var(--aurora-2), transparent 62%),
    radial-gradient(36% 36% at 78% 78%, var(--aurora-4), transparent 62%);
  filter: blur(64px) saturate(1.25);
  animation: auroraDrift 28s ease-in-out infinite alternate;
}
@keyframes auroraDrift {
  0%   { transform: translate3d(0, 0, 0) scale(1) rotate(0deg); }
  50%  { transform: translate3d(3%, 2%, 0) scale(1.12) rotate(6deg); }
  100% { transform: translate3d(-2%, -3%, 0) scale(1.06) rotate(-4deg); }
}

/* Frosted glass surfaces. */
.card, .stat-card, .modal-box, .search-results {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 30px -16px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.07);
}
.topnav {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border-bottom: 1px solid var(--glass-border);
}
/* Keep the hover lift's shadow but preserve the glass inner highlight. */
.card:hover {
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.08), 0 0 0 1px var(--glass-border);
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none !important; }
}

/* Glass for hero/modal panels defined in per-template inline <style> — the
   `body ` prefix outranks those inline rules so they pick up the frosted look. */
body .movie-hero, body .cinema-hero, body .modal-box, body .avail-modal-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
}

/* ── Glass tuning pass (2026-07-23): make the frost obviously glassy ───────────
   More transparent surfaces, brighter/fuller aurora, a diagonal sheen and a
   crisp edge highlight. Appended after the base glass block so it wins. */
:root {
  --glass-bg:     rgba(22, 28, 46, 0.34);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-blur:   24px;
  --aurora-1: rgba(74, 144, 226, 0.60);
  --aurora-2: rgba(0, 224, 184, 0.50);
  --aurora-3: rgba(184, 92, 246, 0.58);
  --aurora-4: rgba(255, 118, 150, 0.46);
}
:root[data-theme="light"] {
  --glass-bg:     rgba(255, 255, 255, 0.42);
  --glass-border: rgba(255, 255, 255, 0.90);
  --glass-blur:   24px;
  --aurora-1: rgba(74, 144, 226, 0.42);
  --aurora-2: rgba(0, 200, 160, 0.34);
  --aurora-3: rgba(180, 120, 240, 0.40);
  --aurora-4: rgba(255, 140, 160, 0.32);
}
/* Brighter, fuller-coverage aurora (keeps the drift animation from the base block). */
body::before {
  background:
    radial-gradient(46% 46% at 16% 20%, var(--aurora-1), transparent 58%),
    radial-gradient(42% 42% at 84% 22%, var(--aurora-3), transparent 58%),
    radial-gradient(52% 52% at 26% 86%, var(--aurora-2), transparent 58%),
    radial-gradient(46% 46% at 82% 82%, var(--aurora-4), transparent 58%),
    radial-gradient(38% 38% at 55% 48%, var(--aurora-1), transparent 60%);
  filter: blur(72px) saturate(1.55);
}
/* Diagonal sheen over the frosted tint + crisp highlight edge. */
.card, .stat-card, .modal-box, .search-results,
body .movie-hero, body .cinema-hero, body .avail-modal-card {
  background:
    linear-gradient(135deg, rgba(255,255,255,.12), rgba(255,255,255,0) 44%),
    var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.7);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.7);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 34px -16px rgba(0,0,0,.6),
              inset 0 1px 0 rgba(255,255,255,.14),
              inset 0 0 0 .5px rgba(255,255,255,.04);
}
.topnav {
  background:
    linear-gradient(135deg, rgba(255,255,255,.10), rgba(255,255,255,0) 60%),
    var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.7);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.7);
  border-bottom: 1px solid var(--glass-border);
}

/* ── Dial down blue in the aurora (user request 2026-07-23) ────────────────────
   The blue blob (--aurora-1) dominated; tone it to a faint indigo and let the
   left/centre blobs be purple/teal so blue recedes without losing colour. */
:root            { --aurora-1: rgba(96, 104, 190, 0.26); }
:root[data-theme="light"] { --aurora-1: rgba(122, 122, 205, 0.18); }
body::before {
  background:
    radial-gradient(46% 46% at 16% 20%, var(--aurora-3), transparent 58%),
    radial-gradient(42% 42% at 84% 22%, var(--aurora-4), transparent 58%),
    radial-gradient(52% 52% at 26% 86%, var(--aurora-2), transparent 58%),
    radial-gradient(46% 46% at 82% 82%, var(--aurora-1), transparent 58%),
    radial-gradient(38% 38% at 55% 48%, var(--aurora-3), transparent 60%);
}

/* ── Softer, less colourful aurora (user request 2026-07-23) ───────────────────
   Halve the aurora opacities again and cut the saturation so the background is
   a subtle wash rather than vivid blobs. */
:root {
  --aurora-1: rgba(96, 104, 190, 0.12);
  --aurora-2: rgba(0, 200, 170, 0.14);
  --aurora-3: rgba(170, 100, 230, 0.15);
  --aurora-4: rgba(240, 120, 150, 0.12);
}
:root[data-theme="light"] {
  --aurora-1: rgba(122, 122, 205, 0.08);
  --aurora-2: rgba(0, 190, 160, 0.10);
  --aurora-3: rgba(175, 120, 235, 0.11);
  --aurora-4: rgba(255, 140, 160, 0.09);
}
body::before { filter: blur(84px) saturate(1.08); }
