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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
/* Typing your name still needs selectable text. */
input { -webkit-user-select: text; user-select: text; }

canvas { display: block; }

/* Underwater tint */
#underwater {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(30, 90, 150, 0.35), rgba(15, 55, 110, 0.6));
  display: none;
}
#underwater.show { display: block; }

/* Crosshair in the center of the screen */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
}
#crosshair::before,
#crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
}
#crosshair::before { left: 9px; top: 2px; width: 2px; height: 16px; }
#crosshair::after { top: 9px; left: 2px; height: 2px; width: 16px; }

/* Mining progress bar under the crosshair */
#mine-progress {
  position: fixed;
  left: 50%;
  top: calc(50% + 24px);
  transform: translateX(-50%);
  width: 64px;
  height: 7px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.1s;
  pointer-events: none;
}
#mine-fill { height: 100%; width: 0%; background: #f0f0f0; border-radius: 4px; }

/* Tool durability bar inside slots */
.dur {
  position: absolute;
  bottom: 3px;
  left: 5px;
  right: 5px;
  height: 4px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  pointer-events: none;
}
.dur-fill { height: 100%; border-radius: 2px; }

/* Error overlay */
#error-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 40px;
  background: #7a1414;
  color: #ffe;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: auto;
}

/* Debug readout (top-right) */
#debug {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10;
  pointer-events: none;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #dfffe0;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 10px;
  border-radius: 6px;
  white-space: pre;
}

/* HUD */
#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#mode-indicator {
  align-self: flex-start;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 700;
  color: #fff;
  background: rgba(60, 90, 130, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
#mode-indicator.creative { background: rgba(90, 150, 70, 0.85); }
#status {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
}

#autorun-indicator {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: rgba(90, 150, 70, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Minimap / GPS */
#minimap {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 9;
  border-radius: 50%;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}
#minimap.expanded {
  right: 50%;
  bottom: 50%;
  transform: translate(50%, 50%);
  z-index: 60;
}

/* Chat */
#chat-log {
  position: fixed;
  bottom: 118px;
  left: 12px;
  z-index: 10;
  max-width: 46%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
}
#chat-log .msg {
  align-self: flex-start;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 13px;
  text-shadow: 0 1px 2px #000;
}
#chat-log .msg b { color: #9ecbff; }
#chat-input {
  position: fixed;
  bottom: 88px;
  left: 12px;
  width: 46%;
  z-index: 21;
  padding: 8px 11px;
  font-size: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
}
#chat-input.hidden { display: none; }

/* Transient hint message (e.g. "need a pickaxe") */
#toast {
  position: fixed;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  pointer-events: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}

/* Hotbar */
#hotbar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
}
.slot {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot .swatch {
  width: 46px;
  height: 46px;
  border-radius: 4px;
  box-shadow: inset 0 -6px 8px rgba(0, 0, 0, 0.25), inset 0 3px 6px rgba(255, 255, 255, 0.25);
}
/* Item (non-block) icons are drawn art on transparent bg — no block bevel. */
.swatch.item-icon { box-shadow: none; border-radius: 0; }
.slot .num {
  position: absolute;
  top: 1px;
  left: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
.slot.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 0 10px rgba(255, 255, 255, 0.4);
  transform: translateY(-4px);
}

/* Inventory */
#inventory {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
#inventory.hidden { display: none; }
.inv-panel {
  background: rgba(30, 34, 40, 0.97);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 20px 24px;
  max-width: 620px;
  width: 90%;
  color: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.inv-panel h2 { margin-bottom: 4px; }
.inv-hint { font-size: 13px; opacity: 0.7; margin-bottom: 16px; }
.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.inv-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  cursor: pointer;
}
.inv-cell:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); }
.inv-cell .swatch { width: 40px; height: 40px; }
.inv-label { font-size: 11px; opacity: 0.85; text-align: center; }

