@font-face {
  font-family: 'Monocraft';
  src: url('../assets/Monocraft.ttf') format('truetype');
}
@font-face {
  font-family: 'Monocraft';
  src: url('../assets/Monocraft-Bold.ttf') format('truetype');
  font-weight: bold;
}

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

:root {
  --slot-bg: #8b8b8b;
  --slot-dark: #373737;
  --slot-light: #ffffff;
  --panel-bg: #c6c6c6;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Monocraft', 'Courier New', monospace;
  image-rendering: pixelated;
}

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

canvas { image-rendering: pixelated; }

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

#crosshair {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 22px;
  mix-blend-mode: difference;
}
.ch-v { position: absolute; left: 50%; top: 0; width: 2px; height: 100%; background: #ddd; transform: translateX(-50%); }
.ch-h { position: absolute; top: 50%; left: 0; height: 2px; width: 100%; background: #ddd; transform: translateY(-50%); }

#hud-bottom {
  position: absolute; bottom: 6px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  gap: 3px;
}

#item-name {
  color: #fff; font-size: 15px;
  text-shadow: 2px 2px 0 #3f3f3f;
  opacity: 0; transition: opacity 0.4s;
  height: 20px;
  margin-bottom: 2px;
}

#stats-row {
  width: 100%;
  display: flex; justify-content: space-between;
  padding: 0 2px;
}
.stat-bar { display: flex; gap: 0px; }
.stat-bar canvas { width: 21px; height: 21px; }
#food { flex-direction: row; }
#bubbles-row { width: 100%; display: flex; justify-content: flex-end; height: 21px; }
#bubbles { visibility: hidden; }

#xp-bar {
  width: 100%; height: 7px;
  background: #14140f;
  border: 1px solid #000;
  box-shadow: 0 0 0 1px #55554d inset;
}
#xp-fill { height: 100%; width: 0%; background: linear-gradient(#a8e84c, #7ac41a); }

#hotbar {
  display: flex;
  background: rgba(20, 20, 20, 0.55);
  border: 2px solid #1a1a1a;
  outline: 2px solid rgba(120,120,120,0.7);
  padding: 0;
}
.hb-slot {
  width: 54px; height: 54px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(60,60,60,0.8);
}
.hb-slot canvas { width: 44px; height: 44px; }
.hb-slot.selected {
  outline: 3px solid #fff;
  outline-offset: -1px;
  z-index: 2;
  background: rgba(255,255,255,0.12);
}
.slot-count {
  position: absolute; right: 3px; bottom: 1px;
  color: #fff; font-size: 15px; font-weight: bold;
  text-shadow: 2px 2px 0 #3f3f3f;
  pointer-events: none;
}
.dur-bar {
  display: none;
  position: absolute; bottom: 4px; left: 6px; right: 6px;
  height: 3px; background: #222;
}
.dur-fill { height: 100%; background: #4caf3f; }

#debug-overlay {
  position: absolute; top: 8px; left: 8px;
  color: #fff; font-size: 13px; line-height: 1.5;
  text-shadow: 1px 1px 0 #333;
  background: rgba(16,16,16,0.35);
  padding: 6px 10px;
  display: none;
  white-space: pre;
}

#toast {
  position: absolute; top: 20%; left: 50%;
  transform: translateX(-50%);
  color: #ffef8e; font-size: 17px;
  text-shadow: 2px 2px 0 #3f3f3f;
  opacity: 0; transition: opacity 0.5s;
  pointer-events: none;
}

#hint-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  text-align: center;
  color: #cfcfcf; font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 4px;
  z-index: 11;
  display: none;
  pointer-events: none;
}
#hint-bar b { color: #ffe97d; }

/* ============ Overlays ============ */
#hurt-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 9;
  background: radial-gradient(ellipse at center, rgba(255,0,0,0) 40%, rgba(200,0,0,0.55) 100%);
  opacity: 0; transition: opacity 0.12s;
}
#water-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 8;
  background: rgba(20, 60, 160, 0.32);
  backdrop-filter: blur(1px);
  display: none;
}
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 7;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 62%, rgba(0,0,0,0.34) 100%);
  display: none;
}

