/* ==========================================================================
   Spoood — monochrome paper-texture theme (brutalist)
   Two themes, true black & white:
     dark ("Night")  — black ground, white text, white lines
     light ("Day")   — white ground, black text, black lines
   Paper texture sits as a separate layer behind content:
     Light: normal paper texture (dark lines visible)
     Dark:  inverted paper texture (light lines visible against black)
   ========================================================================== */

:root {
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", ui-sans-serif, system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
}

/* Dark theme: black ground, white text */
[data-theme="dark"] {
  --bg: #000000;
  --surface: #000000;
  --surface-raised: #111111;
  --surface-sunken: #000000;
  --accent: #ffffff;
  --accent-ink: #000000;
  --accent-quiet: #b3b3b3;
  --accent-secondary: #ffffff;
  --live: #ffffff;
  --text: #ffffff;
  --text-muted: #888888;
  --error: #ff6b6b;
  --shadow: rgba(0, 0, 0, 0.5);
  --atmosphere-opacity: 0.15;
}

/* Light theme: white ground, black text */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-raised: #f0f0f0;
  --surface-sunken: #f8f8f8;
  --accent: #000000;
  --accent-ink: #ffffff;
  --accent-quiet: #ccccd0;
  --accent-secondary: #000000;
  --live: #000000;
  --text: #000000;
  --text-muted: #707070;
  --error: #d1373f;
  --shadow: rgba(0, 0, 0, 0.12);
  --atmosphere-opacity: 0.12;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* ---- Paper texture layer (separate from content) ---- */
/* This ::before is a fixed-position layer behind everything. */
/* Light mode: normal paper texture (dark lines visible on white) */
/* Dark mode: inverted paper texture (white lines visible on black) */

#app::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("assets/paper-texture.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  opacity: 0.06;
}

/* Dark mode: invert the texture image so paper lines appear as light
   (negative-space) lines against the dark background. */
[data-theme="dark"] #app::before {
  filter: invert(1) brightness(0.12);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1; /* above the paper-texture ::before */
}

#screen {
  flex: 1;
  padding-bottom: calc(96px + var(--safe-bottom));
}

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

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

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
}

img {
  display: block;
}

/* ---------- Atmosphere: a quiet color wash from the current artwork ---------- */

#atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.4);
  opacity: 0;
  transition: opacity 1.2s ease, background-image 0.6s ease;
  pointer-events: none;
}

#atmosphere.is-active {
  opacity: var(--atmosphere-opacity);
}

/* ---------- Shared state screens ---------- */

.state-screen {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.error-text {
  color: var(--error);
}

.empty-note {
  color: var(--text-muted);
  padding: 8px 24px 0;
}

/* ---------- Landing screen ---------- */

.landing-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px;
  text-align: center;
}

.landing-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 420px;
  width: 100%;
}

.landing-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(4rem, 14vw, 6rem);
  letter-spacing: -0.04em;
  line-height: 0.9;
  color: var(--accent);
  text-transform: uppercase;
  border: 4px solid var(--accent);
  padding: 16px 24px;
  background: var(--surface);
}

.landing-fineprint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.spotify-attribution {
  color: var(--text-muted);
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ---------- Buttons ---------- */

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 3px solid var(--accent);
  padding: 16px 28px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: transform 0.1s ease;
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-ghost {
  background: transparent;
  border: 3px solid var(--accent);
  color: var(--text);
  padding: 16px 28px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: background 0.1s ease, color 0.1s ease;
  width: 100%;
}

.btn-ghost:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--surface-raised);
}

.btn-icon-large {
  width: 56px;
  height: 56px;
  font-size: 1.6rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 50%;
}

.btn-icon-large:hover {
  opacity: 0.9;
}

.text-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 12px 24px 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-link:hover {
  color: var(--text);
}

/* ---------- Home screen ---------- */

.home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: calc(28px + var(--safe-top)) 24px 4px;
  gap: 16px;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.eq-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.eq-bar {
  width: 3px;
  background: var(--accent);
  animation: eq-bounce 1.1s ease-in-out infinite;
}

.eq-bar:nth-child(1) { height: 6px; animation-delay: -0.9s; }
.eq-bar:nth-child(2) { height: 14px; animation-delay: -0.5s; }
.eq-bar:nth-child(3) { height: 9px; animation-delay: -0.2s; }

@keyframes eq-bounce {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

.greeting {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.avatar-btn {
  background: var(--surface-raised);
  border: 3px solid var(--accent);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ---------- Filter ---------- */

.filter-box {
  padding: 12px 24px 0;
}

.filter-input {
  width: 100%;
  max-width: 360px;
  background: var(--surface-raised);
  border: 3px solid var(--accent);
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.95rem;
}

.filter-input::placeholder {
  color: var(--text-muted);
}

/* ---------- Library rows + grid ---------- */

.library-row {
  padding: 20px 24px 4px;
}

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

.row-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sort-select {
  background: var(--surface-raised);
  border: 3px solid var(--accent);
  color: var(--text-muted);
  padding: 8px 10px;
  font-size: 0.85rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
  padding: 4px 0 24px;
}

.playlist-card {
  position: relative;
}

.card-open {
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  transition: transform 0.18s ease;
}

.card-open:hover {
  transform: translateY(-3px);
}

.card-open:hover .card-art {
  transform: scale(1.015);
}

.card-open:active {
  transform: translateY(-1px) scale(0.99);
}

.card-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface);
  transition: transform 0.25s ease;
  border: 3px solid var(--surface-raised);
}

.card-art-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  color: var(--accent);
  background: linear-gradient(155deg, var(--surface-raised), var(--surface));
  border: 3px solid var(--surface-raised);
}

