:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ed;
  --text: #181b18;
  --muted: #687069;
  --line: #d9ded6;
  --accent: #167c68;
  --accent-2: #d45b38;
  --accent-3: #e9b44c;
  --ok: #258050;
  --danger: #ba3b36;
  --shadow: 0 18px 60px rgb(31 41 35 / 12%);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111412;
    --surface: #1b201d;
    --surface-2: #252b27;
    --text: #f2f4ef;
    --muted: #a8b0a8;
    --line: #354038;
    --accent: #56c0a7;
    --accent-2: #ff8a65;
    --accent-3: #f2c96d;
    --ok: #76d29f;
    --danger: #ff7a75;
    --shadow: 0 18px 60px rgb(0 0 0 / 28%);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--accent-3) 18%, transparent), transparent 34rem),
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, var(--bg)), var(--bg) 34rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 8vw, 4.5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.icon-button span {
  font-size: 1.4rem;
  line-height: 1;
}

.search-zone {
  position: relative;
  z-index: 5;
  margin-bottom: 18px;
}

.search-zone label,
.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 98px;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}

.search-box button,
.primary-button,
.secondary-button,
.danger-button,
.tiny-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
}

.search-box button,
.primary-button {
  color: #fff;
  background: var(--accent);
}

.secondary-button {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}

.danger-button {
  color: #fff;
  background: var(--danger);
}

.tiny-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
  font-size: 0.82rem;
}

.search-results {
  position: absolute;
  inset: calc(100% + 8px) 0 auto;
  display: grid;
  gap: 8px;
  max-height: min(540px, 65vh);
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-result {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.poster,
.poster-small {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--surface-2), color-mix(in srgb, var(--accent) 20%, var(--surface)));
}

.poster-small {
  width: 54px;
  height: 76px;
  border-radius: 6px;
}

.result-title,
.show-name,
.episode-name {
  overflow-wrap: anywhere;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 1rem;
}

.panel-head select {
  width: auto;
  min-width: 142px;
}

.shows-list {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.show-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  background: transparent;
  text-align: left;
}

.show-card:hover,
.show-card.is-active {
  border-color: var(--line);
  background: var(--surface-2);
}

.show-card .poster-small {
  width: 58px;
  height: 82px;
}

.show-name {
  font-weight: 900;
}

.progress-bar {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 72%, transparent);
}

.progress-bar span {
  display: block;
  width: var(--value);
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-3));
}

.detail-panel {
  min-height: 520px;
  overflow: hidden;
}

.empty-state {
  display: grid;
  min-height: 360px;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(130px, 190px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
    var(--surface);
}

.detail-hero .poster {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
}

.detail-copy {
  display: grid;
  align-content: start;
  gap: 12px;
}

.detail-copy h2 {
  font-size: clamp(1.6rem, 5vw, 3rem);
  line-height: 1;
}

.summary {
  max-width: 70ch;
  color: var(--muted);
  line-height: 1.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions button {
  padding: 0 14px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 48%, transparent);
}

.episodes-area {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.season {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.season-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.season-head h3 {
  font-size: 0.95rem;
}

.season-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: end;
}

.episode-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.episode-row:last-child {
  border-bottom: 0;
}

.episode-row.is-seen .episode-name {
  color: var(--muted);
  text-decoration: line-through;
}

.episode-check {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.episode-code {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.is-busy {
  opacity: 0.65;
  pointer-events: none;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 18px, 680px);
    padding-top: 14px;
  }

  .workspace,
  .detail-hero,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .detail-hero .poster {
    width: min(220px, 58vw);
  }

  .panel {
    box-shadow: none;
  }

  .search-result {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .search-result .tiny-button {
    grid-column: 1 / -1;
  }

  .episode-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .episode-code {
    grid-column: 2;
  }
}
