:root {
  --bg: #15171c;
  --panel: #1e2128;
  --panel2: #262a33;
  --border: #333844;
  --text: #e6e8ec;
  --dim: #8b93a3;
  --accent: #f0a63a;
  --accent2: #4aa3ff;
  --loop: rgba(74, 163, 255, 0.25);
  --green: #5ee07a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }

.topbar {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; }
.fetch { display: flex; gap: 8px; flex: 1; min-width: 280px; }
.fetch input[type=url] {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}

button, .btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font: inherit; user-select: none;
}
button:hover, .btn:hover { border-color: var(--dim); }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
button.toggle.on, .presets button.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.play { font-size: 18px; width: 48px; }

.status { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel2); }
.status .bar { width: 200px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
#statusBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.status.error { background: #4a1f24; }

.library {
  position: fixed; right: 0; top: 56px; bottom: 0; width: 340px; max-width: 100%;
  background: var(--panel); border-left: 1px solid var(--border); padding: 12px 16px; overflow: auto; z-index: 10;
}
.library ul, .loops ul { list-style: none; padding: 0; margin: 0; }
.library li, .loops li {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.library li:hover, .loops li:hover { background: var(--panel2); }
.library li .t, .loops li .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library li img { width: 48px; height: 27px; object-fit: cover; border-radius: 3px; }
.del { padding: 2px 7px; color: var(--dim); }

main { padding: 12px 16px 40px; max-width: 1400px; margin: 0 auto; }
main h2 { margin: 4px 0 10px; font-size: 16px; font-weight: 600; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.panel + .panel, .markers + .panel { margin-top: 8px; }
canvas { display: block; width: 100%; }
#wave, #overview { cursor: crosshair; }

.markers { position: relative; height: 26px; margin-top: 8px; }
.marker {
  position: absolute; top: 0; transform: translateX(-50%);
  background: var(--accent2); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px;
  cursor: pointer; white-space: nowrap; user-select: none;
}
.marker::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--accent2); border-bottom: 0;
}

.analysis-head { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; flex-wrap: wrap; }
#analysisInfo { color: var(--dim); }
.chords { display: flex; gap: 6px; flex-wrap: wrap; }
.chord { background: var(--panel2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.chord:first-child { border-color: var(--accent); color: var(--accent); }

.transport {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  margin-top: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
}
.transport .group { display: flex; gap: 6px; align-items: center; }
.transport span { color: var(--dim); }
.time {
  font-family: ui-monospace, Consolas, monospace; background: #f6e7b8; color: #222;
  padding: 4px 10px; border-radius: 12px; font-size: 15px; min-width: 92px; text-align: center;
}
.time.dim { background: #cfe0f5; }
.time.small { min-width: 56px; font-size: 13px; background: #f3c9c9; }
.presets { display: flex; }
.presets button { border-radius: 0; margin-left: -1px; padding: 6px 8px; }
.presets button:first-child { border-radius: 6px 0 0 6px; }
.presets button:last-child { border-radius: 0 6px 6px 0; }
input[type=range] { accent-color: var(--accent); }
#speed { width: 140px; }
#volume { width: 90px; }

.loops { margin-top: 14px; }
.loops h3, .library h3 { margin: 0 0 6px; font-size: 14px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
.loops li.active { background: var(--panel2); outline: 1px solid var(--accent2); }
.hint { color: var(--dim); font-size: 12px; margin-top: 12px; }
kbd { background: var(--panel2); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; font-size: 11px; }

.empty { text-align: center; color: var(--dim); padding: 80px 16px; }

/* tabs */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.title-row h2 { margin: 0; }
.tabs { display: flex; }
.tabs button { border-radius: 0; margin-left: -1px; padding: 6px 14px; }
.tabs button:first-child { border-radius: 6px 0 0 6px; }
.tabs button:last-child { border-radius: 0 6px 6px 0; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #1a1a1a; font-weight: 600; }

/* spectrum */
.spec-toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 8px; }
.spec-toolbar .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.spec-toolbar span, .check { color: var(--dim); }
.spec-toolbar .dim { font-size: 12px; }
.spec-toolbar select, .spec-toolbar input[type=number] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font: inherit;
}
.spec-toolbar input[type=number] { width: 78px; }
.check { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.spec-wrap { position: relative; }
#spec { cursor: crosshair; }
.readout {
  position: absolute; pointer-events: none; background: rgba(0,0,0,.75); color: #fff;
  font: 12px ui-monospace, Consolas, monospace; padding: 3px 6px; border-radius: 4px; white-space: nowrap;
}
.loops li .spec { padding: 2px 7px; color: var(--dim); }

/* user menu */
.user { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 170px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 4px;
  display: flex; flex-direction: column; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.menu button { border: 0; background: none; text-align: left; padding: 8px 10px; }
.menu button:hover { background: var(--panel2); }

/* overlays / cards */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10, 11, 14, 0.82);
}
#loginOverlay { background: var(--bg); }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px;
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; max-height: 100%; overflow: auto;
}
.card.wide { max-width: 760px; }
.card h2 { margin: 0; font-size: 18px; }
.card h3 { margin: 10px 0 0; font-size: 14px; color: var(--dim); }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card input:not([type=checkbox]) {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
.dim { color: var(--dim); }
.error { color: #ff7b7b; min-height: 1em; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input:not([type=checkbox]) { flex: 1; min-width: 140px; }
.notice { background: #1f3a26; border: 1px solid #2f6b3d; border-radius: 6px; padding: 8px 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.notice code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 14px; user-select: all; }
.table-wrap { overflow-x: auto; }
#userTable { width: 100%; border-collapse: collapse; }
#userTable th { text-align: left; color: var(--dim); font-weight: 500; font-size: 12px; padding: 6px; border-bottom: 1px solid var(--border); }
#userTable td { padding: 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#userTable .actions { text-align: right; }
#userTable .actions button { padding: 3px 8px; font-size: 12px; }
#userTable button:disabled { opacity: .4; cursor: default; }
#userTable .actions .del { color: #ff7b7b; }
