:root {
  --bg: #071a2b;
  --bg-2: #0c2d43;
  --surface: #3f3f3f;
  --text: #ffffff;
  --muted: #d0d0d0;
  --accent: #f3f3f3;
  --accent-2: #dddddd;
  --radius: 0;
  --font: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  touch-action: none;
}

.hidden,
[hidden] {
  display: none !important;
}

/* Full-screen menus */
.overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: max(22px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  animation: overlay-in 240ms ease-out both;
}

#titleOverlay {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.overlay > .panel {
  position: relative;
  width: min(100%, 470px);
  max-height: calc(100dvh - 44px);
  overflow: auto;
  padding: clamp(24px, 4.5vw, 40px);
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: rgba(134, 242, 197, 0.35) transparent;
  animation: panel-in 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#titleOverlay > .panel {
  width: min(100%, 510px);
}

.panel h1,
.panel h2,
.panel .title,
.logo,
.game-logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  line-height: 0.98;
  letter-spacing: -0.025em;
  color: var(--text);
  text-shadow: 2px 2px 0 #202020;
}

.panel h1,
.logo,
.game-logo {
  font-size: clamp(45px, 9vw, 72px);
}

.panel h2,
.panel .title {
  font-size: clamp(30px, 6vw, 44px);
}

.gradient-text,
.logo,
.game-logo {
  color: #f3f3f3;
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  -webkit-text-fill-color: currentColor;
}

.subtitle,
.tagline,
.panel > p {
  margin: 14px auto 22px;
  max-width: 38ch;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.panel .row,
.panel .stack {
  gap: 12px;
}

.panel .btn {
  min-height: 48px;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #6f6f6f;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: 2px 2px 0 #292929;
  transition: filter 100ms ease, background 100ms ease;
}

.panel .btn.primary {
  color: #fff;
  background: #6f6f6f;
  box-shadow: none;
}

.panel .btn.big,
#play {
  min-height: 58px;
  padding-inline: 34px;
  font-size: 19px;
}

.panel .btn.ghost {
  color: var(--text);
  background: #555;
}

.panel .btn.danger {
  color: #fff;
  background: #6f6f6f;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
}

.panel .btn:hover {
  filter: brightness(1.14);
  transform: none;
}

.panel .btn:active {
  border-color: #1b1b1b #c6c6c6 #c6c6c6 #1b1b1b;
  transform: translateY(2px);
}

#play {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 280px);
  margin: 22px auto 16px;
  cursor: pointer;
}

.controls,
.controls-summary,
.help,
.control-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 16px;
  margin: 20px 0;
  padding: 16px;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  background: #303030;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

.controls p,
.controls-summary p,
.help p,
.control-summary p {
  margin: 0;
}

kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 3px;
  padding: 2px 6px;
  border: 1px solid #a0a0a0;
  border-bottom: 2px solid #181818;
  border-radius: 0;
  background: #555;
  color: var(--text);
  font: 700 11px/1.4 var(--font);
  text-align: center;
}

#mute {
  cursor: pointer;
}

/* In-game HUD */
.hud {
  position: fixed;
  z-index: 21;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px
    max(14px, env(safe-area-inset-left));
  pointer-events: none;
  background: none;
}

.hud > * {
  pointer-events: auto;
}

.hud .chip,
.hud .badge,
#crystalCount,
#saveState {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  text-shadow: 2px 2px 0 #202020;
  white-space: nowrap;
}

#crystalCount {
  color: #fff;
}

#crystalCount::before {
  content: "◆";
  margin-right: 7px;
  color: #fff;
  font-size: 13px;
  filter: none;
}

#saveState {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

#pause {
  display: grid;
  place-items: center;
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  color: var(--text);
  box-shadow: none;
  cursor: pointer;
  pointer-events: auto;
}

#pause:active {
  transform: scale(0.92);
}

#crosshair {
  position: fixed;
  z-index: 10;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  pointer-events: none;
  filter: drop-shadow(1px 1px 0 #000);
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 0;
  background: #fff;
  transform: translate(-50%, -50%);
}

#crosshair::before {
  width: 18px;
  height: 2px;
}

#crosshair::after {
  width: 2px;
  height: 18px;
}

/* Hotbar */
#hotbar {
  position: fixed;
  z-index: 16;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  max-width: calc(100vw - 20px);
  padding: 5px;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  transform: translateX(-50%);
  touch-action: manipulation;
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 52px;
  margin: 0;
  padding: 5px 3px 3px;
  overflow: hidden;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  outline: 0;
  background: #555;
  color: var(--text);
  cursor: pointer;
  transition: filter 100ms ease, background 100ms ease;
  touch-action: manipulation;
}

.slot:hover {
  background: #666;
}

