:root {
  --bg: #16171a;
  --panel: #23262c;
  --panel-2: #2b2f36;
  --line: #363b44;
  --text: #e8eaed;
  --muted: #9aa1ac;
  --accent: #7fd3f2;
  --accent-ink: #0f2a35;
  --gold: #f0c03c;
  --danger: #ff7a7a;
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { flex: 1; padding-top: 24px; padding-bottom: 32px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, calc((100vw - 1200px) / 2 + 16px));
  background: rgba(35, 38, 44, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 18px; letter-spacing: -.01em; flex: none; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.search { flex: 1; display: flex; gap: 10px; max-width: 720px; margin-left: auto; margin-right: auto; }
.search-field { position: relative; flex: 1; }
.search-ico { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; height: 46px; padding: 0 14px 0 42px;
  background: var(--bg); color: var(--text);
  border: 2px solid #3b6f84; border-radius: 10px;
  font: inherit; font-size: 16px; outline: none;
  transition: border-color .15s;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { filter: invert(.7); }
.btn-primary {
  height: 46px; padding: 0 22px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.08); }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
  max-height: 60vh; overflow-y: auto;
}
.suggest li { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: #343944; }
.suggest img, .suggest .noposter { width: 34px; height: 50px; object-fit: cover; border-radius: 4px; flex: none; background: var(--line); }
.suggest .s-title { font-weight: 600; }
.suggest .s-year { color: var(--muted); font-size: 13px; }
.suggest .s-empty { color: var(--muted); cursor: default; }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid #2c3037; border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.muted { color: var(--muted); }

/* ---------- series header ---------- */
.top { padding-bottom: 18px; }
.top-head { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 16px; }
.top .thumb { width: 52px; height: 78px; object-fit: cover; border-radius: 6px; background: var(--line); flex: none; }
.top .noposter.thumb { display: none; }
.top-title { min-width: 0; text-align: center; }
.top h1 { margin: 0 0 8px; font-size: clamp(22px, 3.4vw, 32px); line-height: 1.15; color: var(--accent); letter-spacing: -.02em; }
.top h1 .yr { color: var(--accent); opacity: .85; font-weight: 600; }
.top .badges { justify-content: center; }
.chart-card { padding-top: 18px; }

.about { display: grid; grid-template-columns: 120px 1fr; gap: 20px; align-items: start; }
.about .poster { width: 120px; aspect-ratio: 2/3; object-fit: cover; border-radius: 10px; background: var(--line); display: block; }
.about .noposter.poster { display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }
.about .meta { color: var(--muted); font-size: 14px; margin: -6px 0 10px; }
.about .plot { margin: 0 0 12px; max-width: 75ch; }
.about .cast { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.about > div > :last-child { margin-bottom: 0; }
.badges { display: flex; flex-wrap: wrap; gap: 10px; }
.badge { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.badge .logo { font-size: 11px; font-weight: 800; padding: 3px 6px; border-radius: 4px; letter-spacing: .02em; }
.badge .logo.imdb { background: #f5c518; color: #000; }
.badge .logo.rt { background: #fa320a; color: #fff; }
.badge .logo.mc { background: #333; color: #fff; border: 1px solid #666; }
.badge b { font-size: 16px; }
.badge small { color: var(--muted); }
.badge.link { color: var(--text); }
.badge.link:hover { text-decoration: none; border-color: var(--accent); }

/* ---------- seasons ---------- */
.seasons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  min-width: 112px; padding: 8px 16px; border-radius: 10px;
  background: var(--bg); border: 2px solid var(--accent); color: var(--accent);
  display: flex; flex-direction: column; align-items: center; line-height: 1.25;
  transition: background .15s, color .15s;
}
.chip:hover { background: #1d2b31; }
.chip small { font-size: 12px; opacity: .8; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chip.all { min-width: 180px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid #2c3037; border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 28px; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; }
.stat .d { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- chart ---------- */
.toggle { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.toggle button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 7px; font-size: 13px; }
.toggle button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); }
.chart { position: relative; width: 100%; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: #343842; stroke-dasharray: 2 4; }
.chart .grid text, .chart .xlab { fill: var(--muted); font-size: 11px; }
.chart .band { fill: #2a2e35; }
.chart .band.alt { fill: transparent; }
.chart .slabel { fill: var(--gold); font-size: 13px; font-weight: 700; text-anchor: middle; cursor: pointer; }
.chart .sep { stroke: var(--gold); stroke-width: 1.5; opacity: .55; }
.chart .avg { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: .8; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--panel); stroke-width: 1.5; }
.chart .dot-nr { fill: var(--panel); stroke: var(--muted); stroke-width: 1.5; }
.legend .nr-key { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--muted); }
.chart .guide { stroke: var(--text); stroke-width: 1; opacity: .35; }
.chart .hl { fill: none; stroke: var(--text); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: #111317; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-width: 180px; max-width: 280px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); font-size: 13px;
}
.tip .tt { font-weight: 650; font-size: 14px; margin: 2px 0 6px; }
.tip .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--gold); }
.legend .scale { display: inline-block; width: 90px; height: 8px; border-radius: 4px; }

/* ---------- rating badge ---------- */
.pill { display: inline-block; min-width: 38px; text-align: center; padding: 2px 7px; border-radius: 6px; font-weight: 750; font-size: 13px; color: #111; }
.pill.none { background: var(--line); color: var(--muted); }

/* ---------- heatmap ---------- */
.two { margin-bottom: 18px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.two > .card { margin-bottom: 0; }
.heat-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px 6px; }
.heat { border-collapse: separate; border-spacing: 3px; font-size: 12px; margin: 0 auto; }
.heat th { color: var(--muted); font-weight: 600; padding: 2px 4px; }
.heat thead th { cursor: pointer; color: var(--gold); }
.heat thead th.on { color: var(--accent); }
.heat tbody th { text-align: right; }
.heat td { width: 40px; min-width: 40px; height: 28px; text-align: center; border-radius: 5px; font-weight: 700; color: #111; cursor: pointer; }
.heat td.empty { background: transparent; cursor: default; }
.heat td.nr { background: var(--line); color: var(--muted); }
.heat td:not(.empty):hover { outline: 2px solid var(--text); }
.heat .dim { opacity: .28; }
.heat tfoot th, .heat tfoot td { padding-top: 6px; }
.heat tfoot td { cursor: default; }

/* ---------- tops ---------- */
.rank { list-style: none; margin: 0 0 18px; padding: 0; }
.rank li { display: grid; grid-template-columns: 26px 56px 1fr auto; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid #2f333b; }
.rank li:last-child { border-bottom: 0; }
.rank .n { color: var(--muted); font-size: 13px; text-align: right; }
.rank .code { color: var(--gold); font-weight: 650; font-size: 13px; }
.rank a { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.rank a:hover { color: var(--accent); }
.subh { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 6px; }

/* ---------- home / results ---------- */
.hero { text-align: center; padding: 56px 0 28px; }
.hero h1 { margin: 0 0 10px; font-size: clamp(28px, 5vw, 46px); letter-spacing: -.03em; line-height: 1.1; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 0 auto; color: var(--muted); max-width: 52ch; font-size: 16px; }
.section-title { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 26px 0 12px; display: flex; justify-content: space-between; align-items: center; }
.linkbtn { background: none; border: 0; color: var(--muted); font-size: 13px; text-transform: none; letter-spacing: 0; }
.linkbtn:hover { color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.tile { background: var(--panel); border: 1px solid #2c3037; border-radius: 12px; overflow: hidden; text-align: left; padding: 0; display: flex; flex-direction: column; transition: transform .15s, border-color .15s; }
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile img, .tile .noposter { width: 100%; aspect-ratio: 2/3; object-fit: cover; background: var(--line); display: block; }
.tile .noposter, .suggest .noposter { display: grid; text-align: center; place-items: center; color: var(--muted); font-size: 12px; }
.tile .tb { padding: 10px 12px 12px; }
.tile .tt { font-weight: 650; line-height: 1.3; }
.tile .ty { color: var(--muted); font-size: 13px; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.examples button { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; color: var(--text); }
.examples button:hover { border-color: var(--accent); color: var(--accent); }

.msg { text-align: center; padding: 60px 16px; color: var(--muted); }
.msg.err { color: var(--danger); }

/* squelettes de chargement */
.sk { background: linear-gradient(90deg, #262a30 0%, #30353d 50%, #262a30 100%); background-size: 200% 100%; animation: sk 1.2s infinite linear; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }

.foot { color: var(--muted); font-size: 13px; padding-top: 8px; padding-bottom: 24px; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .two { grid-template-columns: 1fr; }
  .two > .card { margin-bottom: 18px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .search { order: 2; flex-basis: 100%; }
  .btn-primary { padding: 0 14px; }
  .about { grid-template-columns: 80px 1fr; gap: 14px; }
  .about .poster { width: 80px; }
  .top-head { gap: 12px; }
  .top .thumb { width: 40px; height: 60px; }
  .badge { padding: 6px 10px; }
  .badge small { display: none; }
  .card { padding: 16px; }
  .chip { min-width: 0; padding: 6px 12px; }
  .chip.all { min-width: 0; }
  .stat .v { font-size: 22px; }
  .hero { padding-top: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
