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

:root {
  --bg: #3a3a3a;
  --surface: #1e1e1e;
  --bar-h: 68px;
  --toolbar-h: 44px;
  --accent: #4a9eff;
  --accent-hover: #6db3ff;
  --btn-play: #22c55e;
  --btn-play-hover: #16a34a;
  --text: #f0f0f0;
  --muted: #888;
}

@media (max-width: 480px) {
  :root {
    --bar-h: 56px;
    --toolbar-h: 40px;
  }
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

/* ── Floating toolbar ── */
#toolbar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  height: var(--toolbar-h);
  background: rgba(20, 20, 20, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  z-index: 100;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  white-space: nowrap;
}

#toolbar button {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: background 0.15s;
}
#toolbar button:hover { background: rgba(255,255,255,0.12); }
#toolbar button:disabled { opacity: 0.3; cursor: default; }

#page-display {
  font-size: 13px;
  color: var(--muted);
  padding: 0 4px;
  min-width: 80px;
  text-align: center;
}

#page-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 2px 6px;
}
#page-input {
  width: 36px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: center;
  outline: none;
}
#page-total { font-size: 13px; color: var(--muted); }

.sep {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.15);
  margin: 0 2px;
}

#zoom-level {
  font-size: 12px;
  color: var(--muted);
  min-width: 38px;
  text-align: center;
}

/* ── PDF scroll container ── */
#viewer {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--bar-h);
  overflow-y: scroll;
  overflow-x: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 70px 0 24px;
  gap: 12px;
}

/* prevent centering from clipping pages wider than viewport */
.page-container {
  flex-shrink: 0;
}

/* ── Per-page wrapper ── */
.page-container {
  position: relative;
  display: block;
  flex-shrink: 0;
  box-shadow: 0 4px 24px rgba(0,0,0,0.55);
  border-radius: 2px;
  background: #fff;
  line-height: 0;
}

.page-container canvas {
  display: block;
  border-radius: 2px;
}

/* ── Audio buttons on pages ── */
.audio-btn {
  position: absolute;
  transform: translate(-50%, -50%);
  width: var(--btn-size, 32px);
  height: var(--btn-size, 32px);
  border-radius: 50%;
  background: var(--btn-play);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--btn-font, 10px);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  z-index: 10;
  padding: 0;
  line-height: 1;
  letter-spacing: -0.3px;
}
.audio-btn:hover {
  background: var(--btn-play-hover);
  box-shadow: 0 4px 14px rgba(34,197,94,0.5);
  transform: translate(-50%, -50%) scale(1.18);
}
.audio-btn.playing {
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(74,158,255,0.6);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,158,255,0.55); }
  50%       { box-shadow: 0 0 0 8px rgba(74,158,255,0); }
}

/* ── Bottom audio player bar ── */
#player-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bar-h);
  background: var(--surface);
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  z-index: 100;
}

#play-pause {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#play-pause:hover { background: var(--accent-hover); }

#now-playing {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  min-width: 130px;
  flex-shrink: 0;
}
#now-playing span { color: var(--text); font-weight: 600; }

#progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#progress {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #444;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
#progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
#time-display {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

#volume {
  width: 72px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #444;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--muted);
  cursor: pointer;
}

/* loading state */
#loading {
  position: fixed;
  inset: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  font-size: 15px;
  color: var(--muted);
}
#loading-bar-wrap {
  width: 240px;
  height: 4px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
}
#loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  #toolbar {
    top: 8px;
    gap: 2px;
    padding: 0 10px;
    border-radius: 20px;
  }

  #toolbar button {
    padding: 5px 8px;
    font-size: 14px;
  }

  #page-display { display: none; }

  .sep { display: none; }

  #zoom-level { min-width: 30px; font-size: 11px; }

  #page-input { width: 30px; font-size: 12px; }
  #page-total { font-size: 12px; }

  #viewer {
    padding-top: 60px;
    padding-bottom: 16px;
    gap: 8px;
  }

  /* Player bar: compact single row */
  #player-bar {
    gap: 8px;
    padding: 0 10px;
  }

  #play-pause {
    width: 32px;
    height: 32px;
    font-size: 13px;
    flex-shrink: 0;
  }

  #now-playing {
    min-width: 0;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
  }

  #time-display { display: none; }

  #volume { display: none; }

  /* Audio buttons scale via --btn-size JS variable */
}

/* ── Edit mode ── */
body.edit-mode #viewer {
  right: 280px;
}

#edit-sidebar {
  position: fixed;
  top: 0; right: 0;
  width: 280px;
  bottom: 0;
  background: #111;
  border-left: 1px solid #333;
  display: flex;
  flex-direction: column;
  z-index: 200;
  font-size: 13px;
  color: var(--text);
}

#edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#edit-save {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
#edit-save:hover { background: var(--accent-hover); }

#edit-status {
  padding: 8px 14px;
  border-bottom: 1px solid #222;
  font-size: 12px;
  flex-shrink: 0;
  line-height: 1.6;
}
.stat-ok   { color: #22c55e; }
.stat-miss { color: #f87171; }

#edit-instructions {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid #222;
  flex-shrink: 0;
  line-height: 1.5;
}

#edit-search-wrap {
  padding: 8px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid #222;
}
#edit-search {
  width: 100%;
  background: #222;
  border: 1px solid #444;
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}
#edit-search:focus { border-color: var(--accent); }

#edit-track-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-content: flex-start;
}

.edit-track-item {
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: monospace;
  user-select: none;
  border: 2px solid transparent;
  transition: border-color 0.1s, background 0.1s;
}
.edit-track-item.placed  { background: #1a3a1a; color: #4ade80; }
.edit-track-item.missing { background: #3a1a1a; color: #f87171; }
.edit-track-item.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}
.edit-track-item:hover { opacity: 0.8; }

/* In edit mode, audio buttons are draggable and show delete hint */
body.edit-mode .audio-btn {
  cursor: grab;
  user-select: none;
}
body.edit-mode .audio-btn:active { cursor: grabbing; }
body.edit-mode .audio-btn::after {
  content: '×';
  position: absolute;
  top: -6px; right: -6px;
  width: 14px; height: 14px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  display: none;
}
body.edit-mode .audio-btn:hover::after { display: block; }
