/* ON / BEAT — play screen styles.
   Owned by the render/HUD subagent. main.css (global fonts/theme) is untouched;
   the main agent may override these CSS variables per song from frame.theme.
   Two stacked canvases are positioned here; their backing-store pixel size is
   set only in JS (resize), never by CSS layout reads. */

:root {
  --ob-accent: #ff8a3d;
  --ob-ink: #fff2e6;
  --ob-glow: #f8863a;
  --ob-bg: #3a1108;
  --ob-panel: rgba(14, 10, 12, 0.78);
  --ob-line: rgba(255, 242, 230, 0.14);
  --ob-sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --ob-serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
}

.ob-play {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--ob-bg);
  color: var(--ob-ink);
  font-family: var(--ob-sans);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* --- two canvas layers --------------------------------------------------- */
.ob-bg-canvas,
.ob-game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.ob-bg-canvas { z-index: 0; }
.ob-game-canvas { z-index: 1; }

/* --- HUD layer (non-interactive except explicit controls) ---------------- */
.ob-hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.ob-play .ob-btn { pointer-events: auto; }

/* --- top progress rail ---------------------------------------------------- */
.ob-hud-progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: rgba(246, 239, 230, 0.10);
}
.ob-hud-progress-fill {
  height: 100%; width: 0;
  background: var(--ob-accent);
  opacity: 0.85;
  box-shadow: 0 0 10px var(--ob-accent);
}

/* --- score / accuracy: large serif numerals, same face as the selection --- */
.ob-hud-top {
  position: absolute;
  top: calc(20px + env(safe-area-inset-top));
  left: calc(26px + env(safe-area-inset-left));
  right: calc(26px + env(safe-area-inset-right));
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 11px;
  letter-spacing: 0.22em;
}
.ob-hud-top > span:nth-child(3) { margin-left: auto; }
.ob-hud-label { opacity: 0.68; text-transform: uppercase; }
.ob-hud-score,
.ob-hud-acc {
  font-family: var(--ob-serif);
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: clamp(26px, 3.1vw, 44px);
  line-height: 1;
  letter-spacing: 0;
  opacity: 0.92;
}

