/* App shell: top bar, library, main panel, right panel, player bar. Uses only tokens.css values. */

body { margin: 0; background: var(--bg); color: var(--text); font: var(--fw-regular) var(--fs-md)/1.4 var(--font); -webkit-font-smoothing: antialiased; }
.ap-skip { position: fixed; top: var(--sp-2); left: var(--sp-2); z-index: var(--z-dialog); padding: var(--sp-3); border-radius: var(--r-art); background: var(--panel); color: var(--text); transform: translateY(calc(-100% - var(--sp-4))); }
.ap-skip:focus { transform: none; }
.ap-app { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; height: 100vh; height: 100dvh; overflow: hidden; background: var(--bg); }

/* ---- Signed-out and setup screens ---- */
.ap-center { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: var(--sp-4); padding: var(--sp-5); text-align: center; }
.ap-logo-big { width: min(480px, 86vw); height: auto; }

/* ---- Top bar ---- */
.ap-top { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--sp-4); min-height: 64px; padding: var(--sp-2) var(--sp-4); }
.ap-top-left, .ap-top-center, .ap-top-right { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.ap-top-right { justify-content: flex-end; gap: var(--sp-3); }
.ap-logo { display: block; margin-right: var(--sp-2); }
.ap-logo img { display: block; height: 40px; width: auto; }
.ap-nav { background: rgba(0, 0, 0, .55); color: var(--text); }
:root[data-theme="light"] .ap-nav { background: var(--raised); }
.ap-home { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--raised); color: var(--text); transition: transform var(--t-press) var(--ease), background var(--t-fast); }
.ap-home:hover { background: var(--hover); transform: scale(1.06); text-decoration: none; }
.ap-search { display: flex; align-items: center; width: min(480px, 36vw); min-width: 180px; height: 48px; border: 2px solid transparent; border-radius: var(--r-pill); background: var(--raised); transition: background var(--t-fast), border-color var(--t-fast); }
.ap-search:hover { background: var(--hover); }
.ap-search:focus-within { border-color: var(--text); background: var(--hover); }
.ap-search-icon { display: grid; padding-left: var(--sp-3); color: var(--muted); }
.ap-search:focus-within .ap-search-icon { color: var(--text); }
.ap-search input { flex: 1; min-width: 0; height: 100%; padding: 0 var(--sp-2); border: 0; outline: 0; background: transparent; color: var(--text); font: var(--fw-medium) var(--fs-sm)/1 var(--font); }
.ap-search input::placeholder { color: var(--muted); }
.ap-search input::-webkit-search-cancel-button { display: none; }
.ap-search-clear { display: grid; padding: var(--sp-2); border: 0; background: none; color: var(--muted); cursor: pointer; }
.ap-search-clear:hover { color: var(--text); }
.ap-search-browse { display: grid; place-items: center; align-self: stretch; padding: 0 var(--sp-4); border-left: 1px solid var(--track); color: var(--muted); }
.ap-search-browse:hover { color: var(--text); text-decoration: none; }

.ap-bot { display: flex; align-items: center; gap: var(--sp-2); max-width: 340px; padding: 4px 4px 4px 14px; border-radius: var(--r-pill); background: var(--raised); font-size: var(--fs-xs); }
.ap-bot-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.ap-bot.in .ap-bot-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(30, 215, 96, .25); }
.ap-bot-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.ap-bot-btn { flex: none; min-height: 32px; padding: 8px 16px; font-size: var(--fs-xs); }
.ap-avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; padding: 4px; border: 0; border-radius: 50%; background: var(--raised); cursor: pointer; transition: transform var(--t-press) var(--ease), background var(--t-fast); }
.ap-avatar:hover { background: var(--hover); transform: scale(1.06); }
.ap-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* ---- Panels ---- */
.ap-panels { display: flex; gap: var(--sp-2); min-height: 0; padding: 0 var(--sp-2); }
.ap-lib-wrap { position: relative; display: flex; flex: none; width: var(--lib-w); transition: width var(--t-panel) var(--ease); }
.ap-main { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; border-radius: var(--r-panel); background: var(--panel); }
.ap-main-scroll { --page-pad: var(--sp-5); flex: 1; padding: 0 var(--page-pad) var(--sp-5); container-type: inline-size; }

