/* ============================================================
   Watched — Apple-aesthetic Netflix history
   ============================================================ */

:root {
  --bg: #f5f5f7;
  --bg-elev: rgba(255, 255, 255, 0.72);
  --bg-strong: rgba(255, 255, 255, 0.92);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --accent: #e50914;
  --accent-soft: rgba(229, 9, 20, 0.10);
  --blue: #0071e3;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 2px 8px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.08);
  --shadow-hover: 0 4px 12px rgba(0,0,0,.06), 0 24px 48px rgba(0,0,0,.14);
  --radius: 22px;
  --radius-sm: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0b0b0f;
  --bg-elev: rgba(28, 28, 32, 0.72);
  --bg-strong: rgba(28, 28, 32, 0.94);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #6e6e73;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 2px 8px rgba(0,0,0,.35), 0 16px 40px rgba(0,0,0,.5);
  --shadow-hover: 0 4px 16px rgba(0,0,0,.4), 0 28px 60px rgba(0,0,0,.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .4s ease, color .4s ease;
  overflow-x: hidden;
}

/* ambient background glow */
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(60% 40% at 15% 0%, rgba(229,9,20,.07), transparent 60%),
    radial-gradient(50% 35% at 90% 10%, rgba(0,113,227,.07), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- glass ---------- */
.glass {
  background: var(--bg-elev);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 1px solid var(--border);
}
.glass-strong {
  background: var(--bg-strong);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
}

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  padding-top: env(safe-area-inset-top);
}
.nav-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-sub { color: var(--text-3); font-weight: 500; }

.segmented {
  display: flex; background: rgba(120,120,128,.12);
  border-radius: 12px; padding: 3px; gap: 2px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--text-2);
  font-family: var(--font); font-size: 14px; font-weight: 590;
  padding: 7px 16px; border-radius: 9px; cursor: pointer;
  transition: all .25s cubic-bezier(.2,.8,.2,1);
  white-space: nowrap;
}
.seg-btn.active {
  background: var(--bg-strong); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.segmented.mini .seg-btn { padding: 6px 14px; font-size: 13px; }

.theme-toggle {
  border: 0; background: rgba(120,120,128,.12); color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 17px; cursor: pointer; transition: transform .3s;
}
.theme-toggle:active { transform: rotate(180deg) scale(.9); }

/* ---------- layout ---------- */
.view { display: none; max-width: 1200px; margin: 0 auto; padding: 28px 20px 80px; position: relative; z-index: 1; }
.view.active { display: block; animation: viewIn .5s cubic-bezier(.2,.8,.2,1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 48px 0 40px; }
.hero-eyebrow {
  font-size: 14px; font-weight: 650; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px;
}
.hero-title {
  font-size: clamp(38px, 7vw, 72px); font-weight: 800;
  letter-spacing: -.03em; line-height: 1.04;
}
.grad-text {
  background: linear-gradient(92deg, var(--accent), #ff6a3d 55%, var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { margin-top: 16px; font-size: clamp(16px, 2.5vw, 20px); color: var(--text-2); font-weight: 480; }

/* ---------- cards ---------- */
.card {
  background: var(--bg-elev);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.float { transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s; will-change: transform; }
.float:hover { transform: translateY(-5px); box-shadow: var(--shadow-hover); }

/* ---------- stat grid ---------- */
.stat-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 28px;
}
.stat-card { text-align: left; padding: 20px 22px; animation: viewIn .6s cubic-bezier(.2,.8,.2,1) backwards; }
.stat-card .num {
  font-size: clamp(26px, 4vw, 38px); font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat-card .lbl { font-size: 13px; color: var(--text-2); font-weight: 550; margin-top: 2px; }
.stat-card .sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.stat-card.accent .num { color: var(--accent); }

/* ---------- chart grid ---------- */
.chart-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.card-tag { font-size: 12px; color: var(--text-3); font-weight: 550; }
.chart-wrap { position: relative; height: 220px; }
.chart-wrap.tall { height: 280px; }
.chart-wrap.donut { height: 220px; display: flex; justify-content: center; }

.record-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.record-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14px; }
.record-list .r-lbl { color: var(--text-2); }
.record-list .r-val { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.glass-input {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}
.search-wrap input {
  border: 0; outline: 0; background: transparent; width: 100%;
  font-family: var(--font); font-size: 16px; color: var(--text);
}
.search-wrap .icon { width: 18px; height: 18px; color: var(--text-3); flex-shrink: 0; }
.filter-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.select {
  font-family: var(--font); font-size: 14px; font-weight: 550; color: var(--text);
  padding: 9px 14px; cursor: pointer; outline: none;
  appearance: none; -webkit-appearance: none;
}
.result-count { font-size: 13px; color: var(--text-3); margin: 10px 2px 14px; font-weight: 500; }

/* ---------- poster grid ---------- */
.poster-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.poster-card {
  border-radius: 18px; overflow: hidden; cursor: pointer;
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s;
  animation: viewIn .5s cubic-bezier(.2,.8,.2,1) backwards;
}
.poster-card:hover { transform: translateY(-6px) scale(1.015); box-shadow: var(--shadow-hover); }
.poster-card:active { transform: scale(.98); }
.poster-img {
  aspect-ratio: 2/3; width: 100%; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 34px; letter-spacing: -.02em;
}
.poster-img img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity .6s ease;
}
.poster-img img.loaded { opacity: 1; }
.poster-monogram { position: relative; z-index: 1; text-shadow: 0 2px 12px rgba(0,0,0,.3); }
.poster-info { padding: 12px 14px 14px; }
.poster-title {
  font-size: 14px; font-weight: 650; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25;
  min-height: 2.5em;
}
.poster-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; font-weight: 500; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 20px; margin-top: 8px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.blue { background: rgba(0,113,227,.1); color: var(--blue); }

.load-more-wrap { text-align: center; margin-top: 28px; }
.pill-btn {
  font-family: var(--font); font-size: 15px; font-weight: 600;
  color: var(--blue); background: rgba(0,113,227,.1);
  border: 0; border-radius: 30px; padding: 12px 28px; cursor: pointer;
  transition: all .25s;
}
.pill-btn:hover { background: rgba(0,113,227,.18); }
.pill-btn:active { transform: scale(.96); }

/* ---------- history table ---------- */
.table-card { padding: 6px 0; overflow: hidden; }
.hist-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hist-table th {
  text-align: left; font-size: 12px; font-weight: 650; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 14px 18px 10px; border-bottom: 1px solid var(--border);
}
.hist-table td { padding: 13px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
.hist-table tbody tr:last-child td { border-bottom: 0; }
.hist-table tbody tr { transition: background .2s; cursor: pointer; }
.hist-table tbody tr:hover { background: rgba(120,120,128,.07); }
.td-date { white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; }
.td-title { font-weight: 620; }
.td-ep { color: var(--text-2); }
.type-pill {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; white-space: nowrap;
}
.type-pill.tv { background: rgba(0,113,227,.1); color: var(--blue); }
.type-pill.mv { background: var(--accent-soft); color: var(--accent); }

.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 24px; flex-wrap: wrap; }
.pager button {
  font-family: var(--font); min-width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all .2s;
}
.pager button.cur { background: var(--text); color: var(--bg); border-color: var(--text); }
.pager button:disabled { opacity: .35; cursor: default; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.45);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  display: none; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .3s;
}
.modal-backdrop.open { display: flex; opacity: 1; }
.modal {
  width: 100%; max-width: 640px; max-height: 86vh; overflow-y: auto;
  border-radius: 28px 28px 0 0; padding: 26px;
  border: 1px solid var(--border);
  transform: translateY(40px); transition: transform .4s cubic-bezier(.2,.8,.2,1);
  padding-bottom: calc(26px + env(safe-area-inset-bottom));
}
.modal-backdrop.open .modal { transform: none; }
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 28px; }
}
.modal-close {
  position: sticky; top: 0; float: right;
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgba(120,120,128,.16); color: var(--text-2);
  font-size: 14px; cursor: pointer; z-index: 2;
}
.modal-hero { display: flex; gap: 20px; margin-bottom: 22px; }
.modal-poster {
  width: 110px; min-width: 110px; aspect-ratio: 2/3; border-radius: 14px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 30px; font-weight: 800; box-shadow: var(--shadow);
}
.modal-poster img { width: 100%; height: 100%; object-fit: cover; }
.modal-meta h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.modal-stats { color: var(--text-2); font-size: 14px; margin-top: 8px; line-height: 1.5; }
.modal-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 12px; font-weight: 650; padding: 5px 11px; border-radius: 20px;
  background: rgba(120,120,128,.12); color: var(--text-2);
}
.modal-body h4 {
  font-size: 13px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px;
}
.episode-list { list-style: none; }
.episode-list li {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 10px 2px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.episode-list li:last-child { border-bottom: 0; }
.ep-name { font-weight: 550; }
.ep-season { color: var(--text-3); font-size: 12px; margin-top: 1px; }
.ep-date { color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 13px; }

/* ---------- footer ---------- */
.footer { text-align: center; padding: 30px 20px 50px; color: var(--text-3); font-size: 13px; position: relative; z-index: 1; }

/* ---------- skeleton shimmer ---------- */
.shimmer {
  background: linear-gradient(100deg, rgba(120,120,128,.10) 40%, rgba(120,120,128,.22) 50%, rgba(120,120,128,.10) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .nav-inner { flex-wrap: wrap; justify-content: center; padding: 10px 14px; }
  .brand { width: 100%; justify-content: center; margin-bottom: 6px; }
  .theme-toggle { position: absolute; right: 14px; top: calc(10px + env(safe-area-inset-top)); }
  .chart-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  .poster-img { font-size: 26px; }
  .hero { padding: 34px 0 30px; }
  .view { padding: 18px 14px 60px; }
  .card { padding: 18px; }
  .hide-sm { display: none; }
  .hist-table td, .hist-table th { padding: 11px 12px; }
  .modal-hero { gap: 14px; }
  .modal-poster { width: 92px; min-width: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
