:root {
  --bg: #161616;
  --bar: #1f1f1f;
  --tab: #262626;
  --tab-active: #303030;
  --line: #3a3a3a;
  --text: #ececec;
  --muted: #9a9a9a;
  --play: #2e7d32;
  --stop: #b23a3a;
  --metronome: #6aa8ff;
  --drone: #e0a43a;
  --player: #5fc9a0;
  --rhythm: #d889d8;
  --edge: #000;            /* bar borders */
  --led-off: #444;
  --warn: #ff9a8a;
  --ok: #6fd08c;
  --focus: #6aa8ff;
  --link: #6aa8ff;
  --hover: #ffffff14;
  --press: #ffffff26;
  --shadow: #000a;
  --code: #00000040;
  --native-bg: #6aa8ff;
  --native-fg: #0b1626;
  color-scheme: dark;
}
/* Light theme (theme.js sets data-theme). Accents are darker so text and lines keep their contrast. */
:root[data-theme="light"] {
  --bg: #e4e6e9;
  --bar: #eef0f2;
  --tab: #e2e5e8;
  --tab-active: #ffffff;
  --line: #c3c8ce;
  --text: #1b1e22;
  --muted: #5d646c;
  --metronome: #2462c4;
  --drone: #a86b00;
  --player: #1d8762;
  --rhythm: #8e3f8e;
  --edge: #c3c8ce;
  --led-off: #b9bec4;
  --warn: #b3261e;
  --ok: #1d8742;
  --focus: #2462c4;
  --link: #2462c4;
  --hover: #0000000d;
  --press: #0000001a;
  --shadow: #0003;
  --code: #0000000f;
  --native-bg: #2462c4;
  --native-fg: #fff;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.shell { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Top bar: tab + transport per app ---------- */
.bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  background: var(--bar);
  border-bottom: 1px solid var(--edge);
}

.slot {
  --c: var(--metronome);
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 6px 6px 12px;
  border-radius: 12px;
  background: var(--tab);
  border: 1px solid transparent;
  transition: background-color 150ms, border-color 150ms;
}
.slot[data-app="drone"] { --c: var(--drone); }
.slot[data-app="player"] { --c: var(--player); }
.slot[data-app="rhythm"], .slot[data-app="ear"] { --c: var(--rhythm); }
.slot[hidden] { display: none; }   /* a hidden app and its twin share one place in the bar */
.slot { border-color: color-mix(in srgb, var(--c) 35%, var(--line)); }   /* thin border... */
.slot.active { background: var(--tab-active); border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }   /* ...2px when selected (inset shadow: no layout shift) */
/* light theme: each selector takes its app's faint background (same values as the apps' own --bg) */
:root[data-theme="light"] .slot { background: var(--tint); }
:root[data-theme="light"] .slot[data-app="metronome"] { --tint: #e2eaf5; }
:root[data-theme="light"] .slot[data-app="drone"] { --tint: #e9e3d8; }
:root[data-theme="light"] .slot[data-app="player"] { --tint: #e3ebe8; }
:root[data-theme="light"] .slot[data-app="rhythm"], :root[data-theme="light"] .slot[data-app="ear"] { --tint: #eee5ee; }
.slot.active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -9px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--c);
}

/* the tab itself fills the slot; the play button sits beside it */
.tab {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.tab::before { content: ""; position: absolute; inset: 0; border-radius: 12px; } /* whole slot clickable */
.tab:focus-visible { outline: none; }
.slot:has(.tab:focus-visible) { outline: 2px solid var(--c); outline-offset: 2px; }

.name {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  font-weight: 600;
  white-space: nowrap;
}
.name .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }   /* long translations shrink, never overlap the buttons */
.ico { display: block; width: 22px; height: 22px; flex: 0 0 auto; }
.led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--led-off);
  flex: 0 0 auto;
}
.slot.playing .led { background: var(--c); box-shadow: 0 0 8px var(--c); }   /* no pulse animation: a 1.6 s infinite animation here coincided with audio clicks in the installed Safari app */

.info {
  max-width: 100%;
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info.warn { color: var(--warn); }

.play {
  position: relative;   /* above the slot-wide tab hit area */
  z-index: 1;
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--play);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color 150ms, transform 80ms;
}
.play:active { transform: scale(.94); }
.play:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
.play { padding: 0; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }   /* definite track + no default button padding, so the % sizes below are of the whole button */
.play svg { fill: currentColor; pointer-events: none; }
/* Uniform play/stop symbol, same in every app and at every size: its circumscribed circle is half the button's
   diameter and concentric with the button. Triangle: circle d = 15.45/24 of the icon box, centre (11.27, 12), so the
   box is 77.67% of the button, nudged right 3.04%. Square: d = 16.97/24, so the box is 70.71%. */
