/* Scope all component rules so the same module can mount over Unity or in the demo. */
.sg-hud {
  --sg-surface: #faf8f4;
  --sg-ink: #17342f;
  --sg-muted: #51635d;
  --sg-edge: #c9d5ca;
  --sg-track: #e0e6de;
  --sg-rider: #197065;
  --sg-ghost: #8c621c;
  --sg-ahead: #08734a;
  --sg-behind: #955207;
  --sg-active: #254d43;
  --sg-active-ink: #fff;
  --sg-focus: #067369;
  box-sizing: border-box;
  min-width: 0;
  color: var(--sg-ink);
  background: var(--sg-surface);
  font: 500 14px/1.35 "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: left;
  text-shadow: none;
  isolation: isolate;
}
.sg-hud *, .sg-hud *::before { box-sizing: border-box; }
.sg-hud [hidden] { display: none !important; }
.sg-hud h2, .sg-hud p { margin: 0; }
.sg-hud--panel { padding: clamp(16px, 3vw, 28px); border: 1px solid var(--sg-edge); border-radius: 14px; }
.sg-heading, .sg-split, .sg-result { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sg-heading { justify-content: space-between; }
.sg-title { font-family: inherit; font-size: 19px; line-height: 1.15; font-weight: 650; }
.sg-state { display: inline-flex; align-items: center; gap: .45em; font-size: 12px; color: var(--sg-muted); }
.sg-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sg-hud[data-state="active"] .sg-state { color: var(--sg-ahead); }
.sg-split { align-items: baseline; gap: 12px; margin: 13px 0; }
.sg-delta { font-size: clamp(36px, 4vw, 54px); line-height: 1; letter-spacing: -.06em; font-weight: 630; white-space: nowrap; }
.sg-delta[data-pace="ahead"] { color: var(--sg-ahead); }
.sg-delta[data-pace="behind"] { color: var(--sg-behind); }
.sg-delta[data-pace="pending"], .sg-caption { color: var(--sg-muted); }
.sg-caption, .sg-fact-label, .sg-lane, .sg-hud .sg-target, .sg-hud .sg-history { font-size: 12px; }
.sg-references { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border: 1px solid var(--sg-edge); border-radius: 9px; }
.sg-hud button {
  appearance: none; margin: 0; cursor: pointer; text-align: center;
  color: var(--sg-muted); font: inherit; font-size: 12px; line-height: 1.25; font-weight: 620;
  border: 0; border-radius: 6px; background: transparent; padding: 7px 10px; min-height: 30px;
}
.sg-hud .sg-ref[aria-pressed="true"], .sg-hud .sg-share { color: var(--sg-active-ink); background: var(--sg-active); }
.sg-hud button:not(:disabled):hover { text-decoration: underline; text-underline-offset: .2em; }
.sg-hud button:disabled { cursor: default; opacity: .55; }
.sg-hud button:focus-visible, .sg-hud input:focus-visible { outline: 2px solid var(--sg-focus); outline-offset: 2px; }
.sg-lanes { display: grid; gap: 5px; margin-top: 16px; }
.sg-lane { display: grid; grid-template-columns: 4ch minmax(0,1fr) 4ch; align-items: center; gap: 12px; color: var(--sg-muted); }
.sg-lane--rider { --sg-fill: var(--sg-rider); }
.sg-lane--ghost { --sg-fill: var(--sg-ghost); }
.sg-lane-pct { text-align: right; }
.sg-track { appearance: none; width: 100%; height: 7px; border: 0; border-radius: 0; background: var(--sg-track); color: var(--sg-fill); overflow: hidden; }
.sg-track::-webkit-progress-bar { background: var(--sg-track); }
.sg-track::-webkit-progress-value {
  background: var(--sg-fill);
  clip-path: polygon(0 0, calc(100% - 4px) 0, 100% 50%, calc(100% - 4px) 100%, 0 100%);
}
.sg-track::-moz-progress-bar {
  background: var(--sg-fill);
  clip-path: polygon(0 0, calc(100% - 4px) 0, 100% 50%, calc(100% - 4px) 100%, 0 100%);
}
.sg-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 15px 0 0; padding-top: 12px; border-top: 1px solid var(--sg-edge); }
.sg-fact { display: grid; gap: 3px; }
.sg-fact-label, .sg-score, .sg-history { color: var(--sg-muted); }
.sg-fact-value { font-size: 15px; font-weight: 620; }
.sg-hud .sg-target { margin-top: 12px; }
.sg-hud .sg-history { margin-top: 4px; }
.sg-hud .sg-result { margin-top: 14px; }
.sg-medal { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; }
.sg-medal[data-medal]:not([data-medal=""])::before { content: ""; width: 11px; height: 11px; transform: rotate(45deg); background: var(--sg-medal, var(--sg-ink)); border: 1px solid currentColor; }
.sg-medal[data-medal="bronze"] { --sg-medal: #cb8f68; }
.sg-medal[data-medal="silver"] { --sg-medal: #bfccd2; }
.sg-medal[data-medal="gold"] { --sg-medal: #e6b958; }
.sg-medal[data-medal="diamond"] { --sg-medal: #8bdace; }
.sg-score { font-size: 12px; }
.sg-hud .sg-share { border-radius: 99px; margin-left: auto; }
.sg-manual { display: grid; gap: 4px; font-size: 12px; margin-top: 9px; }
.sg-url { width: 100%; min-width: 0; padding: 5px; font: inherit; user-select: text; -webkit-user-select: text; color: var(--sg-ink); background: var(--sg-surface); border: 1px solid var(--sg-edge); border-radius: 4px; }
.sg-hud .sg-notice { font-size: 12px; margin-top: 8px; overflow-wrap: anywhere; }

.sg-hud--float {
  --sg-surface: #102b31ef; --sg-ink: #f4f6eb; --sg-muted: #c5d6ce; --sg-edge: #51716c;
  --sg-track: #365451; --sg-rider: #7ce8ab; --sg-ghost: #ffc879; --sg-ahead: #7beaab;
  --sg-behind: #ffc16b; --sg-active: #d6e6dc; --sg-active-ink: #17342f; --sg-focus: #ffd98d;
  position: fixed; z-index: 2; left: max(10px, env(safe-area-inset-left)); top: calc(53px + env(safe-area-inset-top));
  width: min(220px, calc(100% - 20px)); border: 1px solid var(--sg-edge); border-radius: 9px; padding: 8px 10px;
  pointer-events: none;
}
.sg-hud--float :is(button,input) { pointer-events: auto; }
#stage:has(#loading:not([hidden])) .sg-hud { visibility: hidden; }
.sg-hud--float .sg-heading, .sg-hud--float .sg-facts, .sg-hud--float .sg-lane--rider { display: none; }
.sg-hud--float .sg-split { margin: 0 0 5px; gap: 8px; }
.sg-hud--float .sg-delta { font-size: 24px; }
.sg-hud--float .sg-caption, .sg-hud--float .sg-lane { font-size: 11px; }
.sg-hud--float .sg-lanes { margin-top: 6px; }
.sg-hud--float .sg-track { height: 5px; }
.sg-hud--float .sg-ref { min-height: 24px; font-size: 11px; padding: 3px 6px; }
.sg-hud--float .sg-target, .sg-hud--float .sg-history { margin-top: 4px; font-size: 11px; }
.sg-hud--menu { position: static; width: min(360px, 90vw); margin: 8px auto 0; pointer-events: auto; }
.sg-hud--menu .sg-split { display: inline-flex; margin-right: 8px; }
.sg-hud--menu .sg-lanes { display: none; }
.sg-hud--menu .sg-result { margin-top: 6px; }
#overlay .card:has(> .sg-hud--menu) { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
@media (pointer: coarse) {
  .sg-hud--menu .sg-ref, .sg-hud--menu .sg-share { min-height: 44px; }
}
@media (max-width: 580px) {
  .sg-hud--float:not(.sg-hud--menu) { top: calc(75px + env(safe-area-inset-top)); }
}
@media (max-width: 360px) {
  .sg-facts { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (forced-colors: active) {
  .sg-track { appearance: auto; }
  .sg-hud button { border: 1px solid ButtonText; }
  .sg-hud button[aria-pressed="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
}
