:root {
  color-scheme: dark;
  --bg: #101115;
  --panel: #181b22;
  --panel-strong: #20242d;
  --ink: #f5f0e7;
  --muted: #c8bdab;
  --line: rgba(245, 240, 231, 0.18);
  --red: #d73e33;
  --gold: #f1b84b;
  --blue: #3b7bbf;
  --green: #3c9b72;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(120deg, rgba(16, 17, 21, 0.92), rgba(16, 17, 21, 0.78)),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 18px),
    radial-gradient(circle at 16% 12%, rgba(215, 62, 51, 0.45), transparent 30rem),
    radial-gradient(circle at 88% 4%, rgba(59, 123, 191, 0.42), transparent 32rem),
    radial-gradient(circle at 50% 95%, rgba(241, 184, 75, 0.28), transparent 34rem),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: linear-gradient(to bottom, #000, transparent 80%);
}

body.viewer-open {
  overflow: hidden;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

.masthead,
main {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
}

.masthead {
  padding: 16px 0 12px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
}

.home-link,
.route-pill,
button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 27, 34, 0.74);
}

.home-link,
.route-pill {
  padding: 9px 12px;
  text-decoration: none;
}

.route-pill {
  color: var(--gold);
}

.hero {
  min-height: 180px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 290px);
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: clamp(18px, 2.5vw, 30px);
  background:
    linear-gradient(135deg, rgba(215, 62, 51, 0.22), transparent 40%),
    linear-gradient(315deg, rgba(59, 123, 191, 0.26), transparent 46%),
    rgba(24, 27, 34, 0.78);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -6% -30% 42%;
  height: 130px;
  border-top: 2px dashed rgba(245, 240, 231, 0.24);
  transform: rotate(-8deg);
}

.hero-copy {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 800;
  font-size: 0.72rem;
}

h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.2rem, 4.8vw, 4.6rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.lede {
  max-width: 560px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(0.96rem, 1.35vw, 1.12rem);
  line-height: 1.4;
}

.passport-stack {
  min-height: 125px;
  position: relative;
}

.stamp {
  position: absolute;
  display: grid;
  place-items: center;
  width: 132px;
  aspect-ratio: 1.6;
  border: 3px solid currentColor;
  border-radius: 8px;
  color: var(--gold);
  font-size: 0.9rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transform: rotate(-9deg);
  opacity: 0.82;
}

.stamp::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px dashed currentColor;
  border-radius: 4px;
}

.stamp-one {
  right: 12px;
  top: 4px;
  color: var(--red);
}

.stamp-two {
  left: 0;
  top: 50px;
  color: var(--blue);
  transform: rotate(7deg);
}

.stamp-three {
  right: 52px;
  bottom: 2px;
  color: var(--green);
  transform: rotate(-15deg);
}

main {
  padding-bottom: 56px;
}

.controls,
.status-row,
.soundtrack,
.drop-zone,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(24, 27, 34, 0.8);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.22);
}

.soundtrack {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(220px, 360px);
  gap: 18px;
  align-items: center;
  margin-bottom: 14px;
  padding: 16px;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(135deg, rgba(215, 62, 51, 0.28), transparent 38%),
    linear-gradient(315deg, rgba(241, 184, 75, 0.18), transparent 44%),
    rgba(24, 27, 34, 0.86);
}

.soundtrack::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 38px, rgba(255, 255, 255, 0.065) 38px 39px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 40%, rgba(59, 123, 191, 0.14));
  pointer-events: none;
}

.soundtrack > * {
  position: relative;
  z-index: 1;
}

.soundtrack-art {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(241, 184, 75, 0.72);
  border-radius: 50%;
  overflow: hidden;
  color: var(--gold);
  background: linear-gradient(135deg, #272b35, #101115);
  box-shadow:
    inset 0 0 0 3px rgba(16, 17, 21, 0.5),
    0 14px 34px rgba(0, 0, 0, 0.28);
}

.soundtrack-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 52% 44%;
}

.soundtrack-copy {
  min-width: 0;
}

.soundtrack-copy .eyebrow {
  margin-bottom: 6px;
}

.soundtrack h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.7rem);
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.soundtrack p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--muted);
}

.soundtrack audio {
  width: 100%;
  height: 42px;
  filter: sepia(0.22) saturate(1.2);
}

.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
  padding: 14px;
  backdrop-filter: blur(16px);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-field {
  flex: 1 1 340px;
  min-width: 0;
}

input,
select,
button {
  min-height: 44px;
  color: var(--ink);
  outline: none;
}

input,
select {
  width: 100%;
  padding: 0 12px;
}

