:root {
  --bg: #f6f6f8; --surface: #fff; --text: #1b1b1f; --muted: #6b6b76; --border: #e2e2e8;
  --accent: #e0a100; --accent-text: #1b1b1f; --done: #2e9d5b; --danger: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121216; --surface: #1c1c22; --text: #ececf1; --muted: #9a9aa6; --border: #2c2c35;
          --accent: #f5b700; --accent-text: #121216; --done: #3fbf74; --danger: #ef5350; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; }
img { background: var(--border); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
.grow { flex: 1; min-width: 0; }

.topbar { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "brand nav user";
          gap: 4px 20px; align-items: center; padding: 10px 16px; position: sticky; top: 0; z-index: 10;
          background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { grid-area: brand; font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 26px; height: 26px; border-radius: 6px; background: none; }
.brand .tld { color: var(--accent); }
.topbar nav { grid-area: nav; display: flex; gap: 14px; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: 4px 0; white-space: nowrap; }
.topbar nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.user-menu { grid-area: user; position: relative; }
.user-menu summary { list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
          background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: .9rem; }
.user-menu[open] .avatar { box-shadow: 0 0 0 3px var(--border); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; z-index: 20;
        background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
        box-shadow: 0 8px 24px rgb(0 0 0 / .14); padding: 6px; }
.menu-user { padding: 8px 10px; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border);
             margin-bottom: 4px; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px;
             border-radius: 6px; color: var(--text); }
a.menu-item { text-decoration: none; }
.menu-item:hover { background: var(--bg); }
.token-new { background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: 12px; margin: 12px 0; }
.token-new code { display: block; overflow-wrap: anywhere; font-size: .9rem; padding: 8px; margin: 8px 0;
                  background: var(--bg); border-radius: 6px; user-select: all; }
.token-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 16px; }
.token-form input[name=name] { flex: 1; min-width: 180px; width: auto; }
select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
         background: var(--surface); color: var(--text); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-head h1 { margin-bottom: 8px; }
a.button { display: inline-block; text-decoration: none; border: 1px solid var(--border); background: var(--surface);
           color: var(--text); border-radius: 8px; padding: 6px 12px; white-space: nowrap; }
a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }

button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
         color: var(--text); border-radius: 8px; padding: 6px 12px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { border: none; background: none; padding: 2px 4px; color: var(--muted); text-decoration: underline; }
button:disabled { opacity: .5; }
input { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
        background: var(--surface); color: var(--text); width: 100%; }
