:root {
  --bg: #0c0d10;
  --text: #f4f0e8;
  --muted: #a0a8b8;
  --accent: #e8c56a;
  --playhead: #ff4d6d;
  --paper: #f3eee3;
  --ink: #1c1820;
  --timeline-h: 2.75rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.score-scroll {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  z-index: 1;
}

.paper {
  padding: 0.05rem 0.05rem 1.5rem;
  transform-origin: top center;
  will-change: transform;
}

.paper svg {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.paper svg .abcjs-cursor {
  stroke: var(--playhead);
  stroke-width: 3;
  stroke-linecap: round;
}

.paper svg .abcjs-note,
.paper svg .abcjs-note * {
  pointer-events: none;
}

.paper svg .note-active {
  fill: #c45a3a !important;
  stroke: #c45a3a !important;
}

/* When pace tracker is off, neutralize any leftover highlight classes */
.app.pace-off .paper svg .note-active {
  fill: inherit !important;
  stroke: inherit !important;
}

.app.pace-off .paper svg .abcjs-lyric.lyric-active,
.app.pace-off .paper svg .abcjs-lyric.lyric-past,
.app.pace-off .paper svg .abcjs-lyric.lyric-future {
  fill: var(--ink) !important;
  opacity: 1 !important;
  font-weight: 650 !important;
}

.paper svg .abcjs-lyric {
  font-size: 1.85em;
  font-weight: 600;
  transition: fill 0.1s ease, opacity 0.1s ease;
}

.paper svg .abcjs-lyric.lyric-future {
  fill: #7a7580 !important;
  opacity: 0.5;
}

.paper svg .abcjs-lyric.lyric-past {
  fill: #4a4550 !important;
  opacity: 0.35;
}

.paper svg .abcjs-lyric.lyric-active {
  fill: #b53a1a !important;
  opacity: 1;
  font-weight: 700;
}

.paper svg .abcjs-title,
.paper svg .abcjs-subtitle,
.paper svg .abcjs-composer,
.paper svg .abcjs-author {
  display: none;
}

/* Always-on bottom timeline */
.timeline {
  flex: 0 0 auto;
  z-index: 6;
  display: grid;
  grid-template-columns: 2.6rem 1fr 2.6rem;
  gap: 0.4rem;
  align-items: center;
  min-height: var(--timeline-h);
  padding: 0.35rem calc(0.75rem + var(--safe-right)) calc(0.4rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left));
  font-family: system-ui, -apple-system, sans-serif;
  background: rgba(12, 13, 16, 0.72);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  color: var(--text);
  pointer-events: auto;
}

.time {
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#scrubber {
  width: 100%;
  accent-color: var(--accent);
  height: 1.5rem;
  cursor: pointer;
}

/* Brief gesture feedback */
.flash {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.85);
  z-index: 8;
  pointer-events: none;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(12, 13, 16, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 0.45rem 0.85rem;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.flash.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (orientation: landscape) {
  .timeline {
    min-height: 2.35rem;
    padding-top: 0.22rem;
    padding-bottom: calc(0.22rem + var(--safe-bottom));
  }
  .time { font-size: 0.65rem; }
  #scrubber { height: 1.25rem; }
  .paper {
    padding: 0 0.02rem 0.75rem;
  }
  .paper svg .abcjs-lyric {
    font-size: 1.7em;
    font-weight: 650;
  }
  .flash { font-size: 1.35rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .paper svg .abcjs-lyric {
    font-size: 1.55em;
  }
  .paper svg .abcjs-cursor {
    stroke-width: 2.1;
  }
}