.card-name {
  font-weight: 600;
  font-size: 0.92rem;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: -6px;
}

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.playlist-card:hover .card-actions,
.playlist-card:focus-within .card-actions {
  opacity: 1;
}

.card-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.card-action-btn.is-active {
  color: var(--accent);
}

.playlist-card-hidden {
  opacity: 0.45;
}

/* ---------- Skeleton loading ---------- */

.skeleton {
  aspect-ratio: 1 / 1;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-raised) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}

/* ---------- Popovers / account menu ---------- */

.popover {
  position: fixed;
  top: calc(64px + var(--safe-top));
  right: 20px;
  background: var(--surface);
  border: 3px solid var(--accent);
  padding: 14px;
  min-width: 200px;
  box-shadow: 0 12px 32px var(--shadow);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popover-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popover-label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.segmented {
  display: flex;
  background: var(--surface-raised);
  border: 3px solid var(--accent);
  padding: 3px;
  gap: 2px;
}

.segmented-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.segmented-btn.is-active {
  background: var(--surface);
  color: var(--text);
}

.popover-item {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 8px 4px;
  font-size: 0.9rem;
  border-top: 3px solid var(--surface-raised);
  padding-top: 12px;
}

.popover-item:hover {
  color: var(--error);
}

/* ---------- Player screen (track list) ---------- */

.player-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: calc(24px + var(--safe-top)) 24px 16px;
}

.player-header h2 {
  font-size: 1.3rem;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 24px;
}

.track-row-btn {
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  color: var(--text);
  text-align: left;
}

.track-row-btn:hover {
  background: var(--surface-raised);
}

.track-row.playing .track-row-btn {
  background: var(--surface-raised);
  box-shadow: inset 3px 0 0 var(--live);
}

.track-row.playing .track-name {
  color: var(--live);
}

.track-index {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  width: 22px;
  flex-shrink: 0;
  text-align: right;
}

.track-art,
.card-art.small {
  width: 44px;
  height: 44px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--surface-raised);
}

.track-art-placeholder {
  background: var(--surface-raised);
}

.track-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.track-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.track-duration {
  color: var(--text-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ---------- Context (followed-playlist) screen ---------- */

.context-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 12px 24px 40px;
}

.context-art {
  width: min(260px, 58vw);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--surface-raised);
  margin-bottom: 14px;
}

.context-title {
  font-size: 1.7rem;
  font-style: italic;
}

.context-owner {
  color: var(--text-muted);
  margin: 0;
}

.context-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 340px;
  margin: 6px 0 4px;
}

.context-actions {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(112px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--error);
  color: #fff;
  padding: 10px 18px;
  border: 3px solid var(--error);
  font-size: 0.9rem;
  max-width: min(90vw, 420px);
  text-align: center;
  z-index: 100;
}

/* ---------- Now-playing bar ---------- */

.now-playing-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 3px solid var(--accent);
  padding: 10px 20px calc(10px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 84px;
  z-index: 30;
}

.now-playing-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 160px;
  flex-shrink: 0;
}

.now-playing-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing-artists {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing-art {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--surface-raised);
}

.now-playing-art.is-spinning {
  animation: vinyl-spin 6s linear infinite;
}

@keyframes vinyl-spin {
  to { transform: rotate(360deg); }
}

.transport {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.time-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  width: 38px;
  flex-shrink: 0;
  text-align: center;
}

.seek-slider {
  flex: 1;
  min-width: 80px;
  accent-color: var(--accent);
}

.volume-slider {
  width: 90px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

input[type="range"] {
  height: 40px;
}

/* ---------- Keyboard shortcuts modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 24px;
}

.modal {
  background: var(--surface);
  border: 3px solid var(--accent);
  padding: 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 60px var(--shadow);
}

.modal h2 {
  font-size: 1.2rem;
  font-style: italic;
  margin-bottom: 16px;
}

.shortcuts-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0 0 20px;
}

.shortcuts-list dt {
  font-family: var(--font-display);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.shortcuts-list dd {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ---------- Compact view ---------- */

.compact-view .card-grid {
  grid-template-columns: 1fr;
  gap: 2px;
}

.compact-view .card-open {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.compact-view .card-art {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.compact-view .card-meta {
  margin-top: 0;
}

/* ---------- Footer attribution ---------- */

.app-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 32px 24px 12px;
  text-align: center;
}

.footer-line {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.footer-creator {
  text-decoration: none;
  color: var(--text-muted);
}

.footer-creator:hover {
  color: var(--text);
}

.footer-brand {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-muted);
}

.footer-creator:hover .footer-brand {
  color: var(--accent);
}

.footer-spotify {
  opacity: 0.7;
}

/* ---------- About button + modal ---------- */

.btn-about {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 8px 16px;
  cursor: pointer;
}

.btn-about:hover {
  color: var(--accent);
}

.about-modal {
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
}

.about-modal h2 {
  font-style: normal;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.about-modal h3 {
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 6px;
  color: var(--text);
}

.about-lead {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 8px;
}

.about-modal p {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.about-domains-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 12px;
}

.about-domains-list li {
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--text-muted);
  padding-left: 0;
}

.about-domains-list code {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.82rem;
  background: var(--surface-raised);
  padding: 1px 6px;
}

.about-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0 0;
}

.about-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .now-playing-bar {
    flex-wrap: wrap;
    padding: 10px 14px calc(10px + var(--safe-bottom));
  }

  .now-playing-info {
    width: auto;
    flex: 1;
  }

  .seek-slider {
    order: 4;
    width: 100%;
    flex-basis: 100%;
  }

  .volume-slider {
    display: none;
  }

  .now-playing-bar:not(.is-expanded) .seek-slider,
  .now-playing-bar:not(.is-expanded) .time-label {
    display: none;
  }
}

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