:root {
  --bg: #efefed;
  --ink: #151311;
  --chrome: #848484;
  --muted: rgba(21, 19, 17, 0.56);
  --line: rgba(21, 19, 17, 0.12);
  --mono: "Geist Mono", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: "Geist", "Helvetica Neue", "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Merriweather", Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
}

button,
input {
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.topbar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  min-height: 42px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
}

.wordmark {
  border: 0;
  background: transparent;
  padding: 0;
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #151311;
  cursor: pointer;
  pointer-events: auto;
}

.topbar-seed {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-width: min(44vw, 560px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
  color: #151311;
}

.count-label,
.gallery-hint,
.seed-label,
.focus-cycle-hint,
.loading-status,
.mono,
.section-label {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.count-label,
.gallery-hint,
.seed-label,
.focus-cycle-hint,
.loading-status,
.section-label {
  color: var(--chrome);
}

.search-form {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.search-stack {
  position: relative;
  min-width: 0;
}

.search-input {
  width: clamp(220px, 28vw, 360px);
  min-height: 44px;
  border: 1px solid rgba(21, 19, 17, 0.08);
  border-radius: 999px;
  background: var(--bg);
  padding: 0 16px;
  color: var(--ink);
  font-size: 14px;
  outline: none;
}

.search-input:focus,
.search-input:focus-visible {
  border-color: rgba(21, 19, 17, 0.68);
}

.search-input::placeholder {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: rgba(21, 19, 17, 0.42);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(420px, 100%);
  max-height: min(420px, 48vh);
  border: 1px solid rgba(21, 19, 17, 0.08);
  border-radius: 18px;
  background: rgba(239, 239, 237, 0.98);
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 32px rgba(21, 19, 17, 0.08);
  overflow: hidden;
  overflow-y: auto;
  z-index: 16;
}

.search-result {
  width: 100%;
  border: 0;
  border-top: 1px solid rgba(21, 19, 17, 0.05);
  background: transparent;
  padding: 13px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.search-result:first-child {
  border-top: 0;
}

.search-result:hover,
.search-result:focus-visible,
.search-result.is-active {
  background: rgba(21, 19, 17, 0.04);
}

.search-result-title {
  display: block;
  color: var(--ink);
  font-size: 0.96rem;
  line-height: 1.2;
}

.search-result-subtitle {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.25;
}

.search-result-year {
  color: var(--chrome);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.search-submit,
.platform-link {
  border-radius: 999px;
  cursor: pointer;
}

.search-submit {
  border: 0;
  background: #151311;
  color: #f4f1ec;
  min-height: 44px;
  padding: 0 16px;
}

.search-submit:disabled {
  opacity: 0.48;
  cursor: wait;
}

.gallery-stage {
  position: absolute;
  inset: 0;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 120px 32px 96px;
  text-align: center;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-state-title {
  max-width: 640px;
  margin: 0;
  color: rgba(21, 19, 17, 0.9);
  font-family: var(--sans);
  font-size: clamp(1.1rem, 1.5vw, 1.6rem);
  font-weight: 340;
  line-height: 1.16;
  letter-spacing: -0.04em;
}

.gallery-hint,
.focus-cycle-hint {
  position: absolute;
  bottom: 20px;
  z-index: 11;
  margin: 0;
}

.gallery-hint {
  left: 20px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease);
}

.focus-cycle-hint {
  right: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease);
}

.app-shell.is-focused .gallery-hint {
  opacity: 1;
  pointer-events: auto;
}

.app-shell.is-focused .focus-cycle-hint {
  opacity: 1;
}

.loading-status {
  position: absolute;
  top: 78px;
  right: 20px;
  z-index: 12;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(21, 19, 17, 0.06);
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.viewport.is-dragging {
  cursor: grabbing;
}

.world {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5200px;
  height: 4200px;
  transform-origin: center center;
  will-change: transform;
}

.song-card {
  position: absolute;
  width: 380px;
  height: 380px;
  border: 0;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #e7e4de;
  box-shadow: 0 18px 28px rgba(28, 24, 20, var(--shadow-alpha, 0.08));
  cursor: pointer;
  transform: perspective(1100px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg)) scale(var(--tilt-scale, 1));
  transform-style: preserve-3d;
  will-change: transform, box-shadow, opacity;
  transition:
    transform 280ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 280ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 280ms var(--ease),
    filter 280ms var(--ease);
}

.song-card:hover,
.song-card:focus-visible {
  box-shadow: 0 24px 36px rgba(28, 24, 20, 0.11);
}

.search-submit:focus-visible,
.search-result:focus-visible,
.song-card:focus-visible,
.platform-link:focus-visible,
.gallery-hint:focus-visible,
.detail-close:focus-visible {
  outline: 3px solid rgba(21, 19, 17, 0.78);
  outline-offset: 3px;
}

.song-card.is-dimmed,
.app-shell.is-focused .song-card {
  opacity: 0.05;
  pointer-events: none;
  filter: blur(6px);
}

.song-card.is-active {
  opacity: 0;
}

.song-card.is-loading {
  background: linear-gradient(135deg, #ece8e0, #dcd7ce);
}

.song-card.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.38), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}

.song-art {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, var(--tone-a), var(--tone-b));
}

.song-art::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.song-art-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.04);
}

.song-art-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 10, 8, 0.06) 0%, rgba(12, 10, 8, 0.34) 100%);
}

.detail-view {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transform: translateY(12px);
  transition:
    opacity 260ms var(--ease),
    transform 260ms var(--ease);
}

