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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #222;
  --text-secondary: #666;
  --accent: #2a6dd4;
  --accent-hover: #1d5ab8;
  --border: #ddd;
  --trim-overlay: rgba(200, 200, 200, 0.55);
  --handle-color: #d44;
  --cursor-color: #2a6dd4;
  --marker-color: #e67300;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px;
}

h1 {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  padding: 8px 0 12px;
}

/* ---- File input ---- */
.file-section {
  text-align: center;
  margin-bottom: 12px;
}

.file-label {
  display: inline-block;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.file-label:active { background: var(--accent-hover); }
.file-label input { display: none; }

.file-info {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---- Spectrogram ---- */
.spectrogram-section {
  display: none;
  margin-bottom: 12px;
}
.spectrogram-section.visible { display: block; }

.spectrogram-wrapper {
  position: relative;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}

.spectrogram-inner {
  position: relative;
  height: 200px;
  min-width: 100%;
}

canvas#spectrogram {
  display: block;
  height: 200px;
  image-rendering: pixelated;
}

/* ---- Frequency axis labels ---- */
.freq-axis {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.freq-label {
  position: absolute;
  left: 4px;
  font-size: 10px;
  color: rgba(0, 0, 0, 0.5);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.8);
  transform: translateY(-50%);
}

/* ---- Trim overlays and handles ---- */
.trim-overlay-left, .trim-overlay-right {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--trim-overlay);
  pointer-events: none;
}
.trim-overlay-left { left: 0; }
.trim-overlay-right { right: 0; }

.trim-handle {
  position: absolute;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--handle-color);
  cursor: ew-resize;
  z-index: 10;
  touch-action: none;
}
.trim-handle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
}
.trim-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 28px;
  border-radius: 3px;
  border: 2px solid var(--handle-color);
  background: rgba(255, 255, 255, 0.85);
}

.playback-cursor {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--cursor-color);
  pointer-events: none;
  z-index: 5;
  display: none;
}

.playback-marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--marker-color);
  pointer-events: none;
  z-index: 4;
  display: none;
}

/* ---- Time bar ---- */
.time-bar {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 2px 4px;
}

/* ---- Zoom controls ---- */
.zoom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0;
}
.zoom-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.zoom-btn:active { background: #eee; }
.zoom-level {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

/* ---- Playback controls ---- */
.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 10px 0;
}

.play-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.play-btn:active { background: var(--accent-hover); }

.rewind-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.rewind-btn:active { background: #eee; }

.time-display {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 120px;
  text-align: center;
}

/* ---- Settings panel ---- */
.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  gap: 10px;
}
.setting-row:last-child { border-bottom: none; }

.setting-label {
  font-size: 14px;
  flex-shrink: 0;
}

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

.setting-value {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  background: #ddd;
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ---- Save button ---- */
.save-section {
  text-align: center;
  margin: 16px 0;
}

.save-btn {
  display: inline-block;
  padding: 14px 32px;
  background: #2a8c4a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.save-btn:active { background: #1f7a3c; }
.save-btn:disabled {
  background: #aaa;
  cursor: not-allowed;
}

/* ---- Loading overlay ---- */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.loading-overlay.visible { display: flex; }

.loading-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px 32px;
  text-align: center;
  font-size: 15px;
}
.loading-box .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #ddd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }
