/* Hand-written, no framework. Dark by default, light if the OS asks for it. */

:root {
  --bg: #12131a;
  --surface: #1b1d27;
  --border: #2c3040;
  --text: #e7e9f0;
  --muted: #9aa0b4;
  --accent: #f47521; /* Crunchyroll orange, used sparingly */
  --accent-soft: #f4752133;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --border: #e2e5ee;
    --text: #1a1c25;
    --muted: #666d82;
    --accent-soft: #f4752122;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- chrome */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }

.kanji {
  margin-left: 7px;
  font-size: 12px;
  font-weight: 400;
  color: var(--accent);
  vertical-align: 1px;
}
.topbar nav { display: flex; gap: 18px; }
.topbar nav a { color: var(--muted); font-size: 14px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); }

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 17px; margin: 34px 0 12px; }

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 40px;
  color: var(--muted);
  font-size: 12px;
}

/* -------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

#filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }

.search {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  min-width: 200px;
}
.search:focus { outline: none; border-color: var(--accent); }
.search::placeholder { color: var(--muted); }

.chips { display: flex; gap: 8px; }

.filter-group { display: flex; align-items: center; gap: 8px; }

.group-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

/* Radios rather than links: one form holds every filter, so htmx submits them together
   and a plain GET still works with scripting off. */
