.sg {
  --sg-ink: #2a2540;
  --sg-glass: rgba(36, 22, 74, 0.1);
  --sg-shadow: 0 2px 18px rgba(36, 22, 74, 0.16);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(180deg, var(--sg-top, #f8dbe8), var(--sg-bottom, #bcc7ee));
  color: #fff;
  font-family: "Manrope Variable", Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
  outline: none;
}
.sg:focus-visible { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.85); }
.sg[data-state="play"] { touch-action: none; }
.sg [hidden] { display: none !important; }

.sg-stage, .sg-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.sg-hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.sg-hud button { pointer-events: auto; }

.sg-bar { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px; min-height: 66px; }
.sg-bar-r { display: flex; gap: 8px; }

.sg-ic {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--sg-glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(36, 22, 74, 0.08);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.15s;
}
.sg-ic:hover { background: rgba(36, 22, 74, 0.18); }
.sg-ic:active { transform: scale(0.94); }
.sg-ic:focus-visible, .sg-pill:focus-visible, .sg-chip:focus-visible, .sg-swatch:focus-visible {
  outline: 2.5px solid #fff;
  outline-offset: 2px;
}
.sg-ic svg { filter: drop-shadow(0 1px 1.5px rgba(36, 22, 74, 0.42)); }

.sg-head { text-align: center; margin-top: -8px; padding: 0 16px; }
.sg-title, .sg-score { line-height: 1; text-shadow: var(--sg-shadow); }
.sg-title { font-weight: 300; font-size: clamp(56px, 14vmin, 124px); letter-spacing: 0.01em; }
.sg-score {
  font-weight: 200;
  font-size: clamp(68px, 16vmin, 144px);
  font-variant-numeric: tabular-nums;
}
.sg-sub {
  min-height: 1.5em;
  margin-top: 10px;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.45;
  text-shadow: 0 1px 2px rgba(36, 22, 74, 0.35), 0 1px 10px rgba(36, 22, 74, 0.3);
}

.sg-toasts { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 10px; padding: 0 16px; }
.sg-toast {
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(30, 22, 56, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-weight: 700;
  font-size: 14px;
  animation: sg-in 0.25s ease-out;
  transition: opacity 0.4s;
}
.sg-toast.sg-out { opacity: 0; }

.sg-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 12px 18px;
}
.sg-foot p { margin: 0; }
.sg-call {
  font-weight: 750;
  font-size: clamp(15px, 2.4vmin, 19px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(36, 22, 74, 0.3), 0 2px 14px rgba(36, 22, 74, 0.35);
  animation: sg-pulse 1.9s ease-in-out infinite;
}
.sg-call:empty, .sg-tut:empty, .sg-sub:empty { visibility: hidden; }
.sg-tut {
  max-width: 32ch;
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(30, 22, 56, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  text-align: center;
  font-weight: 650;
  font-size: 15px;
  line-height: 1.4;
}
.sg-tut:empty { display: none; }

.sg-chips {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 4px 18px rgba(36, 22, 74, 0.12);
}
.sg-chip {
  border: 0;
  border-radius: 999px;
  padding: 9px 15px;
  background: transparent;
  color: var(--sg-ink);
  font-family: inherit;
  font-weight: 750;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.sg-chip:hover { background: rgba(42, 37, 64, 0.08); }
.sg-chip[aria-pressed="true"] { background: var(--sg-ink); color: #fff; }
.sg-chip-s { padding: 7px 12px; font-size: 13px; }
.sg-chip:focus-visible { outline-color: var(--sg-ink); outline-offset: 1px; }

.sg-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 11px 20px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--sg-ink);
  font-family: inherit;
  font-weight: 750;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(36, 22, 74, 0.14);
}
.sg-pill svg { width: 18px; height: 18px; }
.sg-pill-dark { background: var(--sg-ink); color: #fff; }

/* What is visible in which state */
.sg-title, .sg-call, .sg-modes, .sg-speeds, .sg-acts, [data-act="finish"], .sg-only-play { display: none; }
.sg[data-state="ready"] .sg-title { display: block; }
.sg[data-state="ready"] .sg-score { display: none; }
.sg:not([data-state="play"]) .sg-call { display: block; }
.sg:not([data-state="play"]) .sg-modes { display: flex; }
.sg[data-mode="endless"]:not([data-state="play"]) .sg-speeds { display: flex; }
.sg[data-state="over"] .sg-acts { display: flex; }
.sg[data-state="play"][data-mode="zen"] [data-act="finish"] { display: inline-flex; }
.sg[data-state="play"] .sg-only-play { display: grid; }
.sg[data-state="play"]:not(.sg-is-paused) .sg-bar-r { display: none; }
.sg-is-paused .sg-only-play { visibility: hidden; }
.sg-is-paused .sg-bar { position: relative; z-index: 4; }

.sg-pausebox {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: rgba(30, 22, 56, 0.28);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.sg-pausebox p { margin: 0; font-weight: 300; font-size: clamp(34px, 8vmin, 56px); text-shadow: var(--sg-shadow); }

/* Themes sheet */
.sg-sheet {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(30, 22, 56, 0.38);
  cursor: default;
}
.sg-sheet-card {
  display: flex;
  flex-direction: column;
  width: min(660px, 100%);
  max-height: min(100%, 640px);
  overflow: hidden;
  border-radius: 22px;
  background: #fff;
  color: var(--sg-ink);
  box-shadow: 0 24px 60px rgba(30, 22, 56, 0.3);
  animation: sg-up 0.22s ease-out;
}
.sg-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 20px; }
.sg-sheet-head h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.sg-ic-plain { background: #f2eff9; color: var(--sg-ink); backdrop-filter: none; box-shadow: none; }
.sg-ic-plain:hover { background: #e6e1f4; }
.sg-ic-plain svg { filter: none; }
.sg-ic-plain:focus-visible { outline-color: var(--sg-ink); }

.sg-sheet-body {
  --sb-thumb: #c3b5ee;
  --sb-thumb-hover: #9c86dc;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px 8px 16px 16px;
}
.sg-sheet-body::-webkit-scrollbar { width: 14px; }
.sg-sheet-body::-webkit-scrollbar-track { background: transparent; margin: 22px 0; }
.sg-sheet-body::-webkit-scrollbar-thumb {
  border: solid transparent;
  border-width: 3px 6px 3px 3px;
  border-radius: 999px;
  background: var(--sb-thumb);
  background-clip: padding-box;
}
.sg-sheet-body::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); background-clip: padding-box; }
.sg-sheet-body::-webkit-scrollbar-corner { background: transparent; }
@supports not selector(::-webkit-scrollbar) {
  .sg-sheet-body { scrollbar-color: var(--sb-thumb) transparent; scrollbar-width: thin; }
}

.sg-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}
.sg-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0 0 10px;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 16px;
  background: #f6f4fb;
  color: var(--sg-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.sg-swatch:hover { transform: translateY(-1px); border-color: #d9d2ef; }
.sg-swatch canvas { display: block; width: 100%; aspect-ratio: 4 / 3; }
.sg-swatch-name { padding: 8px 10px 0; font-weight: 800; font-size: 14px; }
.sg-swatch-req { min-height: 1.3em; padding: 2px 10px 0; color: #625b78; font-size: 12px; line-height: 1.35; }
.sg-swatch-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.sg-swatch-mark:empty { display: none; }
.sg-swatch-mark svg { width: 16px; height: 16px; stroke-width: 2.8; }
.sg-current { border-color: var(--sg-ink); }
.sg-current .sg-swatch-mark { background: var(--sg-ink); color: #fff; }
.sg-locked { cursor: default; }
.sg-locked:hover { transform: none; border-color: transparent; }
.sg-locked canvas { filter: grayscale(0.8); opacity: 0.55; }
.sg-locked .sg-swatch-mark { background: rgba(255, 255, 255, 0.92); color: var(--sg-ink); }

.sg-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@keyframes sg-pulse { 50% { opacity: 0.55; } }
@keyframes sg-in { from { opacity: 0; transform: translateY(-6px); } }
@keyframes sg-up { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

@media (max-width: 420px) {
  .sg-bar { padding: 10px; }
  .sg-ic { width: 40px; height: 40px; }
  .sg-chip { padding: 9px 12px; font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .sg-call { animation: none; }
  .sg-toast, .sg-sheet-card { animation: none; }
  .sg-ic, .sg-swatch, .sg-chip { transition: none; }
}
