:root {
  --bg: #0c0d0f;
  --surface: #151719;
  --surface-raised: #202225;
  --surface-soft: #292b2f;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5f2;
  --muted: #999a9c;
  --dim: #67686b;
  --accent: #ff8a3d;
  --danger: #ff6b3d;
  --serif: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  background: var(--bg);
  transition: opacity .35s ease, visibility .35s ease;
}

.loading-overlay.fade-out { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-overlay h1 { margin: 12px 0 13px; font: 500 2rem/1 var(--serif); letter-spacing: -.045em; }
.loader-info { width: min(350px, 100%); margin: 20px 0 0; padding: 15px 16px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.035); box-shadow: 0 12px 30px rgba(0,0,0,.18); text-align: left; }
.loader-info h2 { margin: 0 0 7px; color: var(--text); font-size: .84rem; font-weight: 600; letter-spacing: -.015em; }
.loader-info p { margin: 0; color: var(--muted); font-size: .74rem; line-height: 1.5; text-wrap: pretty; }
.loader-mark { height: 46px; display: flex; align-items: flex-end; gap: 4px; }
.loader-mark span { width: 5px; height: 20px; border-radius: 5px; background: var(--accent); animation: key-wave 1.05s ease-in-out infinite alternate; }
.loader-mark span:nth-child(2) { height: 38px; animation-delay: -.7s; }
.loader-mark span:nth-child(3) { height: 29px; animation-delay: -.25s; }
.loader-mark span:nth-child(4) { height: 43px; animation-delay: -.5s; }
@keyframes key-wave { to { height: 9px; opacity: .4; } }
.loader-track { width: min(330px, 100%); height: 2px; overflow: hidden; background: #29292b; }
.loader-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .18s ease; }
.loader-meta { width: min(330px, 100%); display: flex; justify-content: space-between; margin-top: 9px; color: var(--muted); font-size: .66rem; }

.app-shell {
  position: relative;
  width: min(100%, 720px);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
}

.player-screen {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-content: stretch;
  gap: 10px;
  padding: 6px 14px calc(10px + env(safe-area-inset-bottom));
}

