:root {
  --bg: #0d0d0e;
  --bg-raised: #17181a;
  --border: #2a2b2e;
  --text: #e8e8e8;
  --text-dim: #9a9a9c;
  --accent: #e5a00d;
  --accent-dim: #a3760c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* iOS Safari's address/tab bar shows and hides as you scroll, and neither
   100vh (assumes the bar is hidden — too tall) nor 100dvh (inconsistent
   across iOS Safari versions) reliably tracks the real visible height. The
   --vh custom property is computed from visualViewport in app.js, which
   does track it correctly, with 100vh/100dvh as fallbacks if JS hasn't run
   yet or the property is unsupported. */
.screen { height: 100vh; height: 100dvh; height: calc(var(--vh, 1vh) * 100); }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  text-align: center;
  max-width: 320px;
  width: 100%;
  padding: 0 1.5em;
}
.login-box:has(.login-details:not(.hidden)) { max-width: 440px; }
.login-box h1 {
  color: var(--accent);
  letter-spacing: 0.05em;
}
#login-btn {
  background: var(--accent);
  color: #1a1200;
  border: none;
  padding: 0.75em 1.5em;
  border-radius: 6px;
  font-size: 1em;
  font-weight: 600;
}
#login-btn:hover { background: #f5b423; }
.status { color: var(--text-dim); font-size: 0.85em; min-height: 1.2em; }
.login-details {
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7em 0.9em;
  margin-top: 1em;
  font-size: 0.72em;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 40vh;
  overflow-y: auto;
}

/* App layout */
#app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas: "sidebar content" "nowplaying nowplaying";
}

#mobile-bar {
  display: none;
  align-items: center;
  gap: 0.75em;
  padding: calc(0.7em + env(safe-area-inset-top)) 1em 0.7em;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}
#mobile-bar h1 {
  color: var(--accent);
  font-size: 1.1em;
  margin: 0;
  letter-spacing: 0.05em;
}
#menu-toggle {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3em;
  padding: 0.1em 0.3em;
}

#sidebar-backdrop {
  display: none;
}

#sidebar {
  grid-area: sidebar;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  padding: calc(1em + env(safe-area-inset-top)) 1em calc(1em + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1em;
  overflow-y: auto;
}
#sidebar h1 {
  color: var(--accent);
  font-size: 1.3em;
  margin: 0.2em 0 0.5em;
  letter-spacing: 0.05em;
}
#sidebar nav { display: flex; flex-direction: column; gap: 0.25em; }
.nav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  text-align: left;
  padding: 0.5em 0.6em;
  border-radius: 6px;
  font-size: 0.95em;
}
.nav-btn:hover { background: #222327; color: var(--text); }
.nav-btn.active { background: #262218; color: var(--accent); }

.search-box input {
  width: 100%;
  padding: 0.5em 0.7em;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0a0a0b;
  color: var(--text);
}

.library-select {
  width: 100%;
  padding: 0.5em 0.6em;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0a0a0b;
  color: var(--text);
  font-size: 0.85em;
}

.server-info {
  margin-top: auto;
  font-size: 0.75em;
  color: var(--text-dim);
  line-height: 1.4;
}

#logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.5em;
  border-radius: 6px;
}
#logout-btn:hover { color: var(--text); border-color: var(--text-dim); }

#content {
  grid-area: content;
  overflow-y: auto;
  padding: 1.5em 2em;
}

.view h2 {
  margin-top: 0;
  font-weight: 500;
}

.section-heading {
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 1.5em 0 0.75em;
}
.section-heading:first-child { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.2em;
}

.card {
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-raised);
}
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #1e1f22;
}
.card .card-title {
  padding: 0.5em 0.6em 0.1em;
  font-size: 0.9em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .card-sub {
  padding: 0 0.6em 0.6em;
  font-size: 0.78em;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card:hover .card-title { color: var(--accent); }

.list-row {
  cursor: pointer;
  border-radius: 6px;
}
.list-row:hover { background: var(--bg-raised); }

/* Artist grid uses circular art */
.card.artist img { border-radius: 50%; }

/* Album detail */
.album-header {
  display: flex;
  gap: 1.5em;
  align-items: flex-end;
  margin-bottom: 1.5em;
}
.album-header img {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: 6px;
  background: #1e1f22;
}
.album-header h2 { margin: 0 0 0.2em; }
.album-header .sub { color: var(--text-dim); }

.track-row {
  display: grid;
  grid-template-columns: 2em 1fr auto auto;
  gap: 0.75em;
  align-items: center;
  padding: 0.5em 0.6em;
  border-radius: 6px;
  cursor: pointer;
}
.track-row:hover { background: var(--bg-raised); }
.track-row.playing { color: var(--accent); }
.track-row .idx { color: var(--text-dim); text-align: right; }
.track-row .dur { color: var(--text-dim); font-size: 0.85em; }

/* Simple text rows — Library index, tag lists (genres/styles/moods/labels/folders) */
.simple-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9em 0.6em;
  border-radius: 6px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.simple-row:hover { background: var(--bg-raised); }
.simple-row .row-title { font-size: 1em; }
.simple-row .row-sub { color: var(--text-dim); font-size: 0.85em; }
.simple-row .row-chevron { color: var(--text-dim); font-size: 1.1em; margin-left: 1em; }

.back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  margin-bottom: 1em;
  padding: 0;
  font-size: 0.9em;
}
.back-btn:hover { color: var(--text); }

/* Now playing bar */
#now-playing {
  grid-area: nowplaying;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(200px, 2fr) auto;
  align-items: center;
  gap: 1.5em;
  padding: 0.6em 1.5em calc(0.6em + env(safe-area-inset-bottom));
  cursor: pointer;
}
.np-meta { display: flex; align-items: center; gap: 0.7em; overflow: hidden; }
.np-meta img {
  width: 46px; height: 46px; border-radius: 4px; object-fit: cover; background: #1e1f22;
}
.np-text { overflow: hidden; }
#np-title { font-size: 0.9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#np-artist { font-size: 0.78em; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.np-controls { display: flex; gap: 0.8em; align-items: center; }
.np-controls button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2em;
}
.np-controls button:hover { color: var(--accent); }
#np-play { font-size: 1.5em; }

