/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

:root {
  --panel: rgba(16, 16, 20, 0.86);
  --panel-light: rgba(38, 38, 44, 0.92);
  --border-light: #9a9a9a;
  --border-dark: #24242a;
  --slot: rgba(139, 139, 139, 0.55);
  --text: #e8e8e8;
  --text-dim: #a8a8a8;
  --accent: #6aa84f;
  --ui-font: "Segoe UI", "Trebuchet MS", "DejaVu Sans", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0d14;
  color: var(--text);
  font-family: var(--ui-font);
  user-select: none;
  -webkit-user-select: none;
}

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

.hidden { display: none !important; }

/* Block icons should stay crisp. */
.slot-icon, .inv-icon {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── HUD ──────────────────────────────────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud.hud-hidden > *:not(.screen-overlay) { display: none; }

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  mix-blend-mode: difference;
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: #fff;
}
.crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; margin-left: -1px; }
.crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; margin-top: -1px; }

/* Screen tints */
.screen-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  opacity: 0;
}
.water-overlay { background: linear-gradient(rgba(24, 84, 150, 0.45), rgba(12, 48, 96, 0.62)); }
.lava-overlay  { background: linear-gradient(rgba(190, 70, 10, 0.78), rgba(120, 30, 4, 0.88)); }
.damage-overlay { background: radial-gradient(ellipse at center, rgba(160,0,0,0) 35%, rgba(150,0,0,0.85) 100%); transition: opacity 0.1s linear; }
.vignette {
  opacity: 1;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.34) 100%);
}

/* Hotbar */
.hotbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  padding: 3px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(0, 0, 0, 0.6);
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.09) inset;
}
.slot {
  position: relative;
  width: 52px;
  height: 52px;
  margin: 0 1px;
  background: rgba(139, 139, 139, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.10);
  border-radius: 2px;
}
.slot-icon {
  position: absolute;
  inset: 4px;
  background-repeat: no-repeat;
  filter: drop-shadow(1px 2px 1px rgba(0,0,0,0.45));
}
.slot-count {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font: 700 13px/1 var(--mono);
  color: #fff;
  text-shadow: 1.5px 1.5px 0 #3a3a3a;
}
.hotbar-selector {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 54px;
  height: 54px;
  border: 3px solid #f0f0f0;
  border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.55);
  transition: transform 0.07s ease-out;
  pointer-events: none;
}

/* Vitals */
.vitals {
  position: absolute;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 502px;
}
.bar-row { display: flex; gap: 1px; }
.breath-row { justify-content: flex-end; }

.heart, .bubble {
  width: 18px;
  height: 18px;
  background-size: contain;
  background-repeat: no-repeat;
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.6));
}
.heart {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9'%3E%3Cpath d='M1 1h2v1h1V1h2v1h1v3h-1v1H6v1H5v1H4V7H3V6H2V5H1z' fill='%23000' opacity='.45'/%3E%3C/svg%3E");
}
.heart.full {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9'%3E%3Cpath d='M1 1h2v1h1V1h2v1h1v3h-1v1H6v1H5v1H4V7H3V6H2V5H1z' fill='%23e02020'/%3E%3Cpath d='M2 2h1v1H2z' fill='%23ff8a8a'/%3E%3C/svg%3E");
}
.heart.half {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9'%3E%3Cpath d='M1 1h2v1h1V1h2v1h1v3h-1v1H6v1H5v1H4V7H3V6H2V5H1z' fill='%23000' opacity='.45'/%3E%3Cpath d='M1 1h2v1h1v6H4V7H3V6H2V5H1z' fill='%23e02020'/%3E%3C/svg%3E");
}
.bubble { opacity: 0; }
.bubble.full {
  opacity: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9'%3E%3Ccircle cx='4.5' cy='4.5' r='3.5' fill='%23dff0ff' stroke='%23204a78' stroke-width='1'/%3E%3Ccircle cx='3.2' cy='3.2' r='.9' fill='%23fff'/%3E%3C/svg%3E");
}

/* Item name toast */
.item-name {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  font-size: 17px;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.7);
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}

/* Flight indicator */
.status-badge {
  position: absolute;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  padding: 4px 12px;
  font: 700 12px/1 var(--ui-font);
  letter-spacing: 2px;
  color: #dff0ff;
  background: rgba(20, 46, 78, 0.62);
  border: 2px solid rgba(140, 200, 255, 0.5);
  border-radius: 3px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.7);
  animation: badge-pulse 2.4s ease-in-out infinite;
}
.status-badge::before { content: "\2708  "; }

@keyframes badge-pulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

/* Debug */
.debug {
  position: absolute;
  left: 8px;
  top: 8px;
  font: 12px/1.45 var(--mono);
  color: #f4f4f4;
  text-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.85);
  background: rgba(0, 0, 0, 0.32);
  padding: 5px 8px;
  border-radius: 3px;
  max-width: 46ch;
}

/* Log */
.log {
  position: absolute;
  left: 10px;
  bottom: 90px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 44ch;
}
.log-line {
  font: 13px/1.4 var(--ui-font);
  color: #fff;
  background: rgba(0,0,0,0.42);
  padding: 3px 8px;
  border-radius: 3px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.8);
  transition: opacity 1.1s ease;
}
.log-line.fade { opacity: 0; }