.chip {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.chip:hover { color: var(--text); }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}
/* Keyboard focus only. :focus-within would leave a ring behind after every mouse click,
   which reads as a second kind of selection on top of the checked state. */
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.result-count { font-size: 12px; margin: 0 0 12px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sync { display: flex; align-items: center; gap: 10px; }

button {
  background: var(--accent);
  color: #1a1c25;
  border: 0;
  border-radius: var(--radius);
  padding: 7px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }

/* htmx toggles this class while a request is in flight */
.htmx-indicator { opacity: 0; color: var(--muted); font-size: 13px; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------------------------------------------------------------- cards */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.poster-wrap { position: relative; }

.poster {
  width: 100%;
  /* The episode still, so a card shows where you actually are in the show. Portrait
     poster art is used on the overview instead. */
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: var(--border);
}

/* Play overlay: quiet until you look at the card, then unmissable. */
.play {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1c25;
  font-size: 13px;
  padding-left: 2px;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity .15s ease, transform .15s ease;
}
.card:hover .play,
.play:focus-visible { opacity: 1; transform: scale(1); }
.play:hover { text-decoration: none; filter: brightness(1.1); }

/* Touch devices have no hover, so never hide it there. */
@media (hover: none) {
  .play { opacity: 1; transform: scale(1); }
}

.poster.placeholder {
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 700;
  color: var(--muted);
}

.poster.large { width: 150px; aspect-ratio: 3/4; border-radius: var(--radius); }

.card-body { padding: 12px 13px 14px; display: flex; flex-direction: column; gap: 6px; }
.card-body h3 { margin: 0; font-size: 14px; line-height: 1.35; }

.episode { margin: 0; font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }

.series-position {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.episode-title {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}
.bar.wide { max-width: 380px; height: 8px; }
.bar .fill { height: 100%; background: var(--accent); }
.bar.episode-bar .fill { background: var(--muted); }

.meta { margin: 2px 0 0; display: flex; gap: 8px; align-items: center; font-size: 11px; }

.badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
}
.status-not_started .badge { background: var(--border); color: var(--muted); }
.status-season_finished .badge { background: #4ade8033; }

/* --------------------------------------------------------------- detail */

.detail-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.detail-head h1 { margin-bottom: 8px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 0; }

.action {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
}
.action:hover { text-decoration: none; border-color: var(--accent); }
.action.primary { background: var(--accent); border-color: var(--accent); color: #1a1c25; }
.action.primary:hover { filter: brightness(1.08); }

/* --------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.compact { width: auto; min-width: 320px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.pager { display: flex; gap: 16px; align-items: center; margin-top: 18px; font-size: 13px; }

/* --------------------------------------------------------- poster rail */

.rail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.rail-item { min-width: 0; }

.rail-art {
  position: relative;
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--border);
}

.rail-art img,
.rail-art .placeholder {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.rail-art .placeholder {
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  color: var(--muted);
}

.rail-art:hover { text-decoration: none; }
.rail-art:hover img { filter: brightness(1.08); }

.rail-title {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.rail-episode {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rail-when { margin: 1px 0 0; font-size: 11px; color: var(--muted); }

/* -------------------------------------------------------------- recent */

.recent { list-style: none; margin: 0; padding: 0; }

.recent li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.recent li:last-child { border-bottom: 0; }

.recent-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.recent-series { font-weight: 600; }
.recent-episode { font-size: 12px; }
.recent-when { white-space: nowrap; font-size: 12px; }

/* ---------------------------------------------------------------- tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.tile-label { font-size: 12px; color: var(--muted); }
.tile-sub { font-size: 11px; }

.small { font-size: 12px; }

/* ---------------------------------------------------------------- chart */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 190px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bar-col {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  position: relative;
}

.bar-fill {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.bar-count { font-size: 11px; color: var(--text); font-variant-numeric: tabular-nums; }
.bar-label { font-size: 10px; color: var(--muted); }

/* Daily chart: thirty thin bars, so no per-bar counts and only every fifth label. */
.chart.daily { position: relative; gap: 3px; height: 165px; }
.chart.daily .bar-col { justify-content: flex-end; }
.chart.daily .bar-fill { border-radius: 3px 3px 0 0; min-height: 0; }

/* A day with nothing watched still gets a sliver, so the axis reads as continuous. */
.chart.daily .bar-fill.empty { min-height: 2px; background: var(--border); }

.average-line {
  position: absolute;
  left: 12px;
  right: 12px;
  border-top: 1px dashed var(--muted);
  opacity: 0.75;
  pointer-events: none;
  z-index: 1;
}

/* ---------------------------------------------------------------- misc */

.muted { color: var(--muted); }
.faint { opacity: 0.6; font-style: italic; }
.bad { color: var(--bad); }
.empty { color: var(--muted); padding: 28px 0; }

/* --------------------------------------------------------------- banner */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--bad);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 22px;
  font-size: 13px;
}

/* Nothing is broken yet — the data has just gone quiet. */
.banner-stale { border-left-color: var(--accent); }
.banner-never { border-left-color: var(--muted); }

.banner-text { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.banner-text strong { font-size: 14px; }

.banner-error {
  display: block;
  margin-top: 6px;
  padding: 7px 9px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.banner details summary { cursor: pointer; font-size: 12px; }

.banner-close {
  background: none;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  padding: 0 4px;
  font-weight: 400;
}
.banner-close:hover { color: var(--text); filter: none; }

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--muted);
}

code {
  background: var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---------------------------------------------------- series dashboard */

.hero {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 22px;
}

/* Key art as a real element rather than a CSS background, so the URL never has to be
   interpolated into a style attribute. */
.hero-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.35;
  filter: saturate(1.1);
}

/* The scrim: text over cover art is unreadable without one. */
.hero.has-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, var(--surface) 8%, transparent 85%),
              linear-gradient(to top, var(--surface) 2%, transparent 55%);
}

.hero-body { position: relative; z-index: 1; padding: 22px 24px 20px; }
.hero-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.hero-titles { min-width: 240px; flex: 1; }
.hero-titles h1 { margin: 0 0 6px; }

.hero-poster {
  width: 120px;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--border);
}

.hero-episode { margin: 0 0 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.hero-meta { margin: 0; display: flex; gap: 9px; align-items: center; font-size: 12px; }

.hero-progress { margin-top: 20px; max-width: 620px; }
.hero-progress-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.bar.hero-bar { max-width: none; height: 10px; }

.hero-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.pill {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
}
.pill-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pill-value { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pill-sub { font-size: 11px; color: var(--muted); }

/* Two side-by-side panels that fall to one column when there is no room. */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 18px;
  /* Each panel keeps its own height; stretching the short one to match a long season
     list leaves a void under the chart. */
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  min-width: 0;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; }
.panel .empty { padding: 16px 0; }

/* A twenty-one season show would otherwise leave the panel beside it stranded. */
.season-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 340px;
  overflow-y: auto;
}
.season-line { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.season-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.season-list .current .season-name { color: var(--accent); font-weight: 600; }
.season-list .muted { font-variant-numeric: tabular-nums; white-space: nowrap; }

.heatmap { display: flex; flex-direction: column; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat-row { display: flex; gap: 3px; align-items: center; }
.heat-day { width: 30px; font-size: 10px; color: var(--muted); flex: none; }

.heat-cell {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 3px;
  background: var(--border);
}
/* Four shades against the busiest day, plus the empty one. */
.heat-cell.level-1 { background: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.heat-cell.level-2 { background: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.heat-cell.level-3 { background: color-mix(in srgb, var(--accent) 78%, var(--border)); }
.heat-cell.level-4 { background: var(--accent); }
.heat-cell.blank { background: transparent; }

.heat-legend { display: flex; align-items: center; gap: 4px; margin-top: 9px; }

.streaks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.streak {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.streak-value { font-size: 26px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.streak-label { font-size: 11px; color: var(--muted); }

.week-strip { display: flex; gap: 6px; align-items: flex-end; height: 74px; margin-top: 14px; }
.week-day { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; height: 100%; }
.week-bar { background: var(--accent); border-radius: 3px 3px 0 0; min-height: 3px; }
.week-bar.empty { background: var(--border); min-height: 2px; }
.week-label { font-size: 10px; color: var(--muted); text-align: center; }

.records { margin-top: 30px; }
.records summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.records h2 { font-size: 15px; }

@media (max-width: 560px) {
  .hero-body { padding: 16px 15px; }
  .hero-poster { width: 84px; }
}

/* ------------------------------------------------------------- rewatches */

/* The high-water mark a rewatch cannot undo. Quieter than the live bar beside it, so the
   eye lands on where you are now rather than where you once were. */
.bar.hero-bar.past { height: 6px; opacity: 0.55; }
.bar.hero-bar.past .fill { background: var(--muted); }

.hero-progress .hero-progress-line + .bar { margin-bottom: 12px; }

.status-rewatching .badge { background: #60a5fa33; }

/* A submit button that has to sit in a row of link-styled actions. */
button.action {
  background: none;
  color: inherit;
  border: 1px solid var(--border);
  font-weight: 500;
}
button.action:hover { filter: none; border-color: var(--accent); }
.actions form { margin: 0; }

.scope-tabs { display: flex; gap: 8px; margin: 20px 0 4px; }

.scope-tab {
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}
.scope-tab:hover { text-decoration: none; border-color: var(--accent); }
.scope-tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* ----------------------------------------------------------------- login */

.topbar .account { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar .account a { color: var(--muted); font-size: 14px; }
.topbar .account a.active, .topbar .account a:hover { color: var(--text); }
.topbar .account form { margin: 0; }
.topbar .account button { padding: 4px 12px; font-size: 13px; white-space: nowrap; }
/* Narrow screens: let the account controls drop to their own row rather than squeezing the
   brand and the button into two-line stacks. */
.topbar { flex-wrap: wrap; row-gap: 10px; }
.brand { white-space: nowrap; }

.auth-card {
  max-width: 380px;
  margin: 48px auto;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.auth-card.wide { max-width: 460px; }
.auth-card h1 { margin: 0 0 12px; font-size: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 9px 12px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-card button[type="submit"] { margin-top: 6px; padding: 10px 14px; }

.auth-error {
  margin: 16px 0 0;
  padding: 8px 12px;
  list-style: none;
  border-left: 3px solid var(--bad);
  background: #f8717114;
  color: var(--bad);
  font-size: 14px;
}

.rules { list-style: none; margin: -4px 0 0; padding: 0; display: grid; gap: 3px; font-size: 13px; color: var(--muted); }
.rules li::before { content: "○"; display: inline-block; width: 1.4em; }
.rules li.met { color: var(--good); }
.rules li.met::before { content: "✓"; }
.rules li.unmet { color: var(--bad); }
.rules li.unmet::before { content: "✗"; }