button {
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

button:hover,
input:focus,
select:focus,
.home-link:hover {
  border-color: rgba(241, 184, 75, 0.8);
}

.control-cluster {
  display: flex;
  align-items: end;
  gap: 12px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0;
  padding: 12px 14px;
}

.status-row p {
  margin: 0;
  color: var(--muted);
}

.drop-zone {
  margin-bottom: 16px;
  padding: 18px;
  border-style: dashed;
}

.drop-zone.dragging {
  border-color: var(--gold);
  background: rgba(241, 184, 75, 0.12);
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone span {
  margin-top: 4px;
  color: var(--muted);
}

.gif-grid {
  column-count: 4;
  column-gap: 16px;
}

.gif-card {
  display: inline-block;
  width: 100%;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: clip;
  background: rgba(24, 27, 34, 0.9);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
  break-inside: avoid;
}

.gif-frame {
  display: block;
  min-height: 180px;
  background:
    linear-gradient(135deg, rgba(215, 62, 51, 0.22), rgba(59, 123, 191, 0.18)),
    var(--panel-strong);
}

.gif-frame img,
.gif-frame video {
  display: block;
  width: 100%;
  height: auto;
}

.gif-frame video {
  background: #050506;
}

.gif-frame img[hidden],
.gif-frame video[hidden] {
  display: none;
}

.gif-meta {
  display: flex;
  gap: 12px;
  align-items: start;
  justify-content: space-between;
  padding: 12px;
}

.gif-meta h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  line-height: 1.2;
}

.gif-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.gif-actions {
  flex: 0 0 202px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gif-actions button,
.download-button {
  min-height: 34px;
  padding: 0 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(24, 27, 34, 0.74);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.gif-actions button:hover,
.download-button:hover {
  border-color: rgba(241, 184, 75, 0.8);
}

.gif-actions button.is-limited {
  color: var(--muted);
}

.gif-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.viewer-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(120deg, rgba(16, 17, 21, 0.92), rgba(16, 17, 21, 0.78)),
    rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(10px);
  cursor: zoom-out;
}

.viewer-shell {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(245, 240, 231, 0.24);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(215, 62, 51, 0.16), transparent 38%),
    linear-gradient(315deg, rgba(59, 123, 191, 0.16), transparent 44%),
    rgba(24, 27, 34, 0.96);
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.58);
}

.viewer-toolbar,
.viewer-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background: rgba(16, 17, 21, 0.82);
}

.viewer-toolbar {
  justify-content: flex-end;
  border-bottom: 1px solid var(--line);
}

.viewer-stage {
  position: relative;
  min-height: min(62vh, 620px);
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 18px),
    #050608;
}

.viewer-stage img {
  display: block;
  max-width: 100%;
  max-height: min(70vh, 720px);
  width: auto;
  height: auto;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.viewer-copy-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: min(520px, calc(100% - 28px));
  margin: 0;
  transform: translateX(-50%);
  border: 1px solid rgba(241, 184, 75, 0.72);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(16, 17, 21, 0.9);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34);
  text-align: center;
  font-size: 0.92rem;
  font-weight: 800;
  pointer-events: none;
}

.gif-viewer.is-copy-help .viewer-stage {
  outline: 2px solid rgba(241, 184, 75, 0.72);
  outline-offset: -8px;
}

.viewer-meta {
  align-items: start;
  border-top: 1px solid var(--line);
}

.viewer-meta h2 {
  margin: 0 0 5px;
  font-size: clamp(1.05rem, 2vw, 1.5rem);
  line-height: 1.1;
}

.viewer-meta p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.viewer-toolbar button,
.viewer-actions button,
.viewer-actions a {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(24, 27, 34, 0.88);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.viewer-toolbar button:hover,
.viewer-actions button:hover,
.viewer-actions a:hover {
  border-color: rgba(241, 184, 75, 0.8);
}

.viewer-toolbar button:disabled {
  color: var(--muted);
  cursor: default;
  opacity: 0.55;
}

.viewer-actions button.is-limited {
  color: var(--muted);
}

.viewer-actions {
  flex: 0 0 440px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.empty-state {
  display: grid;
  gap: 12px;
  justify-items: start;
  padding: 28px;
}

.empty-state h2,
.empty-state p {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
}

pre {
  width: min(100%, 620px);
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

@media (max-width: 1100px) {
  .gif-grid {
    column-count: 3;
  }
}

@media (max-width: 780px) {
  .masthead,
  main {
    width: min(1440px, calc(100vw - 20px));
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 10px;
    padding: 16px;
  }

  .passport-stack {
    min-height: 72px;
  }

  .stamp {
    width: 96px;
    font-size: 0.66rem;
    border-width: 2px;
  }

  .controls {
    position: static;
  }

  .soundtrack {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .soundtrack audio {
    grid-column: 1 / -1;
  }

  .control-cluster {
    width: 100%;
    min-width: 0;
  }

  .control-cluster label {
    flex: 1;
    min-width: 0;
  }

  .gif-grid {
    column-count: 2;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 2.12rem;
  }

  .lede {
    font-size: 0.9rem;
  }

  .soundtrack {
    gap: 12px;
    padding: 14px;
  }

  .soundtrack-art {
    width: 64px;
    height: 64px;
  }

  .soundtrack h2 {
    font-size: 1.55rem;
  }

  .control-cluster {
    display: grid;
    grid-template-columns: 1fr;
  }

  .control-cluster button {
    width: 100%;
  }

  .gif-grid {
    column-count: 1;
  }

  .gif-meta {
    display: grid;
  }

  .gif-actions {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gif-actions button,
  .download-button {
    width: 100%;
  }

  .gif-viewer {
    padding: 10px;
  }

  .viewer-shell {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .viewer-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .viewer-stage {
    min-height: min(58vh, 460px);
  }

  .viewer-meta {
    display: grid;
  }

  .viewer-actions {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
