/*
 * crappy-tv — base stylesheet (design pass, PLAN.md Task 43 brought forward).
 *
 * Architecture: all colors are CSS custom properties defined once here.
 * Three token sets:
 *   :root                    → light (default)
 *   @media (prefers-color-scheme: dark) + :root:not([data-theme="light"])
 *                            → dark, unless the user forced light
 *   :root[data-theme="dark"] → forced dark (registered-user preference)
 * Registered users pick a scheme in the nav (saved on the account);
 * anonymous visitors follow their OS setting.
 */

:root {
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d8dde4;
  --text: #1d2430;
  --text-muted: #5b6472;
  --accent: #b07d1e;
  --accent-strong: #8f6415;
  --accent-contrast: #ffffff;
  --state-worth: #1a7f4b;
  --state-ok: #9a6d00;
  --state-not: #c42b30;
  --state-undecided: #5b6472;
  --danger-bg: #fbe9e9;
  --ok-bg: #e7f5ee;
  --shadow: 0 1px 3px rgb(16 24 40 / 0.08), 0 4px 12px rgb(16 24 40 / 0.06);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #171b23;
    --surface-2: #1f2530;
    --border: #2c3340;
    --text: #e8eaf0;
    --text-muted: #9aa3b2;
    --accent: #e5b567;
    --accent-strong: #f0c479;
    --accent-contrast: #14181f;
    --state-worth: #4cc38a;
    --state-ok: #e5c07b;
    --state-not: #e5484d;
    --state-undecided: #8b93a5;
    --danger-bg: #3a2224;
    --ok-bg: #1d2f27;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171b23;
  --surface-2: #1f2530;
  --border: #2c3340;
  --text: #e8eaf0;
  --text-muted: #9aa3b2;
  --accent: #e5b567;
  --accent-strong: #f0c479;
  --accent-contrast: #14181f;
  --state-worth: #4cc38a;
  --state-ok: #e5c07b;
  --state-not: #e5484d;
  --state-undecided: #8b93a5;
  --danger-bg: #3a2224;
  --ok-bg: #1d2f27;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.35);
}

/* --- Base --- */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

h1, h2, h3 {
  line-height: 1.25;
  margin: 0 0 0.5em;
}

h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
h2 { font-size: 1.15rem; }

main {
  /* Explicit width: as a flex child with auto margins, main would
     otherwise shrink-to-fit, collapsing auto-fill grids to 1–2 tracks. */
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* --- Header / nav --- */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

header nav a {
  color: var(--text);
  font-weight: 500;
}

header nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

.theme-form {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.theme-form select {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  width: auto;
}

/* --- Footer --- */

footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
  margin-top: auto;
}

footer nav {
  max-width: 1100px;
  margin: 0 auto 0.5rem;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

footer nav a,
footer p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- Cards (browse) --- */

.show-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: grid;
  gap: 1rem;
  /* Deterministic column counts — auto-fill + 1fr tracks carry an
     implicit min-content minimum that can collapse the track count. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 560px) {
  .show-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 820px) {
  .show-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1080px) {
  /* From here up, the poster grid adapts to ANY width: auto-fill with
     a fixed minimum card width (170px) — 6–7 columns on a laptop-scale
     1100px container, ~13 on a capped 2400px ultrawide container. */
  .show-list {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }
}

/* Wide screens: let the content container and the poster grid grow
   so ultrawide displays don't drown in margins. The 85vw/2400px cap
   covers everything up to and incl. 5K 32:9 (5120px → 2400px). */
@media (min-width: 1440px) {
  main,
  header nav,
  footer nav {
    max-width: 1360px;
  }
}

@media (min-width: 1920px) {
  main,
  header nav,
  footer nav {
    max-width: min(85vw, 2400px);
  }
}

.show-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}

.show-card:hover {
  transform: translateY(-2px);
}

.show-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.show-card > div {
  padding: 0.6rem 0.7rem 0.8rem;
}

.show-card h2 {
  font-size: 0.95rem;
  margin: 0 0 0.25rem;
}

.show-card h2 a {
  color: var(--text);
}

.show-card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.result-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --- State badges --- */

.state-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid currentColor;
}

.state-badge.state--worth_to_watch { color: var(--state-worth); background: var(--ok-bg); }
.state-badge.state--ok_to_watch { color: var(--state-ok); }
.state-badge.state--do_not_watch { color: var(--state-not); background: var(--danger-bg); }
.state-badge.state--undecided { color: var(--state-undecided); }

/* --- Level badge --- */

.level-badge {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-contrast);
}

/* --- Detail page --- */

.show-detail-head {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.show-detail-head img {
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--surface-2);
}

