:root {
  --sky-top: #2a1d4a;
  --sky-mid: #4a3b6b;
  --gold: #ffcf4d;
  --gold-deep: #e0a020;
  --stone: #8a8a96;
  --stone-dark: #4a4a55;
  --panel: #211a30;
  --panel-2: #2c2440;
  --panel-3: #372d50;
  --ink: #f4eede;
  --ink-dim: #b6acc4;
  --good: #8bdc7a;
  --locked: #564c6a;
  --accent: #ff7a59;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: #15101f;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.9rem;
  background: linear-gradient(180deg, #2c2440, #1c1530);
  border-bottom: 2px solid #000;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  z-index: 5;
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.5px;
  color: var(--gold);
  text-shadow: 0 2px 0 #000;
  white-space: nowrap;
}
.brand-inc {
  color: var(--ink-dim);
  font-weight: 600;
  font-size: 0.9rem;
}

.hud-stats {
  display: flex;
  gap: 1.1rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
  min-width: 3.5rem;
}
.stat-val {
  font-weight: 800;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.stat-lbl {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.stat-grit .stat-val {
  color: var(--gold);
}
.stat-stars .stat-val {
  color: #ffe27a;
}

.hud-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font);
  font-weight: 700;
  border: none;
  border-radius: 0.6rem;
  cursor: pointer;
  color: #1a1226;
  background: var(--gold);
  padding: 0.5rem 0.9rem;
  box-shadow: var(--shadow);
  transition:
    transform 0.05s ease,
    filter 0.1s ease,
    box-shadow 0.05s ease;
  font-size: 0.92rem;
}
.btn:hover {
  filter: brightness(1.08);
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7) brightness(0.7);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.btn-icon {
  background: var(--panel-3);
  color: var(--ink);
  padding: 0.5rem 0.6rem;
  font-size: 1.1rem;
}
.btn-ascend {
  background: linear-gradient(180deg, #b98bff, #7d54d6);
  color: #fff;
}
.btn-ascend:disabled {
  background: var(--locked);
}

/* ---------- layout ---------- */
#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

#height-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0.8rem;
  width: min(70%, 460px);
  height: 1.5rem;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid #000;
  border-radius: 1rem;
  overflow: hidden;
  z-index: 3;
}
#height-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  transition: width 0.12s linear;
}
#height-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  color: #1a1226;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

#combo-meter {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 3;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 0.7rem;
  padding: 0.4rem 0.7rem;
  text-align: center;
  pointer-events: none;
}
#combo-mult {
  display: block;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 0 #000;
}
#combo-word {
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  color: var(--ink-dim);
}
#combo-bar {
  margin-top: 0.25rem;
  height: 5px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 3px;
  overflow: hidden;
}
#combo-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
}

#push-hint {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.3);
  padding: 0.25rem 0.7rem;
  border-radius: 1rem;
  z-index: 3;
  pointer-events: none;
  white-space: nowrap;
}
#push-hint kbd {
  background: var(--panel-3);
  border-radius: 0.3rem;
  padding: 0 0.3rem;
  font-family: var(--font);
}

#push-btn {
  position: absolute;
  bottom: 2.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  font-size: 1.05rem;
  padding: 0.6rem 2.2rem;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, #ff9466, var(--accent));
  color: #fff;
}

/* floating +grit numbers */
#floaters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}
.floater {
  position: absolute;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--gold);
  text-shadow: 0 2px 3px #000;
  animation: floatup 1s ease-out forwards;
  white-space: nowrap;
}
.floater.crit {
  color: var(--accent);
  font-size: 1.5rem;
}
@keyframes floatup {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.7);
  }
  20% {
    opacity: 1;
    transform: translateY(-12px) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translateY(-70px) scale(1);
  }
}

