:root {
  color-scheme: dark;
  --background: #050505;
  --surface: #0b0b0b;
  --text: #f4f4f4;
  --muted: #8b8b8b;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --radius: 22px;
  --page-width: 1480px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --header-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --header-ease-in: cubic-bezier(0.32, 0.72, 0, 1);
  --header-ease-soft: cubic-bezier(0.33, 1, 0.68, 1);
  --header-duration-expand: 560ms;
  --header-duration-collapse: 420ms;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 255, 255, 0.07), transparent 30rem),
    var(--background);
  color: var(--text);
  font-family: var(--font);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.18;
  background-image: linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 55%);
}

.site-header {
  position: sticky;
  top: 8px;
  z-index: 20;
  width: min(calc(100% - 32px), var(--page-width));
  height: 42px;
  margin: 8px 0 0 max(16px, calc((100% - var(--page-width)) / 2));
  pointer-events: none;
  opacity: 0;
  transform: translate3d(0, -14px, 0);
  animation: headerEnter 780ms var(--header-ease-out) 80ms both;
  transition:
    top var(--header-duration-collapse) var(--header-ease-out),
    height var(--header-duration-collapse) var(--header-ease-out);
}

.site-header.is-compact {
  top: 6px;
  height: 38px;
}

.header-pill {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 13px;
  background: rgba(5, 5, 5, 0.72);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 8px 28px rgba(0, 0, 0, 0.2),
    0 2px 8px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  pointer-events: auto;
  interpolate-size: allow-keywords;
  transform: translateZ(0);
  transform-origin: left center;
  transition:
    width var(--header-duration-expand) var(--header-ease-out),
    height var(--header-duration-collapse) var(--header-ease-out),
    padding var(--header-duration-collapse) var(--header-ease-out),
    border-color 480ms var(--header-ease-soft),
    border-radius 480ms var(--header-ease-soft),
    background 480ms var(--header-ease-soft),
    box-shadow 480ms var(--header-ease-soft),
    backdrop-filter 480ms var(--header-ease-soft),
    -webkit-backdrop-filter 480ms var(--header-ease-soft);
}

.header-pill::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(255, 255, 255, 0.03) 38%,
    transparent 62%
  );
  opacity: 0.7;
  transition: opacity 480ms var(--header-ease-soft);
}

.header-pill::after {
  content: "";
  position: absolute;
  top: 0;
  right: 12%;
  left: 12%;
  z-index: 0;
  height: 1px;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.28),
    transparent
  );
  opacity: 0.55;
  transition:
    opacity 480ms var(--header-ease-soft),
    left 520ms var(--header-ease-out),
    right 520ms var(--header-ease-out);
}

.site-header.is-compact .header-pill {
  width: max-content;
  max-width: 100%;
  height: 38px;
  padding: 0 12px;
  border-color: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(10, 10, 10, 0.9);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 10px 28px rgba(0, 0, 0, 0.34),
    0 2px 10px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(26px) saturate(155%);
  -webkit-backdrop-filter: blur(26px) saturate(155%);
  transition-duration: var(--header-duration-collapse);
  transition-timing-function: var(--header-ease-in);
}

.site-header.is-compact .header-pill::before {
  opacity: 0.95;
}

.site-header.is-compact .header-pill::after {
  right: 18%;
  left: 18%;
  opacity: 0.8;
}

.site-header.is-animating .header-pill {
  /* Size/shape are driven by WAAPI; keep only material transitions in CSS. */
  transition:
    border-color 480ms var(--header-ease-soft),
    background 480ms var(--header-ease-soft),
    box-shadow 480ms var(--header-ease-soft),
    backdrop-filter 480ms var(--header-ease-soft),
    -webkit-backdrop-filter 480ms var(--header-ease-soft);
}

.site-header.is-animating.is-compact .header-pill {
  transition-duration: var(--header-duration-collapse);
  transition-timing-function: var(--header-ease-in);
}

.brand {
  position: relative;
  z-index: 1;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
  transition:
    gap 420ms var(--header-ease-out),
    letter-spacing 420ms var(--header-ease-out),
    opacity 280ms ease,
    transform 420ms var(--header-ease-out);
}

.site-header.is-compact .brand {
  gap: 8px;
  letter-spacing: -0.03em;
}

.brand > span:last-child {
  display: inline-block;
  transition: transform 420ms var(--header-ease-out), opacity 320ms ease;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, 5px);
  grid-template-rows: repeat(2, 5px);
  gap: 2px;
  width: 12px;
  height: 12px;
  transition: transform 420ms var(--header-ease-out);
}

