:root {
  --bg: #0e1014;
  --bg-panel: #161a21;
  --bg-input: #1e242e;
  --border: #2a3140;
  --text: #e8ecf2;
  --text-dim: #8b94a5;
  --accent: #ff4d4d;
  --accent-2: #4d9fff;
  --a-color: #2ecc71;
  --b-color: #ff4d4d;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(14, 16, 20, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand { font-size: 19px; white-space: nowrap; }
.brand b { color: var(--accent); }

.url-form { display: flex; flex: 1; gap: 8px; max-width: 640px; }

.url-form input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
}
.url-form input:focus { border-color: var(--accent-2); }

/* ---- buttons ---- */
.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #28303d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff6666; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 10px 26px; font-size: 18px; }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- layout ---- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 20px;
  max-width: 1280px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
}

.player-wrap {
  position: relative;
  padding-top: 56.25%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- timeline ---- */
.timeline { margin: 18px 0 8px; }

.track {
  position: relative;
  height: 14px;
  background: var(--bg-input);
  border-radius: 7px;
  cursor: pointer;
  touch-action: none;
}

.range {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(46, 204, 113, 0.35), rgba(255, 77, 77, 0.35));
  border-radius: 7px;
  pointer-events: none;
}

.buffer {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 0;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  pointer-events: none;
}

.playhead {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  margin-left: -1.5px;
  background: #fff;
  border-radius: 2px;
  pointer-events: none;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

.handle {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 26px;
  transform: translate(-50%, -50%);
  cursor: ew-resize;
  z-index: 2;
  border-radius: 5px;
  touch-action: none;
}
.handle label {
  display: block;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 26px;
  color: #fff;
  pointer-events: none;
}
.handle .time {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
/* invisible padding so the handles are grabbable with a finger */
.handle::after { content: ""; position: absolute; inset: -8px -10px; }
.handle-a { background: var(--a-color); }
.handle-b { background: var(--b-color); }
.handle:hover, .handle.dragging { filter: brightness(1.25); }

.timeline-times {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  margin-top: 10px;
}

.control-group { display: flex; align-items: center; gap: 8px; }

.ab-field { display: flex; align-items: center; gap: 4px; }

.time-input {
  width: 74px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.time-input:focus { outline: none; border-color: var(--accent-2); }

.loop-stats { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.speed-group {
  gap: 2px;
  padding: 3px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.speed-group .btn {
  border: none;
  background: transparent;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 7px;
}
.speed-group .btn:hover { background: var(--bg-input); }
#speed-reset {
  width: auto;
  padding: 0 10px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  border-radius: 0 7px 7px 0;
  font-size: 12.5px;
  color: var(--text-dim);
}
#speed-reset:hover { color: var(--text); }
#speed-label { font-variant-numeric: tabular-nums; }

.speed-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 28px;
  margin: 0 4px;
  background: transparent;
  cursor: pointer;
}
.speed-group input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.speed-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.18);
}
.speed-group input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.speed-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.18);
}

/* ---- side panels ---- */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.panel-head h2 { font-size: 14px; margin: 0; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.list { list-style: none; margin: 0; padding: 0; }
.list .empty { color: var(--text-dim); font-size: 13px; }

.list li.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
}
.list li.item:hover { background: var(--bg-input); }

.item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item .meta { color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.item .del {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 5px;
  visibility: hidden;
}
.item:hover .del { visibility: visible; }
.item .del:hover { color: var(--accent); background: rgba(255, 77, 77, 0.12); }

.item img { width: 60px; border-radius: 4px; flex-shrink: 0; }

#notes {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 10px;
  font: 13.5px/1.5 inherit;
  font-family: inherit;
}
#notes:focus { outline: none; border-color: var(--accent-2); }

/* ---- hero ---- */
.hero {
  max-width: 760px;
  margin: 56px auto;
  padding: 0 24px;
  text-align: center;
}
.hero h1 { font-size: 34px; margin-bottom: 8px; }
.hero > p { color: var(--text-dim); font-size: 17px; }

.features {
  list-style: none;
  padding: 0;
  margin: 36px 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  text-align: left;
}
.features li {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.features b { display: block; margin-bottom: 6px; }
.features span { color: var(--text-dim); font-size: 13.5px; }

.hint { color: var(--text-dim); }

kbd {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: inherit;
}

/* ---- help dialog ---- */
dialog {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 28px;
  max-width: 420px;
  width: 90%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; }
dialog table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
dialog td { padding: 5px 4px; font-size: 14px; }
dialog td:first-child { width: 130px; }
dialog form { text-align: right; }

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- mobile ---- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand { font-size: 17px; }
  #help-btn { display: none; } /* shortcuts are keyboard-only */
  .url-form { flex-basis: 100%; max-width: none; }
  /* below 16px iOS Safari zooms the page when an input gets focus */
  .url-form input, .time-input, #notes { font-size: 16px; }

  .app { padding: 12px; gap: 14px; }
  .timeline { margin: 26px 0 8px; } /* room for the A/B time bubbles */

  .controls { gap: 10px; margin-top: 12px; }
  .control-group { width: 100%; justify-content: center; flex-wrap: wrap; }
  .time-input { width: 84px; }
  .loop-stats { flex-basis: 100%; text-align: center; }
  .speed-group input[type="range"] { flex: 1; width: auto; }

  .panel { padding: 12px; margin-bottom: 12px; }

  .hero { margin: 32px auto; padding: 0 16px; }
  .hero h1 { font-size: 26px; }
  .hero > p { font-size: 15px; }
}

/* touch devices have no hover to reveal the delete buttons */
@media (pointer: coarse) {
  .item .del { visibility: visible; }
}