.play .i-play { width: 77.67%; height: 77.67%; transform: translateX(3.04%); }
.play .i-stop { width: 70.71%; height: 70.71%; }
.play .i-stop { display: none; }
.slot.playing .play { background: var(--stop); }
.slot.playing .play .i-play { display: none; }
.slot.playing .play .i-stop { display: block; }

/* ---------- App panes ---------- */
.panes { position: relative; flex: 1 1 auto; min-height: 0; }
.panes iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  /* keep inactive pane alive (audio, timers) but out of sight and out of the tab order */
  visibility: hidden;
  /* iPad Safari can let a hidden pane take taps or paint over the active one (the player, last in the DOM,
     covered the metronome after its Presets button was tapped): hidden panes never take input, the active one is on top */
  pointer-events: none;
}
.panes iframe.active { visibility: visible; pointer-events: auto; z-index: 1; }

.copyright {
  flex: none;
  padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--edge);
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}

.copyright a { color: inherit; text-decoration: underline; }
.copyright a:hover { color: var(--text); }

/* Language picker: a globe and the language code; a transparent native select on top opens the menu of full names. */
.lang-pick { position: relative; display: inline; white-space: nowrap; cursor: pointer; }   /* inline, like the other footer items, so the separators share one baseline */
.lang-pick svg { vertical-align: -.125em; margin-right: .25em; }
.lang-pick:hover { color: var(--text); }