.slot.selected {
  z-index: 1;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  outline: 3px solid #f3f3f3;
  outline-offset: 1px;
  background: #666;
  box-shadow: none;
  transform: none;
}

.slot:active {
  transform: scale(0.94);
}

.slot.selected:active {
  transform: scale(0.96);
}

.slot img,
.slot canvas {
  display: block;
  width: 29px;
  height: 29px;
  object-fit: cover;
  border-radius: 0;
  image-rendering: pixelated;
  pointer-events: none;
}

.slot .icon,
.slot .swatch,
.slot .block-icon {
  display: block;
  width: 27px;
  height: 27px;
  border-radius: 0;
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.slot .key,
.slot .number {
  position: absolute;
  top: 2px;
  left: 5px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}

.slot .count {
  position: absolute;
  right: 4px;
  bottom: 2px;
  min-width: 15px;
  color: #fff8e7;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-align: right;
  text-shadow: 0 1px 3px #000, 0 1px 3px #000;
  pointer-events: none;
}

#selectedName {
  position: fixed;
  z-index: 15;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 76px);
  padding: 5px 9px;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  background: #3f3f3f;
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  text-shadow: 2px 2px 0 #202020;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: nowrap;
}

#blocks {
  position: fixed;
  z-index: 17;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 72px);
  min-height: 36px;
  padding: 6px 16px;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 2px 2px 0 #202020;
  transform: translateX(-50%);
  cursor: pointer;
  touch-action: manipulation;
}

#blocks:hover,
#blocks[aria-expanded="true"] {
  background: #6f6f6f;
}

#blocks:active {
  border-color: #1b1b1b #c6c6c6 #c6c6c6 #1b1b1b;
  transform: translate(-50%, 2px);
}

#blockMenu {
  position: fixed;
  z-index: 22;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 116px);
  display: flex;
  flex-direction: column;
  width: calc(100vw - 32px);
  max-width: 760px;
  max-height: 70vh;
  max-height: min(70dvh, calc(100dvh - 140px));
  padding: 12px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
  scrollbar-width: thin;
  scrollbar-color: #8b8b8b #303030;
  touch-action: pan-y;
}

#blockMenu > header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

#blockMenu h2 {
  margin: 0;
  color: #fff;
  font-size: 20px;
  line-height: 1.2;
  text-shadow: 2px 2px 0 #202020;
}

#closeBlocks {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  background: #555;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

#closeBlocks:hover,
#blockCategories button:hover,
#blockSubcategories button:hover {
  background: #666;
}

#blockSearch {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  outline: 0;
  background: #303030;
  color: #fff;
  font-size: 16px;
  line-height: 1.35;
  -webkit-appearance: none;
  appearance: none;
}

#blockSearch::placeholder {
  color: #d0d0d0;
  opacity: 0.8;
}

#blockSearch:focus {
  outline: 3px solid #f3f3f3;
  outline-offset: 1px;
}

#blockCategories,
#blockSubcategories {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0 0 8px;
}

#blockSubcategories:empty {
  display: none;
}

#blockCategories button,
#blockSubcategories button {
  min-height: 38px;
  padding: 7px 12px;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  background: #555;
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  text-align: left;
  text-shadow: 1px 1px 0 #202020;
  cursor: pointer;
  touch-action: manipulation;
}

#blockSubcategories button {
  min-height: 34px;
  padding: 6px 10px;
  background: #454545;
  font-size: 12px;
}

#blockCategories button.selected,
#blockSubcategories button.selected {
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  outline: 2px solid #f3f3f3;
  outline-offset: 1px;
  background: #6f6f6f;
  color: #fff;
}

#blockCategories button:active,
#blockSubcategories button:active,
#closeBlocks:active {
  border-color: #1b1b1b #c6c6c6 #c6c6c6 #1b1b1b;
}

#blockGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  flex: 0 0 auto;
  gap: 7px;
  min-width: 0;
  padding: 2px;
  overflow: visible;
}

#blockGrid > button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 104px;
  padding: 10px 6px 22px;
  border: 2px solid;
  border-color: #8b8b8b #202020 #202020 #8b8b8b;
  border-radius: 0;
  background: #555;
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  text-shadow: 1px 1px 0 #202020;
  cursor: pointer;
  touch-action: manipulation;
}

#blockGrid > button:hover,
#blockGrid > button.selected {
  background: #666;
}

#blockGrid > button.selected {
  outline: 3px solid #f3f3f3;
  outline-offset: 1px;
}

#blockGrid > button:active {
  border-color: #1b1b1b #c6c6c6 #c6c6c6 #1b1b1b;
}

