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

*,
*::before,
*::after {
  box-sizing: border-box;
}

button {
  min-height: 38px;
  border: 1px solid rgba(255, 232, 181, 0.36);
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(50, 58, 50, 0.9), rgba(22, 25, 22, 0.86));
  color: #f8f1e5;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

button:hover,
button.active {
  background: linear-gradient(180deg, #d24f32, #982f24);
  border-color: #ffd59c;
  box-shadow: 0 0 0 1px rgba(255, 213, 156, 0.22), 0 10px 24px rgba(107, 34, 23, 0.35);
}

button:disabled {
  cursor: default;
  opacity: 0.48;
}

#game-root,
#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
}

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

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

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

#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, 1fr));
  gap: 8px;
  pointer-events: none;
}

.stat {
  min-width: 0;
  border: 1px solid rgba(255, 241, 216, 0.24);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(37, 49, 46, 0.83), rgba(16, 24, 21, 0.78));
  padding: 8px 10px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
}

.stat span {
  display: block;
  color: #d5c2a8;
  font-size: 11px;
  line-height: 1.1;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(15px, 2vw, 22px);
  line-height: 1.1;
}

#panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  pointer-events: none;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: auto;
}

.tool-row button {
  padding: 0 12px;
}

#status-line {
  position: fixed;
  top: 78px;
  left: 12px;
  right: 12px;
  min-height: 22px;
  color: #ffe2ad;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.72);
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  background: rgba(4, 6, 5, 0.58);
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: min(520px, 100%);
  max-height: calc(100vh - 28px);
  max-height: calc(100svh - 28px);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255, 231, 190, 0.34);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(29, 39, 35, 0.91), rgba(17, 23, 20, 0.9));
  padding: clamp(16px, 4vw, 24px);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-overflow-scrolling: touch;
}

.dialog h1 {
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(30px, 6vw, 56px);
  line-height: 0.95;
  letter-spacing: 0;
  white-space: nowrap;
}

.dialog p {
  margin: 14px 0 18px;
  color: #e3d2bb;
  line-height: 1.5;
}

.start-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}

.start-controls div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(255, 231, 190, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.start-controls dt {
  color: #ffd59c;
  font-size: 12px;
  font-weight: 850;
}

.start-controls dd {
  margin: 3px 0 0;
  color: #f6e4cc;
  font-size: 12px;
  line-height: 1.35;
}

.mode-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.dialog button {
  width: 100%;
  border-color: #ffd59c;
}

.mode-actions button:first-child {
  background: linear-gradient(180deg, #3d725f, #214b3e);
}

.mode-actions button:nth-child(2) {
  background: linear-gradient(180deg, #3d725f, #214b3e);
  color: #f8f1e5;
  border-color: #b8e0c7;
}

.mode-actions button:hover,
.mode-actions button:focus-visible {
  background: linear-gradient(180deg, #4b876f, #2a5b4b);
  border-color: #d1f2da;
}

.dialog .gameblocks-credit {
  margin: 18px 0 0;
  color: rgba(246, 228, 204, 0.7);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

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

@media (max-width: 760px) {
  #hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #status-line {
    top: 204px;
  }

  #panel {
    grid-template-columns: 1fr;
  }

  .tool-row button {
    flex: 1 1 92px;
  }
}