/* ---- Library ---- */
.ap-lib { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; border-radius: var(--r-panel); background: var(--panel); }
.ap-lib-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-2) var(--sp-2) var(--sp-4); }
.ap-lib.collapsed .ap-lib-head { flex-direction: column; padding: var(--sp-3) 0; }
.ap-lib-toggle { display: inline-flex; align-items: center; gap: var(--sp-3); padding: 4px; border: 0; background: none; color: var(--muted); font: var(--fw-bold) var(--fs-md)/1 var(--font); cursor: pointer; transition: color var(--t-fast); }
.ap-lib-toggle:hover { color: var(--text); }
.ap-lib-plus:hover { background: var(--raised); }
.ap-chips { display: flex; gap: var(--sp-2); padding: var(--sp-1) var(--sp-4) var(--sp-2); overflow-x: auto; scrollbar-width: none; }
.ap-chips::-webkit-scrollbar { display: none; }
.ap-lib-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-3); }
.ap-lib-search { display: flex; flex: 1; align-items: center; gap: var(--sp-2); height: 32px; padding: 0 var(--sp-3); border-radius: var(--r-art); background: var(--raised); color: var(--muted); }
.ap-lib-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: var(--fw-regular) var(--fs-sm)/1 var(--font); }
.ap-sort { display: inline-flex; align-items: center; gap: var(--sp-2); margin-left: auto; padding: 6px 8px; border: 0; border-radius: var(--r-pill); background: none; color: var(--muted); font: var(--fw-medium) var(--fs-sm)/1 var(--font); cursor: pointer; transition: color var(--t-fast), transform var(--t-press) var(--ease); }
.ap-sort:hover { color: var(--text); transform: scale(1.03); }
.ap-lib-list { flex: 1; padding: 0 var(--sp-2) var(--sp-2); }
.ap-lib.collapsed .ap-lib-list { padding: 0; }
.ap-lib-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--r-art); transition: background var(--t-fast); }
.ap-lib.collapsed .ap-lib-item { justify-content: center; padding: var(--sp-2) 0; }
.ap-lib-item:hover { background: var(--raised); text-decoration: none; }
.ap-lib-item.active { background: var(--highlight); }
.ap-lib-item .ui-img { flex: none; }
.ap-lib-text { flex: 1; min-width: 0; }
.ap-lib-name, .ap-lib-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-lib-name { font-weight: var(--fw-medium); }
.ap-lib-name.playing { color: var(--accent); }
.ap-lib-sub { color: var(--muted); font-size: var(--fs-sm); }
.ap-lib-loading { display: grid; gap: var(--sp-2); padding: var(--sp-2); }
.ap-lib-skel { display: flex; align-items: center; gap: var(--sp-3); }
.ap-lib-skel > div:last-child { display: grid; flex: 1; gap: 6px; }
.ap-lib-empty { margin: 0; padding: var(--sp-4); color: var(--muted); font-size: var(--fs-sm); }
.ap-input { width: 100%; padding: 12px 16px; border: 1px solid transparent; border-radius: var(--r-pill); background: var(--raised); color: var(--text); font: inherit; }
.ap-input:focus { outline: none; border-color: var(--text); }

.ap-resize { position: absolute; top: 0; right: -6px; bottom: 0; z-index: 3; width: 8px; cursor: col-resize; }
.ap-resize::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background var(--t-fast); }
.ap-resize:hover::after, .ap-resize.dragging::after, .ap-resize:focus-visible::after { background: var(--faint); }

/* ---- Right panel (Now playing / Queue) ---- */
.ap-right { display: flex; flex: none; flex-direction: column; width: 360px; min-height: 0; border-radius: var(--r-panel); background: var(--panel); animation: ap-slide-in var(--t-panel) var(--ease); }
@keyframes ap-slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.ap-right-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-3) var(--sp-2) var(--sp-4); }
.ap-right-head h2 { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-bold); }
.ap-right-tools { display: flex; align-items: center; gap: var(--sp-2); }
.ap-right-body { flex: 1; padding: 0 var(--sp-4) var(--sp-4); }
.ap-right-art { margin: var(--sp-2) 0 var(--sp-4); border-radius: var(--r-panel); box-shadow: var(--shadow-art); }
.ap-right-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.ap-right-titles { min-width: 0; }
.ap-right-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.ap-right-artist { color: var(--muted); }
.ap-right-sub { margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-md); font-weight: var(--fw-bold); }
.ap-right-empty { color: var(--muted); font-size: var(--fs-sm); }
.ap-artist-card { position: relative; display: block; overflow: hidden; margin-bottom: var(--sp-4); border-radius: var(--r-panel); background: var(--raised); }
.ap-artist-card:hover { text-decoration: none; background: var(--hover); }
.ap-artist-img { border-radius: 0; aspect-ratio: 16 / 10; }
.ap-artist-info { display: grid; gap: 2px; padding: var(--sp-4); }
.ap-artist-label { color: var(--muted); font-size: var(--fs-xs); font-weight: var(--fw-bold); }
.ap-artist-meta { color: var(--muted); font-size: var(--fs-sm); }
.ap-next-head { display: flex; align-items: baseline; justify-content: space-between; }
.ap-link { padding: 0; border: 0; background: none; color: var(--muted); font: var(--fw-bold) var(--fs-sm)/1 var(--font); cursor: pointer; }
.ap-link:hover { color: var(--text); text-decoration: underline; }
.ap-q { display: grid; gap: var(--sp-1); margin: 0 0 var(--sp-2); padding: 0; list-style: none; }
.ap-q-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-1); border-radius: var(--r-art); }
.ap-q-row:hover { background: var(--raised); }
.ap-q-row.current .ap-q-name { color: var(--accent); }
.ap-q-text { min-width: 0; }
.ap-q-name, .ap-q-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-q-name { font-weight: var(--fw-medium); }
.ap-q-sub { color: var(--muted); font-size: var(--fs-sm); }
.ap-q-sub a:hover { color: var(--text); }

