/* Design tokens — dark by default, light theme opt-in via [data-theme="light"] */
:root {
  --bg: #0a0b10;
  --bg-elev: #12141c;
  --surface: #171a24;
  --surface-2: #1e2230;
  --border: #262b3a;
  --border-soft: #1d2130;
  --text: #e9ecf5;
  --text-dim: #a2a9bd;
  --text-mute: #6f778f;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-ink: #ffffff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px -18px rgb(0 0 0 / 0.75);
  --shadow-lg: 0 30px 70px -25px rgb(0 0 0 / 0.85);
  --header-h: 66px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #f4f5f9;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dfe3ec;
  --border-soft: #e8ebf2;
  --text: #141726;
  --text-dim: #4c5468;
  --text-mute: #79819a;
  --shadow: 0 14px 32px -18px rgb(20 23 38 / 0.28);
  --shadow-lg: 0 26px 60px -28px rgb(20 23 38 / 0.35);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
  display: block;
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-mute);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 550;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease), transform 0.16s var(--ease);
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-mute);
}
.btn:active {
  transform: translateY(1px);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: #8f74ff;
  border-color: transparent;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}
.btn-danger {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 40%, transparent);
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  border-color: var(--bad);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}
.btn-icon {
  padding: 9px;
  width: 38px;
  height: 38px;
}

/* ---------- Form controls ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.field .hint {
  font-size: 12px;
  color: var(--text-mute);
}
.input,
select.input,
textarea.input {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.input::placeholder {
  color: var(--text-mute);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea.input {
  resize: vertical;
  min-height: 84px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input {
  appearance: none;
  width: 40px;
  height: 23px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: background 0.18s var(--ease);
  flex: none;
}
.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
}
.switch input:checked {
  background: var(--accent);
  border-color: transparent;
}
.switch input:checked::after {
  transform: translateX(17px);
  background: #fff;
}

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s var(--ease);
}
.chip:hover {
  color: var(--text);
  border-color: var(--text-mute);
}
.chip.active {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.03em;
  background: color-mix(in srgb, var(--text) 12%, transparent);
  color: var(--text);
  backdrop-filter: blur(6px);
}
.badge-quality {
  background: rgb(0 0 0 / 0.62);
  color: #fff;
}
.badge-good {
  background: color-mix(in srgb, var(--good) 20%, transparent);
  color: var(--good);
}
.badge-warn {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
}
.badge-bad {
  background: color-mix(in srgb, var(--bad) 20%, transparent);
  color: var(--bad);
}

/* ---------- Poster cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 22px 18px;
}

.card {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card .poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
}
.card:hover .poster,
.card:focus-visible .poster {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}
.card .poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.poster-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 14px;
  text-align: center;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.3;
  color: var(--text-dim);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
}
.poster .corner {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 5px;
}
.poster .play-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(to top, rgb(0 0 0 / 0.72), rgb(0 0 0 / 0.1) 55%);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.card:hover .play-overlay,
.card:focus-visible .play-overlay {
  opacity: 1;
}
.play-overlay .circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.5);
}
.card .card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .card-sub {
  font-size: 12.5px;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 7px;
}
.progress-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgb(0 0 0 / 0.55);
}
.progress-strip > i {
  display: block;
  height: 100%;
  background: var(--accent);
}

/* ---------- Layout helpers ---------- */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.spacer {
  flex: 1;
}
.section {
  margin: 0 0 42px;
}
.section-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 16px;
}
.section-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.section-head .count {
  color: var(--text-mute);
  font-size: 13px;
}
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-mute);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty h3 {
  color: var(--text-dim);
  margin: 0 0 8px;
  font-size: 16px;
}
.spin {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 3000;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 380px;
  font-size: 13.5px;
  animation: toast-in 0.22s var(--ease);
}
.toast.err {
  border-color: color-mix(in srgb, var(--bad) 55%, transparent);
}
.toast.ok {
  border-color: color-mix(in srgb, var(--good) 55%, transparent);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