/* ============ Layers & Panels ============ */
.modal-layer {
  position: fixed; inset: 0;
  z-index: 20;
  display: none;
  align-items: center; justify-content: center;
}
.modal-layer.dim { background: rgba(0,0,0,0.6); }
.modal-layer.red { background: rgba(120,0,0,0.55); }

.mc-panel {
  background: var(--panel-bg);
  border: 3px solid;
  border-color: #ffffff #555555 #555555 #ffffff;
  box-shadow: 0 0 0 3px #000, 8px 10px 0 rgba(0,0,0,0.4);
  padding: 16px 20px;
  color: #3f3f3f;
}
.panel-title { font-size: 16px; margin-bottom: 10px; color: #3f3f3f; }
.panel-subtitle { font-size: 14px; margin: 10px 0 6px; color: #3f3f3f; }

#inv-grid {
  display: grid;
  grid-template-columns: repeat(9, 52px);
  grid-auto-rows: 52px;
}
#inv-hotbar {
  display: grid;
  grid-template-columns: repeat(9, 52px);
  grid-auto-rows: 52px;
  margin-top: 10px;
}
.slot {
  width: 52px; height: 52px;
  background: var(--slot-bg);
  border: 2px solid;
  border-color: var(--slot-dark) var(--slot-light) var(--slot-light) var(--slot-dark);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.slot:hover { background: #9d9d9d; }
.slot canvas { width: 40px; height: 40px; pointer-events: none; }

.craft-row { display: flex; align-items: center; gap: 14px; margin: 6px 0 4px; }
#craft-grid { display: grid; grid-template-columns: repeat(2, 52px); grid-auto-rows: 52px; }
.craft-arrow { font-size: 26px; color: #7a7a7a; }
.craft-out-slot .slot { width: 58px; height: 58px; }

#furnace-area { display: none; }
.furnace-row { display: flex; align-items: center; gap: 18px; margin: 8px 0; }
.furnace-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#furnace-flame-cv { display: none; }
.furnace-gauge {
  width: 30px; height: 30px;
  position: relative;
  background: #777;
  border: 2px solid #4a4a4a;
  --fill: 0%;
}
.furnace-gauge::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0;
  height: var(--fill);
  background: linear-gradient(#ffd94a, #ff7b1c);
  opacity: 0.35;
}
.furnace-gauge.lit::after { opacity: 1; }
.furnace-gauge-arrow {
  width: 60px; height: 18px;
  background: #7a7a7a;
  position: relative;
  border: 2px solid #4a4a4a;
  --fill: 0%;
  clip-path: polygon(0 30%, 62% 30%, 62% 0, 100% 50%, 62% 100%, 62% 70%, 0 70%);
}
.furnace-gauge-arrow::after {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: var(--fill);
  background: #fff;
}

#cursor-item {
  position: fixed; z-index: 40;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
}
#cursor-item canvas { width: 44px; height: 44px; }
#cursor-item span {
  position: absolute; right: -2px; bottom: -4px;
  color: #fff; font-size: 15px; font-weight: bold;
  text-shadow: 2px 2px 0 #3f3f3f;
}

#tooltip {
  position: fixed; z-index: 41;
  display: none;
  pointer-events: none;
  background: rgba(16, 0, 16, 0.94);
  border: 2px solid #2a0a56;
  outline: 1px solid #100010;
  padding: 6px 10px;
}
.tt-name { color: #fff; font-size: 14px; }
.tt-sub { color: #8a8a8a; font-size: 11px; margin-top: 2px; }

/* ============ Menus ============ */
.modal-layer.full { z-index: 30; }

#title-screen { flex-direction: column; }
#title-panorama {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, #79aef5 0%, #9dc7f7 35%, #cfe6ff 60%, #74a447 60.5%, #4f7a2e 100%);
  filter: saturate(1.05);
}
#title-panorama::after {
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(120px 40px at 20% 20%, rgba(255,255,255,0.85), rgba(255,255,255,0) 70%),
    radial-gradient(160px 50px at 65% 12%, rgba(255,255,255,0.8), rgba(255,255,255,0) 70%),
    radial-gradient(140px 45px at 85% 30%, rgba(255,255,255,0.75), rgba(255,255,255,0) 70%);
}
#title-content {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  padding-top: 8vh;
  width: 100%; height: 100%;
}
#game-logo {
  font-size: 74px; font-weight: bold;
  letter-spacing: 4px;
  color: #d8d8d8;
  text-shadow:
    4px 4px 0 #3d3d3d,
    8px 8px 0 rgba(0,0,0,0.25);
  -webkit-text-stroke: 2px #1f1f1f;
  transform: perspective(400px) rotateX(8deg);
}
#game-sub {
  color: #ffffff; font-size: 18px;
  text-shadow: 2px 2px 0 #3f3f3f;
  margin-bottom: 10px;
}
#splash-text {
  color: #ffff00; font-size: 17px;
  text-shadow: 2px 2px 0 #3f3f00;
  transform: rotate(-12deg) translate(150px, -70px);
  animation: splash 0.9s ease-in-out infinite alternate;
}
@keyframes splash {
  from { transform: rotate(-12deg) translate(150px, -70px) scale(1); }
  to { transform: rotate(-12deg) translate(150px, -70px) scale(1.08); }
}

