:root {
  --bg: #09090b;
  --bg-elevated: #111113;
  --card: #161618;
  --card-hover: #1c1c1f;
  --border: #27272a;
  --border-subtle: #1f1f23;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #ef4444;
  --accent-soft: rgba(239, 68, 68, 0.12);
  --accent-hover: #f87171;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.12);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --blue-hover: #60a5fa;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
}

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

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(239, 68, 68, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(59, 130, 246, 0.05), transparent);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-top: 0.5rem;
}
header .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-radius: 16px;
  font-size: 1.6rem;
  margin-bottom: 1rem;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.3);
}
header h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.4rem;
}
header p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 420px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.card:hover { border-color: #3f3f46; }
.card h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card h2 .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}
input[type="text"], textarea, select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%2371717a' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.2rem;
}
textarea {
  min-height: 120px;
  resize: vertical;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.row > * { flex: 1; min-width: 130px; }

button {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
button:active { transform: scale(0.97); }
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #f87171, #ef4444);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--card-hover);
  border-color: #3f3f46;
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
}
.btn-success:hover:not(:disabled) {
  background: linear-gradient(135deg, #4ade80, #22c55e);
}

.btn-loop {
  background: var(--blue-soft);
  color: var(--blue-hover);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.btn-loop:hover:not(:disabled) { background: rgba(59, 130, 246, 0.25); }
.btn-loop.active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border-color: transparent;
  box-shadow: 0 0 0 3px var(--blue-soft), 0 4px 14px rgba(59, 130, 246, 0.35);
}

.btn-done {
  background: var(--success-soft);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.btn-done:hover:not(:disabled) { background: rgba(34, 197, 94, 0.22); }

#player-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1.15rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#player { width: 100%; height: 100%; }

.current-step {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.04));
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.95rem 1.15rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.current-step .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.current-step .title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.current-step .time-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-left: 0.4rem;
}
.badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.pill.done { background: var(--success-soft); color: #4ade80; }
.pill.looping { background: var(--blue-soft); color: var(--blue-hover); }

.progress-wrap { margin-bottom: 1rem; }
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.extra-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.speed-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  min-width: 130px;
}
.speed-box label {
  margin: 0;
  font-size: 0.8rem;
  white-space: nowrap;
}
.speed-box select {
  border: none;
  background-color: transparent;
  padding: 0.55rem 1.6rem 0.55rem 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: none;
}
.speed-box select:focus { box-shadow: none; border: none; }

.status {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.3em;
}

.steps-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 4px;
}
.steps-list::-webkit-scrollbar { width: 5px; }
.steps-list::-webkit-scrollbar-track { background: transparent; }
.steps-list::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 999px; }

.steps-list li {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.steps-list li:hover {
  background: var(--card-hover);
  border-color: var(--border);
}
.steps-list li.active {
  background: var(--accent-soft);
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.15);
}
.steps-list li.done { opacity: 0.7; }
.steps-list li.done .title {
  text-decoration: line-through;
  color: #86efac;
}
.steps-list li.done.active { opacity: 0.9; }

.check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #3f3f46;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
  transition: all 0.15s;
  color: transparent;
}
.steps-list li.done .check {
  background: var(--success);
  border-color: var(--success);
  color: white;
}
.check:hover { border-color: var(--success); }

.steps-list .time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  min-width: 48px;
}
.steps-list .title {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 500;
}
.steps-list .actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.steps-list li:hover .actions { opacity: 1; }
.steps-list .actions button {
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
}
.steps-list .actions button:hover {
  background: var(--card);
  color: var(--text);
  border-color: #52525b;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.65rem;
  line-height: 1.45;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.15rem;
}
@media (max-width: 780px) {
  .grid { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr 1fr; }
  .extra-controls { grid-template-columns: 1fr; }
  header h1 { font-size: 1.5rem; }
}

.badge {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  border: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.empty-state span {
  display: block;
  font-size: 2rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

/* Search */
.search-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.search-row input {
  flex: 1;
}
.platforms {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}
.platforms-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover {
  border-color: #3f3f46;
  background: var(--card-hover);
}
.chip input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
}
.chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--accent-hover);
}

.search-results {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.search-results-title {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}
.search-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.search-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s;
}
.search-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.search-link .icon {
  font-size: 1.1rem;
}

@media (max-width: 600px) {
  .search-row {
    flex-direction: column;
  }
}

/* Timeline */
.timeline-wrap {
  margin-bottom: 1rem;
  user-select: none;
}
.timeline-bar {
  position: relative;
  height: 14px;
  background: var(--bg-elevated);
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
  overflow: visible;
}
.timeline-bar:hover {
  border-color: #3f3f46;
}
.timeline-buffered {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: #27272a;
  border-radius: 999px;
  width: 0%;
  pointer-events: none;
}
.timeline-progress {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #ef4444, #f87171);
  border-radius: 999px;
  width: 0%;
  pointer-events: none;
  z-index: 1;
}
.timeline-playhead {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--accent);
  left: 0%;
  z-index: 3;
  pointer-events: none;
}
.timeline-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  z-index: 2;
  pointer-events: none;
}
.timeline-marker.in {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}
.timeline-marker.out {
  background: #3b82f6;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}
.timeline-times {
  display: flex;
  justify-content: space-between;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}
.marker-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}
.btn-sm {
  padding: 0.45rem 0.75rem !important;
  font-size: 0.82rem !important;
}
.marker-controls kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  margin-left: 0.15rem;
  color: var(--text-secondary);
}
.marker-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
.marker-info strong {
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
}

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 9999;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  min-width: 180px;
  display: none;
}
.ctx-menu.visible { display: block; }
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}
.ctx-menu button:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}
.modal-range {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 1rem;
}
.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.marker-edit-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.marker-edit-row label {
  margin: 0;
  min-width: 52px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.marker-time-input {
  width: 90px !important;
  padding: 0.4rem 0.55rem !important;
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 0.85rem !important;
  text-align: center;
}
.marker-current {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--text);
  min-width: 90px;
}


/* Capítulos en la línea de tiempo */
.timeline-chapters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.timeline-chapter-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(250, 250, 250, 0.55);
  margin-left: -1px;
}
.timeline-chapter-tick.active {
  background: var(--accent);
  width: 3px;
  margin-left: -1.5px;
}
.timeline-chapter-labels {
  position: relative;
  height: 28px;
  margin-top: 6px;
  overflow: hidden;
}
.timeline-chapter-label {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  max-width: 90px;
  font-size: 0.65rem;
  line-height: 1.2;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  pointer-events: auto;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.timeline-chapter-label:hover,
.timeline-chapter-label.active {
  color: var(--accent-hover);
  background: var(--accent-soft);
}
.timeline-chapter-label:first-child {
  transform: translateX(0);
  text-align: left;
}
