/*
 * MUSIC APP — Brutalist Design System v2
 * Raw. Functional. High-contrast. No decoration.
 */

:root {
  --bg: #FAFAFA;
  --fg: #0A0A0A;
  --border: #0A0A0A;
  --bw: 3px;
  --accent: #E60000;
  --accent-hover: #B80000;
  --muted: #777777;
  --surface: #FFFFFF;
  --surface-alt: #F0F0F0;
  --green: #00A000;
  --blue: #2962FF;
  --font-mono: 'Courier New', 'Menlo', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── TYPOGRAPHY ──────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: -0.02em;
  font-weight: 700;
  line-height: 1.1;
}

h1 { font-size: clamp(1.5rem, 5vw, 2.4rem); }
h2 { font-size: clamp(1.1rem, 4vw, 1.6rem); }
h3 { font-size: clamp(0.9rem, 3vw, 1.2rem); }

/* ── BUTTONS ─────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: .65rem 1.1rem;
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 80ms, color 80ms, transform 80ms;
  border-radius: 0;
}

.btn:hover   { background: var(--fg); color: var(--surface); }
.btn:active  { background: var(--muted); border-color: var(--muted); color: var(--surface); transform: scale(0.96); }
.btn:focus-visible { outline: var(--bw) solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; transform: none; }

.btn--accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn--accent:active { background: var(--accent-hover); transform: scale(0.96); }

.btn--blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn--blue:hover { background: #1E4BD2; border-color: #1E4BD2; color: #fff; }

.btn--small {
  padding: .35rem .7rem;
  font-size: .68rem;
  min-height: 34px;
  min-width: 34px;
  --bw: 2px;
}

.btn--icon {
  padding: .5rem;
  font-size: 1.1rem;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
}

/* ── INPUTS ──────────────────────────────────────── */

input[type="text"],
input[type="search"],
input[type="url"] {
  font-family: var(--font-sans);
  font-size: 16px;
  padding: .65rem .85rem;
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  color: var(--fg);
  width: 100%;
  border-radius: 0;
  min-height: 44px;
  -webkit-appearance: none;
}

input:focus { outline: none; border-color: var(--accent); }
::placeholder { color: var(--muted); opacity: 1; }

/* ── LAYOUT ──────────────────────────────────────── */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

.app-main {
  flex: 1;
  padding: .75rem;
  padding-bottom: calc(152px + var(--safe-bottom));
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn .15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.app-header {
  padding: .75rem 1rem;
  border-bottom: var(--bw) solid var(--fg);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header h1 {
  font-size: .95rem;
  text-align: center;
}

/* ── NAVBAR ──────────────────────────────────────── */

.navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--surface);
  border-top: var(--bw) solid var(--fg);
  display: flex;
  justify-content: center;
  padding-bottom: var(--safe-bottom);
}

.navbar-inner {
  display: flex;
  width: 100%;
  max-width: 768px;
}

.navbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15rem;
  padding: .5rem .15rem;
  border: none;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
  transition: color 80ms, border 80ms, transform 80ms;
  border-top: 3px solid transparent;
}

.navbar button:hover  { color: var(--fg); }
.navbar button:active { transform: scale(0.94); }
.navbar button.active {
  color: var(--fg);
  border-top-color: var(--accent);
}

.navbar button svg { width: 20px; height: 20px; }

/* ── PLAYER BAR ──────────────────────────────────── */

.player-bar {
  position: fixed;
  bottom: calc(52px + var(--safe-bottom));
  left: 0;
  right: 0;
  z-index: 25;
  background: var(--surface);
  border-top: var(--bw) solid var(--fg);
  border-bottom: var(--bw) solid var(--fg);
  display: none;
}

.player-bar.active { display: block; }

.player-inner {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .75rem;
  max-width: 768px;
  margin: 0 auto;
}

.player-thumb {
  width: 38px;
  height: 38px;
  border: 2px solid var(--fg);
  flex-shrink: 0;
  object-fit: cover;
}

.player-info {
  flex: 1;
  min-width: 0;
}

.player-title {
  font-weight: 700;
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-sub {
  font-size: .65rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.player-ctrl {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--fg);
  background: var(--surface);
  cursor: pointer;
  font-size: .9rem;
  color: var(--fg);
  transition: background 80ms, color 80ms, transform 80ms;
  -webkit-tap-highlight-color: transparent;
  border-radius: 0;
}

.player-ctrl:hover  { background: var(--fg); color: var(--surface); }
.player-ctrl:active { transform: scale(0.9); }

/* ── PROGRESS BAR ────────────────────────────────── */

.progress-bar {
  height: 5px;
  background: var(--surface-alt);
  border-top: 2px solid var(--fg);
  cursor: pointer;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width .1s linear;
}

/* ── FULL-SCREEN PLAYER ────────────────────────── */

.fs-player {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--surface);
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: fsUp .2s ease-out;
}