#blockGrid img,
#blockGrid canvas,
#blockGrid .block-icon,
#blockGrid .icon {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 0;
  image-rendering: pixelated;
  pointer-events: none;
}

#blockGrid .name,
#blockGrid .block-name,
#blockGrid .label {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
}

#blockGrid .count,
#blockGrid .block-count {
  position: absolute;
  right: 7px;
  bottom: 5px;
  color: #fff8e7;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

#blockGrid > p,
#blockGrid > .empty {
  grid-column: 1 / -1;
  margin: 12px 0;
  color: var(--muted);
  text-align: center;
}

.desktop-help,
#desktopHelp {
  position: fixed;
  z-index: 9;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 260px;
  color: rgba(244, 250, 235, 0.63);
  font-size: 12px;
  line-height: 1.6;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

/* Touch interface */
#touchControls {
  display: none;
  position: fixed;
  z-index: 14;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

#lookZone {
  position: absolute;
  z-index: 0;
  top: 68px;
  right: 0;
  bottom: 150px;
  width: 55%;
  pointer-events: auto;
  touch-action: none;
}

#joystick {
  position: absolute;
  z-index: 2;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(25px, env(safe-area-inset-bottom));
  width: 118px;
  height: 118px;
  border: 2px solid rgba(214, 255, 237, 0.2);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(134, 242, 197, 0.08) 0 37%, rgba(5, 26, 43, 0.48) 39% 100%);
  box-shadow: inset 0 0 24px rgba(0, 8, 20, 0.24), 0 5px 24px rgba(0, 10, 20, 0.14);
  pointer-events: auto;
  touch-action: none;
}

#stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin: -26px;
  border: 1px solid rgba(225, 255, 240, 0.36);
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(178, 248, 213, 0.64), rgba(81, 160, 151, 0.6));
  box-shadow: 0 5px 14px rgba(0, 10, 20, 0.3), inset 0 1px rgba(255, 255, 255, 0.32);
  pointer-events: none;
  touch-action: none;
  will-change: transform;
}

#mine,
#place,
#jump {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  padding: 0;
  border: 1px solid rgba(217, 255, 239, 0.27);
  border-radius: 50%;
  background: rgba(8, 37, 53, 0.7);
  color: var(--text);
  box-shadow: 0 7px 20px rgba(0, 8, 18, 0.24), inset 0 1px rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 850;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  touch-action: none;
  transition: transform 90ms ease, background 90ms ease, box-shadow 90ms ease;
}

#mine {
  right: max(22px, env(safe-area-inset-right));
  bottom: calc(max(25px, env(safe-area-inset-bottom)) + 61px);
  background: rgba(124, 70, 53, 0.68);
}

#place {
  right: calc(max(22px, env(safe-area-inset-right)) + 71px);
  bottom: max(25px, env(safe-area-inset-bottom));
  background: rgba(38, 113, 93, 0.7);
}

#jump {
  right: max(22px, env(safe-area-inset-right));
  bottom: calc(max(25px, env(safe-area-inset-bottom)) + 139px);
  width: 58px;
  height: 58px;
  background: rgba(30, 85, 116, 0.7);
}

#mine:active,
#place:active,
#jump:active,
#mine.active,
#place.active,
#jump.active,
#mine.pressed,
#place.pressed,
#jump.pressed {
  background: rgba(134, 242, 197, 0.48);
  box-shadow: 0 0 0 4px rgba(134, 242, 197, 0.1), inset 0 2px 8px rgba(0, 25, 28, 0.22);
  transform: scale(0.9);
}

/* Notices and celebration */
.toast {
  position: fixed;
  z-index: 60;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 118px);
  left: 50%;
  width: max-content;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 2px solid;
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  border-radius: 0;
  background: #3f3f3f;
  box-shadow: none;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  word-break: normal;
  overflow-wrap: normal;
  writing-mode: horizontal-tb;
  transform: translateX(-50%);
  pointer-events: none;
  animation: toast-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

#winOverlay > .panel {
  border-color: #c6c6c6 #1b1b1b #1b1b1b #c6c6c6;
  background: #3f3f3f;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
}

#winOverlay h2,
#winOverlay .title {
  color: #fff;
  text-shadow: 2px 2px 0 #202020;
}

#continue {
  margin-top: 12px;
}

