/* KletsMusic — layout: sidebar | content, a fixed player along the bottom, detail drawer on the right.
   The speech bubble (klets = chat) is the visual motif: logo, comment bubbles, rounded "talk" chips. */
:root {
  --bg: #121118;
  --panel: #19181f;
  --raise: #23222c;
  --hover: #2b2a36;
  --line: #312f3d;
  --fg: #f4f1ea;
  --muted: #a4a0b0;
  --accent: #ffcf3a;
  --accent-ink: #1d1600;
  --accent-text: #ffcf3a;
  --love: #ff6b9a;
  --danger: #ff7a6b;
  --shadow: 0 18px 50px rgb(0 0 0 / .45);
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  --player-h: 88px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f1f5; --panel: #ffffff; --raise: #ecebf1; --hover: #e4e2ea; --line: #dcdae3;
    --fg: #17161d; --muted: #67636f; --accent: #ffcf3a; --accent-ink: #1d1600; --accent-text: #8a6200;
    --love: #e0336c; --danger: #c43a2b; --shadow: 0 18px 50px rgb(20 18 30 / .16);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.45 var(--body); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; letter-spacing: -.01em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px;
  padding: 10px 18px; font-weight: 600; background: var(--raise); white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0;
  border-radius: 50%; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn[aria-pressed="true"] { color: var(--accent-text); }
.icon-btn.liked, .btn.liked { color: var(--love); }
.link-btn { border: 0; background: none; color: var(--muted); padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--fg); }

/* ---------- logo ---------- */
.logo { width: 34px; height: 34px; }
.logo svg { width: 100%; height: 100%; }
.logo-big { width: 72px; height: 72px; margin-bottom: 8px; }

/* ---------- login ---------- */
.login {
  min-height: 100%; display: grid; place-items: center;
  padding: 32px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(600px 400px at 20% 10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(500px 400px at 85% 90%, color-mix(in srgb, var(--love) 12%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 32px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 34px; font-weight: 800; }
.login-card p { margin: 0 0 8px; }
.accounts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.account {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 8px;
  border: 2px solid var(--line); border-radius: 16px; background: var(--raise);
  font: 800 16px var(--display); letter-spacing: .02em;
}
.account .avatar { width: 44px; height: 44px; font-size: 20px; }
.account:hover { border-color: var(--muted); }
.account[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--raise)); }
.login-card label { font-weight: 600; font-size: 13px; margin-top: 6px; }
.login-card .btn { justify-content: center; margin-top: 12px; padding: 12px; }
input[type="text"], input[type="password"], input:not([type]), input[type="search"], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--raise); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
.error { color: var(--danger); margin: 0; }

/* ---------- app shell ---------- */
.app {
  height: 100%; display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "side main" "player player";
}
.app.has-detail { grid-template-columns: 250px minmax(0, 1fr) 360px; grid-template-areas: "side main detail" "player player player"; }

.sidebar {
  grid-area: side; display: flex; flex-direction: column; gap: 6px; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line); padding: 20px 12px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 14px; font: 800 20px var(--display); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 500; min-width: 0;
}
.nav-link span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link:hover { background: var(--hover); color: var(--fg); }
.nav-link.active { background: var(--raise); color: var(--fg); }
.nav-link.active svg { color: var(--accent-text); }
.nav-link .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pl-dot { width: 20px; height: 20px; border-radius: 6px; flex: none; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--accent-ink); }
.side-head {
  display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding: 0 4px 0 10px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.nav-playlists { overflow-y: auto; flex: 1; min-height: 0; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 10px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font: 700 12px var(--display); color: #17120a;
}
.avatar.sm { width: 18px; height: 18px; font-size: 10px; }

.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.menu-btn { display: none; }
.search { flex: 1; max-width: 420px; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--muted); width: 18px; height: 18px; }
.search input { padding-left: 38px; border-radius: 999px; }
.topbar .btn-primary { margin-left: auto; }
.view { flex: 1; overflow-y: auto; padding: 28px 28px 40px; }

