:root {
  color-scheme: dark;
  font-family: -apple-system, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: #17181d;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: #17181d;
  color: #f4f4f4;
  overscroll-behavior: none;
}

main {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  margin: 0;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  background: #17181d;
}

#install,
#join,
#login {
  width: min(100%, 24rem);
  margin: 0;
  padding: 1.5rem 1.25rem;
  text-align: center;
}

#join:not(.hidden),
#login:not(.hidden) {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
}

#install p,
#join p,
#login p {
  margin: 0;
}

p {
  line-height: 1.45;
}

form {
  display: grid;
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.95rem;
}

input {
  font: inherit;
  padding: 0.8rem;
  border: 1px solid #444;
  border-radius: 0.5rem;
  background: #1c1c1c;
  color: inherit;
}

button {
  font: inherit;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: #e8e8e8;
  color: #111;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}

button:active:not(:disabled) {
  transform: scale(0.97);
  background: #d2d2d2;
}

.error {
  color: #ffb4b4;
}

#version {
  position: fixed;
  z-index: 10;
  top: calc(env(safe-area-inset-top, 0px) + 0.25rem);
  left: calc(env(safe-area-inset-left, 0px) + 0.5rem);
  margin: 0;
  font-size: 0.7rem;
  line-height: 1;
  color: #777;
  pointer-events: none;
}

.hidden {
  display: none;
}

html:has(#reels:not(.hidden)) {
  height: 100%;
  overflow: hidden;
  background: #17181d;
}

body:has(#reels:not(.hidden)) {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  overflow: hidden;
  overscroll-behavior: none;
  background: #17181d;
}

body:has(#reels:not(.hidden)) main {
  display: block;
  place-items: stretch;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#reels:not(.hidden) {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #17181d;
}

.library {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
  background: #17181d;
}

.library-content {
  min-height: 100%;
  padding:
    calc(env(safe-area-inset-top, 0px) + 1.5rem)
    calc(env(safe-area-inset-right, 0px) + 1rem)
    calc(env(safe-area-inset-bottom, 0px) + 1.5rem)
    calc(env(safe-area-inset-left, 0px) + 1rem);
}

.library-content.settling {
  transition: transform 200ms ease-out;
}

.library-head {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.pull {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 0.6rem);
  right: 0;
  left: 0;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: #9a9ba3;
  opacity: 0;
  pointer-events: none;
}

.notify {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.notify:not(:has(:not(.hidden))) {
  display: none;
}

#library-error,
#storage-error {
  margin: 0 0 0.75rem;
}

#empty {
  margin: 2rem 0;
  text-align: center;
  color: #9a9ba3;
}

.publications {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.publication-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
  border-bottom: 1px solid #2a2b31;
}