.bump,
.pop {
  animation: counter-pop 280ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

button:focus-visible,
.slot:focus-visible {
  outline: 3px solid #f3f3f3;
  outline-offset: 3px;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -10px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@keyframes counter-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

@media (pointer: coarse), (hover: none) {
  #touchControls {
    display: block;
  }

  #hotbar {
    pointer-events: auto;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 188px);
  }

  #lookZone {
    z-index: 0;
    top: calc(max(12px, env(safe-area-inset-top)) + 150px);
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 184px);
    pointer-events: auto;
    touch-action: none;
  }

  #joystick {
    left: max(12px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
    width: 118px;
    height: 118px;
    min-width: 56px;
    min-height: 56px;
    pointer-events: auto;
    touch-action: none;
  }

  #mine,
  #place,
  #jump {
    min-width: 56px;
    min-height: 56px;
    pointer-events: auto;
    touch-action: none;
  }

  #mine {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 64px);
  }

  #place {
    right: calc(max(12px, env(safe-area-inset-right)) + 72px);
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  #jump {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 138px);
  }

  #selectedName {
    bottom: calc(max(20px, env(safe-area-inset-bottom)) + 238px);
  }

  .desktop-help,
  #desktopHelp {
    display: none;
  }

  #pause {
    width: 42px;
    min-width: 42px;
    height: 42px;
  }

  #blocks {
    pointer-events: auto;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 250px);
  }

  .toast {
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 300px);
  }
}

body.touch #touchControls,
.touch #touchControls {
  display: block;
}

body.touch #hotbar,
.touch #hotbar {
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 188px);
}

body.touch #lookZone,
.touch #lookZone {
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 184px);
}

body.touch #jump,
.touch #jump {
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 86px);
}

body.touch #selectedName,
.touch #selectedName {
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 250px);
}

@media (max-width: 600px) {
  .overlay {
    padding: max(14px, env(safe-area-inset-top)) max(13px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom)) max(13px, env(safe-area-inset-left));
  }

  .overlay > .panel {
    max-height: calc(100dvh - 28px);
    padding: 25px 21px;
  }

  .panel h1,
  .logo,
  .game-logo {
    font-size: clamp(43px, 14vw, 60px);
  }

  .panel > p,
  .subtitle,
  .tagline {
    margin-block: 11px 17px;
    font-size: 14px;
  }

  #play {
    margin-top: 17px;
  }

  .controls,
  .controls-summary,
  .help,
  .control-summary {
    margin: 15px 0;
    padding: 13px;
    font-size: 12px;
  }

  #hotbar {
    gap: 3px;
    max-width: calc(100vw - 12px);
    padding: 5px;
    border-radius: 0;
  }

  .slot {
    flex: 0 1 42px;
    width: 42px;
    min-width: 0;
    height: 46px;
    padding-inline: 2px;
    border-radius: 0;
  }

  .slot img,
  .slot canvas,
  .slot .icon,
  .slot .swatch,
  .slot .block-icon {
    width: 25px;
    height: 25px;
  }

  .slot .key,
  .slot .number {
    left: 4px;
    font-size: 8px;
  }

  .slot .count {
    right: 3px;
    font-size: 12px;
  }

  #selectedName {
    font-size: 13px;
  }

  .hud {
    flex-wrap: wrap;
    gap: 8px;
    padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right));
  }

  .hud > .hud-group {
    flex: 1 0 100%;
    min-width: 0;
  }

  .hud > .hud-group:first-child {
    justify-content: space-between;
  }

  .hud-actions {
    justify-content: flex-end;
  }

  .hud .chip,
  .hud .badge,
  #crystalCount,
  #saveState {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 12px;
  }

  #saveState {
    max-width: 155px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #blockMenu {
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    padding: 10px;
    transform: none;
  }

  #blockMenu h2 {
    font-size: 18px;
  }

  #blockCategories,
  #blockSubcategories {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px;
    scrollbar-width: thin;
    touch-action: pan-x;
  }

  #blockCategories button,
  #blockSubcategories button {
    flex: 0 0 auto;
    min-height: 40px;
  }

  #blockGrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  #blockGrid > button {
    min-height: 98px;
    padding-inline: 4px;
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .slot {
    flex-basis: 36px;
    height: 43px;
  }

  .slot img,
  .slot canvas,
  .slot .icon,
  .slot .swatch,
  .slot .block-icon {
    width: 22px;
    height: 22px;
  }

  #saveState {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #joystick {
    width: 106px;
    height: 106px;
  }
}

@media (max-height: 650px) {
  .overlay > .panel {
    padding-block: 20px;
  }

  .panel h1,
  .logo,
  .game-logo {
    font-size: 43px;
  }

  .controls,
  .controls-summary,
  .help,
  .control-summary {
    margin-block: 11px;
    padding-block: 10px;
  }

  #play {
    min-height: 50px;
    margin-block: 13px;
  }

  #joystick {
    width: 100px;
    height: 100px;
  }

  #mine,
  #place {
    width: 58px;
    height: 58px;
  }

  #jump {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 78px);
  }

  #hotbar {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 170px);
  }

  #lookZone {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 166px);
  }

  #selectedName {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 199px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
