:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #171a1d;
  --muted: #6a7076;
  --line: #d9ddd6;
  --accent: #1f7a65;
  --accent-strong: #155848;
  --danger: #b34040;
  --shadow: 0 10px 28px rgba(24, 30, 34, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

.is-hidden {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body.is-authenticating {
  overflow: hidden;
}

body.is-authenticating .app-shell,
body.is-authenticating .mini-player,
body.is-authenticating .tabbar {
  display: none;
}

body.is-now-playing .mini-player {
  display: none;
}

body:not(.has-current-track) .mini-player {
  display: none;
}

body:not(.has-current-track) .app-shell {
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) 14px 156px;
}

.view {
  display: none;
  max-width: 960px;
  margin: 0 auto;
}

.view.is-active {
  display: block;
}

.topbar,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.title-block {
  min-width: 0;
  flex: 1;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.15;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button,
.round-button,
.text-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  box-shadow: none;
}

.icon-button {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}

.playlist-ref-badge {
  position: absolute;
  right: -5px;
  top: -6px;
  display: grid !important;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border: 1px solid var(--panel);
  border-radius: 999px;
  padding: 0 4px;
  background: var(--accent);
  color: white !important;
  font-size: 11px !important;
  font-weight: 800;
  line-height: 1;
}

.text-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 700;
}

.text-button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.search-box {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
}

.search-box textarea {
  width: 100%;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
  resize: vertical;
}

.compact-label {
  margin-bottom: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
}

.inline-form.is-hidden {
  display: none;
}