input[type=radio], input[type=checkbox] { width: auto; padding: 0; margin: 0; accent-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.narrow { max-width: 360px; margin: 40px auto; display: flex; flex-direction: column; gap: 12px; }
.narrow label { display: flex; flex-direction: column; gap: 4px; }

.next-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.next-card { display: flex; gap: 12px; align-items: center; background: var(--surface);
             border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.next-card img { width: 110px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; display: block; }
.next-body { flex: 1; min-width: 0; }
.show-name { font-weight: 600; text-decoration: none; }
button.watch { width: 44px; height: 44px; border-radius: 50%; font-size: 1.2rem; flex: none; }
button.watch:hover { background: var(--done); color: #fff; border-color: var(--done); }

.row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.thumb { width: 52px; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px; display: block; }
.badge { font-size: .75rem; background: var(--accent); color: var(--accent-text); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.clamp { margin: 4px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.show-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
.show-tile { text-decoration: none; }
.show-tile img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; display: block; }
.show-tile.archived { opacity: .5; }
.tile-name { font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 4px; background: var(--border); border-radius: 2px; margin: 4px 0; overflow: hidden; }
.progress div { height: 100%; background: var(--done); }

.show-head { display: grid; grid-template-columns: 180px 1fr; gap: 0 20px; margin-bottom: 16px;
             grid-template-areas: "poster title" "poster summary" "poster actions";
             grid-template-rows: auto auto 1fr; }
.show-head .poster { grid-area: poster; width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; }
.head-title { grid-area: title; }
.head-title h1 { margin-top: 0; }
.show-head .summary { grid-area: summary; margin-top: 0; }
.show-head .actions { grid-area: actions; align-self: start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.season { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin: 10px 0; }
.season summary { display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; font-weight: 600; }
.season-toggle { margin-left: auto; font-weight: normal; }
.ep { display: grid; grid-template-columns: 64px 1fr auto auto; grid-template-areas: "code title meta check";
      gap: 2px 10px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--border); }
.ep .code { grid-area: code; font-variant-numeric: tabular-nums; color: var(--muted); }
.ep .title { grid-area: title; min-width: 0; overflow-wrap: anywhere; }
.ep-meta { grid-area: meta; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.ep .check { grid-area: check; }
.ep.future { opacity: .55; }
.ep.watched .title { color: var(--muted); }
button.check { width: 28px; height: 28px; padding: 0; border-radius: 50%; flex: none; }
.ep.watched button.check { background: var(--done); border-color: var(--done); color: #fff; }
.up-to { font-size: .8rem; }
#search-results.loading { opacity: .55; transition: opacity .15s; }
.result .following { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.section-links { display: flex; gap: 8px; margin: 4px 0 8px; overflow-x: auto; scrollbar-width: none;
                 -webkit-overflow-scrolling: touch; }
.section-links::-webkit-scrollbar { display: none; }
.section-links a { text-decoration: none; white-space: nowrap; padding: 5px 12px; border-radius: 999px;
                   background: var(--surface); border: 1px solid var(--border); font-size: .9rem; }
.show-section { margin-top: 28px; scroll-margin-top: 16px; }
.show-section h2 { font-size: 1.1rem; margin: 0 0 12px; }

.summary[data-expandable] { cursor: pointer; }

/* ---- phones ---- */
@media (max-width: 600px) {
  main { padding: 12px; }
  h1 { font-size: 1.35rem; margin: 4px 0 12px; }
  .topbar { grid-template-columns: 1fr auto; grid-template-areas: "brand user" "nav nav"; padding: 8px 12px 0; }
  .topbar nav { justify-content: space-between; gap: 0; }
  .topbar nav a { flex: 1; text-align: center; padding: 8px 0 10px; font-size: .95rem; }

  .show-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
  .tile-name { font-size: .85rem; margin-top: 4px; }
  .show-tile .small { font-size: .75rem; }
  .show-section { margin-top: 20px; }

  .show-head { grid-template-columns: 96px 1fr; gap: 0 14px; grid-template-rows: auto;
               grid-template-areas: "poster title" "summary summary" "actions actions"; }
  .show-head .summary { margin: 12px 0; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
                        overflow: hidden; }
  .show-head .summary.expanded { display: block; }
  .head-title h1 { margin-bottom: 4px; }
  .head-title p { margin: 0; font-size: .85rem; }

  .ep { grid-template-columns: 56px 1fr auto; grid-template-areas: "code title check" "code meta check";
        padding: 10px 12px; }
  .ep .code { align-self: start; padding-top: 1px; }
  .ep-meta { justify-self: start; }
  button.check { width: 36px; height: 36px; }
  .season summary { padding: 12px; flex-wrap: wrap; }

  .next-grid { grid-template-columns: 1fr; }
  .next-card img { width: 92px; }
}
.divider { display: flex; align-items: center; gap: 10px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.passkey-rename { display: flex; gap: 8px; align-items: center; }
.passkey-rename input { max-width: 220px; }
[hidden] { display: none !important; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; }
.social-signin { display: grid; gap: 8px; margin-top: 12px; }
.social-signin button { width: 100%; }
.social.apple { background: #000; color: #fff; border-color: #000; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 16px 0 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th, .admin-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; white-space: nowrap; }
.admin-table .num { text-align: right; }
.admin-table tr.flagged { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.admin-table tr.disabled { opacity: .6; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.pill.pending { border-color: var(--done); color: var(--done); }
.pill.used { color: var(--muted); }
.pill.revoked, .pill.expired { color: var(--danger); border-color: var(--danger); }
.pill.flag { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); color: var(--text); margin: 1px 0; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.choice-row label, .invite-form label { white-space: nowrap; }
.invite-form { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 12px; }
@media (max-width: 640px) { .invite-form { grid-template-columns: 1fr; } }
code.wrap { word-break: break-all; white-space: normal; }
details.danger summary { cursor: pointer; color: var(--danger); font-size: .85rem; }
button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.notice { padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--done) 15%, transparent); }
.site-footer { text-align: center; padding: 24px 16px 32px; }
.site-footer a { color: inherit; }
.prose { max-width: 680px; line-height: 1.6; }
.prose h2 { margin-top: 1.6em; }
.danger-link { color: var(--danger); }
.inline-code { display: inline; padding: 2px 4px; }