/* Survival inventory layout */
.slot .count {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow: 1px 1px 2px #000;
  pointer-events: none;
}
.inv-top {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.inv-armor { display: flex; flex-direction: column; gap: 4px; }
.armor-slot { opacity: 0.7; border-style: dashed !important; }
.inv-craft { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.craft-grid { display: grid; grid-template-columns: repeat(2, auto); gap: 4px; }
.craft-arrow { font-size: 28px; opacity: 0.8; }
.output-slot { border-color: rgba(255, 220, 120, 0.8) !important; box-shadow: 0 0 8px rgba(255, 210, 90, 0.4); }
.inv-storage {
  display: grid;
  grid-template-columns: repeat(9, auto);
  gap: 4px;
  justify-content: center;
}
.inv-hotbar-row { margin-top: 12px; }
.cursor-item {
  position: fixed;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bigger, more readable slots inside the inventory/table/furnace screens */
.inv-panel { max-width: 760px; }
.slot.big { width: 60px; height: 60px; }
.slot.big .swatch { width: 48px; height: 48px; }
.slot.big .count { font-size: 15px; }
.inv-storage { gap: 5px; }

/* Furnace */
.furnace {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin-bottom: 18px;
}
.furnace-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.flame {
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.flame-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(#ffd24a, #ff6a1a);
}
.cook-arrow {
  width: 110px;
  height: 18px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.cook-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8fe38f, #46c246);
}

/* Start overlay */
#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #6cb6ff, #2e6db4);
}
#start-overlay.hidden { display: none; }
.panel {
  text-align: center;
  color: #fff;
  padding: 32px 40px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  max-width: 420px;
}
.panel h1 { font-size: 40px; margin-bottom: 4px; }
.tagline { opacity: 0.9; margin-bottom: 20px; }
#play-button {
  font-size: 20px;
  font-weight: 700;
  padding: 12px 32px;
  border: none;
  border-radius: 10px;
  background: #7cc043;
  color: #143;
  cursor: pointer;
  box-shadow: 0 6px 0 #5a9130;
  transition: transform 0.05s;
}
#play-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #5a9130; }
.controls {
  list-style: none;
  text-align: left;
  margin: 24px auto 8px;
  display: inline-block;
  font-size: 14px;
  line-height: 1.9;
}
.controls b { display: inline-block; width: 150px; opacity: 0.85; }
kbd {
  background: #fff;
  color: #222;
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 700;
}
.hint { margin-top: 12px; font-size: 13px; opacity: 0.85; }

/* Shared hidden helper + pause/settings overlays */
.hidden { display: none !important; }
#pause-overlay, #settings-overlay, #death-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, rgba(40, 70, 110, 0.92), rgba(18, 36, 64, 0.95));
}
#death-overlay { background: linear-gradient(160deg, rgba(96, 22, 22, 0.94), rgba(44, 10, 10, 0.96)); }

/* Health / hunger bars */
#stats-bar {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  pointer-events: none;
}
.stat-row { display: flex; gap: 2px; }
#hunger-bar { flex-direction: row-reverse; }
.icon { font-size: 18px; line-height: 1; }
.icon.heart { color: #3a1212; text-shadow: 0 1px 1px #000; }
.icon.heart.on { color: #ec3b3b; }
.icon.food { filter: grayscale(1) brightness(0.4); }
.icon.food.on { filter: none; }
.icon.armor { filter: grayscale(1) brightness(0.5); }
.icon.armor.on { filter: none; }
.menu-panel { min-width: 340px; }
.menu-mini { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.menu-mini .menu-btn { width: auto; margin: 0; padding: 8px 18px; font-size: 14px; }
.menu-btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  background: #5a7fb0;
  color: #fff;
  cursor: pointer;
}
.menu-btn:hover { background: #6b93c6; }
.menu-btn.danger { background: #b0524a; }
.menu-btn.danger:hover { background: #c66056; }
.host-code {
  background: rgba(255, 220, 120, 0.18);
  border: 1px solid rgba(255, 220, 120, 0.5);
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 14px;
}
.setting { margin: 14px 0; text-align: left; }
.setting label { display: block; font-size: 14px; margin-bottom: 6px; }
.setting input[type='range'] { width: 100%; }

/* Recipe book (looks like an open book) */
.book-btn {
  display: block;
  margin: 6px auto 12px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  background: #7a5a34;
  color: #fff;
  cursor: pointer;
}
.book-btn:hover { background: #8b6a40; }
.recipe-book {
  align-self: center;
  width: 300px;
  max-height: 78vh;
  overflow-y: auto;
  margin-right: 18px;
  padding: 18px 20px;
  background: linear-gradient(#f2e8cf, #e7d9b6);
  color: #3a2a15;
  border: 5px solid #6b4b2a;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(107, 75, 42, 0.3);
  font-family: Georgia, 'Times New Roman', serif;
}
.recipe-book h2 { margin-bottom: 4px; }
.book-hint { font-size: 12px; opacity: 0.75; margin-bottom: 14px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
.book-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: 6px;
  background: rgba(107, 75, 42, 0.12);
  border: 2px solid transparent;
  cursor: pointer;
}
.book-cell:hover { border-color: #6b4b2a; background: rgba(107, 75, 42, 0.22); }
.book-cell.locked { opacity: 0.35; cursor: default; }
.book-cell.locked:hover { border-color: transparent; background: rgba(107, 75, 42, 0.12); }
.book-cell.needs-table { opacity: 0.5; cursor: default; }
.book-cell.needs-table:hover { border-color: transparent; background: rgba(107, 75, 42, 0.12); }
.need-badge { position: absolute; top: 2px; right: 4px; font-size: 11px; }
.book-cell .swatch { width: 36px; height: 36px; }
.book-label { font-size: 10px; text-align: center; line-height: 1.15; color: #3a2a15; }

/* Start-screen name / code fields */
.fields { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 6px; text-align: left; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; opacity: 0.9; }
.fields input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 15px;
}
#join-code { text-transform: uppercase; letter-spacing: 3px; }
#join-error { min-height: 18px; margin-top: 8px; font-size: 14px; color: #ffd2d2; }

/* ===========================================================================
   Touch screens (iPad). body.touch is set by src/touch.js (and an inline
   script in index.html so the start screen shows finger hints right away).
   =========================================================================== */
body:not(.touch) .touch-only { display: none !important; }
body.touch .desktop-only { display: none !important; }
body.touch, body.touch canvas { touch-action: none; }
body.touch .inv-panel, body.touch .recipe-book, body.touch .panel { touch-action: pan-y; }
body.touch .controls { display: block; max-width: 340px; font-size: 17px; line-height: 2; }
body.touch .controls b { width: 170px; white-space: nowrap; }
body.touch #debug { display: none; }

/* Big hotbar slots, sized to stay clear of the buttons on the right. */
body.touch {
  --slot: clamp(44px, calc((100vw - 440px) / 9 - 6px), 72px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body.touch #hotbar { bottom: calc(12px + var(--safe-b)); gap: 5px; }
body.touch #hotbar .slot { width: var(--slot); height: var(--slot); }
body.touch #hotbar .slot .swatch { width: calc(var(--slot) - 14px); height: calc(var(--slot) - 14px); }
body.touch #hotbar .slot .num { display: none; }
body.touch #stats-bar { bottom: calc(var(--slot) + 36px + var(--safe-b)); }
body.touch #toast { bottom: calc(var(--slot) + 90px + var(--safe-b)); white-space: normal; max-width: 80vw; text-align: center; }
body.touch #hud { top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l)); }
body.touch #minimap:not(.expanded) { top: calc(96px + var(--safe-t)); right: calc(14px + var(--safe-r)); bottom: auto; }
body.touch #mine-progress { width: 110px; height: 12px; top: calc(50% + 56px); border-radius: 6px; }
body.touch #mine-fill { background: #ffd54a; border-radius: 6px; }

#touch-ui { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
#touch-pad { position: absolute; inset: 0; pointer-events: auto; touch-action: none; }

/* Floating joystick: rests bottom-left, jumps to wherever the thumb lands. */
#joy-base {
  position: absolute;
  left: calc(110px + var(--safe-l));
  top: calc(100% - 150px - var(--safe-b));
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.22));
  border: 3px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.15s, border-color 0.15s;
}
#joy-base.active { opacity: 0.9; }
#joy-base.sprint { border-color: #ffd54a; box-shadow: 0 0 14px rgba(255, 213, 74, 0.8); }
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
}

/* Hold-to-break ring: fills around the finger (or the crosshair). */
#touch-ring {
  position: absolute;
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
  border-radius: 50%;
  pointer-events: none;
  background: conic-gradient(#ffd54a var(--p, 0deg), rgba(0, 0, 0, 0.35) 0);
  -webkit-mask: radial-gradient(circle, transparent 34px, #000 35px);
  mask: radial-gradient(circle, transparent 34px, #000 35px);
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
}
#touch-ring.charging { background: conic-gradient(rgba(255, 255, 255, 0.8) var(--p, 0deg), rgba(0, 0, 0, 0.2) 0); }

/* Round buttons */
.tbtn {
  position: relative;
  pointer-events: auto;
  touch-action: none;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 45, 0.38);
  border: 3px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.06s, background 0.06s;
}
.tbtn.pressed { transform: scale(0.92); background: rgba(255, 255, 255, 0.42); }
.tbtn-icon { font-size: 30px; line-height: 1; }
.tbtn-label { font-size: 12px; font-weight: 800; margin-top: 2px; letter-spacing: 0.3px; }

.touch-btns {
  position: absolute;
  right: calc(20px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  display: grid;
  grid-template-columns: 76px 100px;
  grid-template-rows: 80px 100px;
  gap: 14px;
  align-items: end;
  justify-items: center;
}
.tbtn-break { grid-column: 1; grid-row: 1; background: rgba(150, 70, 40, 0.45); }
.tbtn-place { grid-column: 2; grid-row: 1; background: rgba(60, 120, 50, 0.45); }
.tbtn-down { grid-column: 1; grid-row: 2; margin-bottom: 6px; }
.tbtn-jump { grid-column: 2; grid-row: 2; width: 100px; height: 100px; }
.tbtn-jump .tbtn-icon { font-size: 40px; }
.tbtn-break.pressed { background: rgba(230, 120, 70, 0.7); }
.tbtn-place.pressed { background: rgba(110, 200, 90, 0.7); }
/* "Down" is for flying (and ladders); fade it a bit in survival. */
#touch-ui:not(.creative) .tbtn-down { opacity: 0.6; }

.touch-top {
  position: absolute;
  top: calc(10px + var(--safe-t));
  right: calc(14px + var(--safe-r));
  display: flex;
  gap: 10px;
}
.touch-top .tbtn { width: 68px; height: 68px; border-radius: 18px; }
.touch-top .tbtn-icon { font-size: 26px; }
.touch-top .tbtn-label { font-size: 11px; }

/* Bag / crafting / chest screens by finger */
.inv-panel { position: relative; }
.inv-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}
.inv-close:hover { background: rgba(255, 255, 255, 0.26); }
.creative-bar { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.15); }
.inv-panel.creative { display: flex; flex-direction: column; max-height: 88vh; }
.creative-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding-right: 4px; }
.inv-panel.creative .creative-bar { flex: none; }
.creative-bar .slot.selected { border-color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); }
.inv-cell.picked { animation: picked 0.25s ease-out; }
@keyframes picked { 50% { transform: scale(1.15); background: rgba(255, 255, 255, 0.3); } }
.slot.pressed { background: rgba(255, 255, 255, 0.35); }
.cursor-item.touch { transform: translate(-50%, -120%); }
/* The stack you're carrying: draw its icon and count like a slot's. */
.cursor-item .swatch { width: 48px; height: 48px; border-radius: 4px; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.6)); }
.cursor-item .count { position: absolute; right: 2px; bottom: 0; font-size: 15px; font-weight: 700; color: #fff; text-shadow: 1px 1px 2px #000; }
body.touch .inv-panel { max-height: calc(100% - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 18px; }
body.touch .inv-panel.creative { overflow: hidden; }
body.touch .inv-cell:hover { background: rgba(255, 255, 255, 0.06); border-color: transparent; }
body.touch .inv-cell:active { background: rgba(255, 255, 255, 0.2); }
body.touch .slot.big { width: clamp(44px, calc((100vw - 140px) / 9 - 6px), 64px); height: clamp(44px, calc((100vw - 140px) / 9 - 6px), 64px); }
body.touch .inv-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
body.touch .inv-hint { font-size: 15px; opacity: 0.85; padding-right: 48px; }
body.touch #inventory { padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
body.touch .recipe-book { max-height: calc(100% - 24px); }
body.touch .menu-btn { padding: 14px; font-size: 18px; }
body.touch .menu-mini .menu-btn { padding: 12px 20px; font-size: 16px; }
body.touch .panel { max-height: calc(100vh - 24px); overflow-y: auto; }

/* Held upright: ask for sideways (the game still works if they carry on). */
#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #rotate-hint:not(.dismissed) {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 70;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(18, 36, 64, 0.95);
    color: #fff;
    font-size: 26px;
    font-weight: 800;
  }
  #rotate-hint .rotate-icon { font-size: 80px; margin-bottom: 10px; }
  #rotate-hint .menu-btn { width: auto; margin: 22px auto 0; padding: 12px 26px; }
  body.touch .touch-btns { bottom: calc(var(--slot) + 40px + var(--safe-b)); }
}
