/* ═══════════════════════════════════════════════════════════════════════════
   Shared song-player styles (all 9 OSMD pages).
   Per-song variance is config-driven from songs/<id>.js via player.js:
     • --maxw           content column width (default 860px; gullvagninn 900px)
     • #btn-<voice>     per-voice --vc colour rules (dark + light theme)
     • tiny-height compact breakpoint (default 560px; 520px on two pages)
   ═══════════════════════════════════════════════════════════════════════════ */
:root, html.theme-dark {
  --bg: #0b0b1e; --panel: #13132a; --text: #e0e0ff;
  --title: #c0c8ff; --sub: #6870a0; --lyr: #ffffff; --lyr2: #8890bb;
  --accent: #5555cc; --accent2: #9966ff; --track: #1e1e3a;
  --music: #e6e6ff;
}
html.theme-light {
  --bg: #faf8f2; --panel: #faf8f2; --text: #2a2a3a;
  --title: #333355; --sub: #8a8aa0; --lyr: #1a1a2a; --lyr2: #6a6a88;
  --accent: #5555cc; --accent2: #9966ff; --track: #e2e0ee;
  --music: #1a1a28;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: Georgia, serif;
  min-height: 100vh;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: 22px 16px 10px; gap: 6px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  overflow: hidden; min-height: 0;
  transition: background .25s, color .25s;
}
.topbar {
  width: 100%; max-width: var(--maxw, 860px); flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  position: relative;
}
h1 { font-size: 1.4em; color: var(--title); letter-spacing: .04em; text-align: center; line-height: 1.1; }
.themebtn {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--sub);
  background: transparent; color: var(--title); cursor: pointer; font-size: 1.05em;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.themebtn:hover { border-color: var(--accent); }
/* Gear (⚙) — main-voice settings, left side of the topbar, mirrors .themebtn. */
.gearbtn {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--sub);
  background: transparent; color: var(--title); cursor: pointer; font-size: 1.05em;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.gearbtn:hover { border-color: var(--accent); }
.sub { color: var(--sub); font-size: .8em; text-align: center; flex: 0 0 auto; line-height: 1.15; }
.voices-wrap { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.voices-label { color: var(--sub); font-size: .72em; letter-spacing: .02em; }
.voices { flex: 0 0 auto; }
.lyrics { flex: 0 0 auto; }
.controls { flex: 0 0 auto; }
.progress { flex: 0 0 auto; }
.voices { display: flex; gap: 9px; flex-wrap: nowrap; justify-content: center; }
/* Pill: neutral background in BOTH states; the voice colour (var(--vc)) lives on
   the BORDER + the NAME text, and the SWITCH carries the on/off signal. This keeps
   good contrast in dark AND light themes and never inverts text to a near-black. */
.vbtn {
  padding: 6px 15px; border: 2px solid var(--vc); border-radius: 20px;
  cursor: pointer; font-size: .88em; font-weight: bold;
  color: var(--vc);
  background: color-mix(in srgb, var(--vc) 10%, var(--panel));
  transition: opacity .2s, background .2s; user-select: none;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.vbtn .vlbl-short { display: none; }   /* abbreviation shown only on narrow screens */
.vbtn .vswitch {
  position: relative; display: inline-block;
  width: 30px; height: 16px; flex: 0 0 auto;
  border-radius: 9px; border: 1.5px solid var(--vc);
  background: var(--track); transition: background .2s, border-color .2s;
  vertical-align: middle;
}
.vbtn .vswitch::after {            /* the sliding knob */
  content: ''; position: absolute; top: 1px; left: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--sub); transition: left .2s, background .2s;
}
/* ON: track filled with the voice colour, knob a light bg colour slid right. */
.vbtn.on  .vswitch { background: var(--vc); border-color: var(--vc); }
.vbtn.on  .vswitch::after { left: 15px; background: var(--panel); }
/* OFF: grey track, muted knob slid left, whole pill dimmed + neutral background. */
.vbtn.off { opacity: .5; background: var(--panel); border-color: var(--sub); color: var(--sub); }
.vbtn.off .vswitch { border-color: var(--sub); background: var(--track); }
.vbtn.off .vswitch::after { left: 1px; background: var(--sub); }
/* ── Score wrapper ────────────────────────────────────── */
/* #scoreouter is a plain positioned wrapper (kept because the landscape
   immersive mode and the zoom-fit code reference it); #scorewrap fills it. */
#scoreouter {
  width: 100%; max-width: var(--maxw, 860px);
  /* flex-basis 0 (not auto): the score gets exactly the leftover viewport
     space, so its content can never push the controls below the fold; the
     zoom-fit JS then sizes the SVG to the measured box. overflow:hidden
     guarantees clipping over pushing. */
  flex: 1 1 0; min-height: 0; min-width: 0; position: relative;
  display: block; overflow: hidden;
}
/* Per-voice hue (--vc) rules are injected by player.js from the song config. */
.lyrics {
  width: 100%; max-width: var(--maxw, 860px);
  background: var(--panel); border-radius: 10px; padding: 7px 18px;
  text-align: center; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.lyr-ru { font-size: 1.12em; color: var(--lyr); }
.lyr-en { font-size: .78em; color: var(--lyr2); }
#scorewrap {
  width: 100%; height: 100%;
  background: var(--bg); border-radius: 10px;
  overflow-x: auto; overflow-y: hidden;
  padding: 6px 4px;
  min-height: 0;
  display: flex; align-items: center;
  transition: background .25s;
}
#score { }
#score svg { display:block; background: transparent; }

