:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --app-bg: var(--tg-bg-color, #071018);
  --app-text: var(--tg-text-color, #f7fbff);
  --panel: rgba(12, 24, 36, 0.92);
  --panel-strong: rgba(16, 34, 49, 0.96);
  --line: rgba(255, 255, 255, 0.12);
  --muted: rgba(247, 251, 255, 0.68);
  --cyan: var(--tg-button-color, #20c7e8);
  --gold: #f7c948;
  --green: #5ee27a;
  --ink: #061018;
  background: var(--app-bg);
  color: var(--app-text);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #071018 0%, #0d1925 48%, #071018 100%);
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0.85rem 1rem;
  background: var(--cyan);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(32, 199, 232, 0.18);
  transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease;
}

button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button[hidden] {
  display: none;
}

.premium-action {
  background: var(--gold);
  box-shadow: 0 10px 26px rgba(247, 201, 72, 0.18);
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(0.8rem, env(safe-area-inset-top)) 0.85rem max(1.4rem, env(safe-area-inset-bottom));
}

.hero-card,
.hud,
.shop-panel,
.status-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem;
}

.eyebrow,
.subtitle {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0.15rem 0;
  font-size: 2.25rem;
  letter-spacing: 0;
}

.currency-pill {
  flex: 0 0 auto;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  background: rgba(247, 201, 72, 0.14);
  color: var(--gold);
  font-weight: 800;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin: 0.75rem 0;
  padding: 0.65rem;
}

.hud span,
.hud strong {
  display: block;
  text-align: center;
}

.hud span {
  color: var(--muted);
  font-size: 0.8rem;
}

.hud strong {
  margin-top: 0.2rem;
  font-size: 1.2rem;
}

#game-board {
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.38);
  touch-action: none;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.75rem 0;
}

.shop-panel {
  margin: 0.75rem 0;
  padding: 0.75rem;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.shop-item {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.35rem;
  min-height: 150px;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.shop-item strong,
.shop-item span {
  min-width: 0;
}

.shop-title {
  color: var(--app-text);
  font-size: 0.98rem;
  line-height: 1.2;
}

.shop-price {
  color: var(--gold);
  font-weight: 800;
}

.shop-reward {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.3;
}

.shop-buy {
  min-height: 40px;
  padding: 0.65rem 0.75rem;
}

.status-panel {
  min-height: 54px;
  padding: 0.85rem;
  color: rgba(247, 251, 255, 0.84);
  text-align: center;
}

.level-map {
  margin: 0.75rem 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.18);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.55rem;
}

.level-node {
  min-height: 3rem;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--app-text);
  box-shadow: none;
}

.level-node.is-active {
  outline: 2px solid var(--cyan);
  background: var(--cyan);
  color: var(--ink);
}

.level-node.is-completed {
  background: var(--green);
  color: var(--ink);
}

.level-node:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

@media (max-width: 520px) {
  .hero-card {
    align-items: flex-start;
  }

  h1 {
    font-size: 1.9rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .currency-pill {
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .shop-grid {
    grid-template-columns: 1fr;
  }
}
