/* ============================================================
   Lick Looper – Complete Stylesheet
   Dark-themed YouTube looper / musician practice tool
   ============================================================ */

/* --- Reset & Base --- */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  background: #121212;
  color: #e0e0e0;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

ul {
  list-style: none;
}

/* --- App Shell --- */

#app {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- URL Bar --- */

#url-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  position: sticky;
  top: 0;
  z-index: 100;
}

#url-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #2a2a2a;
  color: #e0e0e0;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

#url-input::placeholder {
  color: #777;
}

#url-input:focus {
  border-color: #c9a834;
}

#load-btn {
  padding: 10px 24px;
  background: #c9a834;
  color: #121212;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

#load-btn:hover {
  background: #ddbf44;
}

#load-btn:active {
  background: #b89624;
  transform: scale(0.97);
}

/* --- Main Content (desktop: side-by-side) --- */

#main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px;
  gap: 16px;
}

/* --- Video Section --- */

#video-section {
  width: 100%;
}

#player-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

#player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 1.1rem;
  text-align: center;
  padding: 20px;
}

#player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#player iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* --- Timeline --- */

#timeline-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  margin-top: 8px;
}

/* Small play button in the timeline row */
.timeline-play {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 50%;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.timeline-play:hover {
  background: #3a3a3a;
}

.timeline-play:active {
  background: #222;
}

#timeline-wrapper {
  flex: 1;
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

#timeline-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: #333;
  border-radius: 3px;
  pointer-events: none;
  z-index: 1;
}

/* Golden loop region between A and B markers */
#loop-region {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(201, 168, 52, 0.35);
  border-radius: 3px;
  pointer-events: none;
}

/* Playhead indicator */
#playhead {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 14px;
  background: #fff;
  border-radius: 2px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
  transition: left 0.1s linear;
}

/* A/B markers */
.marker {
  position: absolute;
  top: -10px;
  width: 2px;
  height: calc(100% + 20px);
  background: #c9a834;
  z-index: 2;
  pointer-events: none;
  transform: translateX(-50%);
}

.marker-label {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 700;
  color: #c9a834;
  line-height: 1;
  user-select: none;
}

/* Range scrubber overlays the track */
#timeline-scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  position: relative;
  z-index: 4;
  margin: 0;
}

#timeline-scrubber::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
  border-radius: 3px;
}

#timeline-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e0e0e0;
  border: 2px solid #c9a834;
  margin-top: -4px;
  cursor: pointer;
  transition: transform 0.1s;
}

#timeline-scrubber::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

#timeline-scrubber::-moz-range-track {
  height: 6px;
  background: transparent;
  border-radius: 3px;
  border: none;
}

#timeline-scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e0e0e0;
  border: 2px solid #c9a834;
  cursor: pointer;
}

#time-display {
  font-size: 0.8rem;
  color: #999;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Controls + History wrapper --- */

#controls-history {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Controls Section --- */

#controls-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Control groups (bordered cards) */
.control-group {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 16px;
}

.control-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #c9a834;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2a2a;
}

/* Sub-groups inside Chunking & Speed */
.sub-group {
  margin-top: 14px;
}

.sub-group:first-child {
  margin-top: 0;
}

.sub-group-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 10px;
}

/* Rows of controls */
.control-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

/* --- Buttons --- */

.btn {
  flex: 1;
  padding: 8px 12px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
}

.btn:hover {
  background: #363636;
  border-color: #555;
}

.btn:active {
  background: #222;
  transform: scale(0.97);
}

.btn-full {
  flex: 1;
  width: 100%;
}

/* Large play/pause button */
.btn-large {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #c9a834;
  color: #121212;
  border: none;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}

.btn-large:hover {
  background: #ddbf44;
}

.btn-large:active {
  background: #b89624;
  transform: scale(0.93);
}

.btn-large .icon-play,
.btn-large .icon-pause {
  line-height: 1;
}

/* --- Keyboard Key Styling --- */

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  color: #ccc;
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 3px;
  box-shadow: 0 1px 0 #444;
  vertical-align: baseline;
}

/* --- Toggle Switch (iOS-style) --- */

.loop-toggle-row {
  justify-content: flex-start;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  background: #444;
  border-radius: 13px;
  flex-shrink: 0;
  transition: background 0.25s;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #e0e0e0;
  border-radius: 50%;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Checked state */
.toggle-label input[type="checkbox"]:checked + .toggle-switch {
  background: #4caf50;
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch::after {
  transform: translateX(22px);
}

/* Focus ring for accessibility */
.toggle-label input[type="checkbox"]:focus-visible + .toggle-switch {
  outline: 2px solid #c9a834;
  outline-offset: 2px;
}

/* --- Chunk Settings (dropdowns) --- */

.chunk-settings {
  gap: 16px;
}

.chunk-settings label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #aaa;
}

.chunk-settings select,
select {
  padding: 6px 10px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.chunk-settings select:focus,
select:focus {
  border-color: #c9a834;
}

/* --- Speed Control --- */

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speed-label {
  font-size: 0.78rem;
  color: #777;
  flex-shrink: 0;
  min-width: 32px;
  font-variant-numeric: tabular-nums;
}

#speed-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  background: #333;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #c9a834;
  border: none;
  cursor: pointer;
  transition: transform 0.1s;
}

#speed-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

#speed-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #c9a834;
  border: none;
  cursor: pointer;
}