.brand-mark span {
  background: currentColor;
  border-radius: 0.5px;
  transform-origin: center;
  transition:
    opacity 280ms var(--header-ease-soft),
    transform 420ms var(--header-ease-out),
    background-color 280ms ease;
}

.brand-mark span:nth-child(1) {
  transition-delay: 0ms;
}

.brand-mark span:nth-child(2) {
  opacity: 0.45;
  transition-delay: 40ms;
}

.brand-mark span:nth-child(3) {
  opacity: 0.45;
  transition-delay: 80ms;
}

.brand-mark span:nth-child(4) {
  transition-delay: 120ms;
}

.brand:hover .brand-mark {
  transform: scale(1.06);
}

.brand:hover .brand-mark span {
  opacity: 1;
  transform: scale(1.08);
}

.brand:hover .brand-mark span:nth-child(2),
.brand:hover .brand-mark span:nth-child(3) {
  opacity: 0.72;
}

.brand:active {
  transform: scale(0.985);
}

.brand:focus-visible,
.save-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

@keyframes headerEnter {
  from {
    opacity: 0;
    transform: translate3d(0, -14px, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.feed-shell {
  width: min(calc(100% - 48px), var(--page-width));
  margin: 0 auto;
  padding: 16px 0 80px;
}

.feed {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 22px;
}

.image-card {
  content-visibility: auto;
  contain: layout paint style;
  contain-intrinsic-size: 1px 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.28);
}

.canvas-frame {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #0c0c0c;
}

.canvas-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.045);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  opacity: 0;
  transition: opacity 260ms ease;
}

.image-card.is-ready canvas {
  opacity: 1;
}

.canvas-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 180ms ease;
}

.image-card.is-ready .canvas-loader {
  opacity: 0;
  pointer-events: none;
}

.image-card.is-error .canvas-loader {
  opacity: 0.35;
}

.image-card.is-error .canvas-loader span {
  animation-play-state: paused;
}

.canvas-loader span,
.sentinel span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d8d8d8;
  animation: loaderBounce 1.05s infinite ease-in-out;
}

.canvas-loader span:nth-child(2),
.sentinel span:nth-child(2) {
  animation-delay: 120ms;
}

.canvas-loader span:nth-child(3),
.sentinel span:nth-child(3) {
  animation-delay: 240ms;
}

.image-overlay {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.42);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px) saturate(115%);
  opacity: 0.72;
  transition: opacity 180ms ease, background 180ms ease, border-color 180ms ease;
}

.image-card:hover .image-overlay,
.image-card:focus-within .image-overlay {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(5, 5, 5, 0.58);
}

.image-number {
  color: rgba(255, 255, 255, 0.72);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.save-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.save-button svg {
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.4;
}

.save-button:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.save-button:active {
  transform: translateY(1px);
}

.sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 120px;
}

.noscript-message {
  position: fixed;
  right: 20px;
  bottom: 20px;
  left: 20px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #121212;
  text-align: center;
}

@keyframes loaderBounce {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@media (max-width: 900px) {
  .site-header {
    width: calc(100% - 24px);
    height: 40px;
    margin-left: 12px;
  }

  .site-header.is-compact {
    height: 37px;
  }

  .header-pill {
    height: 40px;
    padding: 0 13px;
  }

  .site-header.is-compact .header-pill {
    height: 37px;
    padding: 0 11px;
  }

  .feed-shell {
    width: min(calc(100% - 28px), var(--page-width));
    padding-top: 14px;
  }

  .feed {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}

@media (max-width: 640px) {
  .site-header {
    top: 7px;
    width: calc(100% - 20px);
    height: 39px;
    margin: 7px 0 0 10px;
  }

  .site-header.is-compact {
    top: 5px;
    height: 36px;
  }

  .header-pill {
    height: 39px;
  }

  .site-header.is-compact .header-pill {
    height: 36px;
  }

  .feed-shell {
    width: min(calc(100% - 28px), var(--page-width));
  }

  .feed {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .image-card {
    border-radius: 16px;
  }

  .image-overlay {
    opacity: 0.88;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .site-header {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .site-header,
  .header-pill,
  .header-pill::before,
  .header-pill::after,
  .brand,
  .brand > span:last-child,
  .brand-mark,
  .brand-mark span {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