.show-detail-head p {
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.genres .genre-tag {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  margin-right: 0.35rem;
  color: var(--text-muted);
}

.show-overview,
.end-date {
  max-width: 70ch;
}

.attribution {
  margin-top: 2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Forms --- */

form label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

/* Checkbox rows (signup consent checkboxes etc.): the checkbox and the
   text that follows sit on one line — the block rule above must not
   split them. */
form input[type="checkbox"] {
  vertical-align: middle;
  margin-right: 0.45rem;
}

form input[type="checkbox"] + label {
  display: inline;
  font-weight: 400;
  margin-bottom: 0;
}

input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  max-width: 26rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.error,
.errorlist {
  color: var(--state-not);
  font-size: 0.9rem;
}

.errorlist {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0;
}

.error {
  background: var(--danger-bg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.signup-prompt {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  max-width: 34rem;
}

/* --- Messages --- */

.message {
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.message-success { background: var(--ok-bg); color: var(--state-worth); }
.message-error { background: var(--danger-bg); color: var(--state-not); }
.message-warning { background: var(--surface-2); color: var(--text); }
.message-info { background: var(--surface-2); color: var(--text); }

/* --- Empty states, misc --- */

.empty-state {
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  max-width: 40rem;
}

.pagination {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 1.25rem 0;
}

.pagination a {
  font-weight: 500;
}

.legal-page,
.auth-page {
  max-width: 46rem;
}

.auth-page form p {
  margin: 0.75rem 0;
}

.activity-list {
  list-style: none;
  padding: 0;
  max-width: 40rem;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.activity-event {
  font-weight: 500;
}

.activity-item time {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.profile-head p {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.karma-total,
.end-date,
.attribution {
  color: var(--text-muted);
}

.show-overview p {
  white-space: pre-line;
}

/* --- Step 3 polish: shell, CTAs, forms, tables, page sections --- */

:root {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

/* Sticky-footer shell: main grows, footer stays down on short pages. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent) !important;
  letter-spacing: 0.01em;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.4rem 0.8rem;
  border-radius: 0 0 6px 0;
  z-index: 10;
}

.skip-link:focus {
  left: 0;
}

/* Anchor buttons (CTAs rendered as links) */

a.button,
a.button-secondary {
  display: inline-block;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
}

a.button {
  background: var(--accent);
  color: var(--accent-contrast);
}

a.button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  text-decoration: none;
}

a.button-secondary {
  color: var(--accent);
  background: transparent;
}

a.button-secondary:hover {
  background: var(--surface-2);
  text-decoration: none;
}

/* Home hero */

.hero {
  padding: 2.5rem 0 1.5rem;
  max-width: 46rem;
}

.hero-logo {
  display: block;
  height: 120px;
  width: auto;
  margin-bottom: 0.75rem;
}

/* The artwork is dark — on the dark theme it sits on a white rounded
   chip instead of vanishing into the background. */
:root[data-theme="dark"] .hero-logo {
  background: #fff;
  border-radius: 12px;
  padding: 10px;
}

.hero h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
}

.hero .tagline {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.hero .cta-row {
  display: flex;
  gap: 0.75rem;
  margin: 1.25rem 0;
  flex-wrap: wrap;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: grid;
  gap: 0.5rem;
}

.feature-list li::before {
  content: "→";
  color: var(--accent);
  font-weight: 700;
  margin-right: 0.5rem;
}

/* Search rows (browse + suggest) */

.search-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 34rem;
  flex-wrap: wrap;
}

.search-form label {
  flex-basis: 100%;
}

.search-form input[type="search"],
.search-form input[type="text"] {
  flex: 1;
  max-width: none;
}

.search-form .sort-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.add-missing-show {
  margin: 1.5rem 0;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.add-missing-show p {
  margin: 0;
  color: var(--text-muted);
}

.add-missing-show a {
  font-weight: 600;
}

/* Suggest results */

.suggest-results {
  list-style: none;
  padding: 0;
  max-width: 46rem;
}

.suggest-results li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.suggest-results form {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.suggest-results form label {
  flex: 1;
  min-width: 12rem;
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.suggest-results form input {
  max-width: none;
}

/* Legal prose + tables (Cookie Notice) */

.legal-page h2 {
  margin-top: 1.5rem;
}

.legal-page table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.legal-page th,
.legal-page td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.legal-page th {
  background: var(--surface-2);
}

/* Auth pages: card look */

.auth-page form,
.signup-prompt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-page form {
  padding: 1.25rem;
  max-width: 26rem;
}

.auth-page .signup-prompt,
.profile-activity .signup-prompt {
  padding: 0.9rem 1.1rem;
}

/* Detail page spacing */

.show-detail section,
.show-detail .end-date {
  margin-top: 1.25rem;
}

/* --- Language switcher (flag dropdown, upper right) --- */

.lang-switcher {
  position: relative;
}

/* The first item of the right-hand corner (Log in for anonymous,
   theme form for authenticated) pushes the corner block to the edge. */
.corner-start {
  margin-left: auto;
}

.lang-switcher summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
}

.lang-switcher summary::-webkit-details-marker {
  display: none;
}

.lang-switcher summary::after {
  content: "▾";
  color: var(--text-muted);
  font-size: 0.75rem;
}

.lang-switcher summary:hover {
  border-color: var(--accent);
}

.lang-switcher img {
  display: block;
  border-radius: 2px;
}

.lang-switcher ul {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0.25rem;
  position: absolute;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 10rem;
  z-index: 20;
}

.lang-switcher li a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--text);
}

.lang-switcher li a:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.lang-switcher li.current a {
  background: var(--surface-2);
  font-weight: 600;
}

.lang-switcher li.current a::after {
  content: "✓";
  color: var(--accent);
  margin-left: auto;
}

/* --- State proposals (Task 20) --- */

.proposals {
  margin-top: 1.5rem;
}

.proposal-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.75rem;
}

.proposal-group > p {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 0 0 0.5rem;
}

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

.proposal-justifications li {
  padding: 0.4rem 0;
  border-top: 1px solid var(--border);
}

.proposal-justifications blockquote {
  margin: 0 0 0.2rem;
  padding: 0 0 0 0.75rem;
  border-left: 3px solid var(--accent);
}

.proposal-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.propose-form form,
.propose-form select,
.propose-form textarea {
  max-width: 34rem;
}

.propose-form textarea {
  display: block;
}

.own-proposal {
  color: var(--text-muted);
}

.not-ended-note {
  color: var(--text-muted);
  font-style: italic;
  margin-top: 1.25rem;
}

.seeded-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  vertical-align: middle;
}

/* --- Bulk import (staff tool) --- */

.bulk-import-form textarea {
  width: 100%;
  max-width: 34rem;
  font-family: monospace;
}

.bulk-import-results {
  margin-top: 1rem;
  border-collapse: collapse;
}

.bulk-import-results th,
.bulk-import-results td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  text-align: left;
}

.bulk-outcome.bulk--imported {
  color: var(--state-ok);
}

.bulk-outcome.bulk--not_ended,
.bulk-outcome.bulk--unknown,
.bulk-outcome.bulk--invalid {
  color: var(--text-muted);
}

.signup-prompt {
  margin-top: 1.25rem;
}

/* --- Moderation queue (Task 22) --- */

.moderation-head h1 {
  margin-bottom: 0.25rem;
}

.moderation-help {
  color: var(--text-muted);
  max-width: 46rem;
}

.moderation-group {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-top: 1rem;
}

.moderation-group h2 {
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.moderation-actions {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.moderation-actions button.approve {
  color: var(--ok-bg);
}

.moderation-actions button.deny {
  color: var(--danger-bg);
}

.moderation-note {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.moderation-empty {
  color: var(--text-muted);
  margin-top: 1.5rem;
}

/* --- Branded error pages (Task 48 / PRELAUNCH.md) --- */

.error-page {
  text-align: center;
  padding: 3rem 1rem;
}

.error-page h1 {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.propose-form .field-help {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.propose-form select {
  max-width: none;
}

/* --- Comment posting form (Task 23) --- */

.comment-form textarea {
  width: 100%;
  max-width: 34rem;
  display: block;
}

/* --- Comment display (Task 24) --- */

.comment-list {
  list-style: none;
  padding: 0;
}

.comment {
  margin: 0.9rem 0;
}

.comment-body {
  margin: 0.3rem 0 0;
  max-width: 46rem;
}

.comment-score {
  color: var(--text-muted);
}

.spoiler-mark {
  color: var(--state-not);
  font-weight: 600;
}

/* Spoiler obscuring: CSS-only per-show toggle — a hidden checkbox before
   the list; checking it un-blurs every spoiler body. Works without JS. */
.spoiler-toggle {
  position: absolute;
  left: -9999px;
}

.spoiler-toggle + label {
  display: inline;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.spoiler-body {
  filter: blur(6px);
  transition: filter 0.2s ease;
}

.spoiler-toggle:checked ~ .comment-list .spoiler-body {
  filter: none;
}

/* --- Comment voting (Task 26) --- */

.vote-form {
  display: inline;
}

.vote-btn {
  padding: 0 0.4rem;
  font-size: 0.8rem;
  line-height: 1.4;
}

.vote-note {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.vote-error {
  color: var(--state-not);
  font-size: 0.85rem;
}