/* --- side panels: real information architecture, not faint decoration ---- */
.ob-hud-side {
  position: absolute;
  top: 23%;
  width: clamp(210px, 21vw, 310px);
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.ob-hud-side--left {
  left: clamp(18px, 3vw, 52px); align-items: flex-start; text-align: left;
  padding-left: 16px; border-left: 1px solid rgba(246,239,230,.22);
}
.ob-hud-side--right {
  right: clamp(18px, 3vw, 52px); align-items: flex-end; text-align: right;
  padding-right: 16px; border-right: 1px solid rgba(246,239,230,.22);
}
/* a short accent rule gives each panel a visible anchor */
.ob-hud-side::before {
  content: ''; position: absolute; top: 0; width: 34px; height: 2px;
  background: var(--ob-accent); opacity: .9;
}
.ob-hud-side--left::before  { left: -1px; }
.ob-hud-side--right::before { right: -1px; }
.ob-hud-side-label {
  font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase; opacity: 0.66;
}
.ob-hud-track-card { display: flex; gap: 14px; align-items: center; width: 100%; }
.ob-hud-cover {
  width: 78px; height: 78px; flex: none;
  object-fit: cover; border-radius: 5px; opacity: 0.96;
  border: 1px solid rgba(246,239,230,.22);
  box-shadow: 0 10px 28px rgba(0,0,0,0.5);
}
.ob-hud-track-meta { min-width: 0; flex: 1; }
.ob-hud-track-title {
  font-family: var(--ob-serif); font-style: italic;
  font-size: 27px; line-height: 1.08; opacity: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ob-hud-track-sub {
  margin-top: 6px; font-size: 12px; letter-spacing: 0.09em; opacity: 0.72;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ob-hud-diff {
  width: 100%; padding-top: 11px;
  border-top: 1px solid var(--ob-line);
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; opacity: 0.70;
}
.ob-hud-section {
  font-size: 15px; font-weight: 600; letter-spacing: 0.20em;
  text-transform: uppercase; opacity: 0.92; min-height: 18px;
  color: var(--ob-accent);
  text-shadow: 0 0 14px rgba(255,180,110,.35);
}
.ob-hud-dist {
  display: flex; gap: 14px;
  font-size: 14px; letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.ob-hud-dist-item { opacity: 0.82; }
.ob-hud-dist-item.is-perfect { color: #ffd166; opacity: 1; }
.ob-hud-dist-item.is-miss { color: rgba(238,224,224,.62); }

/* combo: right margin, serif, hidden entirely until a real combo exists */
.ob-combo-wrap {
  position: absolute;
  top: 44%;
  right: clamp(18px, 3vw, 52px);
  width: clamp(210px, 21vw, 310px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  opacity: 0.9;
  transition: opacity 180ms ease;
}
.ob-combo-label {
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.72;
}
.ob-combo-num {
  font-family: var(--ob-serif);
  font-variant-numeric: lining-nums tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: clamp(52px, 6.2vw, 96px);
  line-height: 1;
  transform-origin: right center;
  opacity: 1;
  text-shadow: 0 0 22px rgba(255,190,120,.35);
}

/* judgement text: ONE shared position, slight rise+fade, no scale rebound */
/* Judgement text: three DISTINCT colours and a large serif face so the hit
   result reads instantly. Fixed semantic hues (not the per-song theme) keep
   it legible on every cover palette. */
.ob-judgement {
  position: absolute;
  top: 69%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--ob-serif);
  font-size: clamp(30px, 4vw, 62px);
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  -webkit-text-stroke: 1px rgba(0, 0, 0, 0.30);
  paint-order: stroke fill;
  will-change: opacity, transform;
}
.ob-judgement[data-result="perfect"] {
  color: #ffd166;
  text-shadow: 0 0 18px rgba(255, 196, 92, .9), 0 0 46px rgba(255, 138, 48, .55),
               0 3px 14px rgba(0, 0, 0, .6);
}
.ob-judgement[data-result="good"] {
  color: #9ed8ff;
  text-shadow: 0 0 15px rgba(120, 200, 255, .75), 0 3px 12px rgba(0, 0, 0, .55);
}
/* MISS: low-saturation, but readable — never a red screen or a full-screen alert. */
.ob-judgement[data-result="miss"] {
  color: rgba(238, 224, 224, .66);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
.ob-judgement.is-show { animation: ob-judge-rise 560ms ease-out forwards; }
@keyframes ob-judge-rise {
  0%   { opacity: 1; transform: translateY(0); }
  34%  { opacity: 1; transform: translateY(-2px); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* countdown before resume */
.ob-countdown {
  position: absolute;
  top: 42%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--ob-serif);
  font-style: italic;
  font-size: clamp(56px, 9vw, 120px);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.55);
}

/* --- pause / calibration / result panels --------------------------------- */
.ob-pause,
.ob-calib,
.ob-result {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(32px + env(safe-area-inset-top)) calc(32px + env(safe-area-inset-right))
           calc(32px + env(safe-area-inset-bottom)) calc(32px + env(safe-area-inset-left));
  background: var(--ob-panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
  text-align: center;
}
.ob-pause-title,
.ob-result-title,
.ob-calib-title {
  font-family: var(--ob-serif);
  font-style: italic;
  font-size: clamp(30px, 5vw, 56px);
  letter-spacing: 0.02em;
}
.ob-pause-hint,
.ob-calib-intro,
.ob-calib-hint { max-width: 46ch; opacity: 0.72; font-size: 14px; line-height: 1.6; }

/* verbatim offset direction — visually distinct, never paraphrased */
.ob-calib-direction {
  max-width: 60ch;
  padding: 12px 18px;
  border: 1px solid var(--ob-line);
  border-radius: 10px;
  color: var(--ob-glow);
  font-size: 14px;
  line-height: 1.7;
}

.ob-calib-rows {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px 20px;
  align-items: center;
  margin: 8px 0;
}
.ob-calib-label {
  text-align: right;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.6;
}
.ob-calib-value {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  letter-spacing: 0.02em;
}
.ob-calib-value-strong { color: var(--ob-glow); font-weight: 600; }
.ob-calib-speed { width: min(320px, 70vw); accent-color: var(--ob-accent); }

.ob-result-score {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: clamp(48px, 8vw, 96px);
  line-height: 1;
  letter-spacing: 0.02em;
}
.ob-result-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(84px, 1fr));
  gap: 12px;
  margin: 12px 0;
  width: min(720px, 92vw);
}
.ob-result-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 6px;
  border: 1px solid var(--ob-line);
  border-radius: 8px;
}
.ob-result-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.55;
}
.ob-result-value { font-variant-numeric: tabular-nums; font-size: 20px; }
.ob-result-perfect .ob-result-value { color: var(--ob-glow); }

/* --- buttons ------------------------------------------------------------- */
.ob-pause-btns,
.ob-calib-actions,
.ob-result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}
.ob-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 26px;
  font-family: var(--ob-sans);
  font-size: 14px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
.ob-btn:hover { transform: translateY(-1px); }
.ob-btn:active { transform: translateY(0); }
.ob-btn-primary { background: #fff; color: #1a1116; }
.ob-btn-ghost { background: transparent; color: var(--ob-ink); border-color: var(--ob-line); }

/* --- milestone combo breath (subtle; disabled under reduced motion) ------ */
.ob-combo-num.is-breath { animation: ob-combo-breathe 260ms ease-out; }
@keyframes ob-combo-breathe {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* --- reduced motion: no displacement, no scaling, no long transitions ---- */
@media (prefers-reduced-motion: reduce) {
  .ob-play *,
  .ob-play *::before,
  .ob-play *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .ob-judgement.is-show { animation: none; opacity: 0; }
  .ob-combo-num.is-breath { animation: none; }
  .ob-btn:hover { transform: none; }
}

/* Landscape is the target; keep controls clear of notches on phones. */
@media (max-width: 720px) {
  .ob-result-grid { grid-template-columns: repeat(3, minmax(80px, 1fr)); }
  .ob-hud-top { font-size: 10px; }
}

/* ---- offline structure rail + spectrum (side-margin design language) --- */
.ob-hud-rail-label {
  font-size: 11px; letter-spacing: .22em; text-transform: uppercase;
  opacity: .64; margin-top: 2px;
}
.ob-hud-rail { display: flex; flex-direction: column; gap: 7px; width: 100%; }
.ob-hud-rail-item {
  display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 8px;
  opacity: .52; transition: opacity 260ms var(--ob-ease, ease-out);
}
.ob-hud-rail-item.is-active { opacity: 1; }
.ob-hud-rail-num { font-size: 11px; letter-spacing: .08em; opacity: .72; }
.ob-hud-rail-name { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.ob-hud-rail-bar {
  grid-column: 1 / -1; height: 2px; background: rgba(246,239,230,.16);
  position: relative; overflow: hidden;
}
.ob-hud-rail-item.is-active .ob-hud-rail-bar::after {
  content: ''; position: absolute; inset: 0; background: var(--ob-accent);
  transform-origin: left; animation: ob-rail-fill 900ms var(--ob-ease, ease-out) both;
}
@keyframes ob-rail-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.ob-hud-elapsed {
  font-size: 13px; letter-spacing: .08em; opacity: .76;
  font-variant-numeric: tabular-nums;
}
.ob-hud-hint {
  font-size: 11px; letter-spacing: .08em; opacity: .62;
  padding-top: 9px; border-top: 1px solid var(--ob-line);
  line-height: 1.6;
}
.ob-hud-spectrum {
  display: flex; align-items: flex-end; justify-content: flex-end; gap: 7px;
  width: 100%; height: 52px; padding-bottom: 4px;
  border-bottom: 1px solid var(--ob-line);
}
.ob-hud-band {
  width: 12px; min-height: 3px; height: 20%;
  background: var(--ob-accent); opacity: .72;
  box-shadow: 0 0 10px rgba(255,170,100,.35);
  transition: height 140ms linear;
}
.ob-hud-band.is-mid { opacity: .86; }
.ob-hud-band.is-high { opacity: 1; }
.ob-hud-band-names { font-size: 10px; letter-spacing: .14em; opacity: .58; }

/* Milestone: one restrained frame-edge pulse at combo 25/50/100.
   Not a full-screen flash — the centre reading zone is untouched. */
.ob-hud::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 1px solid transparent; opacity: 0;
}
.ob-hud.is-milestone::after {
  border-color: var(--ob-accent);
  animation: ob-milestone 620ms var(--ob-ease, ease-out) both;
}
@keyframes ob-milestone {
  0% { opacity: 0; } 18% { opacity: .38; } 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .ob-hud.is-milestone::after, .ob-hud-rail-item.is-active .ob-hud-rail-bar::after { animation: none; }
  .ob-hud-band { transition: none; }
}
