/* tokens.css — the only file in this app allowed to contain literal colours.
   Everything below the variable blocks uses var(--…) only. */

:root {
  --bg: #0b0f14;
  --surface: #11161d;
  --elevated: #171f29;
  --text: #e9eef6;
  --muted: #8b98a9;
  --accent: #8ab4ff;
  --line: #222c38;
  --danger: #ff7b72;
  --radius-card: 14px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: dark;
  accent-color: var(--accent);
}

:root[data-theme="dark"] {
  --bg: #0b0f14;
  --surface: #11161d;
  --elevated: #171f29;
  --text: #e9eef6;
  --muted: #8b98a9;
  --accent: #8ab4ff;
  --line: #222c38;
  --danger: #ff7b72;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --elevated: #eef1f6;
  --text: #0f151c;
  --muted: #5c6875;
  --accent: #2f6feb;
  --line: #dde3ec;
  --danger: #b42318;

  color-scheme: light;
}

/* ---------- reset ---------- */

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1 { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: 0.01em; }
p { margin: 0; }

button,
input { font: inherit; color: inherit; }

button { background: none; border: 0; padding: 0; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- view switch: the body carries data-view ---------- */

[data-view="login"] #app { display: none; }
[data-view="app"] #login-view { display: none; }

/* ---------- login ---------- */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  padding-top: calc(var(--space-4) + env(safe-area-inset-top));
}

.login-card {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

.login-title {
  font-size: 1.125rem;
  text-align: center;
  letter-spacing: 0.02em;
}

.login form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.login-error {
  color: var(--danger);
  font-size: 0.875rem;
  text-align: center;
}

/* ---------- inputs ---------- */

.input {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  appearance: none;
  -webkit-appearance: none;
}

.input::placeholder { color: var(--muted); }
.input:focus { border-color: var(--accent); outline: none; }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.search {
  font-size: 0.9375rem;
}

.btn {
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--elevated);
  color: var(--text);
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.btn:active { transform: translateY(1px); }

/* ---------- app shell ---------- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  padding-top: calc(var(--space-2) + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.9375rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.logout-form { display: flex; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  touch-action: manipulation;
}

.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn:active { background: var(--elevated); }

.icon-btn-small { width: 40px; height: 40px; }

.icon-btn-primary {
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: var(--bg);
}

.icon-btn-primary:hover { background: var(--accent); color: var(--bg); opacity: 0.92; }

.ico {
  width: 22px;
  height: 22px;
  display: block;
}

.icon-btn-primary .ico { width: 26px; height: 26px; }

#btn-play[data-state="playing"] .ico-play { display: none; }
#btn-play[data-state="playing"] .ico-pause { display: block; }
#btn-play:not([data-state="playing"]) .ico-pause { display: none; }

.searchbar {
  padding: var(--space-3) var(--space-4) var(--space-2);
}

.content {
  flex: 1 1 auto;
  padding: 0 var(--space-2) var(--space-3);
}

/* ---------- track list ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-card);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.list li:hover { background: var(--surface); }

.list li[data-current="true"] {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.list li[data-current="true"] .title { color: var(--accent); }

.row-art {
  width: 44px;
  height: 44px;
  border-radius: var(--space-2);
  object-fit: cover;
  background: var(--elevated);
  border: 1px solid var(--line);
}

.row-art-empty { display: block; }

.meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9375rem;
}

.artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--muted);
}

.dur {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding-left: var(--space-1);
}

.empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ---------- player ---------- */

.player {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.np {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.np-art {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: var(--space-2);
  object-fit: cover;
  background: var(--elevated);
  border: 1px solid var(--line);
}

.np-art:not([src]) { border-style: dashed; }

.np-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.np-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9375rem;
  font-weight: 600;
}

.np-artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--muted);
  min-height: 1.2em;
}

.np-extra {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 0 0 auto;
}

.seek-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.time {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 3.2em;
  text-align: center;
}

.seek {
  flex: 1 1 auto;
  min-width: 0;
  height: 24px;
  margin: 0;
  padding: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--elevated);
}

.seek::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.seek::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--elevated);
}

.seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.seek:disabled { opacity: 0.45; cursor: default; }

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

#audio {
  display: block;
  width: 100%;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  left: -9999px;
}

/* ---------- toast ---------- */

.toast {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translate(-50%, var(--space-1));
  max-width: min(22rem, calc(100% - 2 * var(--space-4)));
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--elevated);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 0.8125rem;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms;
  pointer-events: none;
}

.toast[data-visible="true"] {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  .topbar { padding-left: var(--space-3); padding-right: var(--space-3); }
  .searchbar { padding-left: var(--space-3); padding-right: var(--space-3); }
  .content { padding-left: var(--space-2); padding-right: var(--space-2); }
  .player { padding-left: var(--space-3); padding-right: var(--space-3); gap: var(--space-1); }
  .np-extra .icon-btn { width: 40px; height: 40px; }
  .list li { gap: var(--space-2); }
  .np-art { width: 46px; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