/* ---------- panel ---------- */
#panel {
  width: 360px;
  max-width: 42vw;
  background: var(--panel);
  border-left: 2px solid #000;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#tabs {
  display: flex;
  border-bottom: 2px solid #000;
  background: var(--panel-2);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.7rem 0.3rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  position: relative;
}
.tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
  background: var(--panel);
}
.tab-badge {
  position: absolute;
  top: 0.3rem;
  right: 0.5rem;
  background: var(--accent);
  color: #fff;
  border-radius: 1rem;
  font-size: 0.65rem;
  padding: 0 0.35rem;
  min-width: 1.1rem;
}

#tab-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.tab-pane {
  display: none;
  padding: 0.6rem;
}
.tab-pane.active {
  display: block;
}

/* shop / upgrade items */
.item {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 2px solid #000;
  border-radius: 0.7rem;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  color: var(--ink);
  font-family: var(--font);
  transition:
    transform 0.05s ease,
    filter 0.1s;
}
.item:hover:not(:disabled) {
  filter: brightness(1.1);
}
.item:active:not(:disabled) {
  transform: scale(0.99);
}
.item:disabled,
.item.cant {
  cursor: not-allowed;
  filter: grayscale(0.5) brightness(0.6);
}
.item-ico {
  font-size: 1.8rem;
  width: 2.4rem;
  text-align: center;
  flex-shrink: 0;
}
.item-main {
  flex: 1;
  min-width: 0;
}
.item-name {
  font-weight: 800;
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
}
.item-owned {
  color: var(--ink-dim);
  font-weight: 700;
}
.item-desc {
  font-size: 0.72rem;
  color: var(--ink-dim);
  margin-top: 0.15rem;
  line-height: 1.25;
}
.item-cost {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--gold);
  white-space: nowrap;
}
.item-cost.cant {
  color: #d9706a;
}
.item-effect {
  font-size: 0.72rem;
  color: var(--good);
  margin-top: 0.15rem;
}

.pane-empty {
  color: var(--ink-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 1rem;
  line-height: 1.5;
}

/* badges */
#pane-badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.5rem;
}
.badge {
  aspect-ratio: 1;
  border-radius: 0.7rem;
  background: var(--panel-2);
  border: 2px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  cursor: help;
  position: relative;
}
.badge.locked {
  filter: grayscale(1) brightness(0.4);
  color: var(--locked);
}
.badge.unlocked {
  background: linear-gradient(180deg, #3a2f56, #2a2240);
  box-shadow: inset 0 0 0 2px var(--gold-deep);
}

/* stats */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid var(--panel-3);
  font-size: 0.85rem;
}
.stat-row .k {
  color: var(--ink-dim);
}
.stat-row .v {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stats-section-title {
  margin: 0.8rem 0 0.3rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
}

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--panel-3);
  border: 2px solid #000;
  border-left: 5px solid var(--gold);
  border-radius: 0.6rem;
  padding: 0.6rem 0.9rem;
  max-width: 320px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  animation:
    toastin 0.3s ease,
    toastout 0.4s ease 4.6s forwards;
}
.toast.achi {
  border-left-color: var(--gold);
}
.toast.boost {
  border-left-color: var(--accent);
}
.toast.ascend {
  border-left-color: #b98bff;
}
.toast-title {
  font-weight: 800;
  font-size: 0.86rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.toast-sub {
  font-size: 0.74rem;
  color: var(--ink-dim);
  margin-top: 0.15rem;
}
@keyframes toastin {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
}
@keyframes toastout {
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ---------- modal ---------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#modal {
  background: var(--panel);
  border: 2px solid #000;
  border-radius: 1rem;
  padding: 1.4rem;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}
#modal h2 {
  margin: 0 0 0.7rem;
  color: var(--gold);
}
#modal-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink-dim);
}
#modal-body strong {
  color: var(--ink);
}
#modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1.2rem;
}
.btn-ghost {
  background: var(--panel-3);
  color: var(--ink);
}

