:root {
  color-scheme: light;
  --color-background: #f6f7fb;
  --color-surface: #ffffff;
  --color-surface-secondary: #eef1f6;
  --color-surface-elevated: #ffffff;
  --color-text-primary: #10131a;
  --color-text-secondary: #667085;
  --color-text-tertiary: #98a2b3;
  --color-border: rgba(16, 19, 26, .1);
  --color-divider: rgba(16, 19, 26, .08);
  --color-accent: #176bff;
  --color-accent-secondary: #00a88f;
  --color-accent-contrast: #ffffff;
  --color-danger: #d92d20;
  --color-success: #00a88f;
  --color-warning: #b54708;
  --color-overlay: rgba(0, 0, 0, .38);
  --color-shadow: rgba(16, 24, 40, .12);
  --color-shadow-soft: rgba(16, 24, 40, .08);
  --player-gradient-start: #eef4ff;
  --player-gradient-end: #f6f7fb;
  --bg: var(--color-background);
  --surface: var(--color-surface);
  --surface-2: var(--color-surface-secondary);
  --surface-3: #dfe5ee;
  --text: var(--color-text-primary);
  --muted: var(--color-text-secondary);
  --muted-2: var(--color-text-tertiary);
  --line: var(--color-border);
  --accent: var(--color-accent);
  --accent-2: var(--color-accent-secondary);
  --danger: var(--color-danger);
  --warning: var(--color-warning);
  --shadow: 0 12px 36px var(--color-shadow);
  --shadow-soft: 0 6px 18px var(--color-shadow-soft);
  --radius: 8px;
  --radius-lg: 22px;
  --tap: 44px;
  --tabbar-h: 78px;
  --mini-h: 74px;
  --font-scale: 1;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --color-background: #000000;
  --color-surface: #1c1c1e;
  --color-surface-secondary: #2c2c2e;
  --color-surface-elevated: #242426;
  --color-text-primary: #ffffff;
  --color-text-secondary: #aeaeb2;
  --color-text-tertiary: #8e8e93;
  --color-border: rgba(255, 255, 255, .12);
  --color-divider: rgba(255, 255, 255, .1);
  --color-accent: #5b9bff;
  --color-accent-secondary: #30d158;
  --color-accent-contrast: #ffffff;
  --color-danger: #ff453a;
  --color-success: #30d158;
  --color-warning: #ff9f0a;
  --color-overlay: rgba(0, 0, 0, .62);
  --color-shadow: rgba(0, 0, 0, .45);
  --color-shadow-soft: rgba(0, 0, 0, .28);
  --player-gradient-start: #151517;
  --player-gradient-end: #000000;
  --surface-3: #3a3a3c;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: calc(16px * var(--font-scale));
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
}

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

html:not(.theme-booting) body,
html:not(.theme-booting) .tabbar,
html:not(.theme-booting) .mini-player,
html:not(.theme-booting) .bottom-sheet,
html:not(.theme-booting) .player-screen,
html:not(.theme-booting) .card,
html:not(.theme-booting) .track-row,
html:not(.theme-booting) .setting-card,
html:not(.theme-booting) .notice {
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent), var(--surface) 20%);
  outline-offset: 3px;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.svg-sprite,
.visually-hidden,
.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.05rem;
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.28rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.topbar-actions,
.player-controls,
.player-actions,
.toolbar,
.control-row,
.section-head,
.selection-bar,
.sheet-head,
.time-row,
.setting-row,
.form-actions,
.action-list {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 8px;
}

