/* Terravox attribution: of 217 lines, smarter-model help wrote: Claude Code (final reviewer) 55 lines (62-64, 158-172, 174-175, 177-195, 202-208, 210-218); Claude Sonnet 10 lines (7-8, 66-69, 74, 80, 137, 154); GPT-6.1 Terra 17 lines (98, 112-114, 117-129); Gemini 3.8 Flash 3 lines (103-104, 132). The rest by the local models. See ATTRIBUTION.md. */
html, body {
  margin: 0;
  overflow: hidden;
  background: #000;
  font-family: sans-serif;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
}

#hud, #menus {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tv-crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 20px; height: 20px;
  pointer-events: none;
}
.tv-crosshair::before, .tv-crosshair::after {
  content: ''; position: absolute; background: rgba(255,255,255,0.8);
}
.tv-crosshair::before { top: 9px; left: 0; width: 20px; height: 2px; }
.tv-crosshair::after { top: 0; left: 9px; width: 2px; height: 20px; }

.tv-hotbar {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; background: rgba(0,0,0,0.5); padding: 4px; border-radius: 4px;
  flex-wrap: wrap; justify-content: center; max-width: 90vw;
}

.tv-slot {
  width: 48px; height: 48px; background: rgba(100,100,100,0.6);
  border: 2px solid #555; position: relative; display: flex; align-items: center; justify-content: center;
}
.tv-slot img { image-rendering: pixelated; width: 32px; height: 32px; object-fit: contain; }

.tv-slot.selected { border-color: #fff; background: rgba(150,150,150,0.8); }

.tv-count {
  position: absolute; bottom: 2px; right: 2px; font-size: 12px; color: #fff;
  text-shadow: 1px 1px 0 #000; pointer-events: none;
}

.tv-stats-container {
  position: absolute; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; justify-content: center;
}
.tv-hearts {
  /* the HUD's .tv-stats-container already places hearts + hunger above the hotbar: keep them in one row inside it */
  position: static; transform: none;
  display: flex; flex-wrap: nowrap; justify-content: center; gap: 2px;
}
.tv-hearts img {
  image-rendering: pixelated; width: 16px; height: 16px;
  display: block; flex-shrink: 0;
}

.tv-hunger {
  position: static; width: min(160px, 50vw); height: 8px; background: #333; border: 1px solid #000; overflow: hidden;
}
.tv-hunger-fill { display: block; height: 100%; background: #0f0; width: 0%; }

.tv-break {
  position: absolute; bottom: 130px; left: 50%; transform: translateX(-50%);
  width: min(200px, 60vw); height: 8px; background: #333; border: 1px solid #000; overflow: hidden;
}
.tv-break-fill { display: block; height: 100%; background: #fff; width: 0%; }

.tv-debug {
  position: absolute; top: 10px; left: 10px; font-family: monospace; font-size: 14px; color: #fff;
  text-shadow: 1px 1px 0 #000; pointer-events: none; white-space: pre; line-height: 1.4;
  max-width: 90vw; overflow: hidden;
}

.tv-toast {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7); color: #fff; padding: 8px 16px; border-radius: 4px;
  font-size: 16px; text-shadow: 1px 1px 0 #000; pointer-events: none; opacity: 0; transition: opacity 0.3s;
  max-width: 80vw; white-space: normal; text-align: center;
  z-index: 900;
}

.tv-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}

.tv-panel {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.75);
  max-height: 100vh; overflow: auto; pointer-events: auto;
  z-index: 1001;
}
.tv-panel.open { display: flex; z-index: 1001; }

.tv-grid {
  display: grid;
  width: min(90vw, 376px);
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: min(1vw, 2px);
  margin-bottom: 12px;
  box-sizing: border-box;
}

.tv-panel .tv-grid .tv-slot {
  box-sizing: border-box;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  min-width: 0;
}

.tv-panel .tv-grid .tv-slot img {
  width: min(100%, 32px);
  height: min(100%, 32px);
}

.tv-recipes { display: flex; flex-wrap: wrap; gap: 6px; max-width: 90vw; justify-content: center; }

