/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens (matches lofi-player; default = "studio" — cool slate + cyan) ── */
:root {
  --black:    #000000;
  --white:    #f2f2f2;
  --grey:     #666666;
  --dim:      #222222;
  --mid:      #444444;
  --code-bg:  #050505;
  --code-fg:  #cccccc;
  --font:     'Courier New', Courier, monospace;
}

[data-theme="studio"] {
  --black:    #060a0e;
  --white:    #dceaef;
  --grey:     #4a8090;
  --dim:      #0e1820;
  --mid:      #1e3a48;
  --code-bg:  #050a0e;
  --code-fg:  #9ec8d4;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--black);
  color: var(--white);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* Generic visibility utility */
.hidden { display: none !important; }

/* ── App shell ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: stretch;
  height: 44px;
  border-bottom: 1px solid var(--dim);
  flex-shrink: 0;
}

.menu-toggle {
  display: none;                              /* desktop hides it; mobile shows it */
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-right: 1px solid var(--dim);
  color: var(--grey);
  cursor: pointer;
  width: 44px;
  font-family: var(--font);
  font-size: 20px;
  line-height: 1;
}
.menu-toggle:hover { color: var(--white); }

.logo {
  display: flex;
  align-items: center;
  padding: 0 20px;
  color: var(--grey);
  font-size: 18px;
  border-right: 1px solid var(--dim);
  letter-spacing: 0.05em;
  user-select: none;
}

.view-tabs {
  display: flex;
  flex: 1;
}

.tab-btn {
  background: none;
  border: none;
  border-right: 1px solid var(--dim);
  color: var(--grey);
  cursor: pointer;
  padding: 0 22px;
  font-family: var(--font);
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  transition: color 0.15s, background 0.15s;
  height: 100%;
}
.tab-btn:hover  { color: var(--white); background: rgba(255,255,255,0.04); }
.tab-btn.active { color: var(--black); background: var(--white); }

/* ── Body ── */
.body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar (playlist tree) ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--dim);
  overflow-y: auto;
  background: var(--black);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--dim); }

.playlist-tree {
  padding: 4px 0;
}

.pl-group {
  border-bottom: 1px solid rgba(255,255,255,0.02);
}

.pl-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--grey);
  cursor: pointer;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: left;
  transition: color 0.1s, background 0.1s;
}
.pl-header:hover { color: var(--white); background: rgba(255,255,255,0.03); }
.pl-header.active { color: var(--white); }

.pl-toggle {
  display: inline-block;
  width: 12px;
  font-size: 10px;
  transition: transform 0.15s ease;
  color: var(--mid);
}
.pl-group.expanded .pl-toggle { transform: rotate(90deg); }

.pl-label { flex: 1; }

.pl-count {
  font-size: 9px;
  color: var(--mid);
  letter-spacing: 0.15em;
  font-variant-numeric: tabular-nums;
}

.pl-list {
  display: none;
  padding: 2px 0 6px;
}
.pl-group.expanded .pl-list { display: block; }

.pl-song {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  color: var(--grey);
  cursor: pointer;
  padding: 6px 12px 6px 28px;
  font-family: var(--font);
  font-size: 11px;
  text-align: left;
  transition: color 0.08s, background 0.08s, border-color 0.08s;
}
.pl-song:hover  { color: var(--white); background: rgba(255,255,255,0.03); }
.pl-song.active {
  color: var(--white);
  background: rgba(255,255,255,0.05);
  border-left-color: var(--white);
}

.pl-num {
  font-size: 9px;
  color: var(--mid);
  min-width: 18px;
  text-align: right;
  flex-shrink: 0;
  letter-spacing: 0.05em;
}
.pl-song.active .pl-num { color: var(--grey); }

.pl-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.pl-score {
  font-size: 9px;
  color: var(--mid);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.pl-score.positive { color: var(--white); }
.pl-score.negative { color: var(--mid); }

/* Mobile backdrop — hidden by default */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 4;
}

/* ── Play pane (editor + meta) ── */
.play-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;                                /* prevents editor overflow */
}
.play-pane.hidden { display: none; }

/* Song meta strip at the top of the pane */
.song-info {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--dim);
  flex-shrink: 0;
}

.si-row {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: space-between;
}

.si-meta-block {
  flex: 1;
  min-width: 0;
}

.si-counter {
  font-size: 10px;
  letter-spacing: 0.35em;
  color: var(--mid);
  margin-bottom: 6px;
}

.si-title {
  font-size: clamp(1.2rem, 2.2vw, 1.9rem);
  font-weight: bold;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.12;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.si-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.si-badge {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--grey);
  border: 1px solid var(--dim);
  padding: 2px 8px;
}
.si-sep { color: var(--dim); font-size: 9px; }

.si-feel {
  font-size: 11px;
  color: var(--grey);
  font-style: italic;
  margin-bottom: 4px;
  min-height: 14px;
}
.si-chords {
  font-size: 10px;
  color: var(--mid);
  letter-spacing: 0.1em;
  min-height: 12px;
}

