:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1a1d25;
  --panel-2: #232733;
  --line: #2e3342;
  --text: #e8eaf0;
  --muted: #98a0b3;
  --accent: #8f75ff;
  --accent-ink: #ffffff;
  --good: #4cc38a;
  --warn: #e5a54b;
  --danger: #ef6b6b;
  --crunchyroll: #f47521;
  --hidive: #00aeef;
  --prime: #1a98ff;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f5f6f9;
    --panel: #ffffff;
    --panel-2: #eef0f5;
    --line: #dadde6;
    --text: #1b1e27;
    --muted: #626a7d;
    --accent: #6548e8;
    --good: #1e8f5c;
    --warn: #a86a0c;
    --danger: #c93c3c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- header ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 13px;
}
.search { position: relative; display: flex; flex: 1 1 320px; max-width: 640px; }
.search select, .search input {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 9px 12px;
}
.search select { border-radius: 8px 0 0 8px; border-right: 0; }
.search input { flex: 1; min-width: 0; border-radius: 0 8px 8px 0; }
.search input:focus, .search select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results {
  position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; right: 0;
  max-height: min(70vh, 520px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgb(0 0 0 / .35);
}
.results .row { border-bottom: 1px solid var(--line); border-radius: 0; }
.results .row:last-child { border-bottom: 0; }
.results .empty { padding: 16px; }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.btn {
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { background: none; border-color: transparent; color: var(--muted); }
.btn.quiet:hover:not(:disabled) { color: var(--danger); border-color: transparent; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 20px; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tab {
  font: inherit; cursor: pointer; white-space: nowrap;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 12px;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.count {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; text-align: center;
}

.banner {
  margin: 16px 20px 0; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--danger); color: var(--danger);
}
main { padding: 20px; max-width: 1100px; margin: 0 auto; }
section + section { margin-top: 28px; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
h2 .today { color: var(--accent); }

.empty { color: var(--muted); padding: 28px 8px; text-align: center; }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- episode / show rows ---------- */
.list { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--panel); border-radius: 10px;
}
.row.unread { box-shadow: inset 3px 0 0 var(--accent); }
.row .when { flex: 0 0 76px; font-variant-numeric: tabular-nums; }
.row .when small { display: block; color: var(--muted); font-size: 12px; }
.thumb {
  flex: 0 0 auto; width: 38px; height: 54px; border-radius: 5px;
  object-fit: cover; background: var(--panel-2);
}
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .title a { text-decoration: none; }
.row .title a:hover { text-decoration: underline; }
.row .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 11.5px; font-weight: 600; line-height: 1; white-space: nowrap;
  padding: 4px 7px; border-radius: 999px; text-decoration: none;
  color: var(--muted); border: 1px solid var(--line);
}
.badge.mine { color: #fff; border-color: transparent; background: var(--accent); }
.badge.mine.crunchyroll { background: var(--crunchyroll); color: #1b1000; }
.badge.mine.hidive { background: var(--hidive); color: #00202c; }
.badge.mine.prime { background: var(--prime); color: #001a33; }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.kind { text-transform: uppercase; letter-spacing: .04em; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h3 { font-size: 18px; margin-right: auto; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; color: var(--muted); font-size: 12px; padding: 2px 0 4px; }
.cell {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  min-height: 96px; padding: 6px; overflow: hidden;
  background: var(--panel); border: 1px solid transparent; border-radius: 8px;
}
.cell:hover { border-color: var(--line); }
.cell.other { opacity: .45; }
.cell.selected { border-color: var(--accent); }
.cell .num { font-size: 12px; color: var(--muted); }
.cell.today .num {
  align-self: flex-start; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.chip {
  font-size: 11.5px; line-height: 1.3; padding: 2px 5px; border-radius: 4px;
  background: var(--panel-2); border-left: 3px solid var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.past { opacity: .6; }
.chip.crunchyroll { border-left-color: var(--crunchyroll); }
.chip.hidive { border-left-color: var(--hidive); }
.chip.prime { border-left-color: var(--prime); }
.chip.none { border-left-color: var(--muted); }
.more { font-size: 11px; color: var(--muted); }
.day-detail { margin-top: 18px; }

/* ---------- settings ---------- */
.card { background: var(--panel); border-radius: 10px; padding: 16px; }
.card p + p, .card p + .checks, .card .checks + p, .card p + .btn { margin-top: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; }

@media (max-width: 640px) {
  .top { padding: 12px; }
  .top-actions { margin-left: 0; }
  .tabs { padding: 0 8px; }
  main { padding: 14px 10px; }
  .row { flex-wrap: wrap; }
  .row .when { flex-basis: 64px; }
  .row .side { flex-basis: 100%; justify-content: flex-start; }
  .cell { min-height: 58px; padding: 4px; }
  .cell .chip { font-size: 0; height: 5px; padding: 0; border-radius: 3px; border-left-width: 14px; }
  .cell .more { display: none; }
}

/* ---------- forms / sign-in ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-weight: 600; font-size: 13px; }
.field input {
  font: inherit; font-weight: 400; color: var(--text); width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.card .field + p { margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.card .actions + p { margin-top: 8px; min-height: 1.4em; }
.error { color: var(--danger); min-height: 1.4em; }
.auth { max-width: 380px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.auth h3 { font-size: 18px; }
.auth .field { margin-top: 0; }
.signed-out .search, .signed-out .top-actions, .signed-out .tabs { display: none; }
