/* ============================================================
   Jam-in! — minimal, mobile-friendly, dark-mode-first styles
   ============================================================ */

:root {
  --bg: #0f1117;
  --bg-2: #171a23;
  --bg-3: #1f2330;
  --fg: #e8eaf0;
  --fg-dim: #9aa3b2;
  --accent: #6c8cff;
  --accent-2: #00d7a3;
  --danger: #ff5d6c;
  --record: #ff3b46;
  --border: #2a2f3d;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-2: #ffffff;
  --bg-3: #eef0f6;
  --fg: #1a1d26;
  --fg-dim: #5b6373;
  --accent: #3a5cff;
  --accent-2: #00a07a;
  --danger: #e23744;
  --record: #e0202b;
  --border: #d8dbe6;
  --shadow: 0 6px 24px rgba(20, 25, 40, 0.12);
}

* { box-sizing: border-box; }

/* Respect the hidden attribute even when a class sets display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 650; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand h1 { font-size: 20px; letter-spacing: -0.01em; }
.brand .tag { color: var(--fg-dim); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Play-history dropdown ---------- */
.history-wrap { position: relative; }
.history-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(92vw, 360px);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 40;
}
.history-head {
  color: var(--fg-dim);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 6px 8px;
}
.history-empty { color: var(--fg-dim); font-size: 13px; line-height: 1.5; padding: 4px 6px 8px; margin: 0; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  padding: 2px;
}
.history-item:hover { background: var(--bg-3); }
.history-item.current { outline: 1px solid var(--accent); }

.history-load {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.history-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  font-size: 12px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-id { font-variant-numeric: tabular-nums; }

.history-link {
  flex: none;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.history-link:hover { color: var(--fg); background: var(--border); }
.history-del { flex: none; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 18px;
  max-width: 1280px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Stage (player + transport) ---------- */
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.url-row { display: flex; gap: 8px; }
.url-hint {
  margin: -6px 0 0;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
}
.url-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 15px;
}
.url-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Search results dropdown ---------- */
.search-wrap { position: relative; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}
.search-status {
  color: var(--fg-dim);
  font-size: 13px;
  padding: 12px 10px;
  text-align: center;
}
.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  text-align: left;
  color: var(--fg);
}
.search-item:hover,
.search-item:focus-visible { background: var(--bg-3); outline: none; }

.search-thumb {
  flex: none;
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
.search-thumb-wrap { position: relative; flex: none; }
.search-duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.search-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.search-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-author {
  font-size: 12px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.player-wrap > #player,
.player-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
}
.player-overlay:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-overlay {
  position: absolute;
  inset: 0;
  text-align: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 15px;
}

/* ---------- Transport ---------- */
.transport {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 56px;
}
.transport .btn.record {
  padding: 14px 32px;
  font-size: 17px;
  font-weight: 700;
  min-width: 168px;
  border-radius: 999px;
}
.transport-meta {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
}
.rec-indicator {
  color: var(--record);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

.monitor-toggle {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1.4;
}
.monitor-toggle input { margin-top: 2px; }

/* ---------- Sync offset ---------- */
.offset-row { display: flex; align-items: center; gap: 10px; }
.offset-label { color: var(--fg-dim); font-size: 13px; white-space: nowrap; }
.offset-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.offset-readout {
  color: var(--fg);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: right;
}
.offset-hint { margin: -8px 0 0; color: var(--fg-dim); font-size: 12px; line-height: 1.4; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.record { color: var(--record); border-color: var(--record); }
.btn.record.is-recording { background: var(--record); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }

/* ---------- Sidebar / track list ---------- */
.sidebar {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar-head h2 { font-size: 16px; }
.sidebar-actions { display: flex; gap: 6px; }

.empty-hint { color: var(--fg-dim); font-size: 13px; line-height: 1.5; }

.track-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.track {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.track-row { display: flex; align-items: center; gap: 8px; }
.track-name {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
  padding: 2px 0;
}
.track-name:focus { outline: 1px solid var(--accent); border-radius: 4px; }
.track-time { color: var(--fg-dim); font-size: 12px; font-variant-numeric: tabular-nums; }

.waveform { width: 100%; height: 40px; display: block; border-radius: 6px; background: var(--bg); }

.track-controls { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--border); }
.icon-btn.active { background: var(--accent); color: #fff; border-color: transparent; }
.icon-btn.danger:hover { background: var(--danger); border-color: transparent; color: #fff; }
.vol { flex: 1; accent-color: var(--accent); }

.track-sync { display: flex; align-items: center; gap: 6px; }
.track-sync .icon-btn { width: 28px; height: 28px; font-size: 16px; }
.track-sync-label {
  color: var(--fg-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 84px;
  text-align: center;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-dialog {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-dialog h2 { font-size: 18px; margin: 0 0 8px; }
.modal-dialog p {
  color: var(--fg-dim);
  font-size: 14px;
  margin: 0 0 18px;
  line-height: 1.5;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: min(90vw, 480px);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--accent-2); }
