/* ==========================================================================
   Developer Rhapsody — blue-on-black terminal session
   ========================================================================== */

:root {
  --bg: #080b0e;
  --border: #263544;
  --border-dim: #1b2632;
  --text: #c9d6e6;
  --text-dim: #8397ad;
  --text-faint: #5b6d80;
  --accent: #b39a6a;

  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Code", "Courier New", monospace;
}

* { box-sizing: border-box; }

/* Any element using [hidden] must actually disappear. Needed because some
   hidden elements (e.g. .cmd buttons) also set `display` via a class,
   which — being an author style at equal specificity to the UA [hidden]
   rule — would otherwise win and defeat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding: calc(env(safe-area-inset-top, 0px) + 1.5rem) 0 calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  position: relative;
  display: flex;
  flex-direction: column;
}

::selection {
  background: var(--text);
  color: var(--bg);
}

/* ---------- CRT overlays (kept minimal — texture, not effect) ---------- */

.crt-scanlines,
.crt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.crt-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.012) 0px,
    rgba(255, 255, 255, 0.012) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.35;
}

.crt-vignette {
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 60%,
    #000000 100%
  );
  opacity: 0.4;
}

/* ---------- Screens ---------- */
/* No window chrome: each screen is raw content sitting directly on the
   page background, inset only by typographic margins (not a panel). */

.screen {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  padding: 0 1.5rem;
  overflow-y: auto;
}

.screen[hidden] { display: none !important; }

body.state-boot #screen-boot { display: flex; }
body.state-playing #screen-player { display: flex; }

/* ---------- Boot shared layout ---------- */

#screen-boot {
  justify-content: center;
}

.boot-wrap {
  max-width: 42rem;
  width: 100%;
}

.prompt-line {
  font-size: 0.95rem;
  letter-spacing: 0;
  line-height: 1.6;
  margin: 0 0 1.4rem;
  color: var(--text);
}

.prompt-line .prompt-user {
  color: var(--text-dim);
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.82rem;
  letter-spacing: 0;
  margin: -1rem 0 1.6rem;
  padding-left: 1.1rem;
}

.boot-log {
  min-height: 8em;
  max-width: 40rem;
  margin: 0 0 1.6rem;
  font-size: 0.9rem;
  line-height: 1.75;
}

.boot-log .line {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-left: 1.1rem;
  text-indent: -1.1rem;
}

.boot-log .line.warn {
  color: var(--accent);
}

.credits {
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.8;
  margin: 0.5rem 0 1.6rem;
  padding-left: 1.1rem;
}

/* ---------- Inline command-style controls (no button chrome) ---------- */

.cmd {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0;
  cursor: pointer;
  transition: color 0.15s ease;
  /* Touch target: pad the hit area out to >=44x44px without changing the
     visual footprint — the padding is transparent (no box/background) and
     an equal negative margin cancels it out for surrounding layout/flow.
     The label text is wrapped in a single inner `.cmd-content` span so this
     flex container has exactly one flex item; flexbox otherwise drops
     whitespace-only anonymous flex items, which was eating the space
     between the prompt and the bracketed command. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.6rem 0.55rem;
  margin: -0.6rem -0.55rem;
}

.cmd:hover,
.cmd:focus-visible {
  color: #b9c9dc;
  outline: none;
}

.cmd:active {
  color: #ffffff;
}

.cmd.cmd-small {
  font-size: 0.85rem;
}

.cmd-bracket { color: var(--text-faint); }

/* The hover/focus underline is drawn on the visible label text itself
   (start at `[`, end at `]`), not on the padded/negative-margined hit box,
   so it stays aligned with the text regardless of the enlarged tap target. */
.cmd-label {
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.cmd:hover .cmd-label,
.cmd:focus-visible .cmd-label {
  border-bottom-color: var(--text-dim);
}

.cursor-block {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  background: var(--text);
  margin-left: 0.3em;
  vertical-align: text-bottom;
  animation: cursor-blink 1s steps(1) infinite;
}

@keyframes cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor-block { animation-duration: 1.4s; }
}

/* ---------- Player screen ---------- */

body.state-playing {
  /* #screen-player owns the full viewport and its own safe-area padding
     while playing, instead of the generic body padding used by the other
     (scrollable, centered) screens. */
  padding: 0;
}

#screen-player {
  justify-content: flex-start;
  gap: 0.85rem;
  /* Override .screen's `flex: 1` (flex-basis: 0%): with a 0 flex-basis the
     flexbox algorithm ignores the `height` below for main-axis sizing and
     the box grows to fit its content instead, letting the document scroll.
     `flex: 0 0 auto` makes `height` the actual (and only) basis, so this
     screen is really clamped to the viewport and only its internal
     .lyrics-region scrolls. */
  flex: 0 0 auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding: calc(env(safe-area-inset-top, 0px) + 1.1rem) 1.5rem
    calc(env(safe-area-inset-bottom, 0px) + 1.1rem);
}

