* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  color-scheme: dark;
  --bg: #171036;
  --bg-top: #3a1d60;
  --panel: rgba(34, 24, 74, 0.76);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f7fbff;
  --text-soft: #d0d7ea;
  --text-muted: #9da7c4;
  --mint: #80ffe0;
  --sky: #70ceff;
  --gold: #ffd46d;
  --danger: #ff7b7b;
  --app-surface: linear-gradient(180deg, rgba(44, 24, 87, 0.9) 0%, rgba(16, 18, 48, 0.98) 100%);
  --app-border: rgba(255, 255, 255, 0.06);
  --topbar-bg: rgba(41, 22, 76, 0.78);
  --tabbar-bg: rgba(28, 20, 58, 0.88);
  --card-surface: rgba(255, 255, 255, 0.065);
  --card-surface-strong: rgba(255, 255, 255, 0.085);
  --shadow-soft: rgba(6, 8, 24, 0.3);
  --shadow-strong: rgba(7, 8, 24, 0.48);
  --grid-line: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2ff;
  --bg-top: #fff6ef;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(34, 51, 96, 0.1);
  --text: #18254a;
  --text-soft: #586988;
  --text-muted: #8a96b0;
  --mint: #18b999;
  --sky: #4f86ff;
  --gold: #d4922a;
  --danger: #e55e6d;
  --app-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.88) 0%, rgba(246, 247, 255, 0.98) 100%);
  --app-border: rgba(34, 48, 88, 0.08);
  --topbar-bg: rgba(255, 255, 255, 0.78);
  --tabbar-bg: rgba(255, 255, 255, 0.88);
  --card-surface: rgba(255, 255, 255, 0.68);
  --card-surface-strong: rgba(255, 255, 255, 0.78);
  --shadow-soft: rgba(88, 103, 150, 0.14);
  --shadow-strong: rgba(88, 103, 150, 0.24);
  --grid-line: rgba(14, 36, 68, 0.035);
}

:root {
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 80px;
  --glass: rgba(255, 255, 255, 0.03);
  --glass-stroke: rgba(255, 255, 255, 0.08);
  --glass-shine: rgba(255, 255, 255, 0.12);
  --magic-gradient: linear-gradient(135deg, #80ffe0 0%, #70ceff 50%, #ea80fc 100%);
}

html,
body,
#root {
  height: 100%;
  width: 100%;
  background: #0a0a0d;
  background-attachment: fixed;
  color: var(--text);
  font-family: "Satoshi", "Inter", "SF Pro Display", sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 220ms ease, color 220ms ease;
}

body {
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 112px 112px;
  mask-image: linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent 92%);
  opacity: 0.24;
}