#speed-slider::-moz-range-track {
  height: 6px;
  background: #333;
  border-radius: 3px;
  border: none;
}

.speed-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

#speed-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #c9a834;
  font-variant-numeric: tabular-nums;
}

.speed-hint {
  font-size: 0.8rem;
  color: #666;
}

/* --- History Panel --- */

#history-panel {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  overflow: hidden;
}

#history-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #c9a834;
  border-bottom: 1px solid #2a2a2a;
  cursor: default;
}

#history-toggle-btn {
  background: none;
  border: none;
  color: #888;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

#history-toggle-btn:hover {
  color: #e0e0e0;
  background: #2a2a2a;
}

#history-list {
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #444 #1a1a1a;
}

#history-list::-webkit-scrollbar {
  width: 6px;
}

#history-list::-webkit-scrollbar-track {
  background: #1a1a1a;
}

#history-list::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

#history-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #222;
  cursor: pointer;
  transition: background 0.15s;
}

#history-list li:last-child {
  border-bottom: none;
}

#history-list li:hover {
  background: #252525;
}

/* Thumbnail placeholder in history items */
#history-list li .thumb {
  width: 64px;
  height: 36px;
  background: #333;
  border-radius: 4px;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 0.65rem;
}

#history-list li .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#history-list li .history-info {
  flex: 1;
  min-width: 0;
}

#history-list li .history-info .history-video-title {
  font-size: 0.85rem;
  color: #e0e0e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

#history-list li .history-info .history-video-meta {
  font-size: 0.72rem;
  color: #777;
  margin-top: 2px;
}

/* Empty state for history */
#history-list:empty::after {
  content: "No recent videos";
  display: block;
  padding: 24px 16px;
  text-align: center;
  color: #555;
  font-size: 0.85rem;
}

/* --- Seek Feedback Overlay (mobile gestures) --- */

.seek-feedback {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  pointer-events: none;
}

.seek-feedback span {
  display: inline-block;
  padding: 14px 28px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* --- Desktop Layout (>=768px) --- */

@media (min-width: 768px) {
  #main-content {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  #video-section {
    flex: 1;
    min-width: 0;
  }

  #controls-history {
    flex-direction: row;
    width: 100%;
  }

  #controls-section {
    flex: 1;
    flex-direction: row;
    align-items: flex-start;
  }

  .control-group {
    flex: 1;
  }

  #history-panel {
    width: 280px;
    flex-shrink: 0;
  }

  #history-toggle-btn {
    display: none;
  }
}

/* Wide desktop: video + sidebar side-by-side */
@media (min-width: 1024px) {
  #main-content {
    flex-wrap: nowrap;
    flex-direction: column;
  }

  /* Top row: video full width */
  #video-section {
    width: 100%;
  }

  /* Bottom row: controls left, history right */
  #controls-history {
    flex-direction: row;
  }

  #controls-section {
    flex: 1;
    flex-direction: row;
  }

  #history-panel {
    width: 300px;
  }
}

/* --- Mobile Layout (<768px) --- */

@media (max-width: 767px) {
  #url-bar {
    padding: 10px 12px;
  }

  #url-input {
    padding: 12px;
    font-size: 1rem;
  }

  #load-btn {
    padding: 12px 20px;
    min-height: 44px;
  }

  #main-content {
    padding: 12px;
    gap: 12px;
  }

  #player-container {
    border-radius: 6px;
  }

  /* Timeline adjustments */
  #timeline-container {
    gap: 8px;
    padding: 8px 0;
  }

  .timeline-play {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  #time-display {
    font-size: 0.75rem;
    min-width: 80px;
  }

  /* Controls stacked */
  #controls-history {
    flex-direction: column;
    gap: 12px;
  }

  #controls-section {
    flex-direction: column;
    gap: 12px;
  }

  /* Larger touch targets */
  .btn {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn-large {
    width: 72px;
    height: 72px;
    font-size: 1.6rem;
  }

  .toggle-switch {
    width: 52px;
    height: 28px;
    border-radius: 14px;
  }

  .toggle-switch::after {
    width: 22px;
    height: 22px;
  }

  .toggle-label input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(24px);
  }

  .chunk-settings {
    flex-direction: column;
    gap: 10px;
  }

  .chunk-settings select,
  select {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  /* Speed slider thumb bigger on mobile */
  #speed-slider {
    height: 8px;
  }

  #speed-slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  #speed-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  /* Timeline scrubber bigger on mobile */
  #timeline-scrubber::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    margin-top: -7px;
  }

  #timeline-scrubber::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }

  /* History panel collapsible */
  #history-panel {
    border-radius: 8px;
  }

  #history-title {
    cursor: pointer;
  }

  #history-list {
    max-height: 260px;
  }

  #history-panel.collapsed #history-list {
    display: none;
  }

  #history-panel.collapsed #history-toggle-btn {
    transform: rotate(-90deg);
  }

  #history-toggle-btn {
    transition: transform 0.2s, color 0.15s, background 0.15s;
  }

  .seek-feedback span {
    font-size: 1.6rem;
    padding: 16px 32px;
  }
}

/* --- Focus Styles (accessibility) --- */

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #c9a834;
  outline-offset: 2px;
}

/* Remove default focus ring for mouse users */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

/* --- Selection --- */

::selection {
  background: rgba(201, 168, 52, 0.4);
  color: #fff;
}

/* --- Utilities --- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