/* ---------- polish pass ---------- */
/* stage depth vignette (opacity nudged by combo from JS) */
#vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(
    ellipse 75% 70% at 42% 42%,
    rgba(0, 0, 0, 0) 55%,
    rgba(10, 6, 20, 0.55) 100%
  );
  opacity: 0.6;
  transition: opacity 0.25s ease;
}
#vignette.combo {
  background: radial-gradient(
      ellipse 75% 70% at 42% 42%,
      rgba(0, 0, 0, 0) 50%,
      rgba(10, 6, 20, 0.5) 100%
    ),
    radial-gradient(ellipse 90% 85% at 42% 50%, rgba(255, 90, 110, 0) 60%, rgba(255, 70, 90, 0.28) 100%);
}

/* summit banner */
#summit-banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}
#summit-banner.show {
  animation: summitpop 1.5s ease-out forwards;
}
#summit-banner .sb-word {
  font-size: clamp(1.6rem, 6vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--gold);
  display: block;
}
#summit-banner .sb-sub {
  font-size: clamp(0.9rem, 3vw, 1.3rem);
  font-weight: 800;
  color: #fff;
}
@keyframes summitpop {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
  35% {
    transform: translate(-50%, -50%) scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -75%) scale(1);
  }
}

/* PUSH button — tactile glow + idle breathing */
#push-btn {
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.35),
    0 0 22px rgba(255, 122, 89, 0.5);
  animation: pushbreath 2.4s ease-in-out infinite;
}
#push-btn:active {
  animation: none;
}
@keyframes pushbreath {
  0%,
  100% {
    box-shadow:
      0 6px 0 rgba(0, 0, 0, 0.35),
      0 0 18px rgba(255, 122, 89, 0.4);
  }
  50% {
    box-shadow:
      0 6px 0 rgba(0, 0, 0, 0.35),
      0 0 34px rgba(255, 122, 89, 0.75);
  }
}

/* affordability: buyable items glow + breathe; category accent stripe */
.item {
  position: relative;
  border-left-width: 2px;
  overflow: hidden;
}
.item.buyable {
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 207, 77, 0.5),
    0 0 16px rgba(255, 207, 77, 0.22);
  filter: none;
}
.item.buyable:hover:not(:disabled) {
  transform: translateY(-2px);
}
.item-cat {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

/* HUD grit glow + ticking feel */
.stat-grit .stat-val {
  text-shadow: 0 0 14px rgba(255, 207, 77, 0.55);
}
.brand {
  background: linear-gradient(180deg, #ffe27a, #e0a020);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* combo meter punch */
#combo-meter {
  background: linear-gradient(180deg, rgba(40, 20, 30, 0.7), rgba(20, 10, 18, 0.55));
  border: 1px solid rgba(255, 122, 89, 0.4);
  box-shadow: 0 0 18px rgba(255, 90, 110, 0.25);
}
#combo-mult {
  animation: combothrob 0.6s ease-in-out infinite;
}
@keyframes combothrob {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

/* tab badge pulse */
.tab-badge {
  animation: badgepulse 1.6s ease-in-out infinite;
}
@keyframes badgepulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(255, 122, 89, 0.6);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(255, 122, 89, 0);
  }
}

/* newly-unlocked badge sparkle */
.badge.unlocked.fresh {
  animation: badgefresh 0.9s ease-out;
}
@keyframes badgefresh {
  0% {
    transform: scale(0.3) rotate(-20deg);
    box-shadow: 0 0 24px var(--gold);
  }
  60% {
    transform: scale(1.2) rotate(6deg);
  }
  100% {
    transform: scale(1);
  }
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  #layout {
    flex-direction: column;
  }
  #stage {
    flex: none;
    height: 46vh;
  }
  #panel {
    width: 100%;
    max-width: none;
    flex: 1;
    border-left: none;
    border-top: 2px solid #000;
  }
  .hud-stats {
    gap: 0.7rem;
  }
  .brand {
    font-size: 1rem;
  }
  #push-hint {
    display: none;
  }
}
