.topbar {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0; height: 78px;
  display: grid; grid-template-columns: minmax(190px, 1fr) auto minmax(150px, .7fr) auto auto auto;
  align-items: center; gap: 18px; padding: 0 28px; border-bottom: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(12, 6, 20, .96), rgba(12, 6, 20, .7));
  backdrop-filter: blur(20px);
}
.brand { border: 0; background: transparent; display: flex; gap: 12px; align-items: center; padding: 0; text-align: left; }
.brand:hover { transform: none; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 auto; object-fit: cover; border: 1px solid rgba(196,167,255,.52);
  border-radius: 50%; box-shadow: 0 0 24px rgba(139,92,246,.44);
}
.brand strong { display: block; font-size: .92rem; text-transform: uppercase; letter-spacing: .12em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: .61rem; letter-spacing: .11em; text-transform: uppercase; }
.engine-switch {
  display: flex; padding: 3px; border: 1px solid var(--edge); border-radius: 10px;
  background: rgba(8, 4, 14, .68); box-shadow: inset 0 1px rgba(255,255,255,.025);
}
.engine-switch button {
  min-height: 31px; padding: 0 10px; border: 0; border-radius: 7px; color: var(--muted);
  background: transparent; font-size: .57rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
}
.engine-switch button.active {
  color: #fff; background: linear-gradient(135deg, rgba(139,92,246,.55), rgba(232,121,249,.3));
  box-shadow: 0 0 18px rgba(139,92,246,.2);
}
.engine-switch button:disabled { opacity: .55; cursor: wait; }
.now-playing { min-width: 0; }
.now-playing strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; font-size: .82rem; }
.session-stats { display: flex; align-items: center; gap: 22px; }
.session-stats > div { min-width: 74px; }
.session-stats span { color: var(--muted); display: block; font-size: .58rem; letter-spacing: .14em; text-transform: uppercase; }
.session-stats strong { display: block; margin-top: 4px; font: 700 .86rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.health-stat i { display: block; width: 86px; height: 3px; margin-top: 5px; background: rgba(255,255,255,.09); border-radius: 9px; overflow: hidden; }
.health-stat b { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--pink), var(--cyan)); }
.icon-button { min-height: 36px; padding: 0 13px; font-size: .69rem; text-transform: uppercase; letter-spacing: .1em; }
.homepage-link { color: var(--muted); font-size: .67rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; text-decoration: none; transition: color .16s ease; }
.homepage-link:hover { color: var(--cyan); }

main { min-height: 100vh; }
.library { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 150px 0 80px; }
.hero-copy { width: min(740px, 100%); padding: 36px 0 96px; }
.hero-copy h1 { max-width: 700px; margin: 17px 0 18px; font-size: clamp(3rem, 7vw, 6.4rem); line-height: .91; letter-spacing: -.065em; }
.hero-copy > p:not(.kicker) { width: min(580px, 100%); color: #c5b7d2; font-size: 1.03rem; line-height: 1.65; }
.hero-actions { display: flex; gap: 10px; margin-top: 29px; flex-wrap: wrap; }
.development-notice {
  width: min(680px, 100%); margin-top: 22px; padding: 15px 17px;
  display: flex; align-items: baseline; gap: 13px; border: 1px solid rgba(201, 167, 255, .28);
  border-radius: 12px; background: rgba(25, 14, 42, .72); color: #c5b7d2;
  font-size: .78rem; line-height: 1.5;
}
.development-notice strong {
  flex: 0 0 auto; color: var(--cyan); font-size: .65rem; letter-spacing: .12em; text-transform: uppercase;
}
.development-notice a { color: var(--gold); font-weight: 800; }
.hero-copy .legacy-version {
  margin: 11px 0 0; color: rgba(170, 151, 189, .72); font-size: .68rem; line-height: 1.4;
}
.legacy-version a { color: inherit; text-underline-offset: 3px; }
.legacy-version a:hover { color: var(--cyan); }
.library-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.library-toolbar h2 { margin: 5px 0 0; font-size: 1.7rem; letter-spacing: -.035em; }
.search { width: 260px; }
.search span { position: absolute; width: 1px; height: 1px; overflow: hidden; }
.library-section { margin-top: 28px; }
.library-section + .library-section { margin-top: 58px; }
.section-heading {
  min-height: 62px; display: flex; justify-content: space-between; align-items: center; gap: 20px;
  margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--edge);
}
.section-heading > div { display: flex; align-items: center; gap: 12px; }
.section-heading h3 { margin: 4px 0 0; font-size: 1.08rem; }
.section-heading > p { margin: 0; color: var(--muted); font-size: .73rem; }
.source-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; box-shadow: 0 0 14px currentColor; }
.source-dot.included { color: var(--cyan); background: currentColor; }
.source-dot.imported { color: var(--pink); background: currentColor; }
.song-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.song-card {
  min-height: 150px; padding: 18px; text-align: left; position: relative; overflow: hidden;
  background: linear-gradient(145deg, rgba(24, 28, 51, .86), rgba(11, 13, 27, .9));
  box-shadow: inset 0 1px rgba(255,255,255,.035);
}
.song-card::before {
  content: ""; position: absolute; inset: auto -15% -70% 35%; height: 150px;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 28%, transparent), transparent 70%);
}
.song-card:hover { background: linear-gradient(145deg, rgba(31, 36, 64, .94), rgba(13, 15, 30, .95)); }
.song-number { color: var(--accent); font: 700 .63rem ui-monospace, monospace; letter-spacing: .15em; }
.song-duration {
  position: absolute; right: 45px; top: 18px; color: var(--muted);
  font: 700 .63rem ui-monospace, monospace; letter-spacing: .08em;
}
.song-card strong { display: block; margin-top: 26px; max-width: 90%; font-size: 1rem; line-height: 1.25; }
.song-card small { display: block; color: var(--muted); margin-top: 7px; }
.song-card .play-glyph { position: absolute; right: 18px; top: 17px; color: var(--accent); font-size: 1rem; }
.song-card.imported-card { border-color: rgba(255, 104, 184, .2); }
.song-card.imported-card .song-number { color: var(--pink); }
.empty-state { color: var(--muted); text-align: center; padding: 60px; }

