:root {
  color-scheme: dark;
  --bg: #14181C;
  --fg: #CDE;
  --muted: #566778;
  --input: #2D3440;
  --accent: #009839;
  --ep: #e0e0e0;
  --ep-dim: #7a7a7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.page {
  width: min(100% - 20px, 640px);
  margin: 20px auto 0;
  padding: 0 0 64px;
}

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

/* Topbar */

.topbar {
  background: #000;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  width: min(100% - 20px, 640px);
  height: 60px;
  margin: 0 auto;
  padding: 10px 0;
}

.topbar-inner .spacer { flex: 1; }

.topbar-inner a {
  color: var(--fg);
  text-decoration: none;
}

.topbar-inner a:hover { text-decoration: underline; }

/* current page: underlined, not a link */
.topbar-inner .current { text-decoration: underline; }

.brand { margin-left: -2px; }
.logo { display: block; }

/* Header */

.header {
  display: flex;
  gap: 16px;
  margin-bottom: 48px;
}

.search {
  flex: 1;
  height: 36px;
  padding: 0 12px 3px;
  border: none;
  border-radius: 12px;
  corner-shape: squircle;
  background: var(--input);
  color: var(--fg);
  font: inherit;
  outline: none;
}

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

.search:focus { box-shadow: 0 0 0 2px var(--accent); }

.btn {
  display: inline-block;
  height: 35px;
  padding: 0 20px 2px;
  border: none;
  border-radius: 12px;
  corner-shape: squircle;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  line-height: 33px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.1); }

.btn-small {
  height: 32px;
  line-height: 32px;
  padding: 0 14px;
  font-size: 14px;
}

/* Shows */

.show {
  display: flex;
  gap: 20px;
  margin-bottom: 32px;
}

.poster { flex: 0 0 125px; position: relative; }

.season-poster { position: absolute; inset: 0; }

.poster img,
.poster-empty {
  display: block;
  width: 125px;
  aspect-ratio: 2 / 3;
  outline: 1px solid #FFFFFF10;
  box-shadow: #00000080 0px 1px 5px;
  border-radius: 12px;
  corner-shape: squircle;
  object-fit: cover;
  background: var(--input);
}

.details { flex: 1; min-width: 0; }

.title {
  margin: -6px 0 0 0;
  font-size: 28px;
  line-height: 1.2;
  /* single line: hover swaps in episode title, and a wrap would shift the grid under the pointer */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title .ep-code {
  font-variant-numeric: tabular-nums;

  margin-right: 0.25em;
}

.title .ep-code:empty { display: none; }

.subtitle {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.season {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  /* the 8px gap between wrapped lines and between seasons is baked into ep.png cells */
  /* dragging across episodes marks a range, not selects text */
  user-select: none;
  -webkit-user-select: none;
}

.ep {
  display: inline-block;
  width: 32px;
  height: 40px;
  padding: 0;
  border: none;
  background: url("ep.png") no-repeat 0 0 / 384px 80px;
  cursor: pointer;
  --group: 0;
  --col: 1;
  /* 32x40px cells from ep.png, a 12x2 atlas at 2x. Columns: 4 per state (watched / available / upcoming),
     one each for the first, middle, last and single episode of a season. Second row is hovered */
  background-position: calc((var(--group) * 4 + var(--col)) * -32px) 0;
}

.ep.watched   { --group: 0; }
.ep.available { --group: 1; }
.ep.upcoming  { --group: 2; cursor: default; }

.ep.first  { --col: 0; }
.ep.middle { --col: 1; }
.ep.last   { --col: 2; }
.ep.single { --col: 3; }

/* .hovered: part of a range being dragged, see render-season */
.ep:hover, .ep.hovered { background-position-y: -40px; }

.upcoming-label {
  margin-left: 12px;
  font-size: 14px;
  color: var(--muted);
}

/* Search results: .show with .overview + .add instead of episodes */

.overview {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--fg);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  color: var(--muted);
  text-align: center;
  margin: 64px 0;
}

/* Login */

/* whole viewport, content centered vertically */
.page.center {
  min-height: 100svh;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login { text-align: center; }

.login .logo { margin: 0 auto 8px; }
.login .btn { margin: 24px 0 16px; }

@media (max-width: 520px) {
  .page { padding: 24px 0 48px; }
  .header { margin-bottom: 32px; gap: 8px; }
  .topbar { margin-bottom: 32px; }
  /* poster + title/subtitle as a header block, seasons below spanning full width */
  .show {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr);
    /* title row hugs its content, subtitle row absorbs the rest of the poster height */
    grid-template-rows: max-content 1fr;
    gap: 0 14px;
  }
  .details { display: contents; }
  .poster { grid-column: 1; grid-row: 1 / 3; margin-bottom: 12px; }
  .poster img, .poster-empty { width: 100px; }
  .title { grid-column: 2; grid-row: 1; font-size: 22px; }
  .subtitle { grid-column: 2; grid-row: 2; }
  .season { grid-column: 1 / -1; }
  .overview, .add { grid-column: 1 / -1; }
}