/* Death */
.death-screen {
  position: absolute;
  inset: 0;
  background: rgba(120, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  pointer-events: auto;
}
.death-title {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.6);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  font: 600 16px/1 var(--ui-font);
  color: #eaeaea;
  background: linear-gradient(#7d7d7d, #5d5d5d);
  border: 2px solid #2c2c2c;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.28), inset 0 -2px 0 rgba(0,0,0,0.35);
  padding: 12px 22px;
  border-radius: 3px;
  cursor: pointer;
  min-width: 220px;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.22); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#63a04a, #477a34); }
.btn.small { min-width: 64px; padding: 6px 12px; font-size: 13px; }
.btn.small.on { background: linear-gradient(#63a04a, #477a34); }

/* ── Menu ─────────────────────────────────────────────────────────────────── */
.menu {
  position: fixed;
  inset: 0;
  z-index: 40;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(70, 120, 190, 0.35), rgba(0,0,0,0) 60%),
    linear-gradient(160deg, #1b2438, #0b0f18 70%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 30px;
  max-height: 100vh;
  overflow-y: auto;
}
.game-title { text-align: center; }
.title-main {
  display: block;
  font-size: clamp(38px, 8vw, 78px);
  font-weight: 900;
  letter-spacing: 6px;
  color: #f2f2f2;
  text-shadow: 0 4px 0 #3a5a2a, 0 8px 22px rgba(0,0,0,0.7);
}
.title-sub {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
}

.menu-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(460px, 90vw);
}
.menu-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.4px;
}
.menu-form input[type="text"] {
  font: 15px var(--ui-font);
  padding: 10px 12px;
  color: #fff;
  background: rgba(0,0,0,0.55);
  border: 2px solid #555;
  border-radius: 3px;
  outline: none;
}
.menu-form input[type="text"]:focus { border-color: var(--accent); }
.dim { color: #6d6d6d; }

.mode-row { display: flex; gap: 10px; }
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px;
  background: rgba(0,0,0,0.42);
  border: 2px solid #4a4a4a;
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.mode-btn strong { font-size: 16px; color: #ddd; }
.mode-btn span { font-size: 12px; }
.mode-btn.active { border-color: var(--accent); background: rgba(70, 130, 60, 0.28); }
.mode-btn.active strong { color: #fff; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.menu-footer {
  font-size: 12px;
  color: #7c7c7c;
  text-align: center;
  line-height: 1.8;
  max-width: 620px;
}
.pause-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px 26px;
  width: min(760px, 92vw);
}
.setting { display: flex; flex-direction: column; gap: 6px; }
.setting label { font-size: 13px; color: var(--text-dim); }
.setting b { color: #fff; }
.setting.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.setting input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Loading ──────────────────────────────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #16202f, #080b12);
}
.load-box { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.load-title {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 6px;
  color: #efefef;
  text-shadow: 0 3px 0 #3a5a2a;
}
.load-bar {
  width: min(420px, 80vw);
  height: 14px;
  background: rgba(0,0,0,0.6);
  border: 2px solid #555;
  border-radius: 2px;
  overflow: hidden;
}
.load-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4c8c3a, #7cc45c);
  transition: width 0.2s ease;
}
.load-text { font-size: 13px; color: var(--text-dim); }
.load-error { max-width: 80vw; color: #ff9a9a; font-family: var(--mono); }
.load-error pre { white-space: pre-wrap; font-size: 12px; color: #ffbdbd; }

/* ── Inventory ────────────────────────────────────────────────────────────── */
.inventory-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-panel {
  background: var(--panel);
  border: 3px solid #0e0e12;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.10), 0 12px 44px rgba(0,0,0,0.6);
  border-radius: 4px;
  padding: 16px 18px;
  width: min(720px, 94vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.inv-title { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.inv-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.inv-tab {
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-dim);
  background: rgba(0,0,0,0.4);
  border: 2px solid #3a3a40;
  border-bottom: none;
  border-radius: 3px 3px 0 0;
  cursor: pointer;
}
.inv-tab.active { color: #fff; background: rgba(90, 130, 80, 0.35); border-color: var(--accent); }

.inv-search {
  font: 14px var(--ui-font);
  padding: 8px 10px;
  color: #fff;
  background: rgba(0,0,0,0.55);
  border: 2px solid #4a4a50;
  border-radius: 3px;
  outline: none;
}
.inv-search:focus { border-color: var(--accent); }

.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 3px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 4px;
  background: rgba(0,0,0,0.28);
  border-radius: 3px;
}
.inv-main {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
}
.inv-hotbar {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  padding-top: 8px;
  border-top: 2px solid rgba(255,255,255,0.10);
}
.inv-craft { display: flex; align-items: center; gap: 14px; }
.craft-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.craft-arrow { font-size: 24px; color: var(--text-dim); }

.inv-slot {
  position: relative;
  aspect-ratio: 1;
  min-height: 44px;
  background: var(--slot);
  border: 2px solid rgba(255,255,255,0.08);
  box-shadow: inset 1px 1px 0 rgba(0,0,0,0.4);
  border-radius: 2px;
  cursor: pointer;
}
.inv-slot:hover { background: rgba(190, 190, 190, 0.7); }
.inv-slot.result { background: rgba(120, 160, 110, 0.55); }
.inv-icon {
  position: absolute;
  inset: 3px;
  background-repeat: no-repeat;
  pointer-events: none;
  filter: drop-shadow(1px 2px 1px rgba(0,0,0,0.4));
}
.inv-count {
  position: absolute;
  right: 2px;
  bottom: 0;
  font: 700 12px/1 var(--mono);
  color: #fff;
  text-shadow: 1.5px 1.5px 0 #333;
  pointer-events: none;
}
.inv-hint { font-size: 12px; color: #8a8a8a; }

.inv-cursor {
  position: fixed;
  width: 44px;
  height: 44px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
  z-index: 50;
}

.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #ddd;
  background: #10141c;
}

@media (max-width: 620px) {
  .slot { width: 40px; height: 40px; }
  .hotbar-selector { width: 42px; height: 42px; }
  .vitals { width: 390px; }
}
