/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --border: #2e2e42;
  --accent: #6c63ff;
  --accent-dim: #3d3880;
  --green: #22c55e;
  --green-dim: #15803d;
  --red: #ef4444;
  --red-dim: #991b1b;
  --text: #e2e2f0;
  --text-muted: #7b7b9a;
  --handle-a: #6c63ff;
  --handle-b: #f59e0b;
  --radius: 8px;
  --radius-sm: 4px;
  --toolbar-h: 56px;
  --timebar-h: 24px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  transition: background 0.15s, opacity 0.15s;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== UPLOAD PAGE ===== */
#upload-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.upload-card h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #6c63ff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.upload-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 13px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  margin-bottom: 24px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.06);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
}

.drop-zone p {
  color: var(--text-muted);
  font-size: 13px;
}

.drop-zone p strong {
  color: var(--text);
}

.file-info {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  text-align: left;
  display: none;
}

.file-info.visible { display: flex; }

.file-info .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.file-info .file-size {
  color: var(--text-muted);
  flex-shrink: 0;
}

#btn-start {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
}

#btn-start:hover:not(:disabled) {
  background: #7c74ff;
}

.formats {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 20px;
}

.decode-status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 20px;
}

.decode-status.error {
  color: var(--red);
}

/* ===== TRIMMER PAGE ===== */
#trimmer-page {
  display: none;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#trimmer-page.active {
  display: flex;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: var(--toolbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  flex-wrap: nowrap;
}

.toolbar-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.toolbar-label {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-icon {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.btn-icon:hover:not(:disabled) {
  background: var(--border);
}

.btn-icon.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

#btn-play {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  font-size: 16px;
  flex-shrink: 0;
}

#btn-play:hover:not(:disabled) {
  background: #7c74ff;
}

.time-display {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 110px;
}

.time-display span {
  color: var(--text);
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#zoom-slider {
  width: 100px;
}

.zoom-val {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 32px;
}

#btn-add-marker {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  flex-shrink: 0;
  white-space: nowrap;
}

#btn-add-marker:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

#btn-export {
  background: var(--green-dim);
  color: #fff;
  border: 1px solid var(--green);
  padding: 6px 14px;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
  margin-left: auto;
}

#btn-export:hover:not(:disabled) {
  background: var(--green);
}

/* Marker chips row */
.marker-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  min-height: 36px;
}

.marker-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s;
}

.marker-chip.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.marker-chip .chip-del {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0;
  font-size: 14px;
  line-height: 1;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.marker-chip .chip-del:hover {
  background: rgba(255,255,255,0.1);
  color: var(--red);
}

.no-markers-hint {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* Waveform area */
.waveform-outer {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  background: var(--bg);
  cursor: crosshair;
  /* custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.waveform-outer::-webkit-scrollbar {
  height: 8px;
}
.waveform-outer::-webkit-scrollbar-track {
  background: var(--surface);
}
.waveform-outer::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.waveform-inner {
  position: relative;
  height: 100%;
  /* width set dynamically by JS */
}

#waveform-canvas {
  display: block;
  height: 100%;
  /* width set dynamically */
  image-rendering: pixelated;
}

/* Playhead */
#playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  pointer-events: none;
  z-index: 10;
  transform: translateX(-1px);
}

/* Marker handles rendered as DOM overlays */
.marker-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  z-index: 8;
  cursor: ew-resize;
  /* clickable area wider than visual */
}

.marker-handle::before {
  content: '';
  position: absolute;
  left: -5px;
  right: -5px;
  top: 0;
  bottom: 0;
}

.marker-handle-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid currentColor;
  background: var(--bg);
}

/* Status bar */
.statusbar {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
}

.statusbar span {
  font-size: 11px;
  color: var(--text-muted);
}

.statusbar span b {
  color: var(--text);
  font-weight: 500;
}

/* Export modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  display: none;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.1s;
  width: 0%;
}

/* Scrollbar page-level */
body::-webkit-scrollbar { width: 8px; }
body::-webkit-scrollbar-track { background: var(--bg); }
body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