/* ── Theme-aware slim scrollbars (follow --bg / --track via theme class) ── */
/* Firefox */
#scorewrap, body { scrollbar-width: thin; scrollbar-color: var(--track) var(--bg); }
/* WebKit / Blink */
#scorewrap::-webkit-scrollbar, body::-webkit-scrollbar { width: 10px; height: 10px; }
#scorewrap::-webkit-scrollbar-track, body::-webkit-scrollbar-track { background: var(--bg); }
#scorewrap::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb {
  background: var(--track); border-radius: 10px;
  border: 2px solid var(--bg);           /* inset so the thumb reads slimmer */
}
#scorewrap::-webkit-scrollbar-thumb:hover, body::-webkit-scrollbar-thumb:hover { background: var(--accent); }
#scorewrap::-webkit-scrollbar-corner, body::-webkit-scrollbar-corner { background: var(--bg); }
.controls {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap; justify-content: center;
}
.playbtn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--accent); cursor: pointer; font-size: 1.3em; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.playbtn:hover { filter: brightness(1.15); }
.playbtn.loading-state { opacity: .6; cursor: progress; }
.stopbtn {
  width: 38px; height: 38px; border-radius: 8px; border: none;
  background: #441133; cursor: pointer; color: #fff; font-size: 1.1em;
  display: flex; align-items: center; justify-content: center;
}
.stopbtn:hover { background: #662255; }
.tempo-row { display: flex; align-items: center; gap: 8px; color: var(--sub); font-size: .85em; }
input[type=range] { width: 90px; accent-color: var(--accent); }
.progress {
  width: 100%; max-width: var(--maxw, 860px); height: 10px; background: var(--track);
  border-radius: 5px; position: relative; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.progress::before {           /* enlarged invisible hit area (easier to grab) */
  content: ''; position: absolute; left: 0; right: 0; top: -6px; bottom: -14px;
}
.pfill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0%; border-radius: 5px; pointer-events: none; }
.pthumb {
  position: absolute; top: 50%; left: 0%;
  width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: var(--accent2); box-shadow: 0 1px 4px rgba(0,0,0,.45);
  pointer-events: none;
}
.loading { color: var(--sub); font-size: .9em; padding: 30px; }
/* ── Fylgja söng (score following) ── */
.followbtn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 20px;
  border: 2px solid var(--accent2); background: transparent;
  color: var(--accent2); font-weight: bold; font-size: .88em;
  font-family: inherit; cursor: pointer; transition: all .2s; user-select: none;
}
.followbtn:hover { filter: brightness(1.2); }
.followbtn.on { background: var(--accent2); color: #fff; box-shadow: 0 0 10px var(--accent2); }
.fstatus { color: var(--sub); font-size: .8em; }
.fstatus:empty { display: none; }

/* ── Mobile: compact chrome so the whole page fits one screen height ── */
@media (max-width: 640px) {
  body { padding: 16px 8px 8px; gap: 5px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.1em; }
  .themebtn { width: 30px; height: 30px; font-size: .95em; }
  .gearbtn { width: 30px; height: 30px; font-size: .95em; }
  .sub { font-size: .68em; }
  .voices-label { font-size: .64em; }
  /* Narrow phones: guarantee the voice row fits ONE line. Shrink the pill,
     the switch and the gap, and swap the full name for a short abbreviation. */
  .voices { gap: 6px; flex-wrap: nowrap; }
  .vbtn { padding: 4px 9px; font-size: .8em; border-radius: 15px; gap: 5px; }
  .vbtn .vlbl-full { display: none; }
  .vbtn .vlbl-short { display: inline; }
  .vbtn .vswitch { width: 26px; height: 15px; border-radius: 8px; }
  .vbtn .vswitch::after { width: 11px; height: 11px; }
  .vbtn.on .vswitch::after { left: 12px; }
  .lyrics { padding: 5px 12px; min-height: 0; gap: 1px; border-radius: 9px; }
  .lyr-ru { font-size: .98em; }
  .lyr-en { font-size: .7em; }
  #scorewrap { padding: 5px 3px; min-height: 0; }
  .controls { gap: 10px; }
  .playbtn { width: 42px; height: 42px; font-size: 1.15em; }
  .stopbtn { width: 34px; height: 34px; }
  .tempo-row { font-size: .75em; gap: 5px; }
  input[type=range] { width: 70px; }
  .followbtn { padding: 5px 9px; font-size: .74em; gap: 0; border-radius: 14px; }
  .followbtn .flbl { display: none; }
  .fstatus { font-size: .68em; flex-basis: 100%; text-align: center; }
}
/* The very-short-portrait compact rule (h1 shrink, .sub/.voices-label hidden)
   is injected by player.js so its max-height breakpoint stays configurable. */

/* ── Section timeline (pills) ────────────────────────────────────────────── */
:root, html.theme-dark { --pill-fl: 60%; --pill-tl: 76%; --pill-wl: 86%; }
html.theme-light { --pill-fl: 40%; --pill-tl: 30%; --pill-wl: 36%; }
.sections {
  width: 100%; max-width: var(--maxw, 860px); flex: 0 0 auto;
  display: flex; flex-direction: column; gap: 3px;
}
.srow { display: flex; gap: 3px; align-items: stretch; width: 100%; }
.spill {
  flex: 1 1 0; min-width: 0; height: 34px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px 5px; border-radius: 9px; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  background: hsla(var(--sh), 65%, var(--pill-fl), .14);
  border: 1.5px solid hsla(var(--sh), 65%, var(--pill-fl), .45);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.spill:hover { background: hsla(var(--sh), 65%, var(--pill-fl), .28); }
.spill.active {
  background: hsla(var(--sh), 70%, var(--pill-fl), .38);
  border-color: hsl(var(--sh), 70%, var(--pill-fl));
  box-shadow: 0 0 6px hsla(var(--sh), 70%, var(--pill-fl), .55);
}
.spill .sname {
  font-size: .62em; font-weight: bold; line-height: 1.15; letter-spacing: .01em;
  color: hsl(var(--sh), 55%, var(--pill-tl));
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spill .swords {
  font-size: .54em; line-height: 1.1;
  color: hsla(var(--sh), 35%, var(--pill-wl), .85);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spill.narrow .swords { display: none; }
@media (max-width: 640px) {
  .sections { gap: 2px; }
  .spill { height: 27px; border-radius: 7px; padding: 1px 3px; border-width: 1px; }
  .spill .sname { font-size: .56em; }
  .spill .swords { font-size: .48em; }
}

/* ══ LANDSCAPE IMMERSIVE MODE (phone held sideways) ═══════════════════════════
   Trigger: html.immersive is set by JS when matchMedia('(orientation:landscape)
   and (max-height:560px)') matches — i.e. a short, wide (phone-landscape)
   viewport. Desktop and portrait never match, so they are untouched. In
   immersive view the score fills the whole screen; a slim bottom bar carries
   compact play/stop + a ☰ menu button, and a thin scrubbable progress strip sits
   at the very bottom edge. Every other control is REPARENTED (by JS) into #panel,
   an overlay that slides up when ☰ is tapped. The real control elements move —
   one source of truth, all existing handlers keep working. */
.immersivebar, #panel, #menubtn { display: none; }      /* hidden unless immersive */

@media (orientation: landscape) and (max-height: 560px) {
  html.immersive, html.immersive body { height: 100vh; height: 100dvh; }
  html.immersive body {
    padding: 0; gap: 0; overflow: hidden;
    padding-bottom: 0;
  }
  /* Everything that is NOT the score / immersive chrome is hidden from the main
     view. (When reparented into #panel they become visible there again.) */
  html.immersive > body > .topbar,
  html.immersive > body > .sub,
  html.immersive > body > .voices-wrap,
  html.immersive > body > .lyrics,
  html.immersive > body > #sections,
  html.immersive > body > .controls { display: none !important; }

  /* Score fills the viewport (minus the slim progress strip at the very bottom). */
  html.immersive #scoreouter {
    max-width: none; width: 100vw;
    flex: 1 1 auto; min-height: 0; margin: 0;
  }
  html.immersive #scorewrap { border-radius: 0; padding: 2px 2px; }

  /* Slim progress strip pinned to the bottom edge — still fully scrubbable. */
  html.immersive > body > .progress {
    display: block; order: 99;
    width: 100vw; max-width: none; height: 8px; border-radius: 0;
    flex: 0 0 auto; margin: 0;
  }

  /* Slim overlay control bar: compact play/stop at left, ☰ menu at right.
     Overlaid on the score's bottom-left/right corners so it steals no height. */
  html.immersive .immersivebar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; left: 8px; bottom: 14px; z-index: 40;
    padding: 5px 8px; border-radius: 22px;
    background: color-mix(in srgb, var(--panel) 82%, transparent);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0,0,0,.4);
    pointer-events: auto;
  }
  html.immersive #menubtn {
    display: flex; align-items: center; justify-content: center;
    position: fixed; right: 10px; bottom: 14px; z-index: 40;
    width: 42px; height: 42px; border-radius: 50%; border: none;
    background: color-mix(in srgb, var(--panel) 82%, transparent);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0,0,0,.4);
    color: var(--title); font-size: 1.25em; line-height: 1; cursor: pointer;
  }
  html.immersive #menubtn:hover { filter: brightness(1.15); }
}

