/* ---------------------------------------------------------------- variables */

:root {
  --bg: #08090d;
  --bg-raised: #10131a;
  --bg-input: #171b24;
  --border: #232936;
  --border-bright: #323a4b;
  --text: #eef1f6;
  --text-dim: #98a1b3;
  --text-faint: #67707f;
  --accent: #4c8dff;
  --accent-hot: #6ba1ff;
  --danger: #ff5a5f;
  --good: #3ecf8e;
  --warn: #ffb648;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px rgb(0 0 0 / 45%);
  --header-h: 56px;
}

/* --------------------------------------------------------------- foundation */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The `button` and `.btn` rules below set an explicit display, which beats the
 * user-agent style for [hidden] and leaves hidden buttons on screen. */
[hidden] {
  display: none !important;
}

html {
  /* Stops iOS from inflating text in landscape. */
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* Kills the grey flash on tap in Safari, and the double-tap zoom delay. */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hot);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}

/* ------------------------------------------------------------------- layout */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left)) calc(64px + env(safe-area-inset-bottom));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-left)) 0;
  background: rgb(8 9 13 / 82%);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header .brand {
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  font-size: 16px;
  white-space: nowrap;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-header nav::-webkit-scrollbar {
  display: none;
}

.site-header nav a,
.site-header nav button {
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  background: none;
  border: 0;
  cursor: pointer;
}

.site-header nav a:hover,
.site-header nav button:hover {
  background: var(--bg-input);
  color: var(--text);
}

.site-header nav a.active {
  color: var(--text);
  background: var(--bg-input);
}

/* ------------------------------------------------------------------ pieces */

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
  font-size: 13px;
}

.page-title {
  font-size: clamp(24px, 5vw, 34px);
  margin-bottom: 4px;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  font-weight: 650;
  margin: 28px 0 12px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.badge.good {
  color: var(--good);
  border-color: rgb(62 207 142 / 35%);
}

.badge.warn {
  color: var(--warn);
  border-color: rgb(255 182 72 / 35%);
}

.badge.hot {
  color: var(--accent);
  border-color: rgb(76 141 255 / 40%);
}

/* ------------------------------------------------------------------ buttons */

button,
.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

button:hover:not(:disabled),
.btn:hover {
  background: #1e2431;
  border-color: #3d4658;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05070c;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hot);
  border-color: var(--accent-hot);
}

.btn-danger {
  color: var(--danger);
  border-color: rgb(255 90 95 / 35%);
}

.btn-danger:hover:not(:disabled) {
  background: rgb(255 90 95 / 12%);
}

.btn-ghost {
  background: none;
  border-color: transparent;
  color: var(--text-dim);
}

.btn-sm {
  padding: 6px 10px;
  min-height: 32px;
  font-size: 13px;
}

.btn-lg {
  padding: 14px 22px;
  min-height: 50px;
  font-size: 16px;
}

/* ------------------------------------------------------------------- inputs */

input,
select,
textarea {
  font: inherit;
  /* 16px minimum, or iOS zooms the whole page when the field is focused. */
  font-size: 16px;
  width: 100%;
  padding: 11px 13px;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
}

/* Sliders need the native appearance back, and none of the text-field padding,
 * or the thumb collapses into a dot. */
input[type='range'] {
  appearance: auto;
  padding: 0;
  border: 0;
  background: none;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type='checkbox'] {
  width: auto;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgb(76 141 255 / 45%);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field {
  margin-bottom: 14px;
}

.field-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-faint);
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 0;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
  appearance: auto;
}

/* -------------------------------------------------------------------- login */

.centered {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------- collections */

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.collection-card {
  display: block;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  transition: transform 0.16s, border-color 0.16s;
}

.collection-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-bright);
  color: var(--text);
}

.collection-card .art {
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #1b2130, #0d1017);
  display: grid;
  place-items: center;
  position: relative;
}

.collection-card .art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.collection-card .art .placeholder {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

.collection-card .meta {
  padding: 12px 14px 14px;
}

.collection-card .meta strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 3px;
}

/* ------------------------------------------------------------------- hero */

.hero {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  background: var(--bg-raised);
}

.hero img {
  width: 100%;
  max-height: 380px;
  object-fit: cover;
}

.hero .hero-empty {
  height: 180px;
  background: linear-gradient(135deg, #1b2130, #0d1017);
}

.hero .hero-text {
  position: absolute;
  inset: auto 0 0 0;
  padding: 40px 22px 20px;
  background: linear-gradient(to top, rgb(8 9 13 / 95%), rgb(8 9 13 / 0%));
}

.hero h1 {
  font-size: clamp(26px, 6vw, 42px);
}

/* --------------------------------------------------------------- episodes */

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.episode-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
}

