/* XENOSPHERE — page styles. The piece is always black: colour comes from
 * the music. Desktop first, with a compact layout for phones. */
:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #f5f4fa;
  --dim: rgba(255, 255, 255, 0.66);
  --faint: rgba(255, 255, 255, 0.42);
  --line: rgba(255, 255, 255, 0.28);
  --sec: 300;
  --ch: 300;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  background: #000;
}

.mono { font-family: var(--mono); }
.small { font-size: 12px; color: var(--dim); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#hud.hidden { display: none; }

#readout {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  max-width: min(42vw, 560px);
  padding: 12px 22px 14px 16px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0.5) 70%, rgba(0, 0, 0, 0));
  border-left: 3px solid hsl(var(--ch) 100% 62%);
  transition: border-color 0.25s;
}
.tuning { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.chip {
  font: 800 13px/1 var(--mono);
  letter-spacing: 0.08em;
  padding: 4px 7px 3px;
  background: hsl(var(--sec) 100% 62%);
  color: #000;
  text-transform: uppercase;
}
#tuningSub { font-size: 13px; color: var(--dim); }
#tuningStat { margin-top: 5px; }
#chordBox { margin-top: 10px; }
.chord-name {
  font: 900 clamp(40px, 5.4vw, 88px) / 0.98 var(--sans);
  letter-spacing: -0.02em;
  color: hsl(var(--ch) 100% 72%);
  text-shadow: 0 0 22px hsl(var(--ch) 100% 50% / 0.55), 0 2px 0 rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
.chord-name .sym { font-weight: 700; font-size: 0.6em; color: #fff; }
#chordBox.pop .chord-name { animation: pop 0.36s cubic-bezier(0.2, 0.9, 0.3, 1.25); }
@keyframes pop {
  0% { transform: translateX(-12px) scale(1.08); filter: brightness(2.2); }
  100% { transform: none; filter: none; }
}
.quality { font: 600 15px/1.3 var(--sans); margin-top: 6px; color: #fff; }
.ratio { font-size: 21px; font-weight: 700; color: #fff; letter-spacing: 0.03em; margin-top: 2px; }
#chordRel, #chordCents { margin-top: 3px; }
.fn { font: 500 14px/1.35 var(--sans); color: hsl(var(--ch) 100% 84%); margin-top: 7px; }
.meter { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 11px; color: var(--faint); }
.meter .bar { display: block; width: 120px; height: 4px; background: rgba(255, 255, 255, 0.15); }
.meter .bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, hsl(165 100% 55%), hsl(50 100% 58%), hsl(320 100% 64%));
  transition: width 0.3s;
}

#secinfo {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  max-width: min(34vw, 420px);
  padding: 10px 14px 12px 22px;
  text-align: right;
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0.45) 70%, rgba(0, 0, 0, 0));
}
.secnum { font: 700 12px var(--mono); color: var(--dim); letter-spacing: 0.14em; }
.sectitle {
  font: 900 clamp(20px, 2.3vw, 32px) / 1.05 var(--sans);
  color: hsl(var(--sec) 100% 70%);
  letter-spacing: 0.02em;
  margin-top: 3px;
}
.secsub { font-size: 12px; color: var(--dim); margin-top: 4px; }
.transport { font-size: 12px; margin-top: 9px; color: #fff; }
.beats { display: flex; gap: 3px; margin: 6px 0 0 auto; width: 170px; height: 6px; }
.beats i { background: rgba(255, 255, 255, 0.16); }
.beats i.on { background: hsl(var(--sec) 100% 66%); }
.stat { font-size: 12px; margin-top: 7px; color: hsl(var(--sec) 100% 82%); }
.timeline { display: flex; gap: 2px; margin: 9px 0 0 auto; width: 250px; height: 4px; }
.timeline i { position: relative; overflow: hidden; background: rgba(255, 255, 255, 0.14); }
.timeline i::after {
  content: "";
  position: absolute;
  inset: 0;
  transform-origin: left;
  transform: scaleX(var(--p, 0));
  background: hsl(var(--sec) 100% 66%);
}
.timeline i.done::after { background: rgba(255, 255, 255, 0.55); }

/* ------------------------------------------------------------- controls */
#controls {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  z-index: 5;
  transition: opacity 0.4s;
}
#controls[hidden] { display: none; }
body.idle #controls { opacity: 0.3; }
#controls button {
  font: 600 12px var(--sans);
  color: #fff;
  background: rgba(0, 0, 0, 0.66);
  border: 1px solid var(--line);
  padding: 7px 11px;
  min-height: 34px;
  min-width: 34px;
  border-radius: 3px;
  cursor: pointer;
}
#controls button:hover { border-color: #fff; }
#controls button:focus-visible, .start:focus-visible, input:focus-visible { outline: 2px solid hsl(var(--sec) 100% 65%); outline-offset: 2px; }
#controls #btnStop { background: #fff; color: #000; font-weight: 800; border-color: #fff; }
#controls #btnStop.paused { background: hsl(var(--sec) 100% 62%); border-color: transparent; }
#controls button[aria-pressed="true"] { border-color: hsl(var(--sec) 100% 65%); color: hsl(var(--sec) 100% 80%); }
.vol { display: inline-flex; align-items: center; padding: 0 4px; }
.vol input { width: 92px; accent-color: hsl(var(--sec) 100% 62%); }