/* Compact immersive play/stop buttons (reuse engine via togglePlay/stopAll). */
.immersivebar .iplay {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 1.05em; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.immersivebar .iplay:hover { filter: brightness(1.15); }
.immersivebar .istop {
  width: 32px; height: 32px; border-radius: 7px; border: none;
  background: #441133; color: #fff; font-size: .95em; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.immersivebar .istop:hover { background: #662255; }

/* ── Settings panel (overlay that holds the reparented controls) ── */
#panel {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .28s ease;
  padding: 0; overflow: hidden;
}
#panel.open { transform: translateY(0); }
html.immersive #panel { display: flex; }          /* participates only in immersive */
#panelhdr {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--track);
}
#panelhdr .ptitle { color: var(--title); font-size: 1.05em; letter-spacing: .03em; }
#panelclose {
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--sub);
  background: transparent; color: var(--title); font-size: 1.2em; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
#panelclose:hover { border-color: var(--accent); }
#panelbody {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
}
/* Reparented groups stretch nicely inside the panel. */
#panelbody .voices-wrap, #panelbody .lyrics,
#panelbody #sections, #panelbody .controls { width: 100%; max-width: 640px; }
#panelbody .sub { display: block; text-align: center; }

/* ── "Mín rödd" main-voice picker (trigger in .voices-wrap + shared popup) ── */
/* The voices-wrap trigger travels into #panelbody in immersive mode (it is a
   child of .voices-wrap, which the immersive controller reparents), so the
   picker is reachable on desktop, portrait AND inside the landscape panel. */
