html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #110f0c;
  color: #f9f1dc;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#game-root,
#game-canvas {
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #110f0c;
  color: #ffe7a9;
  font-size: 18px;
  font-weight: 800;
}

body:not(.is-loading) .loading-screen {
  display: none;
}

body.is-loading #hud,
body.is-loading #overlay {
  visibility: hidden;
  pointer-events: none;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: auto minmax(120px, 260px) repeat(4, auto);
  gap: 10px;
  align-items: center;
}

.stat {
  min-width: 82px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 236, 183, 0.22);
  border-radius: 6px;
  background: rgba(22, 17, 12, 0.62);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.stat span {
  display: block;
  color: #d9be86;
  font-size: 11px;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  color: #fff8df;
  font-size: 20px;
  line-height: 1.15;
}

.bar {
  height: 14px;
  border: 1px solid rgba(255, 236, 183, 0.24);
  border-radius: 999px;
  background: rgba(37, 25, 15, 0.72);
  overflow: hidden;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2bd47d, #f1c84b, #f45d48);
  transform-origin: left center;
}

.message {
  position: absolute;
  left: 50%;
  top: 88px;
  max-width: min(540px, calc(100vw - 32px));
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(20, 14, 9, 0.66);
  color: #ffe7a9;
  text-align: center;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 160ms ease;
}

.message.visible {
  opacity: 1;
}

.controls {
  display: none;
}

.controls span {
  padding: 6px 8px;
  border: 1px solid rgba(255, 236, 183, 0.18);
  border-radius: 6px;
  background: rgba(18, 13, 8, 0.58);
  color: #ecd3a1;
  font-size: 12px;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px;
  background: linear-gradient(rgba(30, 21, 14, 0.44), rgba(10, 8, 6, 0.82));
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  display: none;
}

.menu-panel {
  box-sizing: border-box;
  width: min(760px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 26px 28px 24px;
  border: 1px solid rgba(255, 236, 183, 0.2);
  border-radius: 6px;
  background: rgba(22, 15, 9, 0.68);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.overlay h1 {
  margin: 0 0 12px;
  max-width: 100%;
  overflow: hidden;
  color: #fff3cf;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 0.95;
  letter-spacing: 0;
  white-space: nowrap;
}

.overlay p {
  width: min(620px, 100%);
  margin: 0 auto 18px;
  color: #ead2a2;
  font-size: 17px;
  line-height: 1.55;
}

.start-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(620px, 100%);
  margin: 0 auto 18px;
}

.start-controls span {
  padding: 8px 10px;
  border: 1px solid rgba(255, 234, 188, 0.18);
  border-radius: 6px;
  background: rgba(46, 30, 15, 0.5);
  color: #ffe8b8;
  font-size: 13px;
}

.start-controls kbd {
  color: #fff7df;
  font: inherit;
  font-weight: 850;
}

.mode-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.hidden {
  display: none !important;
}

.overlay button {
  min-width: 148px;
  padding: 12px 18px;
  border: 0;
  border-radius: 6px;
  background: #e7b54f;
  color: #251609;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.overlay .gameblocks-credit {
  margin: 18px auto 0;
  color: rgba(234, 210, 162, 0.76);
  font-size: 12px;
  line-height: 1.2;
}

.gameblocks-credit a {
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .stat {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .topbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .start-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