/* ---------- Compile progress bar (pinned above the status line) ---------- */

.compile-bar-wrap {
  width: 100%;
  /* Deliberate breathing room around the bar so it reads as its own beat
     rather than crowding the safe-area padding above or the topbar/lyrics
     below, plus a restrained separator rule (matching .player-bottom's
     border-top above the transport controls) marking it off from the
     lyrics/status area. This comes out of the lyrics-region's flex-grow
     height (see #screen-player's fixed 100dvh + flex layout) rather than
     the screen's overall height, so the bottom controls never get pushed
     off-screen — the max-width:480px override below shrinks the margins
     (keeping the separator) so the lyrics region keeps usable height on
     phones. */
  margin-top: 2rem;
  padding-bottom: 1.15rem; /* space between the status line and the separator */
  border-bottom: 1px solid var(--border-dim);
  /* Space below the separator itself, before the topbar. #screen-player's
     own 0.85rem flex `gap` already contributes some of this, so this margin
     is only the remainder needed to bring the divider-to-topbar gap up to
     a full ~2rem (32px) total. */
  margin-bottom: 1.15rem;
}

.compile-track {
  width: 100%;
  height: 3px;
  background: var(--border-dim);
  overflow: hidden;
}

.compile-fill {
  height: 100%;
  width: 0%;
  background: var(--text-dim);
  transition: width 0.25s linear, background-color 0.25s linear;
}

.compile-fill.failed {
  background: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  .compile-fill {
    transition: none;
  }
}

.compile-status {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.compile-status.failed {
  color: var(--accent);
}

.player-topbar {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  letter-spacing: 0;
}

#track-counter {
  color: var(--text);
}

.now-playing-label {
  color: var(--text-dim);
}

.track-title {
  color: var(--text);
}

.lyrics-region {
  flex: 1;
  min-height: 0;
  width: 100%;
  /* Pinned-to-bottom "terminal" buffer: scrolling is driven entirely by
     pinLyricsToBottom() in js/app.js (programmatic scrollTop still works
     on an overflow:hidden element). overflow:hidden also means there is
     never a scrollbar to hide, but scrollbar-width/::-webkit-scrollbar are
     kept as a defensive no-op in case that ever changes. */
  overflow: hidden;
  overscroll-behavior: contain;
  padding: 0.25rem 0;
  scrollbar-width: none;
}

.lyrics-region::-webkit-scrollbar {
  display: none;
}

.lyrics-panel {
  width: 100%;
  font-size: 0.98rem;
  line-height: 1.85;
  color: var(--text);
}

.lyrics-panel .lyric-line {
  min-height: 1em;
}

/* Untimed fallback: whole block fades/staggers in once at track start. */
.lyrics-panel .lyric-line.stagger-in {
  opacity: 0;
  transform: translateY(2px);
  animation: lyric-in 0.4s ease forwards;
}

/* Timed reveal: a newly-activated line fades in quickly, no stagger/motion. */
.lyrics-panel .lyric-line.timed-in {
  opacity: 0;
  animation: lyric-in-fast 0.15s ease forwards;
}

.lyrics-panel .lyric-line.past {
  color: var(--text-dim);
}

.lyrics-panel .lyric-line.active {
  color: var(--text);
}

/* Typed-prefix text + the singleton typing cursor (see js/app.js
   getCursorEl/beginTypingLine). The cursor is a plain inline sibling
   appended right after the `.lyric-text` span, so it always sits
   immediately after the last typed character and wraps naturally with
   the text on narrow screens — no absolute positioning needed. It keeps
   its normal .cursor-block blink the whole time, while typing and while
   idle at the end of a completed active line. */
.lyrics-panel .lyric-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.lyrics-panel .cursor-block.lyric-cursor {
  margin-left: 0.05em;
}

@media (prefers-reduced-motion: reduce) {
  .lyrics-panel .cursor-block.lyric-cursor {
    animation: none;
    opacity: 1;
  }
}

/* Compiler-error ending output: exact spacing preserved. The block is
   authored narrow enough (widest line 33 chars) to fit at 375px without
   wrapping or horizontal scrolling, so there is no per-line overflow-x
   strip (that created a nested scroll strip on phones). */
.lyrics-panel .lyric-line.compiler-line {
  white-space: pre;
  max-width: 100%;
}

.lyrics-panel .lyric-line.compiler-error {
  color: var(--accent);
}

/* Synchronized-with-the-bar progress lines during the ending ramp: whole
   lines (no typing), dim like other terminal output, monospace (inherited
   from body). */
.lyrics-panel .lyric-line.progress-line {
  color: var(--text-dim);
}

/* "# human covers wanted..." note, printed after the compiler output.
   Unlike .compiler-line (fixed-width `pre`, authored to never wrap), this
   wraps normally so it never causes horizontal overflow at 375px. */