.analysis-view { min-height: 100vh; padding: 135px 24px 40px; }
.analysis-card {
  width: min(540px, 100%); margin: 7vh auto 0; padding: 44px; border: 1px solid var(--edge);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); text-align: center;
}
.analysis-card h2 { margin: 18px 0 8px; font-size: 2rem; }
.analysis-card p:not(.kicker) { color: var(--muted); }
.scanner { height: 112px; display: flex; align-items: center; justify-content: center; gap: 9px; }
.scanner i { display: block; width: 5px; height: 24%; border-radius: 8px; background: var(--cyan); animation: scan 1s ease-in-out infinite alternate; }
.scanner i:nth-child(2), .scanner i:nth-child(4) { animation-delay: -.3s; }
.scanner i:nth-child(3) { animation-delay: -.55s; background: var(--pink); }
@keyframes scan { to { height: 86%; filter: drop-shadow(0 0 13px var(--cyan)); } }
.progress-track { height: 5px; border-radius: 8px; background: rgba(255,255,255,.08); margin: 28px 0 10px; overflow: hidden; }
.progress-track b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--violet), var(--cyan)); transition: width .2s ease; }
#analysis-percent { display: block; color: var(--cyan); font: 700 .75rem ui-monospace, monospace; margin-bottom: 24px; }

