:root {
  --bg: #12082b;
  --bg2: #1d0f3f;
  --surface: #241448;
  --surface-2: #32205e;
  --text: #f2ecff;
  --muted: #b9a8d8;
  --accent: #ffd166;
  --fx: #ffd166;
  --good: #6ee7a0;
  --radius: 14px;
}

/* tier themes: hue drifts warmer/redder as things escalate */
body[data-tier="3"], body[data-tier="4"] { --bg: #1b0a2e; --bg2: #34104a; }
body[data-tier="5"], body[data-tier="6"] { --bg: #250a2c; --bg2: #4a103f; --fx: #ffb066; }
body[data-tier="7"], body[data-tier="8"] { --bg: #2c0a22; --bg2: #58122d; --fx: #ff8f66; }
body[data-tier="9"], body[data-tier="10"] { --bg: #330909; --bg2: #611414; --fx: #ff6666; --accent: #ffab66; }
body[data-tier="11"] { --bg: #000; --bg2: #1c0533; --fx: #d18cff; --accent: #d18cff; }

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(120% 100% at 50% 0%, var(--bg2), var(--bg) 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  transition: background 1.2s;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.app {
  max-width: 1020px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-areas: "top top" "stage shop" "content content" "footer footer";
  gap: 16px;
}

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.top h1 { font-size: 1.5rem; margin: 8px 0 0; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 0.55em 1em;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }
.ghost { background: transparent; }

#btn-mute { font-size: 1.1rem; padding: 0.4em 0.7em; }

/* --- stage ---------------------------------------------------------------- */
.stage { grid-area: stage; text-align: center; }

.loudness {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}
.db-wrap {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tier-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.meter-track {
  height: 8px;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
  margin: 6px auto 0;
  max-width: 460px;
}
.meter-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--good), var(--accent));
  transform-origin: left;
  transform: scaleX(0);
}

.sax-zone { position: relative; height: 340px; }
#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sax {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  font-size: 9rem;
  line-height: 1;
  background: none;
  border: none;
  padding: 0.05em 0.1em;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.5));
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button.sax:hover:not(:disabled) { background: none; scale: 1.04; }

@media (prefers-reduced-motion: no-preference) {
  .sax.pressed { animation: squash 0.14s ease-out; }
  @keyframes squash {
    30% { scale: 0.92 1.06; rotate: -3deg; }
    70% { scale: 1.06 0.94; }
  }
  body[data-tier="5"] .sax-zone, body[data-tier="6"] .sax-zone { animation: shake 0.7s infinite; }
  body[data-tier="7"] .sax-zone, body[data-tier="8"] .sax-zone { animation: shake 0.4s infinite; }
  body[data-tier="9"] .sax-zone, body[data-tier="10"] .sax-zone,
  body[data-tier="11"] .sax-zone { animation: shake 0.22s infinite; }
  @keyframes shake {
    25% { transform: translate(1.5px, -1px) rotate(0.15deg); }
    75% { transform: translate(-1.5px, 1px) rotate(-0.15deg); }
  }
}

.tier-banner {
  position: absolute;
  left: 50%;
  top: 12%;
  translate: -50%;
  padding: 0.4em 1.1em;
  border-radius: 999px;
  background: var(--accent);
  color: #201230;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.tier-banner.show { animation: banner 2.4s ease-out forwards; }
@keyframes banner {
  0% { opacity: 0; scale: 0.6; }
  12% { opacity: 1; scale: 1.08; }
  20% { scale: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; translate: -50% -18px; }
}

.stats {
  display: flex;
  justify-content: center;
  gap: 34px;
  margin: 0;
}
.stats dt { color: var(--muted); font-size: 0.8rem; }
.stats dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}
.encore { background: var(--accent); color: #201230; font-weight: 700; }
.encore-note { color: var(--muted); font-size: 0.85rem; }

/* --- shop ------------------------------------------------------------------ */
.shop-panel { grid-area: shop; }
.shop-panel h2 { font-size: 1rem; color: var(--muted); margin: 4px 0 8px; }
.shop { display: flex; flex-direction: column; gap: 8px; }

.upgrade[hidden] { display: none; }
.upgrade {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 8px 10px;
}
.u-emoji { font-size: 1.5rem; }
.u-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.u-name { font-weight: 600; }
.u-desc { color: var(--muted); font-size: 0.78rem; }
.u-cost {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* --- content ----------------------------------------------------------------- */
.content {
  grid-area: content;
  max-width: 68ch;
  margin: 8px auto 0;
  color: var(--muted);
  line-height: 1.6;
}
.content h2, .content h3 { color: var(--text); }
.content strong { color: var(--text); }
.fineprint { font-size: 0.8rem; }

.table-wrap { overflow-x: auto; }
.tier-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
.tier-table th, .tier-table td {
  text-align: left;
  padding: 6px 12px 6px 0;
  border-bottom: 1px solid var(--surface-2);
}
.tier-table th { color: var(--text); }
.tier-table td:first-child {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- toast ------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  translate: -50% 20px;
  background: var(--surface-2);
  padding: 0.7em 1.2em;
  border-radius: var(--radius);
  opacity: 0;
  transition: 0.3s;
  pointer-events: none;
  max-width: 90vw;
  z-index: 6;
}
.toast.show { opacity: 1; translate: -50%; }

/* --- mobile -------------------------------------------------------------------- */
/* --- footer & static pages ----------------------------------------------------- */
.site-footer {
  grid-area: footer;
  margin-top: 28px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--surface-2);
  text-align: center;
}
.site-footer nav {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
}
.site-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.site-footer a:hover { color: var(--text); }

.app-page { display: block; }
.content-page { margin-top: 8px; }
.content-page h2 { margin-top: 1.6em; }
.content-page code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0 0.35em;
}
.content a { color: var(--accent); }

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "stage" "shop" "content" "footer";
  }
  .sax-zone { height: 260px; }
  .sax { font-size: 7rem; }
  .db-wrap { font-size: 2.3rem; }
}