.lyrics-panel .lyric-line.covers-note-line {
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  /* Safety margin so the 33-char-wide error block never wraps at 375px. */
  .lyrics-panel .lyric-line.compiler-line {
    font-size: 0.85rem;
  }
}

.lyrics-panel .lyric-line.replay-prompt-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.6rem;
}

.lyrics-panel .lyric-line.replay-prompt-line .prompt-user {
  color: var(--text-dim);
}

/* "press ? for about" hint + `$ cat ABOUT` easter egg, appended after the
   replay prompt (see printAboutHint/showAbout in js/app.js). */
.lyrics-panel .lyric-line.about-hint-line {
  color: var(--text-dim);
  margin-top: 0.6rem;
}

.lyrics-panel .lyric-line.about-output-line {
  color: var(--text);
}

.lyrics-panel .lyric-line.about-link-line {
  margin-top: 0.1rem;
}

.lyrics-panel .about-link {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--text-dim);
  transition: color 0.15s ease;
  /* Same padding + equal negative-margin trick as .cmd: pads the tap
     target out to >=44px tall without changing the visible text's size
     or position. */
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.6rem 0;
  margin: -0.6rem 0;
}

.lyrics-panel .about-link:hover,
.lyrics-panel .about-link:focus-visible {
  color: #ffffff;
  text-decoration-color: var(--text);
}

@keyframes lyric-in {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lyric-in-fast {
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lyrics-panel .lyric-line.stagger-in,
  .lyrics-panel .lyric-line.timed-in {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

.error-line {
  width: 100%;
  color: var(--accent);
  font-size: 0.82rem;
}

.player-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--border-dim);
  padding-top: 0.75rem;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.time {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-width: 2.4rem;
  text-align: center;
}

/* Deliberately NOT an <input type=range>: a plain div, non-interactive,
   display-only progress indicator. No seek/scrub affordance whatsoever. */
.progress-track {
  flex: 1;
  height: 3px;
  background: var(--border-dim);
  pointer-events: none;
  position: relative;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--text-dim);
  pointer-events: none;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.volume-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.volume-slider {
  width: 7rem;
  max-width: 40vw;
  accent-color: var(--text-dim);
}

/* iOS Safari ignores programmatic audio.volume, so the slider is dead
   weight there — hide it on coarse-pointer (touch) devices and rely on
   the mute toggle instead. Desktop (fine pointer) keeps the slider. */
@media (pointer: coarse) {
  .volume-slider {
    display: none;
  }
}

.tap-continue {
  color: var(--accent);
}

/* ---------- Jukebox (post-ending mini player) ---------- */
/* Sibling of .player-bottom: only one of the two is ever visible at a time
   (see setState/showJukebox/hideJukebox in js/app.js). Seeking is allowed
   here — unlike .progress-track, .jukebox-seek-track is a real interactive
   control. */

.jukebox {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--border-dim);
  padding-top: 0.75rem;
  min-height: 0;
}

.jukebox-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.jukebox-track {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}

.jukebox-track-marker {
  display: inline-block;
  width: 1.2em;
  flex: none;
  color: var(--text);
}

.jukebox-track-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.jukebox-track:not(.is-current) .jukebox-track-marker {
  visibility: hidden;
}

.jukebox-track:not(.is-current) .cmd-label {
  color: var(--text-dim);
}

.jukebox-track.is-current .cmd-label {
  color: var(--text);
}

.jukebox-seek-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Visually a thin 3px bar, but padded (with an equal negative margin, same
   trick as .cmd) so the real pointer hit area is >=24px tall — comfortably
   tappable on phones without changing how the bar looks. */
.jukebox-seek-track {
  flex: 1;
  position: relative;
  cursor: pointer;
  padding: 11px 0;
  margin: -11px 0;
  touch-action: none;
}

.jukebox-seek-track::before {
  content: "";
  display: block;
  height: 3px;
  background: var(--border-dim);
}

.jukebox-seek-fill {
  position: absolute;
  left: 0;
  top: 11px;
  height: 3px;
  width: 0%;
  background: var(--text-dim);
  pointer-events: none;
}

.jukebox-transport-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.jukebox-legend {
  color: var(--text-faint);
  font-size: 0.72rem;
}

@media (pointer: coarse) {
  .jukebox-legend {
    display: none;
  }
}

.jukebox-actions-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .screen { padding: 0 1.1rem; }
  .controls-row { justify-content: flex-start; }
  .volume-slider { width: 6rem; }
  .compile-bar-wrap {
    margin-top: 1.25rem;
    padding-bottom: 0.4rem; /* space between the status line and the separator */
    /* + the .85rem flex gap below = ~1.25rem (20px) total below the divider */
    margin-bottom: 0.4rem;
  }
}
