:root {
  color-scheme: dark;
  font-family: "Aptos", "Segoe UI", sans-serif;
  --ink: #111116;
  --paper: #f2efe7;
  --muted: rgba(242, 239, 231, 0.5);
  --quiet: rgba(242, 239, 231, 0.16);
  --accent: #786bff;
  --accent-rgb: 120, 107, 255;
  --edge: rgba(255, 255, 255, 0.16);
  --pad: clamp(1.25rem, 3vw, 2.75rem);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
}

button,
a {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 4px;
}

.app {
  isolation: isolate;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100vw;
  height: 100dvh;
  min-height: 32rem;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.025), transparent 35%),
    var(--ink);
  transition: background-color 1.5s ease;
}

.ambient {
  position: absolute;
  z-index: -1;
  top: -45vmax;
  right: -35vmax;
  width: 95vmax;
  height: 95vmax;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.55);
  filter: blur(9vmax);
  opacity: 0.36;
  transform: translate3d(0, 0, 0);
  transition: background-color 1.5s ease, opacity 1.5s ease;
}

.topbar,
.bottombar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--pad);
}

.topbar {
  border-bottom: 1px solid var(--edge);
}

.brand {
  font-family: "Arial Narrow", "Aptos Narrow", sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  text-decoration: none;
}

.track-meta {
  display: grid;
  gap: 0.12rem;
  max-width: min(55vw, 30rem);
  margin: 0;
  text-align: right;
}

.track-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#trackTitle {
  font-size: 0.85rem;
  font-weight: 650;
}

#trackArtist {
  color: var(--muted);
  font-size: 0.7rem;
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  padding: var(--pad);
}

.idle-view,
.listening-view,
.lyrics-view {
  grid-area: 1 / 1;
  align-self: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(1rem);
  transition: opacity 350ms ease, transform 500ms cubic-bezier(0.22, 1, 0.36, 1), visibility 350ms;
}

.app[data-state="idle"] .idle-view,
.app[data-state="listening"] .listening-view,
.app[data-state="playing"] .lyrics-view {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.idle-view {
  width: min(100%, 70rem);
  min-width: 0;
}

.eyebrow,
.intro,
.listening-detail {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 clamp(1.5rem, 4vh, 3rem);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  max-width: 14ch;
  margin: 0;
  font-family: "Arial Black", "Aptos Display", sans-serif;
  font-size: clamp(3.25rem, 9vw, 8.5rem);
  line-height: 0.86;
  letter-spacing: -0.075em;
}

.intro {
  margin: clamp(1.5rem, 4vh, 2.75rem) 0 0;
  font-size: clamp(0.95rem, 1.5vw, 1.15rem);
}

.primary-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 22rem);
  margin-top: clamp(1.5rem, 4vh, 2.75rem);
  padding: 1rem 1.1rem;
  border: 1px solid var(--paper);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background-color 180ms ease, color 180ms ease;
}

.primary-action:hover {
  background: transparent;
  color: var(--paper);
}

.listening-view {
  justify-self: center;
  text-align: center;
}

.listening-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 4.5rem;
  gap: 0.36rem;
}

.listening-mark span {
  width: 0.28rem;
  height: 16%;
  border-radius: 999px;
  background: var(--paper);
  animation: listen 900ms ease-in-out infinite alternate;
}

.listening-mark span:nth-child(2),
.listening-mark span:nth-child(4) {
  animation-delay: -450ms;
}

.listening-mark span:nth-child(3) {
  animation-delay: -225ms;
}

.listening-title {
  margin: 0.7rem 0 0;
  font-family: "Arial Black", "Aptos Display", sans-serif;
  font-size: clamp(2.5rem, 7vw, 5.75rem);
  letter-spacing: -0.055em;
}

.listening-detail {
  min-height: 1.3em;
  margin: 0.8rem 0 0;
  font-size: 0.85rem;
}

.lyrics-view {
  position: relative;
  display: grid;
  grid-template-columns: 2px minmax(0, 1fr);
  width: min(100%, 84rem);
  max-width: 100%;
  min-width: 0;
  height: min(64vh, 42rem);
  margin-inline: auto;
  gap: clamp(1.25rem, 4vw, 4rem);
}

.timing-rail {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: var(--quiet);
}

.timing-progress {
  position: absolute;
  inset: 0 0 auto;
  height: 0;
  background: var(--paper);
  transition: height 250ms linear;
}

.lyrics-stack {
  display: grid;
  grid-template-rows: minmax(2rem, 0.8fr) minmax(5rem, auto) minmax(2rem, 0.8fr);
  align-items: center;
  min-width: 0;
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
  cursor: ns-resize;
}

.sync-indicator {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  min-width: 4.25rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.35rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app[data-state="playing"] .lyrics-view:not(.is-plain) .sync-indicator.is-adjusting {
  opacity: 1;
  transform: translateY(0) scale(1.03);
}

.lyric {
  max-width: 21ch;
  min-width: 0;
  margin: 0;
  overflow-wrap: break-word;
  text-wrap: balance;
  transition: opacity 260ms ease, transform 260ms ease;
}

.lyric.previous,
.lyric.next {
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 500;
  line-height: 1.25;
}

.lyric.previous {
  align-self: end;
}

.lyric.next {
  align-self: start;
}

.lyric.current {
  padding-block: clamp(1rem, 3vh, 2.5rem);
  font-family: "Arial Black", "Aptos Display", sans-serif;
  font-size: clamp(2.25rem, 7.5vw, 6.6rem);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

.lyric.current.is-changing {
  opacity: 0;
  transform: translateY(0.65rem);
}

.plain-lyrics {
  display: none;
  min-height: 0;
  overflow-y: auto;
  color: var(--paper);
  font-family: "Arial Black", "Aptos Display", sans-serif;
  font-size: clamp(1.4rem, 4vw, 3.5rem);
  line-height: 1.2;
  letter-spacing: -0.035em;
  white-space: pre-line;
  scrollbar-color: var(--paper) transparent;
}

.lyrics-view.is-plain .lyrics-stack,
.lyrics-view.is-plain .timing-rail {
  display: none;
}

.lyrics-view.is-plain {
  display: block;
}

.lyrics-view.is-plain .plain-lyrics {
  display: block;
  height: 100%;
}

.bottombar {
  min-height: 4.75rem;
  border-top: 1px solid var(--edge);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: currentColor;
}

.app[data-state="listening"] .status-dot {
  background: #ff775f;
  box-shadow: 0 0 0 0.3rem rgba(255, 119, 95, 0.12);
}

.app[data-state="playing"] .status-dot {
  background: var(--paper);
}

.detect-next {
  padding: 0.45rem 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.app[data-state="playing"] .detect-next {
  opacity: 0.7;
  pointer-events: auto;
}

.detect-next:hover {
  opacity: 1;
}

@keyframes listen {
  from { height: 18%; }
  to { height: 88%; }
}

@media (max-width: 40rem) {
  .app {
    min-height: 28rem;
  }

  .topbar,
  .bottombar {
    min-height: 4.25rem;
  }

  h1 {
    width: 100%;
    max-width: 100%;
    font-size: clamp(2.75rem, 12vw, 5rem);
    overflow-wrap: break-word;
  }

  .lyrics-view {
    height: min(66vh, 35rem);
    gap: 1.25rem;
  }

  .sync-indicator {
    top: -0.25rem;
    min-width: 4.25rem;
  }

  .lyric.current {
    font-size: clamp(2.2rem, 11vw, 4.5rem);
  }
}

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