:root {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.64);
  --line: rgba(255, 255, 255, 0.12);
  --brand: #2735d4;
  --danger: #ff6961;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

img,
video {
  display: block;
}

:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.brand {
  display: flex;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px 0;
}

.brand a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 8px;
}

/* The logo file is black and the page is dark. */
.brand img {
  height: 22px;
  width: auto;
  filter: invert(1);
}

main {
  max-width: 430px;
  margin: 0 auto;
}

#editor,
#result {
  padding: 8px 16px 0;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}

/* Capped by height so the player, the slots and the button fit on one phone screen. */
.player {
  position: relative;
  width: min(100%, calc(52dvh * 9 / 16));
  margin: 16px auto 0;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
}

.player video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Same framing as bin/video: scaled to the frame height, centred, sides cropped. */
#preview-photo {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  max-width: none;
  transform: translateX(-50%);
  pointer-events: none;
}

.player-toggle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  cursor: pointer;
}

.player-toggle:focus-visible {
  outline-offset: -2px;
}

.player.is-playing .player-glyph {
  visibility: hidden;
}

.player-progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.24);
  pointer-events: none;
}

.player-progress-bar {
  height: 100%;
  background: #fff;
  transform: scaleX(0);
  transform-origin: left;
}

.slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.slot {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.slot:disabled {
  cursor: default;
}

.slot.is-active::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -6px;
  left: 0;
  height: 2px;
  border-radius: 1px;
  background: #fff;
}

.slot[data-state="empty"] {
  border: 1px dashed rgba(255, 255, 255, 0.4);
  background: transparent;
}

.slot img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.slot[data-state="uploading"] img,
.slot[data-state="failed"] img {
  opacity: 0.5;
}

.slot-number,
.slot-alert {
  position: absolute;
  top: 4px;
  left: 4px;
  display: none;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.slot[data-state="empty"] .slot-number {
  display: grid;
  inset: 0;
  width: auto;
  height: auto;
  font-size: 22px;
  font-weight: 400;
  color: var(--muted);
}

.slot[data-state="filled"] .slot-number {
  display: grid;
  background: rgba(0, 0, 0, 0.6);
}

.slot[data-state="failed"] .slot-alert {
  display: grid;
  background: var(--danger);
  color: #000;
}

.slot-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  display: none;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.slot[data-state="uploading"] .slot-spinner {
  display: block;
}

#status {
  min-height: 21px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.actions {
  position: sticky;
  bottom: 0;
  margin: 0 -16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.button:active:not(:disabled) {
  opacity: 0.8;
}

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

.button-primary:disabled {
  opacity: 0.4;
  cursor: default;
}

#primary:disabled {
  background: #2a2a2a;
  color: var(--muted);
  opacity: 1;
}

.button-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 10px;
  vertical-align: -3px;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.button-secondary {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: transparent;
  color: #fff;
}

.button-text {
  background: transparent;
  color: #fff;
  font-weight: 500;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 0 calc(16px + env(safe-area-inset-bottom));
}

#save-hint {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.sheet {
  width: 100%;
  max-width: min(430px, 100%);
  margin: auto auto 0;
  padding: 0 0 env(safe-area-inset-bottom);
  border: 0;
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  color: var(--text);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.sheet h2 {
  padding: 16px 16px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.sheet-note {
  margin-top: -8px;
  padding: 0 16px 12px;
  font-size: 14px;
  color: var(--muted);
}

.sheet-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.sheet-item:active {
  background: var(--line);
}

.sheet-item:focus-visible {
  outline-offset: -2px;
}

.sheet-item-destructive {
  color: var(--danger);
}

.sheet-item-cancel {
  font-weight: 600;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .slot-spinner,
  .button-spinner {
    animation: none;
  }
}
