:root {
  color-scheme: dark;
  --background: #141414;
  --panel: #242424;
  --edge: #666;
  --divider: #373737;
  --text: #f7f7f7;
  --muted: #c5c5c5;
  --accent: #f2343d;
  --brand: #e50914;
  --action-red: #c91822;
  --focus-fill: #f7f7f7;
  --focus-text: #141414;
  --focus-glow: #e509144d;
  --scrim: #060606df;
  --gutter: clamp(1rem, 4vw, 4rem);
  font: 24px/1.4 Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
}

main { padding: 5vh var(--gutter); }

h1, h2, p { margin: 0; }

h1 { font: 750 2.4rem/1.06 Arial, sans-serif; }

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

.masthead, .actions, .controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.masthead {
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.home-screen { padding: 0 0 3rem; }

.cinema-header, .cinema-header nav, .cinema-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
}

.cinema-header {
  position: sticky;
  top: 0;
  z-index: 3;
  gap: clamp(.6rem, 2vw, 1.7rem);
  padding: .65rem var(--gutter);
  background: #080808;
  border-bottom: 1px solid #272727;
}

.cinema-brand {
  color: var(--brand);
  font: 800 1.5rem/1 "Arial Narrow", Impact, Arial, sans-serif;
  letter-spacing: .04em;
  white-space: nowrap;
}

.cinema-actions { margin-left: auto; min-width: 0; }

.cinema-header button {
  color: var(--muted);
  padding: .42rem .48rem;
  font-size: .76rem;
  white-space: nowrap;
  background: transparent;
  border-color: transparent;
}

.cinema-header button[aria-pressed="true"] {
  color: var(--text);
  font-weight: 700;
  border-bottom-color: var(--brand);
}

.cinema-header button:focus {
  color: var(--text);
  background: #292929;
  border-color: transparent;
  box-shadow: none;
}

#catalog-message:not(:empty) { margin: .85rem var(--gutter); color: var(--muted); }

#catalog-search {
  width: clamp(6rem, 14vw, 12rem);
  min-width: 0;
  padding: .42rem .62rem;
  font-size: .76rem;
  border: 1px solid var(--edge);
  background: #141414;
}

.primary-button {
  background: var(--action-red);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}

.primary-button:focus { background: var(--action-red); color: #fff; }

.collection { margin-top: .95rem; }
.collection h2 { padding: 0 var(--gutter); font-size: .98rem; }

.shelf {
  display: flex;
  gap: .36rem;
  overflow: auto hidden;
  padding: .45rem var(--gutter) .55rem;
  scroll-padding-inline: var(--gutter);
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.shelf .listing {
  position: relative;
  flex: 0 0 clamp(8rem, 17vw, 13rem);
  aspect-ratio: 16 / 24;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  text-align: left;
  border: 0;
  border-radius: .18rem;
  background: #292929;
}

.collection-posters .listing { flex-basis: clamp(5rem, 11vw, 8rem); }

.listing-art {
  position: absolute;
  inset: 0;
}

.listing-art img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 35%; }
.listing-caption {
  position: absolute;
  inset: auto 0 0;
  padding: .65rem .45rem .4rem;
  background: linear-gradient(transparent, #090909f0 65%);
  color: var(--text);
}
.listing-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .68rem; font-weight: 700; line-height: 1.18; overflow-wrap: anywhere; }
.listing-meta { display: block; font-size: .72rem; color: var(--muted); }
.listing-caption .listing-meta { margin-top: .12rem; font-size: .57rem; }
.shelf .listing:hover, .shelf .listing:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#details { position: relative; isolation: isolate; min-height: 100vh; }

.details-backdrop {
  position: absolute;
  inset: 0 0 auto auto;
  width: min(75%, 52rem);
  height: 80vh;
  object-fit: cover;
  object-position: center 38%;
  opacity: .27;
  z-index: -2;
}

#details::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, var(--background), transparent 90%),
    linear-gradient(0deg, var(--background) 20%, transparent 100%);
}

.details-layout {
  display: flex;
  gap: 1.5rem;
  align-items: start;
}

.details-poster { width: min(25vw, 12rem); flex-shrink: 0; border-radius: .4rem; }
.details-layout section { min-width: 0; max-width: 39rem; }
.details-layout h1 { margin-top: .25rem; }
.details-actions { margin: .9rem 0; flex-wrap: wrap; }
#details-description { margin-top: .6rem; }
#details-info { display: grid; grid-template-columns: max-content 1fr; gap: .35rem .7rem; font-size: .8rem; }
#details-info dt, .source-credit { color: var(--muted); }
#details-info dd { margin: 0; overflow-wrap: anywhere; }
.source-credit { font-size: .7rem; }

.server-form { display: grid; gap: .6rem; max-width: 26rem; }
.server-form button { justify-self: start; }
.account-settings { margin-top: 2rem; max-width: 38rem; }
.account-settings h2 { margin-bottom: .6rem; }
#account-status, #pair-status { color: var(--muted); }
#pair-input { max-width: 13rem; }
#pair-code strong { display: block; margin-bottom: .4rem; font-size: 2rem; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
#pair-owner h3 { margin: 1.15rem 0 .35rem; }
#sync-key-output { display: block; width: 100%; margin: .6rem 0; font-family: monospace; }
#legacy-import, #pair-disconnect { margin-top: .7rem; }
#rating-form { align-items: center; margin: .9rem 0; }
#rating-input { width: 4rem; }
#rating-status { margin: 0; }