.tv-button, .tv-recipe-btn, .tv-inv-close {
  background: #c6c6c6; border: 2px solid #fff; border-right-color: #555; border-bottom-color: #555;
  padding: 8px 12px; font-family: sans-serif; font-size: 14px; cursor: pointer; color: #000;
  text-shadow: none;
}
.tv-button:hover, .tv-recipe-btn:hover, .tv-inv-close:hover { background: #d6d6d6; }
.tv-button:active, .tv-recipe-btn:active, .tv-inv-close:active { border-color: #555; border-right-color: #fff; border-bottom-color: #fff; }

.tv-title { font-size: 48px; color: #fff; text-shadow: 2px 2px 0 #000; margin-bottom: 24px; text-align: center; }
.tv-menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }

#menus button, #menus input, #menus select,
#hud button, #hud input, #hud select { pointer-events: auto; }
#menus .tv-overlay { pointer-events: auto; }

@media (max-width: 600px) {
  .tv-slot { width: 36px; height: 36px; }
  .tv-slot img { width: 24px; height: 24px; }
  .tv-hotbar { gap: 2px; padding: 2px; }
  .tv-hearts { gap: 1px; }
  .tv-hearts img { width: 12px; height: 12px; }
  .tv-hunger { position: static; }
}

/* ===== Loading indicator (all devices) — Claude Code ===== */
#tv-loading {
  position: fixed; inset: 0; z-index: 300; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.72); color: #fff; font: 600 20px/1.3 system-ui, sans-serif; letter-spacing: .02em;
}

/* ===== Mobile-first touch UI (body.touch is set on phones/tablets) — Claude Code ===== */
body.touch, body.touch * { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
body.touch { touch-action: none; overscroll-behavior: none; }
body.touch #game { touch-action: none; }
body.touch .tv-hotbar { pointer-events: auto !important; bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  width: min(92vw, 420px) !important; }
body.touch .tv-slot { min-height: 0; aspect-ratio: 1 / 1; }
body.touch .tv-slot img { width: 70%; height: 70%; }
body.touch .tv-stats-container { bottom: calc(10px + min(10.2vw, 47px) + env(safe-area-inset-bottom, 0px)) !important; }
body.touch .tv-debug { pointer-events: none; }

#touch { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#touch .tc-look { position: absolute; top: 0; right: 0; bottom: 0; left: 40%; pointer-events: auto; touch-action: none; z-index: 1; }
#touch .tc-stick {
  position: absolute; pointer-events: auto; touch-action: none;
  left: calc(18px + env(safe-area-inset-left, 0px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  width: min(34vw, 150px); aspect-ratio: 1 / 1; border-radius: 50%;
  background: rgba(255, 255, 255, 0.10); border: 2px solid rgba(255, 255, 255, 0.35);
}
#touch .tc-knob {
  position: absolute; left: 50%; top: 50%; width: 44%; aspect-ratio: 1 / 1; border-radius: 50%;
  background: rgba(255, 255, 255, 0.45); transform: translate(-50%, -50%);
}
#touch .tc-buttons {
  position: absolute; pointer-events: none; display: grid; gap: 12px;
  right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  grid-template-columns: repeat(2, min(17vw, 72px)); grid-template-areas: "place jump" "mine jump";
}
#touch .tc-btn {
  pointer-events: auto; touch-action: none; aspect-ratio: 1 / 1; border-radius: 50%; padding: 0;
  font: 600 min(7vw, 28px) / 1 system-ui, sans-serif; color: #fff;
  background: rgba(0, 0, 0, 0.38); border: 2px solid rgba(255, 255, 255, 0.55);
  z-index: 2;
}
#touch .tc-use, #touch .tc-fly, #touch .tc-down, #touch .tc-top > * {
  pointer-events: auto; touch-action: none; z-index: 2;
  background: rgba(0, 0, 0, 0.38); border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 12px; color: #fff; font-weight: 600; font-size: min(7vw, 28px); line-height: 1;
}
#touch .tc-btn.on { background: rgba(255, 255, 255, 0.35); }
#touch .tc-place { grid-area: place; } #touch .tc-mine { grid-area: mine; } #touch .tc-jump { grid-area: jump; align-self: center; }
#touch .tc-top {
  position: absolute; pointer-events: none; display: flex; gap: 10px;
  top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px));
}
#touch .tc-small { width: 48px; font-size: 20px; border-radius: 12px; z-index: 2; }
body.touch .tv-inv-panel .tv-slot { min-width: 0; }
body.touch #menus button, body.touch .tv-recipe-btn, body.touch .tv-inv-close { min-height: 44px; font-size: 17px; }

/* small screens in general (phones in portrait) */
@media (max-width: 600px) {
  .tv-title-h1 { font-size: clamp(32px, 11vw, 56px) !important; }
  .tv-controls-list { font-size: 0.85rem !important; }
}
