:root {
  color-scheme: dark;
  --ink: #f9f4df;
  --muted: #c9c2a8;
  --panel: rgba(26, 25, 21, 0.74);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #f6c85f;
  --ale: #d98924;
  --danger: #e45c4f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #16130e;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.17);
  border-color: rgba(255, 255, 255, 0.34);
}

button:active {
  transform: translateY(1px);
}

a {
  color: inherit;
  text-decoration: none;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 560px;
  background: #222;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  left: 18px;
  top: 18px;
  right: 18px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 12px;
  align-items: stretch;
  pointer-events: none;
}

.brand,
.stats,
.controls,
.back-link,
.shop-toggle,
.shop,
.toast {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.back-link {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 4;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 900;
  pointer-events: auto;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.17);
  border-color: rgba(255, 255, 255, 0.34);
}

.brand {
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 0;
}

.brand span {
  display: block;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand small,
.stats span,
.shop small {
  color: var(--muted);
  font-size: 12px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  border-radius: 8px;
  overflow: hidden;
}

.stats div {
  padding: 10px 14px;
  border-left: 1px solid var(--line);
  min-width: 74px;
}

.stats div:first-child {
  border-left: 0;
}

.stats b {
  display: block;
  font-size: 18px;
}

.controls {
  display: grid;
  grid-template-columns: 140px 112px;
  gap: 8px;
  border-radius: 8px;
  padding: 8px;
  pointer-events: auto;
}

.controls button:first-child {
  background: linear-gradient(180deg, #e6a543, #a95f16);
  border-color: rgba(255, 222, 141, 0.55);
}

.shop-toggle {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 4;
  min-height: 48px;
  padding: 0 18px;
  pointer-events: auto;
}

.shop {
  position: absolute;
  right: 18px;
  bottom: 76px;
  z-index: 5;
  width: min(315px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 12px;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  visibility: hidden;
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.shop.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.shop h2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  font-size: 16px;
}

.shop-close {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.shop button[data-upgrade] {
  width: 100%;
  min-height: 58px;
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 10px;
  padding: 9px 11px;
  text-align: left;
}

.shop button[data-upgrade] small {
  grid-column: 1 / 3;
}

.shop button[data-upgrade].affordable {
  border-color: rgba(246, 200, 95, 0.62);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 380px));
  min-width: 260px;
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
  font-weight: 800;
  color: #fff7d0;
}

@media (max-width: 820px) {
  .hud {
    grid-template-columns: 1fr;
    right: auto;
    width: calc(100vw - 36px);
  }

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

  .shop {
    left: 18px;
    right: 18px;
    width: auto;
    bottom: 76px;
    max-height: calc(100vh - 285px);
    overflow-y: auto;
  }

  .toast {
    bottom: 82px;
    width: calc(100vw - 36px);
  }

  .back-link {
    bottom: 18px;
    min-height: 42px;
    padding: 0 12px;
    font-size: 13px;
  }
}