.inline-form input {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.inline-form .text-button {
  min-height: 40px;
}

.status-line {
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
}

.track-list,
.playlist-list {
  display: grid;
  gap: 8px;
}

.track-row,
.playlist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.track-row > div:first-child,
.playlist-row > span:first-child {
  min-width: 0;
}

.track-row:not(.is-missing) {
  cursor: pointer;
}

.playlist-row {
  width: 100%;
  text-align: left;
}

.playlist-row.is-child {
  position: relative;
}

.playlist-row.is-child::before {
  content: "";
  position: absolute;
  left: var(--tree-guide, 14px);
  top: 18px;
  bottom: 18px;
  width: 2px;
  background: var(--line);
}

.track-row.is-missing {
  opacity: 0.58;
}

.track-row.is-current {
  border-color: var(--accent);
  background: #edf7f3;
  box-shadow: inset 3px 0 0 var(--accent);
}

.track-row.is-current strong {
  color: var(--accent-strong);
}

.track-row strong,
.playlist-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.track-row span,
.playlist-row span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.empty-state {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  color: var(--muted);
}

.empty-state.compact {
  padding: 12px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 16px;
}

.empty-state p {
  font-size: 14px;
}

.playlist-layout {
  display: grid;
  gap: 16px;
}

.playlist-row.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.playlist-row.is-included {
  border-color: rgba(31, 122, 101, 0.5);
  background: #edf7f3;
  box-shadow: inset 3px 0 0 var(--accent);
}

.playlist-row.is-included strong {
  color: var(--accent-strong);
}

.playlist-detail {
  min-width: 0;
}

.now-playing-view {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-height: calc(100vh - 280px);
  padding-top: 24px;
  text-align: center;
}

.cover {
  width: min(72vw, 340px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #25312e, #e8ece4);
  box-shadow: var(--shadow);
  background-position: center;
  background-size: cover;
}

.large-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.now-progress {
  display: grid;
  gap: 6px;
  width: min(74vw, 360px);
}

.now-progress input {
  width: 100%;
}

.time-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.round-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 28px;
}

.round-button.primary {
  width: 70px;
  height: 70px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.mini-player {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  grid-template-columns: auto 48px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.mini-cover {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #25312e, #e8ece4);
  background-position: center;
  background-size: cover;
}

.mini-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mini-meta strong,
.mini-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-meta span {
  color: var(--muted);
  font-size: 12px;
}

input[type="range"] {
  accent-color: var(--accent);
}

.sort-bar {
  margin-bottom: 8px;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: var(--panel);
}

.segmented-control button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented-control button.is-active {
  background: var(--accent);
  color: white;
}

.load-sentinel {
  height: 1px;
}

.playlist-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.apple-music-card {
  display: grid;
  gap: 12px;
}

.am-tabs {
  display: flex;
  gap: 0;
  margin-top: 22px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.am-tab {
  flex: 1;
  appearance: none;
  border: none;
  background: #0e0e0f;
  color: var(--muted);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.am-tab.is-active {
  background: var(--accent);
  color: white;
}

.am-tab-panel {
  display: none;
  margin-top: 14px;
}

.am-tab-panel.is-active {
  display: block;
}

.am-tab-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  min-height: 32px;
}

.am-tab-status .text-button {
  flex: 0 0 auto;
}

.am-tab-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.apple-music-library {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.apple-playlist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.apple-playlist-row > strong,
.apple-playlist-row > span,
.apple-track-preview {
  grid-column: 1;
}

.apple-update-button {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  padding: 8px 10px;
}

.apple-playlist-row.is-selectable {
  cursor: pointer;
}

.apple-playlist-row strong,
.apple-playlist-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apple-playlist-row > span {
  color: var(--muted);
  font-size: 13px;
}

.apple-track-preview {
  display: grid;
  gap: 3px;
  padding-top: 4px;
}

.apple-track-preview span {
  color: var(--muted);
  font-size: 12px;
}

.job-progress {
  width: 100%;
  height: 12px;
  accent-color: var(--accent);
}

.job-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
}

.job-log summary {
  cursor: pointer;
  font-weight: 800;
}

.job-log pre {
  max-height: 220px;
  overflow: auto;
  margin: 10px 0 0;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 12px;
}

.extra-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.icon-button.is-active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.sheet-actions {
  display: grid;
  gap: 8px;
}

.sheet-actions .text-button {
  justify-self: stretch;
}

.compact-sheet {
  padding-bottom: max(22px, env(safe-area-inset-bottom));
}

.queue-list {
  display: grid;
  gap: 6px;
}

.queue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  cursor: pointer;
}

.queue-row.is-active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.queue-row:hover {
  background: #f0f2ed;
}

.queue-meta strong,
.queue-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta strong {
  font-size: 14px;
}

.queue-meta span {
  color: var(--muted);
  font-size: 12px;
}

.queue-remove {
  width: 32px;
  height: 32px;
  font-size: 18px;
  border-radius: 50%;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  width: min(72vw, 340px);
}

.volume-row span {
  font-size: 18px;
  line-height: 1;
}

.volume-row input {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.96);
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.tab.is-active {
  background: var(--ink);
  color: white;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(148px + env(safe-area-inset-bottom));
  z-index: 40;
  display: none;
  max-width: 620px;
  margin: 0 auto;
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
}

.toast.is-visible {
  display: block;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(23, 26, 29, 0.38);
}

.sheet-backdrop.is-hidden {
  display: none;
}

.bottom-sheet {
  max-height: min(78dvh, 680px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 14px 14px max(18px, env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: var(--shadow);
}

.picker-list {
  padding-bottom: 10px;
}

.danger {
  color: var(--danger);
}

.login-screen.is-hidden {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow-y: auto;
  padding: max(34px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
}

.login-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-copy {
  color: var(--muted);
  font-size: 14px;
}

.token-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.login-card input {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 100%;
  min-height: 46px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  font-size: 16px;
}

@media (min-width: 760px) {
  .app-shell {
    padding-left: 28px;
    padding-right: 28px;
  }

  .playlist-layout {
    grid-template-columns: 320px minmax(0, 1fr);
    align-items: start;
  }

  .inline-form {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
  }

  .mini-player {
    left: 50%;
    right: auto;
    width: min(940px, calc(100vw - 40px));
    transform: translateX(-50%);
  }
}