/* Vote buttons sit to the right of the meta on desktop */
.vote-bar {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.vote-btn {
  background: none;
  border: 1px solid var(--mid);
  color: var(--white);
  cursor: pointer;
  width: 48px;
  height: 48px;
  font-family: var(--font);
  font-size: 22px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s, border-color 0.1s, transform 0.05s;
}
.vote-btn:hover  { background: var(--white); color: var(--black); border-color: var(--white); }
.vote-btn:active { transform: scale(0.96); }
.vote-btn.active { background: var(--white); color: var(--black); border-color: var(--white); }
.vote-btn.flash  { background: var(--white); color: var(--black); border-color: var(--white); }

/* ── Strudel editor — iframe to strudel.cc ──
   We embed the real strudel.cc REPL instead of hosting the editor
   ourselves. strudel.cc is already proven to work on mobile, so we
   sidestep every CSS / AudioContext / touch-handling problem by
   handing the whole editor experience to the iframe. */
.editor {
  display: block;
  width: 100%;
  flex: 1 1 0;
  min-height: 320px;
  border: 0;
  background: #000;
}

.hints {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 22px;
  border-top: 1px solid var(--dim);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--mid);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.hints .sep { color: var(--dim); }
/* Show keyboard hints on desktop, touch hint on phone */
.hints .hint-mobile  { display: none; }
@media (max-width: 768px) {
  .hints .hint-desktop { display: none; }
  .hints .hint-mobile  { display: inline; }
}

/* ── Board pane (same shape as lofi-player) ── */
.board-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.board-pane.hidden { display: none; }

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--dim);
  flex-shrink: 0;
}
.board-title { font-size: 10px; letter-spacing: 0.35em; color: var(--grey); font-weight: normal; }
.board-refresh-timer {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--dim);
  transition: color 0.2s;
}
.board-refresh-timer.live    { color: var(--white); animation: live-pulse 1.6s ease-in-out infinite; }
.board-refresh-timer.loading { color: var(--grey); }
@keyframes live-pulse { 0%,100%{opacity:0.55;} 50%{opacity:1;} }

.board-content { flex: 1; overflow-y: auto; }
.board-content::-webkit-scrollbar       { width: 4px; }
.board-content::-webkit-scrollbar-track { background: transparent; }
.board-content::-webkit-scrollbar-thumb { background: var(--dim); }

.board-empty, .board-loading {
  padding: 40px 24px;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: 0.3em;
  text-align: center;
}

.lb-table { padding: 4px 0; }
.lb-head, .lb-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px 32px 32px 52px;
  padding: 8px 24px;
  gap: 0 8px;
}
.lb-head {
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--mid);
  border-bottom: 1px solid var(--dim);
  padding-bottom: 10px;
}
.lb-row {
  font-size: 11px;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  transition: background 0.08s;
  cursor: pointer;
}
.lb-row:hover { background: rgba(255,255,255,0.025); }

.lb-rank { font-size: 9px; color: var(--dim); align-self: center; }
.lb-name { color: var(--white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; }
.lb-tag  { font-size: 9px; color: var(--grey); letter-spacing: 0.2em; text-align: center; align-self: center; }
.lb-up, .lb-down { font-size: 10px; color: var(--grey); text-align: center; align-self: center; }
.lb-score { font-size: 12px; text-align: right; align-self: center; color: var(--grey); }
.lb-score.positive { color: var(--white); }
.lb-score.negative { color: var(--mid); }

/* ══════════════════════════════════════════════════════════════
   Responsive — mobile drawer for the sidebar, compact paddings
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { width: 220px; }
  .song-info { padding: 14px 16px 12px; }
  .hints { padding: 6px 16px; }
}

@media (max-width: 768px) {
  body { font-size: 13px; }

  .header { height: 40px; }
  .menu-toggle { display: flex; }
  .logo { padding: 0 12px; font-size: 16px; }
  .tab-btn { padding: 0 14px; font-size: 9px; letter-spacing: 0.18em; }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 40px;
    bottom: 0;
    left: 0;
    width: 78%;
    max-width: 320px;
    border-right: 1px solid var(--dim);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 5;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }

  /* Pane takes the full width when the drawer is closed */
  .play-pane, .board-pane { width: 100%; }

  /* Stack vote bar under the meta on phone — less horizontal cramping */
  .si-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .vote-bar { gap: 10px; }
  .vote-btn { flex: 1; height: 42px; font-size: 20px; }

  .si-title { font-size: clamp(1.05rem, 5vw, 1.4rem); white-space: normal; }
  .si-meta  { gap: 6px; }
  .si-feel  { font-size: 10px; }

  /* Mobile: switch the whole page to natural document flow. The desktop
     "everything is one viewport-locked flex column" model was trapping
     touch scrolls inside the editor's internal scroller (CodeMirror
     captures touchmove), which is why scrolling didn't work. Letting
     the body scroll like a normal webpage avoids the nested-scroll
     problem entirely — the editor still has its own internal scroll
     for long code, but the page above and below it scrolls naturally. */
  html, body {
    height: auto;
    overflow: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .app  { height: auto; min-height: 100vh; }
  .body { display: block; overflow: visible; }
  .play-pane, .board-pane {
    display: block;
    overflow: visible;
  }
  .play-pane.hidden, .board-pane.hidden { display: none; }

  .editor {
    flex: 0 0 auto;
    height: 70vh;
    min-height: 500px;
  }

  .hints { font-size: 9px; letter-spacing: 0.12em; }

  /* Tighten leaderboard columns for narrow screens */
  .lb-head, .lb-row {
    grid-template-columns: 28px 1fr 28px 28px 44px;
    padding: 7px 14px;
    font-size: 10px;
  }
  .lb-head .lb-tag, .lb-row .lb-tag { display: none; }
}

@media (max-width: 380px) {
  .si-title  { font-size: clamp(1rem, 6vw, 1.2rem); }
  .vote-btn  { height: 38px; font-size: 18px; }
  .pl-header { padding: 9px 10px; font-size: 10px; }
}
