[x-cloak] { display: none !important; }

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #14161a;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-2: #ef4444;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.16);
  --radius: 14px;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --border: #2a2f3a;
  --text: #eef0f4;
  --text-muted: #9aa1b0;
  --accent: #818cf8;
  --accent-2: #6366f1;
  --success: #4ade80;
  --danger: #f87171;
  --danger-2: #ef4444;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --border: #2a2f3a;
    --text: #eef0f4;
    --text-muted: #9aa1b0;
    --accent: #818cf8;
    --accent-2: #6366f1;
    --success: #4ade80;
    --danger: #f87171;
    --danger-2: #ef4444;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; overflow-wrap: break-word; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
h3 { font-size: 1.05rem; margin: 0; }
p { color: var(--text-muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}
.brand-icon { font-size: 1.3rem; }

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.75rem;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.section-head > *:first-child {
  min-width: 0;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-2); }

.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.25rem 0;
  margin-bottom: 1rem;
}
.btn-back:hover { color: var(--text); }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--border); }
.icon-btn.small { width: 30px; height: 30px; font-size: 0.9rem; }

.loading, .empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.empty-state h2 { color: var(--text); }
.empty-state .btn { margin-top: 1rem; }

.show-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.show-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.show-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.show-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.show-card-top h3 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.show-card-menu {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}
.show-card-meta {
  display: flex;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar.thin { height: 5px; margin: 0.6rem 0 0; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
  transition: width 0.25s ease;
}
.progress-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 2.6em;
  text-align: right;
}

.season-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.season-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem 1rem;
  box-shadow: var(--shadow);
}
.season-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 0.75rem;
}
.season-header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
.season-title { font-weight: 600; }
.season-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
}
.season-header-right {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}
.chevron {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
.chevron.open { transform: rotate(90deg); }

.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.episode-chip {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.episode-chip:hover { border-color: var(--accent); }
.episode-chip.watched {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.field input {
  /* iOS Safari auto-zooms the whole page on focus for any input with a
     computed font-size under 16px, and the zoom often doesn't reset
     afterwards in an SPA (no full page reload) -- leaving the page stuck
     zoomed in, which reads as broken/overflowing layout. Must stay >=16px. */
  font-family: inherit;
  font-size: 16px;
  font-weight: 400;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}
.field small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.toast {
  position: fixed;
  top: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  z-index: 200;
  max-width: 90vw;
  font-size: 0.9rem;
}
.toast-close { opacity: 0.8; }

.app-footer {
  text-align: center;
  padding: 1rem 1.25rem 2rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (max-width: 600px) {
  .section-head { flex-direction: row; align-items: center; }
  h1 { font-size: 1.25rem; }
  .episode-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
}
