* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  height: 100dvh;
  background: #f5e6c8;
  color: #5c3d2e;
  font-family: "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden; /* game scales to fit; no page scroll */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#wrap {
  width: 480px;
  max-width: 100vw;
  max-height: 100dvh;
  max-height: 100svh;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
  flex-wrap: wrap;
  width: 100%;
  flex: 0 0 auto;
}

#hud-left, #hud-mid, #hud-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

#build-tag {
  display: none;
}

#speed-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
}

#speed-ctrl button {
  width: 24px;
  height: 24px;
  line-height: 1;
  border: 2px solid #d4a574;
  border-radius: 6px;
  background: #fff8e7;
  color: #8b4513;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#speed-ctrl button:active {
  background: #f0dcb4;
}

#speed-label {
  min-width: 34px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #8b4513;
}

#level-name {
  color: #8b4513;
}

#recipe-tray {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 32px;
  margin-bottom: 4px;
  padding: 3px 6px;
  background: #fff8e7;
  border: 2px solid #d4a574;
  border-radius: 8px;
  flex-wrap: wrap;
  width: 100%;
  flex: 0 0 auto;
}

#recipe-tray .slot {
  width: 28px;
  height: 28px;
  border: 2px dashed #c9a06a;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #faf0dc;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  opacity: 0.45;
}

#recipe-tray .slot.got {
  opacity: 1;
  border-style: solid;
  border-color: #6b8e23;
  background: #e8f5d0;
}

#recipe-tray .slot img {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game {
  display: block;
  width: auto;
  height: auto;
  max-width: min(480px, 100vw - 16px);
  /* JS also sets pixel size; this caps tall monitors so no scroll */
  max-height: calc(100dvh - 96px);
  background: #faf0dc;
  border: 3px solid #c49a6c;
  border-radius: 4px;
  cursor: none;
  touch-action: none;
  flex: 0 1 auto;
}

#hint {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.8;
  text-align: center;
  flex: 0 0 auto;
  width: 100%;
}


/* Title / How to Play: hide play HUD so the card can breathe */
#wrap.menu-mode #hud,
#wrap.menu-mode #recipe-tray {
  visibility: hidden;
  min-height: 0;
  height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: none;
}

#wrap.menu-mode #hint {
  opacity: 1;
  font-weight: 600;
}


@media (max-width: 480px) {
  #hud {
    font-size: 12px;
    gap: 4px;
  }
  #hud-left, #hud-mid, #hud-right {
    gap: 8px;
  }
  #recipe-tray {
    min-height: 28px;
    gap: 4px;
    padding: 2px 4px;
  }
  #recipe-tray .slot {
    width: 26px;
    height: 26px;
  }
  #hint {
    font-size: 11px;
    line-height: 1.35;
    padding: 0 4px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #hud { font-size: 11px; }
  #recipe-tray { min-height: 24px; margin-bottom: 2px; }
  #hint { font-size: 10px; margin-top: 2px; }
  #game { max-height: calc(100svh - 72px); }
}