/* ---- Player bar ---- */
.ap-player { display: grid; grid-template-columns: minmax(180px, 30%) minmax(0, 1fr) minmax(180px, 30%); align-items: center; gap: var(--sp-4); min-height: 80px; padding: var(--sp-1) var(--sp-4) var(--sp-2); }
.ap-np { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.ap-np .ui-img { flex: none; width: 56px; }
.ap-np-meta { min-width: 0; }
.ap-np-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.ap-np-title.idle { color: var(--muted); }
.ap-np-by { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--fs-xs); }
.ap-np-by a:hover { color: var(--text); }
.ap-transport { display: grid; gap: var(--sp-2); justify-items: center; width: 100%; max-width: 722px; margin: 0 auto; }
.ap-buttons { display: flex; align-items: center; gap: var(--sp-4); }
.ap-ctl { position: relative; }
.ap-ctl.on::after { animation: ap-dot var(--t-fast) var(--ease); content: ""; position: absolute; bottom: 0; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.ap-toggle { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--text); color: var(--bg); cursor: pointer; transition: transform var(--t-press) var(--ease); }
.ap-toggle:hover { transform: scale(1.06); }
.ap-toggle:active { transform: scale(.96); }
.ap-toggle[disabled] { opacity: .5; pointer-events: none; }
.ap-progress { display: flex; align-items: center; gap: var(--sp-2); width: 100%; }
.ap-time { min-width: 40px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ap-time:first-child { text-align: right; }
.ap-extra { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-1); }
.ap-volume { display: flex; align-items: center; gap: var(--sp-1); }
.ap-volume .ui-slider { flex: none; width: 100px; }

.ui-iconbtn.ap-only-narrow { display: none; }

.ap-connect { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: 2px var(--sp-4); background: var(--accent); color: var(--accent-ink); font: var(--fw-bold) var(--fs-xs)/20px var(--font); animation: ap-fade var(--t-panel) ease; }
@keyframes ap-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ap-dot { from { transform: scale(0); } to { transform: scale(1); } }

/* Keyboard shortcuts dialog */
.ap-keys { display: grid; gap: var(--sp-2); margin: 0; }
.ap-keys > div { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.ap-keys dt { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
.ap-keys dd { margin: 0; text-align: right; }
.ap-keys kbd { display: inline-block; min-width: 24px; padding: 2px 8px; border-radius: var(--r-art); background: var(--hover); color: var(--text); font: var(--fw-bold) var(--fs-xs)/1.6 var(--font); text-align: center; }

/* ---- Small screens: the library becomes a drawer, the right panel a sheet ---- */
@media (max-width: 860px) {
  /* Two rows: logo and account on top, home + search full width underneath. */
  .ap-top { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "left right" "center center"; gap: var(--sp-2); min-height: 0; padding: var(--sp-2); }
  .ap-top-left { grid-area: left; }
  .ap-top-center { grid-area: center; }
  .ap-top-right { grid-area: right; }
  .ap-logo img { height: 28px; }
  .ap-nav { display: none; }
  .ap-search { flex: 1; width: auto; min-width: 0; }
  .ap-search-browse, .ap-bot-label { display: none; }
  .ap-bot { padding: 4px; }
  .ap-lib-wrap.drawer { position: fixed; inset: 112px 8px 96px; z-index: 30; width: auto; box-shadow: var(--shadow-menu); }
  .ap-right { position: fixed; inset: 8px 8px 96px; z-index: 30; width: auto; }
  .ap-player { grid-template-columns: 1fr auto; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3); }
  .ap-transport { grid-column: 1 / -1; grid-row: 2; }
  .ap-extra { display: none; }
  .ui-iconbtn.ap-only-narrow { display: inline-grid; }
  .ap-np { grid-column: 1; }
  .ap-main-scroll { --page-pad: var(--sp-3); }
}
@media (prefers-reduced-motion: reduce) {
  .ap-right, .ap-connect { animation: none; }
}