.episode-row:hover {
  border-color: var(--border-bright);
  background: #141821;
  color: var(--text);
}

.episode-row .num {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.episode-row .info {
  min-width: 0;
  flex: 1;
}

.episode-row .info strong {
  display: block;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ player */

.watch-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}

@media (max-width: 940px) {
  .watch-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 10px max(8px, env(safe-area-inset-left)) calc(20px + env(safe-area-inset-bottom));
  }
}

.player-shell {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.player-shell video {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  /* object-fit keeps letterboxed sources from stretching. */
  object-fit: contain;
}

.gate {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgb(5 6 10 / 88%);
  backdrop-filter: blur(6px);
}

.gate[hidden] {
  display: none;
}

.gate .gate-inner {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 340px;
}

.gate h2 {
  font-size: 20px;
}

.overlay-note {
  position: absolute;
  z-index: 8;
  left: 12px;
  bottom: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgb(5 6 10 / 82%);
  border: 1px solid var(--border-bright);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  pointer-events: none;
  transition: opacity 0.2s;
}

.overlay-note[hidden] {
  display: none;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
}

@media (max-width: 640px) {
  .controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .controls .spacer {
    display: none;
  }
  .controls .time {
    grid-column: span 2;
    text-align: right;
  }
}

.controls .time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.scrub {
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  height: 26px;
  accent-color: var(--accent);
  appearance: auto;
  cursor: pointer;
}

.sync-pill {
  font-size: 12px;
  font-weight: 650;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sync-pill.ok {
  color: var(--good);
  border-color: rgb(62 207 142 / 30%);
}

.sync-pill.off {
  color: var(--warn);
  border-color: rgb(255 182 72 / 30%);
}

.sync-pill.bad {
  color: var(--danger);
  border-color: rgb(255 90 95 / 30%);
}

/* -------------------------------------------------------------------- party */

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.member .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex: none;
}

.member.buffering .dot {
  background: var(--warn);
}

.member .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 7px;
  height: 300px;
  overflow-y: auto;
  padding: 4px 2px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-line {
  font-size: 14px;
  word-wrap: break-word;
}

.chat-line .who {
  font-weight: 700;
  color: var(--accent);
  margin-right: 5px;
}

.chat-line.system {
  color: var(--text-faint);
  font-size: 13px;
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
}

.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--text);
}

.reaction-float {
  position: absolute;
  z-index: 9;
  bottom: 60px;
  font-size: 34px;
  pointer-events: none;
  animation: floatUp 1.8s ease-out forwards;
}

@keyframes floatUp {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-130px) scale(1.5);
  }
}

/* -------------------------------------------------------------------- admin */

.admin-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 340px minmax(0, 1fr);
  align-items: start;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

td.tight {
  width: 1%;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.drop-zone {
  border: 2px dashed var(--border-bright);
  border-radius: var(--radius);
  padding: 26px 18px;
  text-align: center;
  color: var(--text-dim);
  background: var(--bg-input);
  cursor: pointer;
}

.drop-zone.hot {
  border-color: var(--accent);
  color: var(--text);
  background: rgb(76 141 255 / 8%);
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
  margin-top: 10px;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}

.code-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-raised);
}

.code-item.inactive {
  opacity: 0.55;
}

.code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text);
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  text-transform: uppercase;
}

/* ----------------------------------------------------------------- progress */

.bar {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
  margin-top: 8px;
}

.bar.thin {
  height: 3px;
  margin-top: 6px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.is-complete {
  color: var(--good) !important;
}

/* A finished collection reads as green at a glance from the grid. */
.collection-card.complete {
  border-color: rgb(62 207 142 / 45%);
}

.collection-card.complete .bar span {
  background: var(--good);
}

.complete-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: #05070c;
  background: var(--good);
  box-shadow: 0 2px 10px rgb(0 0 0 / 45%);
}

.episode-row.complete .num {
  color: var(--good);
  background: rgb(62 207 142 / 12%);
}

.episode-row.complete .info strong {
  color: var(--text-dim);
}

/* -------------------------------------------------------------------- misc */

.toast-host {
  position: fixed;
  z-index: 100;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}

.toast {
  padding: 11px 16px;
  border-radius: 999px;
  background: #1b212e;
  border: 1px solid var(--border-bright);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  animation: toastIn 0.18s ease-out;
}

.toast.error {
  border-color: rgb(255 90 95 / 45%);
  color: #ffc9cb;
}

.toast.warn {
  border-color: rgb(255 186 73 / 45%);
  color: #ffd9a0;
}

.toast.good {
  border-color: rgb(62 207 142 / 45%);
  color: #b6f0d5;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-dim);
}

.empty-state h2 {
  margin-bottom: 8px;
  color: var(--text);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-bright);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
