:root {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #242830;
  --border: #2f343e;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #ff7a1a;
  --accent-2: #ffb15c;
  --loop: rgba(255, 122, 26, 0.28);
  --loop-off: rgba(139, 147, 163, 0.18);
  --danger: #e5484d;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  user-select: none;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

/* ---------- topo ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; white-space: nowrap; }
.brand span { color: var(--accent); }
.url-form { display: flex; gap: 8px; flex: 1; }
.url-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  user-select: text;
}
.url-form input:focus { outline: none; border-color: var(--accent); }
.url-form input.invalid { border-color: var(--danger); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; display: flex; flex-direction: column; padding: 14px 16px; gap: 10px; min-width: 0; overflow-y: auto; overflow-x: hidden; }
.sidebar {
  width: 330px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
}

/* ---------- vídeo ---------- */
.video-wrap {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 360px);
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px; font-size: 16px;
}
.placeholder .muted { font-size: 13px; }
.jog-overlay { position: absolute; inset: 0; cursor: ew-resize; touch-action: none; }
.jog-badge, .gap-badge {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .75); color: #fff;
  padding: 6px 14px; border-radius: 999px; font-variant-numeric: tabular-nums;
  pointer-events: none; font-size: 15px;
}
.gap-badge { top: auto; bottom: 16px; background: var(--accent); color: #111; font-weight: 600; }
.error-box {
  position: absolute; inset: 0; background: rgba(10, 10, 12, .92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 6px;
}

/* ---------- tempo ---------- */
.time-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.time-now { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.video-title { margin-left: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.rep-counter {
  background: var(--panel-2); border: 1px solid var(--accent); color: var(--accent-2);
  border-radius: 999px; padding: 2px 10px; font-size: 13px; white-space: nowrap;
}

/* ---------- timeline ---------- */
.timeline-block { display: flex; flex-direction: column; gap: 6px; }
.timeline {
  position: relative;
  height: 46px;
  touch-action: none;
  cursor: pointer;
}
.timeline.zoom { height: 52px; }
.zoom-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.tl-track {
  position: absolute; left: 0; right: 0; top: 20px; height: 14px;
  background: var(--panel-2); border-radius: 4px; overflow: hidden;
}
.tl-progress { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255, 255, 255, .08); }
.tl-region { position: absolute; top: 0; bottom: 0; background: var(--loop); border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); }
.tl-region.off { background: var(--loop-off); border-color: var(--muted); }
.tl-head {
  position: absolute; top: 14px; height: 26px; width: 2px; margin-left: -1px;
  background: #fff; pointer-events: none; box-shadow: 0 0 4px rgba(255, 255, 255, .6);
}
.tl-handle {
  position: absolute; top: 14px; height: 26px; width: 18px; margin-left: -9px;
  cursor: ew-resize; z-index: 2;
}
.tl-handle::before {
  content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 2px;
}
.tl-handle span {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #111; font-weight: 700; font-size: 10px;
  border-radius: 3px; padding: 0 4px; line-height: 14px;
}
.tl-ticks { position: absolute; left: 0; right: 0; top: 0; height: 18px; pointer-events: none; overflow: hidden; }
.tick { position: absolute; top: 0; height: 18px; border-left: 1px solid var(--border); }
.tick span { position: absolute; left: 3px; top: 1px; font-size: 10px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tl-hover {
  position: absolute; bottom: -2px; transform: translateX(-50%);
  font-size: 10px; background: var(--panel-2); color: var(--text); padding: 0 4px; border-radius: 3px;
  pointer-events: none; opacity: 0; font-variant-numeric: tabular-nums; z-index: 3;
}
.tl-hover.show { opacity: 1; }
.zoom-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px 2px; }

/* ---------- controles ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 10px; }
.group {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px;
}
.group > label { color: var(--muted); font-size: 12px; margin-right: 4px; }
.speed input[type=range] { width: 160px; }
.speed-value { min-width: 46px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--accent-2); }
.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.volume { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.volume input { width: 80px; }
.loop-point { display: flex; align-items: center; gap: 4px; }
.loop-time {
  min-width: 70px; text-align: center; font-variant-numeric: tabular-nums;
  background: var(--bg); border-radius: 4px; padding: 3px 6px; color: var(--accent-2);
}

input[type=range] { accent-color: var(--accent); }

.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.icon { width: 42px; height: 38px; padding: 0; font-size: 17px; }
.btn.icon.big { width: 54px; font-size: 18px; background: var(--accent); color: #111; border-color: var(--accent); }
.btn.small { padding: 4px 9px; }
.btn.tiny { padding: 2px 7px; font-size: 12px; }
.btn.tiny.active { border-color: var(--accent); color: var(--accent-2); }
.btn.toggle.on { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- sidebar ---------- */
.panel { background: var(--panel-2); border-radius: var(--radius); margin-bottom: 8px; padding: 0 10px; }
.panel > summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.panel[open] { padding-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 76px; gap: 6px 8px; align-items: center; margin-top: 6px; }
.form-grid label { font-size: 12px; color: var(--muted); }
.form-grid input, input.rename {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 6px; width: 100%; font-size: 13px; user-select: text;
}
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.trainer-status { margin-top: 8px; color: var(--accent-2); }

.loop-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.loop-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; cursor: pointer;
}
.loop-item:hover { border-color: var(--border); }
.loop-item.active { border-color: var(--accent); }
.loop-item .idx { width: 14px; color: var(--muted); font-size: 12px; text-align: center; }
.loop-item .info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.loop-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loop-item .range { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.shortcuts { width: 100%; border-collapse: collapse; font-size: 12px; }
.shortcuts td { padding: 3px 0; vertical-align: top; }
.shortcuts td:first-child { white-space: nowrap; padding-right: 10px; }
kbd {
  background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: inherit;
}

@media (max-width: 1050px) {
  .sidebar { width: 280px; }
}

/* ---------- projeto (topo) ---------- */
.project-box { display: flex; align-items: center; gap: 8px; min-width: 0; }
#projectName {
  width: 260px; background: transparent; color: var(--text); font: inherit; font-weight: 600; font-size: 15px;
  border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; text-overflow: ellipsis;
}
#projectName:hover:not(:disabled) { border-color: var(--border); }
#projectName:focus { outline: none; border-color: var(--accent); background: var(--bg); }
#projectName:disabled { opacity: .5; }
.save-state { font-size: 11px; color: var(--muted); white-space: nowrap; min-width: 58px; }
.btn:disabled { opacity: .4; pointer-events: none; }
.placeholder a { color: var(--accent-2); }

/* ---------- novo trecho (N → Enter → Enter) ---------- */
.capture-banner {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(20, 22, 26, .92); border: 1px solid var(--danger); border-radius: 20px;
  padding: 7px 16px; font-size: 13px; white-space: nowrap; pointer-events: none;
}
.capture-banner .dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--danger);
  margin-right: 4px; animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .25; } }
.btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.active-section {
  background: var(--loop); border: 1px solid var(--accent); color: var(--accent-2);
  border-radius: 12px; padding: 1px 10px; font-size: 12px; white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- biblioteca (modal) ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px;
}
.modal-card {
  width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 18px; flex: none; }
.modal-head input, .new-project input {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font: inherit;
}
.modal-head input { flex: 1; }
.modal-head input:focus, .new-project input:focus { outline: none; border-color: var(--accent); }
.new-project { display: flex; gap: 8px; padding: 10px; background: var(--panel-2); border-radius: var(--radius); }
.new-project input { flex: 2; min-width: 0; }
.new-project input + input { flex: 1.3; }
.new-project input.invalid { border-color: var(--danger); animation: shake .3s; }
.lib-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.lib-item {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid transparent; cursor: pointer;
}
.lib-item:hover { border-color: var(--border); }
.lib-item.active { border-color: var(--accent); }
.lib-item img { width: 112px; height: 63px; object-fit: cover; border-radius: 6px; flex: none; background: var(--panel-2); }
.lib-item .info { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.lib-item .name { font-weight: 600; font-size: 15px; }
.lib-item .info > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .meta { color: var(--accent-2); }
.lib-empty { text-align: center; padding: 20px 0; margin: 0; }

/* trechos salvos na linha do tempo principal */
.tl-sections { position: absolute; left: 0; right: 0; top: 20px; height: 14px; pointer-events: none; z-index: 1; }
.tl-sec {
  position: absolute; top: 0; bottom: 0; min-width: 8px; pointer-events: auto; cursor: pointer;
  background: rgba(139, 147, 163, .35); border-left: 1px solid var(--muted); border-right: 1px solid var(--muted);
  border-radius: 2px; transition: background .12s;
}
.tl-sec:hover { background: rgba(255, 177, 92, .55); border-color: var(--accent-2); }
.tl-sec span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: 9px; font-weight: 700; line-height: 1; color: var(--text); pointer-events: none;
  text-shadow: 0 0 3px #000;
}

/* ---------- modo online / offline ---------- */
.mode-btn { white-space: nowrap; min-width: 92px; }
.mode-btn.offline { border-color: #3fb27f; color: #7ee2b3; }
.mode-btn.busy { border-color: var(--accent); color: var(--accent-2); }
.lib-item .offline-tag { color: #7ee2b3; }
.guitar-btn { white-space: nowrap; }
.guitar-btn.on { background: #3fb27f; border-color: #3fb27f; color: #0d1a14; font-weight: 600; }
.guitar-btn.off { border-color: var(--danger); color: #ff9a9d; }
.guitar-btn.busy { border-color: var(--accent); color: var(--accent-2); }