.song-identity {
  min-height: 124px;
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 16px;
}
.song-artwork { width: 108px; height: 108px; overflow: hidden; border-radius: 24px; background: var(--surface-soft); box-shadow: 0 18px 38px rgba(0,0,0,.32); }
.procedural-art { width: 100%; height: 100%; display: block; }
.song-copy { min-width: 0; }
.style-badge { display: block; overflow: hidden; margin-bottom: 7px; color: var(--accent); font: 600 clamp(.66rem, 2.7vw, .8rem)/1 var(--sans); letter-spacing: .1em; text-overflow: ellipsis; white-space: nowrap; }
.song-copy h1 { display: -webkit-box; overflow: hidden; margin: 0 0 5px; padding-bottom: 2px; color: var(--text); font: 500 clamp(1.65rem, 7vw, 2.3rem)/1.06 var(--serif); letter-spacing: -.055em; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.song-copy p { overflow: hidden; margin: 0; color: var(--muted); font-size: .7rem; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }

.round-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--muted);
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, color .15s ease;
}
.round-button:active:not(:disabled) { transform: scale(.93); }
.round-button:disabled { opacity: .35; cursor: default; }
.round-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.heart-button.saved { color: var(--accent); background: rgba(255,138,61,.13); }
.heart-button.saved svg { fill: currentColor; }
.song-actions { width: 46px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.info-button { flex: 0 0 auto; color: var(--text); background: rgba(255,255,255,.07); }
.info-button span { font-size: 1.05rem; font-weight: 600; line-height: 1; }

.info-modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 22px; background: rgba(3,4,5,.7); backdrop-filter: blur(14px); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s ease, visibility .2s ease; }
.info-modal.open { opacity: 1; visibility: visible; pointer-events: auto; }
.info-sheet { position: relative; width: min(390px, 100%); padding: 25px 24px 23px; border: 1px solid var(--line-strong); border-radius: 24px; background: #1b1d20; box-shadow: 0 28px 70px rgba(0,0,0,.46); transform: translateY(12px) scale(.98); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
.info-modal.open .info-sheet { transform: translateY(0) scale(1); }
.info-kicker { display: block; margin-bottom: 9px; color: var(--accent); font-size: .58rem; font-weight: 600; letter-spacing: .14em; }
.info-sheet h2 { margin: 0 36px 11px 0; font-size: 1.45rem; font-weight: 600; letter-spacing: -.045em; }
.info-sheet p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.install-sheet p { color: #b5b6b8; }
.creator-links { display: grid; gap: 8px; margin-top: 18px; }
.creator-links a { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.04); color: inherit; text-decoration: none; transition: background .15s ease, transform .12s ease; }
.creator-links a:active { transform: scale(.98); background: rgba(255,138,61,.1); }
.creator-links span { color: var(--muted); font-size: .63rem; }
.creator-links strong { overflow: hidden; color: var(--text); font-size: .69rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.info-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; display: grid; place-items: center; padding: 0 0 2px; border: 0; border-radius: 50%; background: var(--surface-soft); color: var(--text); font-size: 1.35rem; line-height: 1; cursor: pointer; }

.visualizer-stage {
  position: relative;
  height: clamp(190px, 46dvh, 390px);
  min-height: 0;
  overflow: hidden;
  border-radius: 22px;
  background: var(--surface);
}
#noteCanvas { width: 100%; height: 100%; display: block; }
.visualizer-meta { position: absolute; inset: 13px 14px auto; display: flex; justify-content: space-between; color: rgba(255,255,255,.34); font-size: .5rem; font-weight: 600; letter-spacing: .13em; pointer-events: none; }
.visualizer-meta > span:first-child { display: flex; align-items: center; gap: 5px; }
.visualizer-meta > span:first-child::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.buffering-label { position: absolute; inset: 48% auto auto 50%; transform: translate(-50%,-50%); padding: 7px 9px; border-radius: 8px; background: rgba(9,9,10,.8); color: var(--accent); font-size: .54rem; font-weight: 600; letter-spacing: .12em; opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.buffering-label.show { opacity: 1; }

.playback-area { align-self: center; width: 100%; padding: 0 4px; }
.next-preview { --next-hue: 26; --next-hue-two: 42; width: 100%; height: 50px; display: grid; grid-template-columns: 40px minmax(0,1fr) 20px; align-items: center; gap: 11px; margin-bottom: 8px; padding: 5px 9px 5px 5px; overflow: hidden; border: 1px solid hsl(var(--next-hue) 50% 70% / .14); border-radius: 14px; background: radial-gradient(circle at 8% 40%, hsl(var(--next-hue) 58% 50% / .3), transparent 48%), radial-gradient(circle at 84% 10%, hsl(var(--next-hue-two) 56% 43% / .2), transparent 52%), rgba(255,255,255,.025); box-shadow: 0 10px 28px hsl(var(--next-hue) 65% 45% / .12); text-align: left; cursor: pointer; transition: transform .15s ease, filter .15s ease, background .35s ease, border-color .35s ease, box-shadow .35s ease; }
.next-preview:active { transform: scale(.985); filter: brightness(1.14); }
.next-preview-artwork { width: 40px; height: 40px; overflow: hidden; border-radius: 10px; background: var(--surface-soft); }
.next-preview-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.next-preview-copy small { color: hsl(var(--next-hue) 72% 76%); font-size: .45rem; font-weight: 600; letter-spacing: .14em; }
.next-preview-copy strong { overflow: hidden; font: 500 .76rem/1.2 var(--serif); letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }
.next-preview > svg { width: 17px; height: 17px; fill: none; stroke: hsl(var(--next-hue-two) 42% 72%); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.timeline { padding-top: 4px; }
.timeline-track { height: 5px; overflow: hidden; border-radius: 5px; background: #2b2b2d; }
.timeline-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--text); transition: width .1s linear; }
.timeline-labels { display: flex; justify-content: space-between; margin-top: 7px; color: #898a8d; font-size: .72rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.transport { height: 78px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.transport-spacer { justify-self: start; }
.install-button { grid-column: 1; justify-self: start; display: inline-flex; align-items: center; justify-content: center; gap: 6px; max-width: 112px; min-height: 42px; padding: 0 12px; border: 1px solid rgba(255, 138, 61, 0.25); border-radius: 16px; background: rgba(255, 138, 61, 0.05); color: var(--accent); font-size: .62rem; font-weight: 600; cursor: pointer; transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.install-button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.install-button:active { transform: scale(.95); background: rgba(255, 138, 61, 0.2); border-color: rgba(255, 138, 61, 0.6); }
.install-button[hidden] { display: none; }
@media (hover: hover) and (pointer: fine) {
  .install-button:hover { background: rgba(255, 138, 61, 0.12); border-color: rgba(255, 138, 61, 0.45); box-shadow: 0 0 12px rgba(255, 123, 42, 0.15); }
}
.side-control:last-child { grid-column: 3; justify-self: end; }
.play-button { grid-column: 2; width: 68px; height: 68px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--text); color: #111; cursor: pointer; transition: transform .12s ease, opacity .15s ease; }
.play-button:active:not(:disabled) { transform: scale(.94); }
.play-button:disabled { opacity: .35; cursor: default; }
.play-button svg { grid-area: 1 / 1; width: 39px; height: 39px; fill: currentColor; }
.play-button .pause-icon { display: none; }
.play-button.playing .play-icon { display: none; }
.play-button.playing .pause-icon { display: block; }
.side-control:last-child { position: relative; width: 52px; height: 52px; color: #201d1b; border: 0; background-color: rgba(245,243,240,.97); box-shadow: 0 0 0 rgba(255,123,42,0); transition: background-color .18s ease, box-shadow .18s ease, filter .18s ease; }
.side-control:last-child:not(:disabled) { animation: skip-glow 3.5s ease-in-out infinite; }
.side-control:last-child:active:not(:disabled) { transform: none; filter: brightness(.94); }
.side-control:last-child.skip-pressed svg { animation: skip-icon-slide .42s cubic-bezier(.22,.78,.24,1); }
@media (hover: hover) and (pointer: fine) {
  .side-control:last-child:hover:not(:disabled) { animation: none; background-color: rgba(235,190,157,.95); box-shadow: 0 0 22px rgba(255,123,42,.42), 0 0 36px rgba(255,123,42,.18); }
}
@keyframes skip-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(255,123,42,0); background-color: rgba(245,243,240,.97); }
  50% { box-shadow: 0 0 20px rgba(255,123,42,.38), 0 0 34px rgba(255,123,42,.16); background-color: rgba(238,205,181,.94); }
}
@keyframes skip-icon-slide { 0% { transform: translateX(0); opacity: 1; } 44% { transform: translateX(24px); opacity: 0; } 45% { transform: translateX(-18px); opacity: 0; } 100% { transform: translateX(0); opacity: 1; } }
.library-meta { flex: 0 0 auto; height: 36px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .57rem; border-bottom: 1px solid var(--line); }
.song-grid { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 9px; padding: 14px 0 10px; }
.song-card { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); align-items: center; gap: 10px; padding: 7px; border-radius: 16px; background: var(--surface); }
.song-card-art { position: relative; height: 100%; width: auto; max-height: 92px; aspect-ratio: 1 / 1; overflow: hidden; border-radius: 13px; background: var(--surface-soft); }
.song-card-actions { align-self: stretch; flex: 0 0 auto; display: flex; align-items: flex-end; padding-top: 34px; }
.card-play { position: static; width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--accent); color: #111; cursor: pointer; }
.card-play svg { width: 19px; height: 19px; fill: currentColor; }
.library-playing-bars { display: none; height: 18px; align-items: flex-end; gap: 2px; }
.library-playing-bars i { width: 3px; height: 7px; border-radius: 2px; background: currentColor; animation: library-wave .75s ease-in-out infinite alternate; }
.library-playing-bars i:nth-child(2) { height: 16px; animation-delay: -.4s; }
.library-playing-bars i:nth-child(3) { height: 11px; animation-delay: -.2s; }
.card-play.playing { background: var(--text); color: #161719; }
.card-play.playing .library-play-symbol { display: none; }
.card-play.playing .library-playing-bars { display: flex; }
@keyframes library-wave { to { height: 4px; } }
.song-card-copy { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 5px 0 0; }
.song-card-copy > div { min-width: 0; }
.song-card-copy h3 { overflow: hidden; margin: 0 0 5px; font: 500 1rem var(--serif); letter-spacing: -.03em; text-overflow: ellipsis; white-space: nowrap; }
.song-card-copy p { overflow: hidden; margin: 0; color: var(--muted); font-size: .54rem; text-overflow: ellipsis; white-space: nowrap; }
.remove-song { position: absolute; top: 7px; right: 7px; width: 27px; height: 27px; display: grid; place-items: center; padding: 0; border: 1px solid rgba(255,75,85,.24); border-radius: 8px; background: rgba(255,75,85,.12); color: #ff626b; cursor: pointer; }
.remove-song:active { background: rgba(255,75,85,.22); color: #ff8188; }
.remove-song svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.empty-library { min-height: 0; flex: 1; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-library.show { display: flex; }
.empty-library > span { color: var(--accent); font: 400 2.7rem var(--serif); }
.empty-library h3 { margin: 4px 0; font: 500 1.35rem var(--serif); letter-spacing: -.035em; }
.empty-library p { margin: 0; color: var(--muted); font-size: .62rem; }
.empty-library button { height: 36px; margin-top: 16px; padding: 0 15px; border: 0; border-radius: 20px; background: var(--surface-soft); cursor: pointer; font-size: .6rem; }
.library-pager { flex: 0 0 34px; display: flex; align-items: center; justify-content: center; gap: 18px; }
.library-pager button { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--surface-soft); color: var(--muted); cursor: pointer; }
.library-pager button:disabled { opacity: .25; cursor: default; }
.library-pager svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.library-pager span { min-width: 36px; color: var(--muted); font-size: .55rem; text-align: center; font-variant-numeric: tabular-nums; }

@media (min-width: 721px) {
  body { background: #050506; }
  .app-shell { box-shadow: 0 0 80px rgba(0,0,0,.45); }
  .player-screen { padding-inline: 24px; }
  .song-identity { grid-template-columns: 118px minmax(0,1fr) 48px; }
  .song-artwork { width: 118px; height: 118px; }
}

@media (max-height: 700px) {
  .player-screen { gap: 7px; padding-top: 2px; padding-bottom: calc(5px + env(safe-area-inset-bottom)); }
  .song-identity { min-height: 92px; grid-template-columns: 82px minmax(0,1fr) 42px; gap: 11px; }
  .song-artwork { width: 82px; height: 82px; border-radius: 18px; }
  .song-copy h1 { font-size: 1.4rem; }
  .round-button { width: 42px; height: 42px; }
  .song-actions { width: 42px; gap: 6px; }
  .install-button { max-width: 94px; min-height: 38px; padding-inline: 9px; font-size: .56rem; }
  .install-button svg { width: 12px; height: 12px; stroke-width: 2.2; }
  .side-control:last-child { width: 47px; height: 47px; }
  .visualizer-stage { height: clamp(180px, 44dvh, 310px); }
  .transport { height: 68px; }
  .play-button { width: 60px; height: 60px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell { width: 100%; max-width: none; }
  .player-screen { grid-template-columns: minmax(220px, .75fr) minmax(360px, 1.25fr); grid-template-rows: minmax(0, 1fr) auto; gap: 10px 16px; padding: calc(50px + env(safe-area-inset-top)) 18px calc(8px + env(safe-area-inset-bottom)); }
  .song-identity { grid-column: 1; grid-row: 1; align-self: start; }
  .visualizer-stage { grid-column: 2; grid-row: 1 / 3; }
  .visualizer-stage { height: auto; }
  .playback-area { grid-column: 1; grid-row: 2; }
}

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

/* Two-page mobile shell */
.app-shell { grid-template-rows: minmax(0, 1fr) auto; }
.app-page { min-height: 0; display: none; }
.app-page.active { display: grid; }
.player-screen { padding: calc(12px + env(safe-area-inset-top)) 14px 8px; }

.library-page {
  min-height: 0;
  padding: calc(16px + env(safe-area-inset-top)) 16px 10px;
  overflow: hidden;
}
.library-page.active { display: flex; flex-direction: column; }
.library-page-header { flex: 0 0 auto; }
.library-page-header > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.library-page-header > div:first-child > span { color: var(--accent); font-size: .52rem; font-weight: 600; letter-spacing: .14em; }
.library-page-header h1 { margin: 0; font: 500 clamp(2rem, 9vw, 3rem)/1 var(--serif); letter-spacing: -.055em; }
.library-page .library-meta { margin-top: 10px; }

.bottom-nav {
  height: calc(62px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 7px 14px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 22, 24, .96);
  backdrop-filter: blur(18px);
}
.bottom-nav > button { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-raised); color: var(--muted); font-size: .63rem; font-weight: 500; cursor: pointer; transition: background .15s ease, color .15s ease, transform .12s ease; }
.bottom-nav > button:active { transform: scale(.97); }
.bottom-nav > button.active { border-color: rgba(255,138,61,.4); background: rgba(255,138,61,.14); color: var(--accent); }
.bottom-nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (max-height: 700px) {
  .player-screen { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .library-page { padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .bottom-nav { height: calc(56px + env(safe-area-inset-bottom)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .player-screen { padding: calc(8px + env(safe-area-inset-top)) 18px 6px; }
  .library-page { padding: calc(8px + env(safe-area-inset-top)) 18px 6px; }
  .bottom-nav { height: calc(48px + env(safe-area-inset-bottom)); padding-inline: 28%; }
}