button, input {
  color: inherit;
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: .35rem;
  padding: .55rem .8rem;
  font: inherit;
}

button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }

button:focus, input:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-color: var(--accent);
  box-shadow: 0 0 .8rem var(--focus-glow);
  scroll-margin-top: 4rem;
}

button:focus {
  background: var(--focus-fill);
  color: var(--focus-text);
}

#movies {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .85rem;
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.movie {
  display: grid;
  gap: .25rem;
  padding: .8rem;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--divider);
  border-radius: .5rem;
}

.movie button { text-align: left; overflow-wrap: anywhere; }
.movie small { color: var(--muted); overflow-wrap: anywhere; }
.movie .remove { justify-self: start; font-size: .75rem; }

#source-form {
  display: grid;
  gap: .48rem;
  max-width: 32rem;
}

#source-form > label { margin-top: .55rem; }
#kind { justify-self: start; }
#file { min-width: 0; width: 13rem; }
#source-form .actions { margin-top: .65rem; }
#source-status, #feedback { color: var(--accent); }

#watch {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0;
  background: transparent;
}

body.watching { background: transparent; }
#stage { flex: 1; min-height: 0; }

#video, #av-surface {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

#video { background: #000; }
.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .55rem 1rem;
  padding: .7rem var(--gutter);
  background: linear-gradient(180deg, #1c1c1c, #141414);
  border-top: 1px solid var(--divider);
}
.watch-info { grid-column: 1 / -1; min-width: 0; }
.watch-info h1 { font-size: 1.1rem; overflow-wrap: anywhere; }
.watch-info p { font-size: .7rem; }
#playback-status:empty { display: none; }
#watch:focus { outline: none; }
.watch-timeline {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .65rem;
  font-size: .67rem;
  font-variant-numeric: tabular-nums;
}
#watch-progress {
  width: 100%;
  height: .22rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #535353;
}
#watch-progress::-webkit-progress-bar { background: #535353; }
#watch-progress::-webkit-progress-value { background: var(--accent); }
#watch-progress::-moz-progress-bar { background: var(--accent); }
#watch-duration { color: var(--muted); }
.watch-transport, .watch-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.watch-actions { justify-content: end; }
.controls button { white-space: nowrap; font-size: .75rem; padding: .4rem .65rem; }
#toggle { min-width: 5.25rem; font-weight: 700; }
#watch-settings { display: inline-flex; align-items: center; gap: .25rem; }
#watch-settings span { font-size: 1.05rem; line-height: 1; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--edge);
  border-radius: .5rem;
  max-width: 28rem;
  padding: 1.2rem;
}

dialog .actions { margin-top: 1rem; }
dialog::backdrop { background: var(--scrim); }

#playback-menu {
  inset: auto var(--gutter) 1.1rem auto;
  width: min(33rem, calc(100vw - 2 * var(--gutter)));
  max-width: none;
  max-height: calc(100vh - 2rem);
  margin: 0;
  padding: 1rem;
  border: 1px solid #424242;
  border-radius: .65rem;
  background: #1b1b1b;
  box-shadow: 0 .6rem 2rem #0009;
}
#playback-menu::backdrop { background: #0008; }
.playback-menu-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.playback-menu-header h2 { font-size: 1.05rem; }
#playback-menu-close { min-width: 1.65rem; padding: 0 .35rem; font-size: 1.1rem; }
.playback-menu-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: .7rem; margin-top: .8rem; }
#playback-menu-categories, #playback-menu-options { display: grid; align-content: start; gap: .25rem; padding: .25rem; }
.playback-menu-choices { min-width: 0; border-left: 1px solid var(--divider); padding-left: .65rem; }
.playback-menu-choices h3 { margin: 0 .25rem .25rem; color: var(--muted); font-size: .7rem; font-weight: 600; }
#playback-menu-options { max-height: min(48vh, 13rem); overflow-y: auto; scrollbar-width: thin; }
#playback-menu-categories button, #playback-menu-options button {
  min-width: 0;
  padding: .4rem .55rem;
  background: #242424;
  border: 1px solid transparent;
  font-size: .72rem;
  text-align: left;
  overflow-wrap: anywhere;
}
#playback-menu-categories button { display: grid; gap: .05rem; }
#playback-menu-categories small { color: var(--muted); font-size: .61rem; }
#playback-menu-options button { display: flex; justify-content: space-between; align-items: center; gap: .4rem; }
#playback-menu-categories button[aria-pressed="true"] { border-left-color: var(--accent); background: #363636; }
#playback-menu-options button[aria-pressed="true"]::after { content: '✓'; color: var(--accent); }
#playback-menu button:focus { outline-offset: 0; background: #363636; color: var(--text); }

@media (min-width: 1600px) {
  :root { font-size: 30px; }
}

@media (max-width: 750px) {
  :root { font-size: 16px; }
  #movies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .masthead { align-items: start; flex-direction: column; }
  .cinema-header { flex-wrap: wrap; gap: .5rem; }
  .cinema-actions { margin-left: 0; }
  .details-layout { gap: .8rem; }
  #details-info { grid-template-columns: 1fr; }
  .controls { gap: .45rem; }
  .controls button { padding-inline: .4rem; }
  #toggle { min-width: 0; }
  #playback-menu { padding: .65rem; }
  .playback-menu-body { gap: .35rem; }
  .playback-menu-choices { padding-left: .35rem; }
}