.fs-player.active { display: flex; }

@keyframes fsUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.fs-close {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  left: 1rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--fg);
  z-index: 5;
  transition: background 80ms, color 80ms, transform 80ms;
  -webkit-tap-highlight-color: transparent;
}
.fs-close:hover  { background: var(--fg); color: var(--surface); }
.fs-close:active { transform: scale(0.9); }

.fs-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem 2rem;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.fs-thumb {
  width: min(70vw, 320px);
  aspect-ratio: 1;
  border: var(--bw) solid var(--fg);
  object-fit: cover;
  margin-bottom: 1.5rem;
  background: var(--surface-alt);
}

.fs-info {
  width: 100%;
  text-align: center;
  margin-bottom: 1.5rem;
}

.fs-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: .2rem;
}

.fs-sub {
  font-size: .75rem;
  color: var(--muted);
}

.fs-progress-wrap {
  width: 100%;
  margin-bottom: 1.5rem;
}

.fs-progress {
  height: 8px;
  background: var(--surface-alt);
  border: 2px solid var(--fg);
  cursor: pointer;
  position: relative;
  margin-bottom: .3rem;
}

.fs-fill {
  height: 100%;
  background: var(--accent);
  transition: width .1s linear;
}

.fs-times {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: .65rem;
  font-weight: 700;
  color: var(--muted);
}

.fs-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.fs-ctrl {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--fg);
  transition: background 80ms, color 80ms, transform 80ms;
  -webkit-tap-highlight-color: transparent;
}
.fs-ctrl:hover  { background: var(--fg); color: var(--surface); }
.fs-ctrl:active { transform: scale(0.9); }

.fs-play {
  width: 64px;
  height: 64px;
  font-size: 1.4rem;
  border-width: var(--bw);
}

/* ── CARDS & SECTIONS ────────────────────────────── */

.card {
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  padding: .85rem;
  margin-bottom: .75rem;
}

.card--dashed { border-style: dashed; }

.section-title {
  font-family: var(--font-mono);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: .6rem;
  margin-top: 1.25rem;
}

/* ── SONG ROW ────────────────────────────────────── */

.song-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .4rem;
  border-bottom: 2px solid var(--surface-alt);
  cursor: pointer;
  transition: background 80ms;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.song-row:hover   { background: var(--surface-alt); }
.song-row:active  { background: var(--fg); color: var(--surface); transform: scale(0.995); }
.song-row:active .song-sub { color: var(--muted); }

.song-row--playing {
  background: var(--fg);
  color: var(--surface);
}
.song-row--playing .song-sub { color: var(--surface-alt); }

.song-index {
  font-family: var(--font-mono);
  font-size: .7rem;
  font-weight: 700;
  min-width: 26px;
  text-align: center;
  color: var(--muted);
}

.song-row--playing .song-index { color: var(--accent); }

.song-thumb {
  width: 40px;
  height: 40px;
  border: 2px solid var(--fg);
  flex-shrink: 0;
  object-fit: cover;
}

.song-meta {
  flex: 1;
  min-width: 0;
}

.song-title {
  font-weight: 700;
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-sub {
  font-size: .65rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── SEARCH ──────────────────────────────────────── */

.search-results { margin-top: .6rem; }

.search-result {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .4rem;
  border-bottom: 2px solid var(--surface-alt);
  transition: background 80ms;
}

.search-result:hover { background: var(--surface-alt); }

.search-result .song-meta { flex: 1; min-width: 0; }

.result-actions {
  display: flex;
  gap: .3rem;
  flex-shrink: 0;
}

/* ── PLAYLIST CARD ───────────────────────────────── */

.playlist-card {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem;
  border: var(--bw) solid var(--fg);
  margin-bottom: .4rem;
  cursor: pointer;
  transition: background 80ms, transform 80ms;
  -webkit-tap-highlight-color: transparent;
}

.playlist-card:hover  { background: var(--fg); color: var(--surface); }
.playlist-card:active { transform: scale(0.98); }
.playlist-card:hover .playlist-card-icon,
.playlist-card:hover .playlist-card-count { color: var(--surface); border-color: var(--surface); }

.playlist-card-icon {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--fg);
  flex-shrink: 0;
  transition: border-color 80ms, color 80ms;
}

.playlist-card-meta { flex: 1; min-width: 0; }

.playlist-card-name {
  font-weight: 700;
  font-size: .82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-card-count {
  font-size: .65rem;
  color: var(--muted);
  transition: color 80ms;
}

/* ── SONG GRID (2 cols) ─────────────────────────── */

.song-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.song-card {
  border: 2px solid var(--fg);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: transform 80ms;
  -webkit-tap-highlight-color: transparent;
}
.song-card:active { transform: scale(0.97); }

.song-card-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  border-bottom: 2px solid var(--fg);
  background: var(--surface-alt);
}

.song-card-body {
  padding: .4rem .5rem .5rem;
}

.song-card-title {
  font-weight: 700;
  font-size: .7rem;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  margin-bottom: .05rem;
}

.song-card-sub {
  font-size: .6rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── MODAL ────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.8);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: .5rem;
  animation: overlayIn .15s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: var(--bw) solid var(--fg);
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  animation: modalUp .2s ease-out;
}