.publication {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.85rem;
  align-items: center;
  width: 100%;
  padding: 0.65rem 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.publication:active:not(:disabled) {
  transform: none;
  background: #202127;
}

.publication:disabled .cover {
  opacity: 0.5;
}

.publication-action {
  padding: 0.45rem 0.7rem;
  background: #2a2b31;
  color: #f4f4f4;
  font-size: 0.8rem;
}

.publication-action:active:not(:disabled) {
  background: #34353c;
}

.removed-head {
  margin: 1.5rem 0 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #9a9ba3;
}

.removed-item {
  padding: 0.65rem 0;
}

.removed-item .publication-title {
  color: #9a9ba3;
}

.cover {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 0.35rem;
  background: #25262c;
}

.cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.publication-text {
  display: grid;
  gap: 0.2rem;
}

.publication-title {
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.publication-meta {
  font-size: 0.85rem;
  color: #9a9ba3;
}

.pull-hint {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: #6d6e75;
}

.back {
  position: absolute;
  z-index: 7;
  top: calc(env(safe-area-inset-top, 0px) + 1.25rem);
  left: calc(env(safe-area-inset-left, 0px) + 0.75rem);
  padding: 0.5rem 0.85rem;
  background: rgb(0 0 0 / 45%);
  color: #f4f4f4;
  font-size: 0.9rem;
}

.back:active:not(:disabled) {
  background: rgb(0 0 0 / 60%);
}

.stage {
  position: relative;
  display: grid;
  height: 100%;
  min-height: 100%;
  place-items: center;
  background: #17181d;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.stage video {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.stage.slideshow video {
  pointer-events: none;
}

.strip {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  display: flex;
  height: 100%;
}

.strip.settling {
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.strip .slide {
  flex: 0 0 auto;
  display: grid;
  height: 100%;
  place-items: center;
  background: #17181d;
}

.strip .slide img,
.strip .slide canvas.held-frame {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.strip .slide.held img {
  display: none;
}

.stage.slideshow video:not(.live),
.stage.slideshow img.poster {
  display: none;
}

.stage.slideshow video.live {
  display: block;
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  aspect-ratio: auto;
  transform: none;
  object-fit: contain;
  background: #17181d;
  opacity: 1;
  visibility: visible;
}

.stage.slideshow.video-ready:not(.is-swiping) video.live {
  z-index: 4;
}

.stage.slideshow.video-ready:not(.is-swiping):not(.is-seeking) .strip {
  visibility: hidden;
}

.stage.slideshow.is-seeking .strip {
  z-index: 5;
  visibility: visible;
}

#slide-status {
  position: absolute;
  z-index: 6;
  top: calc(env(safe-area-inset-top, 0px) + 1.4rem);
  right: 0;
  left: 0;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: #aaa;
  pointer-events: none;
}

.clip-copy {
  position: absolute;
  z-index: 6;
  right: calc(env(safe-area-inset-right, 0px) + 1rem);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
  left: calc(env(safe-area-inset-left, 0px) + 1rem);
  display: grid;
  gap: 0.2rem;
  margin: 0;
  color: #f4f4f4;
  text-align: center;
  pointer-events: none;
}

.clip-section,
.clip-sequence,
.clip-caption,
.clip-match {
  margin: 0;
}

.clip-section {
  font-size: 0.85rem;
  font-weight: 600;
  color: #aaa;
}

.clip-sequence {
  font-weight: 600;
}

.clip-caption {
  font-size: 0.95rem;
}

.clip-match {
  font-size: 0.85rem;
  color: #aaa;
}

.stage video:not(.live),
.stage img.poster {
  z-index: 1;
  grid-area: 1 / 1;
  width: min(90%, calc(90dvh * var(--frame-ratio, 1.7778)));
  height: auto;
  max-height: 90dvh;
  margin: 0;
  aspect-ratio: var(--frame-ratio, 1.7778);
  background: transparent;
  border-radius: 0;
  object-fit: contain;
  pointer-events: none;
}

.stage video.active {
  z-index: 2;
}

.stage video:not(.active),
.stage video.unpainted,
.stage.is-swiping video {
  visibility: hidden;
}

.stage.slideshow video.live,
.stage.slideshow video.live.unpainted {
  visibility: visible;
}

.stage.slideshow.is-swiping video.live {
  visibility: visible;
  z-index: 4;
}

.stage.slideshow.is-swiping video.live.swipe-settle {
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stage.slideshow.is-swiping.strip-swipe video.live {
  visibility: hidden;
}

.stage img.poster.hidden {
  display: none;
}

.stage img.poster.settling {
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (orientation: landscape) {
  .stage video:not(.live),
  .stage img.poster {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    object-fit: cover;
  }

  .stage.slideshow:not(.chrome-on) #back {
    visibility: hidden;
  }

  .stage.slideshow #clip-copy {
    visibility: hidden;
  }
}

.progress {
  position: absolute;
  z-index: 4;
  transform: translateZ(1px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  height: 3px;
  background: #333;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: #f4f4f4;
}

.stage-message,
.ended,
.controls {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  transform: translateZ(1px);
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}

.stage-message {
  margin: 0;
  padding:
    max(1.5rem, env(safe-area-inset-top, 0px))
    max(1.5rem, env(safe-area-inset-right, 0px))
    max(1.5rem, env(safe-area-inset-bottom, 0px))
    max(1.5rem, env(safe-area-inset-left, 0px));
  text-align: center;
}

.controls {
  align-content: center;
  gap: 0.9rem;
  background: rgb(0 0 0 / 35%);
}

.controls:not(.hidden),
.ended:not(.hidden) {
  animation: fade-in 150ms ease-out;
}

.control-row {
  display: flex;
  gap: 0.6rem;
}

#toggle-play {
  min-width: 7rem;
}

.stage button {
  touch-action: manipulation;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .controls:not(.hidden),
  .ended:not(.hidden) {
    animation: none;
  }

  button,
  .library-content.settling,
  .stage img.poster.settling,
  .strip.settling,
  .stage.slideshow.is-swiping video.live.swipe-settle {
    transition: none;
  }
}

.hidden {
  display: none;
}