/* Theme toggle: icon of the theme it switches to, plus its name on wide screens */
#themeBtn svg { vertical-align: -.125em; margin-right: .3em; }   /* inline like the Share button, so it sits on the same baseline as the other footer items */
:root[data-theme="light"] #themeBtn .i-sun, :root:not([data-theme="light"]) #themeBtn .i-moon { display: none; }
.lang-pick select { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; font: inherit; }
.lang-pick:has(select:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

/* ---------- Per-app volume button + popover ---------- */
.vol {
  position: relative; z-index: 1; flex: 0 0 auto;
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%;
  background: var(--hover); color: var(--muted); cursor: pointer;   /* disk background */
  display: grid; place-items: center;
}
.vol:hover, .vol[aria-expanded="true"] { color: var(--text); background: var(--press); }
.vol:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
.vol svg { width: 20px; height: 20px; }
.slot.muted .vol .waves { display: none; }
.slot:is([data-app="ear"], [data-app="rhythm"]) :is(.vol, .play) { display: none; }   /* the exercise twins (ear training, rhythm practice): no volume or play button */

.volpop {
  position: fixed; z-index: 10;
  width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 8px; border-radius: 12px;
  background: var(--tab-active); border: 1px solid var(--line); box-shadow: 0 8px 24px var(--shadow);
}
.volpop[hidden] { display: none; }
.volname { order: 3; font-size: .72rem; font-weight: 600; color: var(--muted); }
.volpop input {
  order: 2;
  writing-mode: vertical-lr; direction: rtl;   /* vertical, minimum at the bottom */
  width: 28px; height: 140px; margin: 0;
  accent-color: var(--c, var(--metronome)); cursor: pointer;
}
.volpop output { order: 1; font-variant-numeric: tabular-nums; font-size: .85rem; }

/* narrow screens: tab labels become icons, compact slots */
@media (max-width: 600px) {
  .bar { gap: 6px; }
  .slot { gap: 2px; padding: 6px 6px 6px 8px; }
  .name .label { display: none; }
  .slot.playing .name .ico { color: var(--c); }
  .led { display: none; }
  .info:not(.warn) { display: none; }
  .vol { width: 28px; height: 28px; }
  .vol svg { width: 18px; height: 18px; }
  .play { width: 36px; height: 36px; }
  .theme-label { display: none; }
  #themeBtn svg { margin-right: 0; }   /* icon only: no gap before the separator */
  .gh-link { display: none; }   /* footer room for the language picker and longer translations */
}

@media (display-mode: standalone) { #installBtn, .install-sep { display: none; } }

/* very small screens: no room for Credits in the footer */
@media (max-width: 349px) { .credits-link { display: none; } }

/* Small screens, only while the Install button is shown: "Buy me a coffee ☕" shrinks to "coffee? ☕" */
@media (max-width: 600px) {
  @media not (display-mode: standalone) {
    .copyright:has(#installBtn:not([hidden])) .cof-long { display: none; }
    .copyright:has(#installBtn:not([hidden])) .cof-q { display: inline; }
  }
}

#installBtn { text-decoration: none; background: var(--muted); color: var(--bar); padding: 0 .5rem; border-radius: 4px; }
/* On load: slide in from the right, then a quick wiggle, then a pulse ring for ~5s (4 x 1.25s). */
@keyframes install-slide { from { opacity: 0; transform: translateX(4rem); } to { opacity: 1; transform: none; } }
@keyframes install-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-8deg); }
  40% { transform: rotate(7deg); }
  60% { transform: rotate(-5deg); }
  80% { transform: rotate(3deg); }
}
@keyframes install-pulse {
  from { box-shadow: 0 0 0 0 rgba(106, 168, 255, .75); }
  to   { box-shadow: 0 0 0 10px rgba(106, 168, 255, 0); }
}
#installBtn {
  animation:
    install-slide .4s ease-out .3s both,
    install-wiggle .6s ease-in-out .7s,
    install-pulse 1.25s ease-out 1.3s 4;
}
@media (prefers-reduced-motion: reduce) { #installBtn { animation: none; } }
#installBtn:hover { background: var(--text); color: var(--bar); }

/* ---------- Credits link + dialog ---------- */
.linklike { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
#shareBtn { text-decoration: none; background: none; border: 1px solid currentColor; padding: 0 .5rem; border-radius: 4px; }
#shareBtn:hover { border-color: var(--text); }
.linklike .share-ico { vertical-align: -.125em; margin-left: .3em; }
.linklike:hover { color: var(--text); }
.linklike:focus-visible, .copyright a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

#creditsDialog, #changelogDialog {
  width: min(92vw, 560px); max-height: min(86dvh, 640px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--tab-active); color: var(--text); box-shadow: 0 20px 60px var(--shadow);
  overflow: hidden;
}
#creditsDialog[open], #changelogDialog[open] { display: flex; flex-direction: column; }
#creditsDialog::backdrop, #changelogDialog::backdrop { background: rgba(0, 0, 0, .65); }
/* Changelog: each release with its version as a rehearsal mark (the boxed bold label over a section of a score) above
   its notes, which take the full width. The newest release's mark is filled, older ones outlined. Footer: "Do not show
   again" left, Close right. */
#changelogDialog .changelog-body { padding: 22px 24px 14px; }
#changelogDialog .changelog-body h2 { margin: 0 0 18px; font-size: 1.25rem; }
.release + .release { margin-top: 22px; }
.release .mark {
  display: inline-block; margin: 0 0 10px; padding: 5px 7px;
  border: 2px solid var(--text); border-radius: 2px;
  font: 800 .9rem/1 system-ui, sans-serif; font-variant-numeric: tabular-nums;
  letter-spacing: 0; text-transform: none; color: var(--text);
}
.release:first-child .mark { background: var(--text); color: var(--tab-active); }
.release .notes > :last-child { margin-bottom: 0; }
.dlg-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px 16px; border-top: 1px solid var(--line); }
.dlg-foot .dlg-btn { padding: 0 22px; }
.dlg-check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); cursor: pointer; }
.dlg-check:hover { color: var(--text); }
.dlg-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--focus); }
.credits-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 20px 6px; line-height: 1.5; font-size: .9rem; }
.credits-body:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.credits-body h2 { margin: 0 0 10px; font-size: 1.15rem; }
.credits-body h3 { margin: 16px 0 6px; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.credits-body p { margin: 0 0 10px; }
.credits-body ul { margin: 0 0 10px; padding-left: 20px; }
.credits-body a { color: var(--link); overflow-wrap: anywhere; }
.credits-body code { font-size: .85em; background: var(--code); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
/* buttons inside the Credits and Share dialogs */
.dlg-btn { display: flex; align-items: center; justify-content: center; gap: .4em; min-height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--tab); color: var(--text); font: 600 .95rem system-ui, sans-serif; cursor: pointer; }
.dlg-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.dlg-close { flex: none; margin: 8px 20px 16px; }


/* ---------- Install dialog (iOS steps) ---------- */
#installDialog {
  width: min(92vw, 360px); padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--tab-active); color: var(--text); box-shadow: 0 20px 60px var(--shadow);
}
#installDialog[open] { display: flex; flex-direction: column; }
#installDialog::backdrop { background: rgba(0, 0, 0, .65); }
.install-body { padding: 18px 20px 6px; }
.install-body h2 { margin: 0 0 12px; font-size: 1.15rem; text-align: center; }
.install-body ol { margin: 0; padding-left: 1.4em; line-height: 1.5; }
.install-body li + li { margin-top: 8px; }
.ios-share { vertical-align: -.25em; color: var(--link); }

/* ---------- Share dialog (QR code) ---------- */
#shareDialog {
  width: min(92vw, 360px); padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--tab-active); color: var(--text); box-shadow: 0 20px 60px var(--shadow);
}
#shareDialog[open] { display: flex; flex-direction: column; }
#shareDialog::backdrop { background: rgba(0, 0, 0, .65); }
.share-body { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 20px 6px; text-align: center; }
.share-body h2 { margin: 0; font-size: 1.15rem; }
.share-body img { width: min(220px, 70vw); height: auto; aspect-ratio: 1; border-radius: 8px; image-rendering: pixelated; }
#shareCopy, #shareNative { align-self: stretch; }
#shareCopy.done { color: var(--ok); border-color: var(--ok); }
#shareNative { border: 0; background: var(--native-bg); color: var(--native-fg); }
#shareNative[hidden] { display: none; }