/* --- Layout --- */
.app-container {
  display: flex;
  height: 100dvh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* --- App Store download banner (web only) --- */
:root {
  --appstore-banner-h: 64px;
}

.appstore-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--appstore-banner-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px 0 44px;
  color: #fff;
  background: linear-gradient(135deg, rgba(44, 24, 87, 0.98) 0%, rgba(86, 41, 196, 0.96) 52%, rgba(160, 80, 255, 0.94) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 6px 24px rgba(12, 8, 32, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: border-box;
}

.appstore-banner__close {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.1);
  transition: background 150ms ease, color 150ms ease;
}

.appstore-banner__close:hover {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.appstore-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.appstore-banner__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.appstore-banner__title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appstore-banner__subtitle {
  font-size: 0.8rem;
  line-height: 1.25;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appstore-banner__cta {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  padding: 9px 16px;
  border-radius: 12px;
  color: #fff;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.appstore-banner__cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}

.appstore-banner__cta:active {
  transform: translateY(0);
}

.appstore-banner__apple {
  flex-shrink: 0;
}

.appstore-banner__cta-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
  text-align: left;
}

.appstore-banner__cta-top {
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.85);
}

.appstore-banner__cta-bottom {
  font-size: 1rem;
  font-weight: 600;
}

/* Push the app down so the fixed banner doesn't cover it. */
html[data-appstore-banner="1"] .app-container {
  height: calc(100dvh - var(--appstore-banner-h) - env(safe-area-inset-top, 0px));
  min-height: calc(100dvh - var(--appstore-banner-h) - env(safe-area-inset-top, 0px));
  margin-top: calc(var(--appstore-banner-h) + env(safe-area-inset-top, 0px));
}

@media (max-width: 640px) {
  :root {
    --appstore-banner-h: 60px;
  }

  .appstore-banner {
    gap: 10px;
    padding-left: 38px;
    padding-right: 12px;
  }

  .appstore-banner__subtitle {
    display: none;
  }

  .appstore-banner__icon {
    width: 38px;
    height: 38px;
  }

  .appstore-banner__cta {
    padding: 8px 12px;
  }
}

.main-content {
  flex: 1;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

button,
input,
textarea {
  border: none;
  background: none;
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

textarea {
  resize: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

::selection {
  background: rgba(122, 244, 207, 0.26);
}

::-webkit-scrollbar {
  display: none;
}

/* --- Premium Animations --- */
@keyframes orb-float {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.8; }
  50% { transform: translateY(-20px) scale(1.1); opacity: 1; }
}

@keyframes text-shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

.magic-text {
  background: var(--magic-gradient);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: text-shimmer 3s linear infinite;
}

.glass-panel {
  background: var(--panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-stroke);
  border-radius: 20px;
  box-shadow: 0 8px 32px var(--shadow-strong);
}

.rhythmic-pulse {
  transition: transform 100ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform: scale(calc(1 + var(--pulse-intensity, 0) * 0.05));
}


/* --- Mobile Responsiveness --- */
@media (max-width: 980px), (hover: none) and (pointer: coarse) {
  .sidebar {
    display: none !important;
  }
  
  .app-container {
    flex-direction: column;
    height: 100dvh;
    min-height: 100dvh;
  }
  
  .main-content {
    width: 100%;
    max-width: 100vw;
  }
}

html[data-platform="ios"] .sidebar {
  display: none !important;
}

html[data-platform="ios"] .app-container {
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
}

/*
 * Restore the banner-aware height on touch platforms.
 *
 * The rule above and the mobile media query both re-assert 100dvh, and
 * `html[data-platform="ios"] .app-container` carries exactly the same
 * specificity as `html[data-appstore-banner="1"] .app-container` while being
 * declared later — so it won. The container therefore kept its full viewport
 * height *and* took the banner's 60px margin-top, which pushed its last flex
 * child 60px below the fold. That child is the tab bar: the app's primary
 * navigation was reduced to a few tappable pixels on every mobile tab whenever
 * the App Store banner was showing.
 *
 * Two attributes beat one, so this settles it without touching the rules above.
 */
html[data-appstore-banner="1"][data-platform="ios"] .app-container,
html[data-appstore-banner="1"][data-platform="web"] .app-container {
  height: calc(100dvh - var(--appstore-banner-h) - env(safe-area-inset-top, 0px));
  min-height: calc(100dvh - var(--appstore-banner-h) - env(safe-area-inset-top, 0px));
}

html[data-platform="ios"] .main-content {
  width: 100%;
  max-width: 100vw;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================================
   Notices — transient feedback from any screen (src/lib/notify.ts)
   Top-anchored so they never fight the tab bar or the player for
   the bottom edge, and inside the safe area on every device.
   ============================================================ */
.notices {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  pointer-events: none;
}

.notice {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px 11px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg, #0a0a0d) 82%, var(--text, #f5f5f7) 10%);
  border: 1px solid color-mix(in srgb, var(--text, #f5f5f7) 14%, transparent);
  color: var(--text, #f5f5f7);
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  animation: notice-in 180ms ease-out;
}

.notice--error { border-color: color-mix(in srgb, #ff8574 55%, transparent); }
.notice--success { border-color: color-mix(in srgb, #3fce9a 50%, transparent); }

.notice__text { flex: 1; min-width: 0; }

.notice__action {
  border: 0;
  background: transparent;
  color: var(--brand-soft, #5bc9ec);
  font: inherit;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
}

.notice__close {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.6;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
}

@keyframes notice-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .notice { animation: none; }
}

/*
 * Modal sheets sit above the App Store banner (z-index 1000).
 *
 * The banner is fixed to the top of the mobile web viewport, and these sheets
 * were below it — so their top-right close button was covered and the sign-in
 * sheet could not be dismissed at all. Inline `auth--screen` (the Profile tab
 * when signed out) is part of the page and stays where it is.
 */
html .auth:not(.auth--screen),
html .profile-editor,
html .piano-roll-backdrop {
  z-index: 1100;
}

/*
 * Library rows on a phone: the title is the row. The quick-action cluster
 * (remix, video, publish) squeezed it to three characters — every one of those
 * actions is also in the row's ⋯ menu, so on narrow screens only the star and
 * the menu stay inline.
 */
@media (max-width: 640px) {
  html .lib-row:hover .lib-row__hover-actions,
  html .lib-row.is-selected .lib-row__hover-actions,
  html .lib-row__hover-actions {
    display: none;
  }
  .lib-row__info { min-width: 0; flex: 1 1 auto; }
}

/* ============================================================
   Mini player — the default, collapsed state of MusicPlayerBar.
   Sits where the full player sits (above the tab bar on phones,
   beside the sidebar on desktop) at a height that leaves the
   screen usable. Tap the song to open the full player.
   ============================================================ */
.beat-mini {
  position: absolute;
  left: 306px;
  right: 20px;
  bottom: 18px;
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 64px;
  padding: 0 8px 0 8px;
  border-radius: 14px;
  overflow: hidden;
  background: color-mix(in srgb, var(--bg, #0a0a0d) 88%, var(--text, #f5f5f7) 8%);
  border: 1px solid color-mix(in srgb, var(--text, #f5f5f7) 12%, transparent);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
  color: var(--text, #f5f5f7);
}

.beat-mini__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--brand-soft, #5bc9ec);
  transform-origin: left center;
  transition: transform 250ms linear;
}

.beat-mini__open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.beat-mini__cover {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
}

.beat-mini__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.beat-mini__copy strong {
  font-size: 14.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.beat-mini__copy span {
  font-size: 12.5px;
  color: var(--text-soft, #b4b4be);
  font-variant-numeric: tabular-nums;
}

.beat-mini__play,
.beat-mini__close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.beat-mini__play {
  background: var(--text, #f5f5f7);
  color: var(--bg, #0a0a0d);
  width: 40px;
  height: 40px;
}

.beat-mini__close { opacity: 0.7; }

.beat-player__collapse {
  position: absolute;
  top: 12px;
  right: 56px;
  z-index: 4;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e8ecf4;
  cursor: pointer;
}

@media (max-width: 1080px) {
  .beat-mini { left: 12px; right: 12px; bottom: 12px; }
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
  .beat-mini { left: 12px; right: 12px; bottom: 12px; }
}

/* Studio hides the app sidebar, so the bar spans the workspace there. */
.app-container:has(.st-root) .beat-mini { left: 20px; }
@media (max-width: 1080px) {
  .app-container:has(.st-root) .beat-mini { left: 12px; }
}

/* Phones: the tab bar is in flow at the bottom; the mini bar floats above it. */
.app-container:has(.tab-bar) .beat-mini,
.app-container:has(.st-root):has(.tab-bar) .beat-mini {
  left: 10px;
  right: 10px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

/* Studio on iOS: its nav strip is the first thing on screen, so it has to
   start below the status bar and Dynamic Island, like every other tab. */
html[data-platform="ios"] .main-content--studio {
  padding-top: env(safe-area-inset-top, 0px);
}

/* Expanded player on a phone is a full-screen Now Playing sheet. As a
   floating card its turntable art hung above the card's own background, so
   whatever was underneath showed through it. */
@media (max-width: 980px), (hover: none) and (pointer: coarse) {
  html .beat-player.is-expanded {
    position: fixed;
    inset: 0;
    z-index: 1050;
    border-radius: 0;
    border: 0;
    background: var(--bg, #0b0b0e);
    padding: calc(env(safe-area-inset-top, 0px) + 56px) 0 calc(env(safe-area-inset-bottom, 0px) + 16px);
    overflow-y: auto;
    align-content: center;
  }
  html .beat-player.is-expanded .beat-player__close,
  html .beat-player.is-expanded .beat-player__collapse {
    top: calc(env(safe-area-inset-top, 0px) + 10px);
  }
}

/* Starter clips stay transparent until they are really playing; the
   artwork underneath is the baseline. See HomeScreen. */
html .starter__cover--video { background: transparent; opacity: 0; transition: opacity 300ms ease; }
html .starter__cover--video[data-ready="1"] { opacity: 1; }