.views {
  height: calc(100dvh - 116px - var(--tabbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding-bottom: calc(var(--mini-h) + 14px);
  scrollbar-width: none;
}

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

.view.active {
  display: block;
}

.content-section {
  margin: 0 0 22px;
}

.section-head {
  justify-content: space-between;
  gap: 12px;
}

.notice,
.card,
.track-row,
.playlist-row,
.setting-card,
.bookmark-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.notice {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.notice p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.35;
}

.notice.subtle {
  color: var(--warning);
  background: color-mix(in srgb, var(--color-warning), var(--surface) 86%);
}

.icon-button,
.primary-icon-button,
.play-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.primary-icon-button,
.play-button,
.primary-button {
  color: var(--color-accent-contrast);
  background: var(--accent);
}

.icon-button.large {
  min-width: 50px;
  min-height: 50px;
}

.icon-button.active,
.pill-button.active {
  color: var(--color-accent-contrast);
  background: var(--accent);
}

.play-button {
  min-width: 74px;
  min-height: 74px;
}

.play-button svg {
  width: 32px;
  height: 32px;
}

.primary-button,
.ghost-button,
.danger-button,
.pill-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 700;
}

.ghost-button,
.pill-button {
  color: var(--text);
  background: var(--surface-2);
}

.danger-button {
  color: var(--color-accent-contrast);
  background: var(--danger);
}

.rail {
  display: grid;
  grid-auto-columns: minmax(152px, 42%);
  grid-auto-flow: column;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 0 10px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

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

.album-card {
  min-width: 0;
  max-width: 100%;
  padding: 10px;
  scroll-snap-align: start;
}

.artwork {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 18px;
  background: var(--surface-2);
}

.album-card strong,
.track-main > strong,
.track-title {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.album-card small,
.track-subtitle,
.meta-line {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: .82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.stat-card strong {
  display: block;
  font-size: 1.45rem;
}

.stat-card span {
  color: var(--muted);
  font-size: .83rem;
}

.toolbar {
  gap: 10px;
  margin-bottom: 12px;
}

.search-field {
  display: flex;
  flex: 1;
  align-items: center;
  min-height: var(--tap);
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  color: var(--text);
  background: transparent;
  outline: 0;
}

.control-row {
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

select,
input[type="text"],
input[type="number"],
textarea {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
}

select {
  padding: 0 12px;
}

.selection-bar {
  gap: 8px;
  overflow-x: auto;
  padding: 8px;
  margin-bottom: 12px;
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.track-list {
  display: grid;
  gap: 10px;
}

.track-list.grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.track-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 9px;
}

.track-row.selected {
  border-color: color-mix(in srgb, var(--accent), transparent 25%);
  background: color-mix(in srgb, var(--accent), var(--surface) 92%);
}

.inline-status {
  width: 16px;
  height: 16px;
  margin-left: 4px;
  color: var(--accent-2);
  vertical-align: -2px;
}

.track-list.grid .track-row {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.track-list.grid .track-row .row-artwork {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.row-artwork {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--surface-2);
}

.track-main {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-align: left;
  color: inherit;
  background: transparent;
}

.track-progress {
  width: 100%;
  height: 5px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.track-progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 44px 18px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.empty-state p {
  max-width: 32rem;
  color: var(--muted);
  line-height: 1.45;
}

.empty-art {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 24px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent), transparent 88%);
}

.empty-art svg {
  width: 38px;
  height: 38px;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.collection-card {
  min-height: 112px;
  padding: 14px;
  border-radius: var(--radius-lg);
  color: var(--text);
  text-align: left;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.collection-card svg {
  color: var(--accent);
}

.settings-stack {
  display: grid;
  gap: 14px;
}

.setting-card {
  padding: 14px;
}

.setting-row {
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  border-top: 1px solid var(--line);
}

.setting-row:first-of-type {
  border-top: 0;
}

.setting-row label {
  color: var(--muted);
}

.setting-row select,
.setting-row input {
  max-width: 52%;
}

.theme-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.theme-choice {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 8px;
  min-height: 118px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--text);
  text-align: left;
  background: var(--surface-2);
}

.theme-choice svg {
  width: 26px;
  height: 26px;
  color: var(--text);
}

.theme-choice strong,
.theme-choice span {
  overflow-wrap: anywhere;
}

.theme-choice span {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.25;
}

.theme-choice[aria-checked="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent), var(--surface) 88%);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent), transparent 45%);
}

.theme-choice[aria-checked="true"] svg {
  color: var(--accent);
}

.mini-player {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  left: max(12px, env(safe-area-inset-left));
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: var(--mini-h);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface), transparent 8%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.mini-main {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-align: left;
  background: transparent;
}

.mini-main img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
}

.mini-main strong,
.mini-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-main small {
  color: var(--muted);
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 6%);
  backdrop-filter: blur(20px);
}

.tab {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  border-radius: 16px;
  color: var(--muted);
  background: transparent;
  font-size: .72rem;
  font-weight: 700;
}

.tab span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tab.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent), transparent 90%);
}

.player-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(180px, 38dvh) auto auto auto 1fr;
  gap: 16px;
  padding: calc(env(safe-area-inset-top) + 14px) max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 18px) max(20px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--accent), transparent 82%), transparent 46%), linear-gradient(180deg, var(--player-gradient-start), var(--player-gradient-end));
}

.player-top {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.player-artwork {
  width: min(74vw, 360px);
  max-height: 38dvh;
  aspect-ratio: 1;
  justify-self: center;
  align-self: center;
  object-fit: cover;
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.player-meta {
  text-align: center;
}

.player-meta h2 {
  margin: 0 0 5px;
  font-size: 1.5rem;
  line-height: 1.15;
}

.player-meta p {
  margin: 0;
  color: var(--muted);
}

.range {
  width: 100%;
  accent-color: var(--accent);
}

.time-row {
  justify-content: space-between;
  color: var(--muted);
  font-size: .82rem;
}

.player-controls {
  justify-content: center;
  gap: 8px;
}

.player-actions {
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--color-overlay);
}

.bottom-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 90;
  max-height: min(82dvh, 760px);
  overflow-y: auto;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet-grabber {
  width: 46px;
  height: 5px;
  margin: 4px auto 12px;
  border-radius: 999px;
  background: var(--surface-3);
}

.sheet-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-head h2 {
  margin: 0;
}

.action-list {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  background: var(--surface-2);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.form-grid input,
.form-grid textarea,
.form-grid select {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
}

.form-grid textarea {
  min-height: 92px;
  resize: vertical;
}

.form-actions {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.artwork-editor {
  display: grid;
  gap: 10px;
}

.artwork-preview {
  width: 156px;
  aspect-ratio: 1;
  border-radius: 22px;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: var(--shadow-soft);
}

.artwork-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toast-region {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  left: max(14px, env(safe-area-inset-left));
  z-index: 120;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 16px;
  color: var(--color-accent-contrast);
  background: color-mix(in srgb, var(--color-text-primary), var(--color-background) 12%);
  box-shadow: var(--shadow);
}

.toast.error {
  background: color-mix(in srgb, var(--danger), var(--color-background) 35%);
}

.import-progress {
  display: grid;
  gap: 8px;
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 980px;
    margin: 0 auto;
  }

  .track-list.grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .collection-grid,
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .bottom-sheet {
    right: calc((100vw - min(720px, 100vw)) / 2);
    left: calc((100vw - min(720px, 100vw)) / 2);
    border-radius: 26px 26px 0 0;
  }
}

@media (max-width: 390px) {
  .player-controls {
    gap: 4px;
  }

  .icon-button.large {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .view,
  .bottom-sheet,
  .player-screen,
  .toast,
  button {
    transition: transform .2s ease, opacity .2s ease, background-color .2s ease, color .2s ease;
  }

  button:active {
    transform: scale(.97);
  }
}

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