.app-shell.is-focused .detail-view {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.detail-layout {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 56px;
  width: min(1360px, calc(100vw - 72px));
  max-height: calc(100vh - 120px);
}

.detail-close {
  position: absolute;
  top: -16px;
  right: 0;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(21, 19, 17, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  cursor: pointer;
}

@media (min-width: 901px) {
  .detail-close {
    display: none;
  }
}

.detail-close:hover {
  background: #151311;
  color: #f4f1ec;
}

.detail-cover-wrap {
  flex: 0 0 42%;
  transform-origin: top left;
  position: relative;
  z-index: 1;
}

.detail-cover {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  box-shadow: 0 30px 56px rgba(28, 24, 20, 0.14);
  background: linear-gradient(145deg, #d8d1c8, #8a816d);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: 28px;
}

.detail-cover-media {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  transform: scale(1.04);
}

.detail-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 10, 8, 0.08) 10%, rgba(12, 10, 8, 0.42) 100%);
}

.detail-content {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 2;
}

.detail-content > * {
  opacity: 0;
  transform: translateY(-18px);
  transition:
    opacity 620ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 620ms cubic-bezier(0.16, 1, 0.3, 1);
}

.detail-content.is-visible > * {
  opacity: 1;
  transform: translateY(0);
}

.detail-content.is-visible > :nth-child(1) {
  transition-delay: 40ms;
}

.detail-content.is-visible > :nth-child(2) {
  transition-delay: 110ms;
}

.detail-content.is-visible > :nth-child(3) {
  transition-delay: 190ms;
}

.detail-heading h1 {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(2.8rem, 4vw, 4rem);
  font-weight: 500;
  line-height: 0.92;
}

.detail-artist {
  margin: 14px 0 0;
  font-size: 1.5rem;
  font-weight: 400;
  color: rgba(21, 19, 17, 0.86);
}

.detail-meta-row {
  margin-top: 32px;
  color: var(--chrome);
}

.detail-columns {
  margin-top: 36px;
}

.detail-main {
  max-width: 760px;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
}

.stat-item {
  color: var(--chrome);
}

.stat-item strong {
  display: block;
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--ink);
  letter-spacing: 0;
  text-transform: none;
}

.palette-section,
.platform-section {
  margin-top: 34px;
}

.section-label {
  margin: 0 0 14px;
}

.platform-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.platform-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid rgba(21, 19, 17, 0.16);
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.platform-link svg {
  width: 14px;
  height: 14px;
}

.platform-link:hover,
.platform-link:focus-visible {
  background: #151311;
  color: #f4f1ec;
}

.side-body {
  color: var(--muted);
  line-height: 1.55;
  font-size: 1rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  border: 1px solid rgba(21, 19, 17, 0.08);
  border-radius: 999px;
  padding: 7px 10px;
  color: rgba(21, 19, 17, 0.72);
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100svh;
  }

  .topbar {
    top: 0;
    left: 0;
    right: 0;
    min-height: 84px;
    padding: 20px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }

  .wordmark {
    font-size: 22px;
    text-align: center;
  }

  .topbar-seed {
    position: static;
    transform: none;
    max-width: min(100%, 320px);
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
  }

  .search-form {
    position: absolute;
    left: 20px;
    right: 20px;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    width: auto;
    justify-content: stretch;
    align-items: center;
    gap: 8px;
    z-index: 14;
  }

  .empty-state {
    padding: 96px 24px 132px;
  }

  .empty-state-title {
    font-size: clamp(0.875rem, 4.5vw, 1.2rem);
  }

  .search-stack {
    flex: 1 1 auto;
  }

  .search-input {
    width: 100%;
    font-size: 16px;
  }

  .search-submit {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .search-results {
    top: auto;
    bottom: calc(100% + 8px);
    width: 100%;
    max-height: min(320px, 36svh);
  }

  .count-label {
    order: 3;
  }

  .loading-status {
    top: 88px;
    left: 20px;
    right: 20px;
    bottom: auto;
  }

  .viewport {
    top: 92px;
  }

  .world {
    width: 3600px;
    height: 4600px;
  }

  .song-card {
    width: 240px;
    height: 240px;
  }

  .detail-view {
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell.is-focused .search-form {
    opacity: 0;
    pointer-events: none;
  }

  .detail-layout {
    width: min(720px, calc(100vw - 40px));
    max-height: none;
    padding: 110px 0 92px;
    flex-direction: column;
    gap: 32px;
  }

  .detail-close {
    top: 24px;
    right: 0;
  }

  .detail-cover-wrap,
  .detail-cover {
    width: 100%;
    max-width: none;
  }

  .detail-columns,
  .detail-stats {
    gap: 24px;
  }

  .detail-cover-wrap {
    order: 1;
  }

  .detail-content {
    order: 2;
  }

  .detail-heading h1 {
    font-size: 2.5rem;
  }

  .detail-artist {
    margin-top: 10px;
    font-size: 1.3rem;
  }

  .detail-meta-row {
    margin-top: 18px;
  }

  .gallery-hint {
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
  }

  .search-form {
    justify-content: stretch;
  }

  .focus-cycle-hint {
    display: none;
  }

  .app-shell.is-focused .gallery-hint {
    padding: 12px 18px;
    border-radius: 999px;
    background: #151311;
    color: #f3f1ed;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .song-card,
  .detail-content > *,
  .detail-view,
  .detail-cover-wrap,
  .world {
    transform: none !important;
  }
}