/* ---------- view header ---------- */
.vh { display: flex; align-items: flex-end; gap: 22px; margin-bottom: 24px; flex-wrap: wrap; }
.vh-art {
  width: 132px; height: 132px; border-radius: 18px; flex: none; display: grid; place-items: center;
  font: 800 56px var(--display); color: var(--accent-ink); box-shadow: var(--shadow);
}
.vh-text { min-width: 0; flex: 1; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.vh h1 { font-size: clamp(30px, 5vw, 52px); font-weight: 800; line-height: 1.02; margin: 4px 0 8px; overflow-wrap: anywhere; }
.vh h1[contenteditable="true"] { outline: none; border-bottom: 2px dashed var(--line); }
.vh h1[contenteditable="true"]:focus { border-bottom-color: var(--accent); }
.vh-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
}
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---------- track list ---------- */
.tracks { display: flex; flex-direction: column; }
.track {
  display: grid; align-items: center; gap: 14px;
  grid-template-columns: 28px 44px minmax(0, 1.6fr) minmax(0, 1fr) 54px 124px;
  padding: 7px 10px; border-radius: 10px;
}
.track:hover { background: var(--raise); }
.track.playing { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.track.playing .t-title { color: var(--accent-text); }
.t-num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; position: relative; }
.t-num .t-play { display: none; position: absolute; right: -6px; top: 50%; translate: 0 -50%; }
.track:hover .t-num .n { visibility: hidden; }
.track:hover .t-num .t-play { display: inline-grid; }
.t-main { min-width: 0; cursor: pointer; }
.t-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-artist { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-by { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; min-width: 0; }
.t-by span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-dur { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.t-actions { display: flex; align-items: center; gap: 0; }
.t-actions .icon-btn { width: 32px; height: 32px; }
.t-actions svg { width: 18px; height: 18px; }
.badge { font-size: 11px; font-variant-numeric: tabular-nums; margin-left: -4px; min-width: 12px; color: var(--muted); }
.list-head {
  display: grid; gap: 14px; grid-template-columns: 28px 44px minmax(0, 1.6fr) minmax(0, 1fr) 54px 124px;
  padding: 0 10px 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.list-head .r { text-align: right; }

.cover {
  width: 44px; height: 44px; border-radius: 8px; flex: none; background-size: cover; background-position: center;
  display: grid; place-items: center; font: 800 18px var(--display); color: var(--accent-ink);
}
.cover-np { width: 56px; height: 56px; font-size: 22px; background: var(--raise); }

/* ---------- empty states ---------- */
.empty {
  border: 2px dashed var(--line); border-radius: 20px; padding: 48px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 560px; margin: 24px auto;
}
.empty h2 { font-size: 24px; }
.empty p { margin: 0; color: var(--muted); max-width: 40ch; }

/* ---------- kletshoek feed ---------- */
.feed { display: flex; flex-direction: column; gap: 14px; max-width: 720px; }
.post {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.post-head { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.post-head b { color: var(--fg); }
.post-track { display: flex; align-items: center; gap: 12px; min-width: 0; }
.post-track .cover { width: 56px; height: 56px; font-size: 22px; }
.post-track .t-main { flex: 1; }
.post .composer input { padding: 8px 14px; }
.bubble {
  position: relative; background: var(--raise); padding: 9px 13px; border-radius: 16px 16px 16px 4px;
  max-width: 100%; overflow-wrap: anywhere; align-self: flex-start;
}
.bubble.mine { background: color-mix(in srgb, var(--accent) 22%, var(--raise)); border-radius: 16px 16px 4px 16px; align-self: flex-end; }
.bubble .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; display: flex; gap: 6px; align-items: center; }

.ts {
  display: inline; border: 0; padding: 0 5px; margin: 0 1px; border-radius: 6px; font: inherit; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--accent-text); background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.ts:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- detail drawer ---------- */
.detail {
  grid-area: detail; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; overflow-y: auto;
  padding: 18px 20px 24px; display: flex; flex-direction: column; gap: 16px;
}
.detail-top { display: flex; justify-content: space-between; align-items: center; }
.detail-head { display: flex; gap: 14px; align-items: center; }
.detail-title { min-width: 0; }
.cover.detail-cover { width: 88px; height: 88px; border-radius: 12px; font-size: 36px; }
.detail h2 { font-size: 24px; overflow-wrap: anywhere; }
.detail .field { display: flex; flex-direction: column; gap: 6px; }
.detail .field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.thread { display: flex; flex-direction: column; gap: 8px; }
.composer { display: flex; gap: 8px; }
.composer input { border-radius: 999px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- player ---------- */
.player {
  grid-area: player; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: center; gap: 20px; min-height: var(--player-h);
  padding: 12px max(20px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--panel); border-top: 1px solid var(--line);
}
.np { display: flex; align-items: center; gap: 12px; min-width: 0; }
.np-text { min-width: 0; }
.np-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.buttons { display: flex; align-items: center; gap: 8px; }
.play-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--fg); color: var(--bg);
  display: grid; place-items: center;
}
.play-btn:hover { transform: scale(1.05); }
.seek { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 560px; }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 36px; text-align: center; }
.vol { display: flex; align-items: center; gap: 8px; justify-content: flex-end; color: var(--muted); }
.vol input[type="range"] { flex: none; width: 120px; }
input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 0; height: 18px; }

/* ---------- popover menu ---------- */
.popover {
  position: fixed; z-index: 50; min-width: 220px; max-width: calc(100vw - 32px); max-height: 60vh; overflow-y: auto;
  background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: var(--shadow);
}
.popover .mi {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none;
  padding: 9px 10px; border-radius: 8px;
}
.popover .mi:hover { background: var(--hover); }
.popover .mi.danger { color: var(--danger); }
.popover .sep { height: 1px; background: var(--line); margin: 4px 0; }
.popover .label { font-size: 11px; color: var(--muted); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- confirm dialog ---------- */
.ask {
  width: min(400px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  background: var(--panel); color: var(--fg); box-shadow: var(--shadow);
}
.ask::backdrop { background: rgb(0 0 0 / .5); }
.ask h2 { font-size: 20px; overflow-wrap: anywhere; }
.ask p { margin: 8px 0 18px; }
.ask-buttons { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }

/* ---------- dropzone + toasts ---------- */
.dropzone {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(4px);
}
.dropzone div {
  border: 3px dashed var(--accent); border-radius: 28px; padding: 60px 80px; font: 800 32px var(--display); color: var(--accent-text);
}
.toasts {
  position: fixed; z-index: 70; right: max(16px, env(safe-area-inset-right)); bottom: calc(var(--player-h) + 16px);
  display: flex; flex-direction: column; gap: 8px; width: min(340px, calc(100vw - 32px));
}
.toast {
  background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
}
.toast .bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.toast .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.toast.err { border-color: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .app.has-detail { grid-template-columns: 250px minmax(0, 1fr); grid-template-areas: "side main" "player player"; }
  .detail { position: fixed; z-index: 40; top: 0; right: 0; bottom: var(--player-h); width: min(380px, 100%); box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .app, .app.has-detail { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "player"; }
  .sidebar {
    position: fixed; z-index: 45; top: 0; bottom: 0; left: 0; width: min(290px, 85vw);
    padding-top: calc(20px + env(safe-area-inset-top)); translate: -100% 0; transition: translate .2s;
  }
  .sidebar.open { translate: 0 0; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 0; z-index: 44; background: rgb(0 0 0 / .45); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); gap: 8px; }
  .topbar .btn-primary span { display: none; }
  .topbar .btn-primary { padding: 10px; }
  .view { padding: 20px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); }
  .list-head { display: none; }
  .track { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; padding: 7px 4px; }
  .track .t-num, .track .t-by, .track .t-dur { display: none; }
  .vh-art { width: 88px; height: 88px; font-size: 38px; }
  .player { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "np buttons" "seek seek"; gap: 6px 12px; padding-top: 10px; }
  .np { grid-area: np; }
  .controls { display: contents; }
  .buttons { grid-area: buttons; gap: 2px; }
  .buttons #shuffle, .buttons #repeat { display: none; }
  .seek { grid-area: seek; max-width: none; }
  .vol { display: none; }
  .cover-np { width: 44px; height: 44px; }
  .detail { bottom: var(--player-h); top: 0; width: 100%; padding-top: calc(18px + env(safe-area-inset-top)); z-index: 46; }
  .toasts { bottom: calc(var(--player-h) + 40px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
