:root {
  --bg: #121212;
  --head: #161616;
  --card: #1c1c1c;
  --card2: #262626;
  --line: #2c2c2c;
  --text: #fff;
  --muted: #a7a7a7;
  --green: #1ed760;
  --green-bg: #173a24;
  --red: #f3727f;
  --red-bg: #3a1a1e;
  --radius: 22px;
}

* { box-sizing: border-box; margin: 0; }
/* Thin dark scroll bars instead of the browser's chunky white ones */
* { scrollbar-width: thin; scrollbar-color: #3a3a3a transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }
html, body { height: 100%; }
body {
  background: radial-gradient(120% 55% at 50% 0%, #2b2020 0%, var(--bg) 65%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
a { color: inherit; }
.hidden { display: none !important; }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  background: var(--head);
  border-bottom: 1px solid #1f1f1f;
}
.titles { flex: 1; min-width: 0; }
.topbar h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.icon { width: 44px; height: 44px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; flex: none; }
.icon svg { width: 20px; height: 20px; }

main { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 520px; margin: 0 auto; padding: 16px; min-height: 0; }

/* Generic */
.center { flex: 1; display: grid; place-items: center; text-align: center; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 340px; }
.hero h2 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.hero p { color: var(--muted); }
.logo { width: 72px; height: 72px; border-radius: 22px; background: var(--green-bg); display: grid; place-items: center; color: var(--green); }
.logo svg { width: 36px; height: 36px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 24px; border-radius: 999px; font-weight: 700; text-decoration: none; width: 100%; }
.btn.primary { background: var(--green); color: #000; }
.btn.ghost { background: var(--card2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--red); font-size: 14px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--card2); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Playlist list */
.list { display: flex; flex-direction: column; gap: 10px; }
.list .note { margin-bottom: 4px; }
.pl { display: flex; align-items: center; gap: 14px; padding: 12px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 18px; width: 100%; }
.pl img, .pl .ph { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--card2); }
.pl div { min-width: 0; display: flex; flex-direction: column; }
.pl strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl span { color: var(--muted); font-size: 14px; }
.pl .tag { color: var(--green); }
/* Playlist row: the box is the row, so the reset icon sits inside it on the right */
.row { display: flex; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.row .pl { flex: 1; min-width: 0; background: none; border: 0; }
.row .reset { width: 40px; height: 40px; margin-right: 10px; background: none; color: var(--muted); }
.row .reset svg { width: 18px; height: 18px; }
.row .reset:active { color: var(--text); }

/* Swipe */
.swipe { flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.bar { height: 4px; background: var(--card2); border-radius: 4px; overflow: hidden; flex: none; }
.bar div { height: 100%; background: var(--green); transition: width .3s; }
.deck { position: relative; flex: 1; min-height: 300px; }
.card {
  position: absolute; inset: 0;
  border-radius: var(--radius); overflow: hidden;
  background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  touch-action: none; user-select: none; -webkit-user-select: none;
  transition: transform .25s ease;
  --keep: 0; --cut: 0;
}
.card.top { cursor: grab; }
.card.under { transform: scale(.94) translateY(14px); opacity: .6; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.card img.bg { object-fit: cover; filter: blur(40px) brightness(.55); transform: scale(1.3); }
.card img.art { object-fit: contain; object-position: center top; }
.card .meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 80px 20px 20px;
  background: linear-gradient(to top, rgba(0,0,0,.92) 0%, rgba(0,0,0,.6) 55%, transparent 100%);
}
.card h2 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.card p { color: #d0d0d0; margin-top: 4px; }
.stamp {
  position: absolute; top: 28px; padding: 6px 14px; border: 4px solid; border-radius: 12px;
  font-size: 30px; font-weight: 900; letter-spacing: .06em; background: rgba(0,0,0,.35);
}
.stamp.keep { left: 22px; color: var(--green); transform: rotate(-14deg); opacity: var(--keep); }
.stamp.cut { right: 22px; color: var(--red); transform: rotate(14deg); opacity: var(--cut); }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; flex: none; padding-bottom: env(safe-area-inset-bottom); }
.ctl { border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--card); border: 1px solid var(--line); }
.ctl svg { width: 45%; height: 45%; }
.ctl.small { width: 44px; height: 44px; color: var(--muted); }
.ctl.big { width: 56px; height: 56px; border-width: 2px; }
.ctl.play { width: 62px; height: 62px; background: #fff; border-color: #fff; color: #000; }
.ctl.cut { color: var(--red); border-color: var(--red); background: var(--red-bg); }
.ctl.keep { color: var(--green); border-color: var(--green); background: var(--green-bg); }
.ctl:active:not(:disabled) { transform: scale(.92); }

/* Pop-up box */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet {
  width: 100%; max-width: 420px; max-height: 100%;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--head); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.sheet h3 { font-size: 20px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
.field {
  width: 100%; min-height: 52px; padding: 0 16px; flex: none;
  border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  color: var(--text); font: inherit; font-size: 16px;
}
.field:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.sheet .list { overflow-y: auto; min-height: 0; }
.sheet .btn { flex: none; }

/* Debug box */
.debug-box { overflow-y: auto; }
.debug-box section { flex: none; }
.debug-box h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.dbg-row { padding: 8px 10px; margin-bottom: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 14px; }
.dbg-row span { color: var(--muted); }
.dbg-row code { display: block; margin-top: 2px; font-size: 11px; color: #777; word-break: break-all; }
#dbgLog {
  max-height: 180px; overflow: auto; margin: 0; padding: 8px;
  background: #0b0b0b; border: 1px solid var(--line); border-radius: 10px;
  color: #9fe7b4; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap;
}
.dbg-btns { display: flex; gap: 8px; flex: none; }
.dbg-btns .btn { flex: 1; width: auto; padding: 0 12px; }
.debug-box .btn { min-height: 46px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; flex: none; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--green); }
.ok { color: var(--green); }

/* On-screen log overlay, pinned under the header so it doesn't cover the buttons */
#debug {
  position: fixed; left: 8px; right: 8px; top: calc(78px + env(safe-area-inset-top)); z-index: 15; /* under pop-ups */
  max-height: 32dvh; overflow: hidden; margin: 0; padding: 8px;
  background: rgba(0,0,0,.82); border: 1px solid #333; border-radius: 10px;
  color: #9fe7b4; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap;
  pointer-events: none;
}

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100% - 32px);
  background: #2e2e2e; border: 1px solid #3a3a3a; border-radius: 14px;
  padding: 12px 16px; font-size: 14px; z-index: 10;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