.setup-view { min-height: 100vh; padding: 112px 24px 60px; }
.setup-shell { width: min(1120px, 100%); margin: 0 auto; }
.setup-back { border: 0; background: transparent; color: var(--muted); padding: 8px 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .11em; }
.setup-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin: 22px 0 30px; }
.setup-heading h2 { margin: 9px 0 6px; font-size: clamp(2.2rem, 5vw, 4rem); letter-spacing: -.055em; }
.setup-heading p:not(.kicker) { color: var(--muted); margin: 0; }
.setup-launch { min-width: 180px; }
.setup-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr); gap: 16px; }
.setup-controls, .chart-lab { border: 1px solid var(--edge); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.setup-controls { padding: 8px 24px; }
.setup-block { padding: 22px 0; border-bottom: 1px solid var(--edge); }
.setup-block:last-child { border-bottom: 0; }
.setup-block > .eyebrow { margin-bottom: 14px; color: var(--cyan); }
.setup-block .setting-group { margin-bottom: 0; }
.atmosphere-block label { display: block; color: var(--muted); font-size: .67rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.atmosphere-block select { margin-top: 7px; }
.theme-signature { position: relative; height: 48px; margin: 15px 0 10px; overflow: hidden; border: 1px solid rgba(196,167,255,.14); border-radius: 8px; background: rgba(7,3,14,.48); }
.theme-signature i { position: absolute; display: block; transition: .25s ease; }
.theme-signature.minimal i:first-child { inset: 23px 12% auto; height: 1px; background: #d8ccf0; }
.theme-signature.minimal i:nth-child(2) { width: 6px; height: 6px; left: 50%; top: 20px; border: 1px solid #d8ccf0; border-radius: 50%; }
.theme-signature.minimal i:nth-child(3) { display: none; }
.theme-signature.pulse i { width: 38px; height: 22px; top: 12px; border: 1px solid #c4a7ff; border-radius: 50%; }
.theme-signature.pulse i:first-child { left: 21%; }
.theme-signature.pulse i:nth-child(2) { left: calc(50% - 19px); transform: scale(1.35); border-color: #e879f9; }
.theme-signature.pulse i:nth-child(3) { right: 21%; }
.theme-signature.club { background: linear-gradient(180deg, rgba(139,92,246,.12), rgba(7,3,14,.7)); }
.theme-signature.club i { width: 1px; height: 54px; top: -4px; background: linear-gradient(#f0abfc, transparent); transform-origin: top; }
.theme-signature.club i:first-child { left: 26%; transform: rotate(-25deg); }
.theme-signature.club i:nth-child(2) { left: 50%; }
.theme-signature.club i:nth-child(3) { right: 26%; transform: rotate(25deg); }
.theme-signature.party i { width: 9px; height: 9px; top: 19px; background: #fb7185; transform: rotate(25deg); }
.theme-signature.party i:first-child { left: 23%; border-radius: 50%; background: #5eead4; }
.theme-signature.party i:nth-child(2) { left: calc(50% - 5px); background: #facc15; transform: rotate(45deg) scale(1.2); }
.theme-signature.party i:nth-child(3) { right: 23%; border-radius: 50% 50% 0; background: #e879f9; }
.theme-signature.overdrive i { width: 42%; height: 1px; top: 23px; background: linear-gradient(90deg, transparent, #f0abfc); }
.theme-signature.overdrive i:first-child { left: 0; transform: rotate(12deg); }
.theme-signature.overdrive i:nth-child(2) { right: 0; transform: rotate(-12deg) scaleX(-1); }
.theme-signature.overdrive i:nth-child(3) { width: 18px; height: 18px; left: calc(50% - 9px); top: 14px; border: 1px solid #c4a7ff; transform: rotate(45deg); background: transparent; }
.atmosphere-block small { color: var(--muted); }
.setup-intensity { margin-top: 16px; }
.setup-intensity span, .setup-intensity output { float: right; color: var(--text); }
.setup-intensity input { width: 100%; margin-top: 10px; accent-color: var(--pink); }
.chart-lab { padding: 28px; position: relative; overflow: hidden; }
.chart-lab::before { content: ""; position: absolute; width: 260px; height: 260px; right: -100px; top: -100px; border-radius: 50%; background: radial-gradient(circle, rgba(139,92,246,.18), transparent 70%); }
.analysis-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 22px 0; position: relative; }
.analysis-facts div { padding: 14px; border: 1px solid var(--edge); border-radius: 11px; background: rgba(255,255,255,.025); }
.analysis-facts span, .tempo-hypotheses > span { display: block; color: var(--muted); font-size: .61rem; text-transform: uppercase; letter-spacing: .11em; }
.analysis-facts strong { display: block; margin-top: 5px; }
.tempo-hypotheses { padding: 14px 0; }
#tempo-hypotheses { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
#tempo-hypotheses i { padding: 6px 9px; border: 1px solid var(--edge); border-radius: 99px; color: var(--cyan); font: normal 700 .65rem ui-monospace, monospace; }
.section-map { display: flex; height: 34px; gap: 2px; margin: 15px 0; border-radius: 7px; overflow: hidden; }
.section-map i { min-width: 3px; display: grid; place-items: center; color: rgba(255,255,255,.7); font: normal 600 .5rem ui-monospace, monospace; background: color-mix(in srgb, var(--violet) calc(35% + var(--energy) * 45%), #21122f); overflow: hidden; }
.chart-summary { min-height: 46px; color: var(--muted); font-size: .75rem; line-height: 1.5; }


.drawer {
  position: fixed; z-index: 50; top: 0; right: 0; width: min(420px, 92vw); height: 100vh; height: 100dvh; padding: 26px;
  border-left: 1px solid var(--edge); background: rgba(10, 12, 24, .97); backdrop-filter: blur(24px);
  overflow: auto; transform: translateX(102%); transition: transform .25s ease; box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 28px; }
.drawer-header h2 { margin: 5px 0 0; }
.setting-group { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.setting-group label, .range-setting, .setting-label { color: var(--muted); font-size: .67rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.setting-group select { margin-top: 7px; }
.range-setting { display: block; margin: 22px 0; }
.range-setting span { display: flex; justify-content: space-between; margin-bottom: 10px; }
.range-setting output { color: var(--cyan); }
input[type="range"] { width: 100%; accent-color: var(--cyan); }
.setting-block { padding: 19px 0; border-top: 1px solid var(--edge); }
.keybinds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 10px; }
.keybinds button { height: 39px; font-size: .7rem; }
.keybinds { grid-template-columns: repeat(4, 1fr); }
.keybinds button { font: 800 .85rem ui-monospace, monospace; }
.keybinds button.listening { border-color: var(--pink); color: var(--pink); animation: listen .7s infinite alternate; }
@keyframes listen { to { box-shadow: 0 0 18px rgba(255,104,184,.28); } }
.setting-block small { display: block; margin-top: 8px; color: var(--muted); }
.drawer-actions { display: grid; gap: 8px; padding-top: 10px; }
.practice-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 2px 0 22px; }
.practice-actions button { min-height: 40px; font-size: .67rem; text-transform: uppercase; letter-spacing: .07em; }
.scrim { position: fixed; z-index: 40; inset: 0; border: 0; border-radius: 0; background: rgba(0,0,0,.52); opacity: 0; pointer-events: none; }
.scrim.visible { opacity: 1; pointer-events: auto; }

dialog { width: min(620px, calc(100% - 32px)); border: 1px solid var(--edge); border-radius: 22px; color: var(--text); background: rgba(10, 12, 24, .98); box-shadow: var(--shadow); padding: 38px; }
dialog::backdrop { background: rgba(3, 4, 10, .78); backdrop-filter: blur(8px); }
.result-grade { float: right; font-size: 5.4rem; line-height: .8; color: var(--cyan); font-weight: 900; text-shadow: 0 0 30px rgba(184,132,255,.4); }
dialog h2 { margin: 9px 0 28px; font-size: 2rem; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; clear: both; }
.result-grid div { padding: 17px; border: 1px solid var(--edge); border-radius: 12px; background: rgba(255,255,255,.025); }
.result-grid span { display: block; color: var(--muted); font-size: .65rem; text-transform: uppercase; letter-spacing: .11em; }
.result-grid strong { display: block; margin-top: 6px; font-size: 1.1rem; }
.dialog-actions { display: flex; gap: 9px; margin-top: 24px; }
.section-results { display: grid; gap: 7px; margin-top: 20px; }
.section-result { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; font-size: .72rem; color: var(--muted); }
.section-result i { display: block; height: 4px; border-radius: 5px; background: rgba(255,255,255,.07); overflow: hidden; grid-column: 1 / -1; }
.section-result b { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--violet), var(--pink)); }
.toast-stack { position: fixed; z-index: 80; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 13px 16px; border: 1px solid var(--edge); border-radius: 10px; background: rgba(16,19,34,.96); box-shadow: var(--shadow); font-size: .78rem; animation: toast-in .22s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 930px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto auto; padding: 0 16px; gap: 13px; }
  .now-playing, .session-stats, .homepage-link { display: none; }
  .song-grid { grid-template-columns: repeat(2, 1fr); }
  .setup-grid { grid-template-columns: 1fr; }
  .setup-shell { max-width: 720px; }
}
@media (max-width: 600px) {
  .topbar {
    height: calc(68px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    gap: 9px;
  }
  .brand { min-width: 0; }
  .brand-mark { width: 28px; height: 28px; flex: 0 0 auto; }
  .brand strong { font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand small, .homepage-link { display: none; }
  .engine-switch button { padding-inline: 7px; font-size: .49rem; letter-spacing: .035em; }
  .icon-button { min-height: 42px; padding: 0 11px; }
  .library { width: min(100% - 28px, 1180px); padding-top: 110px; }
  .hero-copy { padding: 28px 0 64px; }
  .hero-copy h1 { font-size: clamp(2.75rem, 14vw, 3.6rem); }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .hero-actions .button { width: 100%; padding-inline: 10px; }
  .development-notice { align-items: flex-start; flex-direction: column; gap: 5px; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading > p { line-height: 1.5; }
  .search { width: 100%; }
  .song-grid { grid-template-columns: 1fr; }
  .song-card { min-height: 128px; }
  .setting-group, .result-grid { grid-template-columns: 1fr; }
  .analysis-card { padding: 30px 22px; }
  .analysis-view { padding: calc(90px + env(safe-area-inset-top)) 14px 30px; }
  .setup-view { padding: calc(84px + env(safe-area-inset-top)) 14px calc(32px + env(safe-area-inset-bottom)); }
  .setup-heading { align-items: stretch; flex-direction: column; }
  .setup-controls, .chart-lab { border-radius: 14px; }
  .setup-controls { padding-inline: 18px; }
  .chart-lab { padding: 22px 18px; }
  .drawer {
    width: 100vw; padding: calc(20px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
      calc(24px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  }
  dialog { max-height: calc(100dvh - 20px); overflow: auto; padding: 28px 20px calc(24px + env(safe-area-inset-bottom)); }
  dialog h2 { font-size: 1.55rem; }
  .result-grade { font-size: 4.3rem; }
  .dialog-actions { display: grid; }
  .toast-stack {
    left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .toast { max-width: none; }
}

@media (max-width: 380px) {
  .hero-actions { grid-template-columns: 1fr; }
}
