:root {
  --bg: #0b0d10;
  --bg2: #14181d;
  --bg3: #1d232a;
  --fg: #e8ecef;
  --fg2: #9aa4ad;
  --accent: #ff4d4d;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ---------- login ---------- */
#login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100;
}
.login-box { display: flex; flex-direction: column; gap: 14px; width: min(320px, 85vw); text-align: center; }
.login-box h1 { font-size: 28px; letter-spacing: -0.5px; }
.login-box input {
  font-size: 24px; text-align: center; letter-spacing: 8px;
  background: var(--bg2); border: 1px solid var(--bg3); border-radius: var(--radius);
  color: var(--fg); padding: 14px;
}

/* ---------- chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 6px;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.logo { font-size: 22px; font-weight: 300; letter-spacing: -0.5px; }
.logo b { font-weight: 700; color: var(--accent); }
.vtitle { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view { padding-bottom: 90px; }

.btn {
  background: var(--bg3); color: var(--fg); border: none; border-radius: var(--radius);
  padding: 10px 16px; font-size: 15px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--fg2); }
.btn.danger { color: #ff7b7b; }
.btn:active { transform: scale(0.97); }

.err { color: #ff7b7b; font-size: 14px; }
.status { color: var(--fg2); padding: 18px 16px; font-size: 15px; }

/* ---------- search ---------- */
.searchwrap { padding: 10px 16px; }
#searchForm { display: flex; gap: 8px; }
#searchForm input {
  flex: 1; font-size: 17px; background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: var(--radius); color: var(--fg); padding: 13px 16px; min-width: 0;
}
#searchForm input:focus { outline: 1px solid var(--accent); }

/* ---------- results ---------- */
.results { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 4px 8px; }
@media (min-width: 640px) { .results { grid-template-columns: 1fr 1fr; } }

.vcard {
  display: grid; grid-template-columns: 148px 1fr; gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius); cursor: pointer;
}
.vcard:active { background: var(--bg2); }
.vcard.playing { background: var(--bg3); }
.vcard .thumbwrap { position: relative; }
.vcard img { width: 148px; aspect-ratio: 16/9; object-fit: cover; border-radius: 10px; background: var(--bg2); display: block; }
.vcard .dur {
  position: absolute; right: 5px; bottom: 5px; background: rgba(0,0,0,.8);
  font-size: 12px; padding: 1px 5px; border-radius: 5px;
}
.vcard .vt { font-size: 15px; line-height: 1.3; max-height: 3.9em; overflow: hidden; }
.vcard .vm { font-size: 13px; color: var(--fg2); margin-top: 4px; }

.results.compact .vcard { grid-template-columns: 100px 1fr; }
.results.compact .vcard img { width: 100px; }
.results.compact .vcard .vt { font-size: 14px; max-height: 2.6em; }

/* ---------- playlists ---------- */
.sectionhead { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 8px; }
.sectionhead h2 { font-size: 18px; }
.addpl { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 8px; }
.addpl input {
  flex: 1; min-width: 200px; font-size: 15px; background: var(--bg2);
  border: 1px solid var(--bg3); border-radius: var(--radius); color: var(--fg); padding: 12px 14px;
}
.plgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 8px 16px; }
.plcard { cursor: pointer; border-radius: var(--radius); overflow: hidden; background: var(--bg2); }
.plcard:active { transform: scale(0.97); }
.plcard img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--bg3); }
.plcard .plph {
  width: 100%; aspect-ratio: 16/9; background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--fg2);
}
.plcard .plt { padding: 10px 12px 2px; font-size: 14px; font-weight: 600; line-height: 1.3; }
.plcard .plm { padding: 0 12px 12px; font-size: 12px; color: var(--fg2); }
.plactions { display: flex; gap: 8px; padding: 8px 16px; }

/* ---------- player ---------- */
#playerView {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  overflow-y: auto; padding-bottom: 30px;
}
#playerShell { width: 100%; background: #000; }
#playerShell iframe, #ytplayer { width: 100%; aspect-ratio: 16/9; display: block; border: 0; }
@media (min-width: 700px) {
  #playerShell { max-width: 820px; margin: 0 auto; }
  .nowinfo, .playerctl, #queueWrap { max-width: 820px; margin-left: auto; margin-right: auto; }
}
.nowinfo { padding: 14px 16px 4px; }
.nowinfo h2 { font-size: 17px; line-height: 1.35; }
.nowinfo p { color: var(--fg2); font-size: 14px; margin-top: 6px; }
.playerctl { display: flex; gap: 10px; padding: 12px 16px; }
.playerctl .btn { font-size: 20px; padding: 10px 22px; }
#queueWrap { padding: 6px 8px; }
#queueWrap h3 { font-size: 15px; padding: 8px 8px; color: var(--fg2); }

/* player minimized: keep iframe alive offscreen-ish but audible */
#playerView.mini {
  inset: auto 0 0 0; height: 1px; overflow: hidden; opacity: 0.01; pointer-events: none;
}

/* ---------- mini bar ---------- */
#miniBar {
  position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border-radius: var(--radius);
  padding: 8px 10px; box-shadow: 0 4px 24px rgba(0,0,0,.5);
  cursor: pointer;
}
#miniBar img { width: 56px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; }
.minitext { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.minitext span:first-child {
  font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.minitext span:last-child { font-size: 12px; color: var(--fg2); }
#miniBar .btn { font-size: 18px; padding: 8px 10px; }