.menu-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; align-items: center; }
.menu-stack.wide { min-width: 460px; }

.mc-btn {
  width: 340px;
  padding: 11px 0 9px;
  font-family: 'Monocraft', monospace;
  font-size: 16px;
  color: #e0e0e0;
  text-shadow: 2px 2px 0 #38383f;
  background: linear-gradient(#8c8c8c, #6f6f6f 45%, #5d5d5d);
  border: 2px solid #000;
  box-shadow:
    inset 2px 2px 0 rgba(255,255,255,0.45),
    inset -2px -2px 0 rgba(0,0,0,0.45);
  cursor: pointer;
}
.mc-btn:hover {
  background: linear-gradient(#a1b3e0, #7f92c4 45%, #6b7eb0);
  color: #ffffa0;
}
.mc-btn:active {
  box-shadow:
    inset -2px -2px 0 rgba(255,255,255,0.35),
    inset 2px 2px 0 rgba(0,0,0,0.45);
}
.mc-btn:disabled { opacity: 0.45; cursor: default; }

#title-footer {
  position: absolute; bottom: 8px; left: 0; right: 0;
  display: flex; justify-content: space-between;
  padding: 0 12px;
  color: #fff; font-size: 12px;
  text-shadow: 1px 1px 0 #333;
}

.menu-center {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.menu-title {
  color: #fff; font-size: 24px;
  text-shadow: 2px 2px 0 #3f3f3f;
}
.menu-title.big { font-size: 52px; color: #fff; }
.death-sub { color: #eee; font-size: 16px; text-shadow: 2px 2px 0 #5f1f1f; }

.opt-row {
  display: flex; align-items: center; gap: 12px;
  color: #fff; font-size: 15px;
  text-shadow: 2px 2px 0 #3f3f3f;
  width: 100%;
}
.opt-row > span:first-child { width: 130px; text-align: right; }
.opt-val { width: 80px; }
.opt-row input[type=range] {
  flex: 1;
  appearance: none;
  height: 12px;
  background: #000;
  border: 2px solid #a0a0a0;
  cursor: pointer;
}
.opt-row input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 22px;
  background: linear-gradient(#9c9c9c, #6f6f6f);
  border: 2px solid #000;
  box-shadow: inset 1px 1px 0 rgba(255,255,255,0.5);
}

#load-bar {
  width: 420px; height: 22px;
  border: 2px solid #fff;
  background: #222;
  padding: 3px;
}
#load-fill { height: 100%; width: 0%; background: #52a535; transition: width 0.2s; }
#load-tip { color: #bbb; font-size: 13px; text-shadow: 1px 1px 0 #333; }

#inv-screen { z-index: 25; }