/* -------------------------------------------------------- warning screen */
#warning {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(120, 40, 160, 0.22), rgba(0, 0, 0, 0) 60%),
    #000;
}
#warning[hidden] { display: none; }
.warn-card { width: min(640px, 100%); line-height: 1.5; }
.kicker { font: 700 12px var(--mono); letter-spacing: 0.2em; color: hsl(300 100% 72%); margin: 0 0 10px; text-transform: uppercase; }
.warn-card h1 { font: 900 clamp(26px, 5vw, 40px) / 1.1 var(--sans); margin: 0 0 16px; color: #ffd84a; }
.warn-card p { margin: 0 0 12px; color: #e9e7f2; font-size: 16px; }
.warn-card strong { color: #fff; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 16px; margin: 18px 0 6px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: #ffd84a; flex: none; }
.note { font-size: 14px !important; color: #ffd84a !important; }
.startvol { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--dim); margin: 12px 0 20px; }
.startvol input { width: 180px; accent-color: #ffd84a; }
.start {
  font: 900 20px var(--sans);
  letter-spacing: 0.06em;
  padding: 15px 48px;
  background: #fff;
  color: #000;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 20px;
}
.start:hover { background: #ffd84a; }
.fine { font-size: 13px !important; color: var(--dim) !important; }
.keys { font-family: var(--mono); font-size: 12px !important; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: #000; color: #fff; margin: 0; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 719px) {
  #readout {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    max-width: calc(100vw - 20px);
    padding: 8px 12px 10px 10px;
  }
  .chip { font-size: 11px; }
  #tuningSub, #tuningStat, #chordRel, #chordCents, .meter { display: none; }
  #chordBox { margin-top: 6px; }
  .chord-name { font-size: clamp(30px, 10.5vw, 48px); }
  .quality { font-size: 13px; }
  .ratio { font-size: 16px; }
  .fn { font-size: 12px; margin-top: 4px; }
  #secinfo {
    top: auto;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 48px);
    right: max(10px, env(safe-area-inset-right));
    max-width: 62vw;
    padding: 6px 10px;
  }
  .sectitle { font-size: 18px; }
  .secsub, .stat, .beats { display: none; }
  .transport { margin-top: 4px; font-size: 11px; }
  .timeline { width: 150px; margin-top: 6px; }
  #controls { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); gap: 4px; justify-content: center; }
  #controls button { padding: 6px 8px; font-size: 11px; min-height: 36px; }
  #btnFull, .vol { display: none !important; }
}

@media (max-height: 520px) and (orientation: landscape) {
  #readout { max-width: 36vw; padding: 6px 10px; }
  #tuningStat, #chordRel, #chordCents, .meter, .fn { display: none; }
  .chord-name { font-size: clamp(26px, 6vw, 44px); }
  #secinfo .secsub, #secinfo .stat, #secinfo .beats { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #chordBox.pop .chord-name { animation: none; }
  #controls, .meter .bar i { transition: none; }
}