.mainvoice-trigger {
  margin-top: 2px;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 11px; border-radius: 14px;
  border: 1px solid var(--sub); background: transparent;
  color: var(--sub); font-family: inherit; font-size: .72em; letter-spacing: .01em;
  cursor: pointer; user-select: none; transition: border-color .2s, color .2s;
}
.mainvoice-trigger:hover { border-color: var(--accent); color: var(--title); }
.mainvoice-trigger .mv-ico { font-size: 1.05em; line-height: 1; }
.mainvoice-trigger .mv-cur { color: var(--title); font-weight: bold; }
.mainvoice-trigger.disabled { opacity: .55; }
@media (max-width: 640px) { .mainvoice-trigger { font-size: .66em; padding: 2px 9px; } }

/* Shared popup menu — fixed, positioned by JS relative to whichever trigger
   opened it; above the immersive panel (z-index 60) so it works there too. */
.voicemenu {
  position: fixed; z-index: 80; min-width: 170px; max-width: 86vw;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--track); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  padding: 8px; display: none; flex-direction: column; gap: 2px;
}
.voicemenu.open { display: flex; }
.voicemenu .vm-title {
  font-size: .72em; color: var(--sub); letter-spacing: .03em;
  padding: 2px 8px 6px; border-bottom: 1px solid var(--track); margin-bottom: 4px;
}
.voicemenu .vm-list { display: flex; flex-direction: column; gap: 2px; }
.voicemenu .vm-list.disabled { opacity: .5; pointer-events: none; }
.voicemenu .vm-item {
  text-align: left; padding: 7px 10px; border-radius: 8px;
  border: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: .9em; cursor: pointer; white-space: nowrap;
}
.voicemenu .vm-item:hover { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.voicemenu .vm-item.sel {
  background: color-mix(in srgb, var(--accent2) 26%, var(--panel));
  color: var(--title); font-weight: bold;
}
.voicemenu .vm-item.sel::after { content: ' ✓'; color: var(--accent2); }
.voicemenu .vm-note {
  display: none; font-size: .68em; color: var(--sub);
  padding: 6px 8px 2px; line-height: 1.3; max-width: 230px;
}