/* These are full-color emoji glyphs, so CSS `color` can't distinguish
   active/inactive state — opacity works on any glyph, colored or not. */
.control-toggle { font-size: 1em; opacity: 0.4; position: relative; transition: opacity 0.15s ease; }
.control-toggle:hover { opacity: 0.7; }
.control-toggle.active { opacity: 1; }
.control-toggle.active:hover { opacity: 1; }
.control-toggle.repeat-one::after {
  content: "1";
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: 0.55em;
  background: var(--accent);
  color: #1a1200;
  border-radius: 50%;
  width: 1.2em;
  height: 1.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.np-progress { display: flex; align-items: center; gap: 0.6em; font-size: 0.75em; color: var(--text-dim); }
.np-progress input[type=range] { flex: 1; }

.np-volume { display: flex; align-items: center; gap: 0.4em; }
.np-volume input[type=range] { width: 80px; }

input[type=range] {
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

@media (max-width: 700px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "mobilebar" "content" "nowplaying";
  }
  #mobile-bar { display: flex; grid-area: mobilebar; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 80vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
  }
  #sidebar.open { transform: translateX(0); }

  #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
  }
  #sidebar-backdrop.hidden { display: none; }

  #now-playing { grid-template-columns: 1fr auto; grid-template-areas: "meta controls" "progress progress"; }
  .np-progress { grid-column: 1 / -1; }
  .np-volume { display: none; }
  /* Mini-player stays minimal on mobile — shuffle/repeat live in the
     full-screen view (opened by tapping the mini-player) instead. */
  #now-playing .control-toggle { display: none; }
}

/* Full-screen now-playing overlay */
.now-playing-full {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(1em + env(safe-area-inset-top)) 1.5em calc(2em + env(safe-area-inset-bottom));
  transform: translateY(0);
  transition: transform 0.3s ease;
}
.now-playing-full.hidden { transform: translateY(100%); display: flex !important; visibility: hidden; }

.fs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.fs-header button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.6em;
  line-height: 1;
  padding: 0.2em 0.4em;
}
.fs-header-title {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.fs-header-actions { display: flex; gap: 0.5em; }
.fs-header-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.7em !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35em 0.6em !important;
  border-radius: 20px;
}
.fs-header-btn.active { color: var(--accent); border-color: var(--accent-dim); }

#fs-main-view, #fs-lyrics-view, #fs-queue-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#fs-lyrics-view.hidden, #fs-queue-view.hidden, #fs-main-view.hidden { display: none; }

.fs-art-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.fs-art-wrap img {
  max-width: min(80vw, 420px);
  max-height: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: var(--bg-raised);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.fs-meta { text-align: center; margin: 1.2em 0 0.5em; flex-shrink: 0; }
#fs-title { font-size: 1.3em; font-weight: 600; }
#fs-artist { color: var(--text-dim); margin-top: 0.3em; }

/* Lyrics */
#fs-lyrics-view { overflow-y: auto; padding: 1em 0; }
.lyrics-line {
  padding: 0.5em 0.2em;
  font-size: 1.15em;
  color: var(--text-dim);
  text-align: center;
  transition: color 0.2s ease;
}
.lyrics-line.current { color: var(--text); font-weight: 600; }

/* Queue */
#fs-queue-view { overflow-y: auto; }
.queue-row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.5em 0.3em;
  border-bottom: 1px solid var(--border);
}
.queue-row.current .queue-row-title { color: var(--accent); }
.queue-row-main { flex: 1; overflow: hidden; cursor: pointer; }
.queue-row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-row-sub { color: var(--text-dim); font-size: 0.8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-row-actions { display: flex; gap: 0.3em; flex-shrink: 0; }
.queue-row-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1em;
  padding: 0.2em 0.4em;
}
.queue-row-actions button:hover { color: var(--text); }
.queue-section-heading {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 0.8em 0.3em 0.3em;
}

.add-to-queue-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1em;
  padding: 0 0.4em;
  flex-shrink: 0;
}
.add-to-queue-btn:hover { color: var(--accent); }

.fs-progress { flex-shrink: 0; margin: 1em 0; }
.fs-progress input[type=range] { width: 100%; }
.fs-times { display: flex; justify-content: space-between; font-size: 0.75em; color: var(--text-dim); margin-top: 0.3em; }

.fs-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.8em;
  flex-shrink: 0;
}
.fs-controls button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.6em;
}
.fs-controls .control-toggle { font-size: 1.1em; }
#fs-play { font-size: 2.6em; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6em + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(0);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7em 1.2em;
  border-radius: 8px;
  font-size: 0.9em;
  z-index: 400;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }

/* A little something for anyone clicking the logo too many times */
@keyframes discoHue {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}
body.disco { animation: discoHue 1.2s linear infinite; }
#sidebar-logo, #mobile-bar h1 { cursor: pointer; user-select: none; }