@keyframes modalUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem;
  border-bottom: var(--bw) solid var(--fg);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-weight: 700;
  font-size: .9rem;
}

.modal-close {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--fg);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  transition: background 80ms, color 80ms, transform 80ms;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover  { background: var(--fg); color: var(--surface); }
.modal-close:active { transform: scale(0.9); }

.modal-body {
  padding: .75rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: .6rem .75rem;
  border-top: var(--bw) solid var(--fg);
  display: flex;
  gap: .5rem;
  flex-shrink: 0;
}

.modal-footer .btn { flex: 1; }

/* ── MODAL SONG SELECTION ────────────────────────── */

.modal-song-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .3rem;
  border-bottom: 1px solid var(--surface-alt);
  cursor: pointer;
  transition: background 80ms;
}

.modal-song-row:hover { background: var(--surface-alt); }

.modal-song-row .song-thumb { width: 36px; height: 36px; }

.modal-song-row.added {
  opacity: .5;
  pointer-events: none;
}

.modal-filter {
  margin-bottom: .5rem;
}

.modal-filter input {
  border-width: 2px;
  min-height: 38px;
  font-size: 16px;
  padding: .45rem .7rem;
}

/* ── REORDER BUTTONS ─────────────────────────────── */

.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.reorder-btns button {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--fg);
  background: var(--surface);
  cursor: pointer;
  font-size: .55rem;
  font-weight: 700;
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  transition: background 80ms, transform 80ms;
}

.reorder-btns button:hover  { background: var(--fg); color: var(--surface); }
.reorder-btns button:active { transform: scale(0.85); }

/* ── UTILITY ─────────────────────────────────────── */

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.text-mono   { font-family: var(--font-mono); }

.mb05 { margin-bottom: .25rem; }
.mb1  { margin-bottom: .5rem; }
.mb2  { margin-bottom: .75rem; }
.mb3  { margin-bottom: 1.25rem; }
.mt1  { margin-top: .5rem; }
.mt2  { margin-top: .75rem; }

.flex-space {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
}

.flex-gap { display: flex; gap: .4rem; flex-wrap: wrap; }

.badge {
  font-family: var(--font-mono);
  font-size: .58rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: .12rem .4rem;
  border: 2px solid var(--fg);
  display: inline-flex;
  align-items: center;
  gap: .2rem;
}

.box {
  border: var(--bw) solid var(--fg);
  background: var(--surface);
  padding: .4rem .8rem;
}

/* ── EMPTY STATE ─────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  border: var(--bw) solid var(--fg);
  border-style: dashed;
}

.empty-state-icon {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: .6rem;
  color: var(--muted);
}

.empty-state p {
  font-size: .8rem;
  color: var(--muted);
  max-width: 260px;
  margin: 0 auto;
}

/* ── INLINE FORM ─────────────────────────────────── */

.inline-form {
  display: flex;
  gap: .4rem;
}

.inline-form input { flex: 1; }
.inline-form .btn  { flex-shrink: 0; }

/* ── TOAST ───────────────────────────────────────── */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .7rem;
  text-transform: uppercase;
  padding: .5rem 1rem;
  border: var(--bw) solid var(--fg);
  background: var(--fg);
  color: var(--surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  white-space: nowrap;
}

.toast.show { opacity: 1; }

/* ── DIVIDER ─────────────────────────────────────── */

.hr {
  border: none;
  border-bottom: var(--bw) solid var(--fg);
  margin: .75rem 0;
}

/* ── RESPONSIVE ──────────────────────────────────── */

@media (min-width: 768px) {
  .app-main { padding: 1.25rem 2rem; }
  .modal-overlay { align-items: center; }
  .modal {
    max-height: 70vh;
    border-width: var(--bw);
  }
  .navbar button { min-height: 56px; font-size: .62rem; }
  .navbar button svg { width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
