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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, sans-serif;
  user-select: none;
}

.hidden { display: none !important; }

#game { position: fixed; inset: 0; display: block; }

/* Fadenkreuz */
#crosshair {
  position: fixed;
  left: 50%; top: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
  content: '';
  position: absolute;
  background: #fff;
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

/* Ess-Fortschritt */
#eatbar-wrap {
  position: fixed;
  left: 50%; top: calc(50% + 26px);
  transform: translateX(-50%);
  width: 90px; height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 3px;
  pointer-events: none;
}
#eatbar {
  height: 100%;
  width: 0%;
  background: #c8963c;
  border-radius: 2px;
}

/* HUD unten */
#hud {
  position: fixed;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}
#status-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}
/* Herzen + Hunger sauber auf einer Zeile ausgerichtet */
#bars-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}
.status-row {
  display: flex;
  gap: 1px;
  font-size: 16px;
  line-height: 18px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}
.status-row span { width: 18px; text-align: center; }

#hotbar {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px;
  border-radius: 6px;
  pointer-events: none;
}
.slot {
  width: 52px; height: 52px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  position: relative;
  background: rgba(0, 0, 0, 0.25);
}
.slot.selected { border-color: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, 0.6); }
.slot canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.slot .num {
  position: absolute;
  top: 1px; left: 4px;
  font-size: 10px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.slot .cnt {
  position: absolute;
  bottom: 1px; right: 4px;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
/* Haltbarkeitsbalken */
.slot .dur, .islot .dur {
  position: absolute;
  bottom: 3px; left: 10%;
  height: 3px;
  border-radius: 1px;
  pointer-events: none;
}

/* Debug (F3) */
#debug {
  position: fixed;
  top: 8px; left: 8px;
  color: #fff;
  font: 12px/1.5 Consolas, monospace;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.7);
  white-space: pre;
  pointer-events: none;
}

/* Overlays */
#water-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 60, 140, 0.35);
  display: none;
  pointer-events: none;
}
body.underwater #water-overlay { display: block; }

#damage-overlay {
  position: fixed; inset: 0;
  background: rgba(200, 20, 20, 0.35);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
body.hurt #damage-overlay { opacity: 1; transition: opacity 0.05s; }

/* Menüs */
#overlay {
  position: fixed; inset: 0;
  background: rgba(10, 20, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#overlay.hidden { display: none; }
.menu {
  text-align: center;
  color: #fff;
  min-width: 340px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 10px;
}
.menu h1 { font-size: 52px; letter-spacing: 2px; text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5); }
.menu h2 { font-size: 30px; margin-bottom: 16px; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5); }
.menu h4 { margin: 14px 0 6px; color: #cfe3f5; }
.menu .sub { color: #cfe3f5; margin: 4px 0 18px; text-shadow: 1px 1px 0 rgba(0,0,0,0.6); }
.death-title { color: #ff5a5a; }

.mbtn {
  display: block;
  width: 280px;
  margin: 8px auto;
  font-size: 18px;
  padding: 11px 0;
  cursor: pointer;
  background: #57a64e;
  color: #fff;
  border: 2px solid #2d5c28;
  border-radius: 4px;
}
.mbtn:hover { background: #4c9344; }
.mbtn.secondary { background: #5a6a78; border-color: #38444e; }
.mbtn.secondary:hover { background: #4d5b68; }
.mbtn.danger { background: #a64e4e; border-color: #5c2828; }
.mbtn.danger-big { background: #a64e4e; border-color: #5c2828; }
.mbtn.danger-big:hover { background: #8f3e3e; }
.mbtn.slot-btn { width: auto; padding: 6px 12px; margin: 0; font-size: 14px; display: inline-block; }

/* Save-Slots */
.slot-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 430px;
  margin: 8px auto;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  text-align: left;
}
.slot-card .info { flex: 1; min-width: 0; }
.slot-card .info .t { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-card .info .d { font-size: 12px; color: #9fc3dd; }
.slot-btns { display: flex; gap: 6px; flex-shrink: 0; }

/* Welterstellung */
.form-row {
  width: 300px;
  margin: 10px auto;
  text-align: left;
}
.form-row label { display: block; font-size: 13px; color: #cfe3f5; margin-bottom: 4px; }
.form-row input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 15px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #5a6a78;
  border-radius: 4px;
  color: #fff;
}
.check-row label { display: flex; align-items: center; gap: 8px; font-size: 15px; color: #fff; cursor: pointer; }
.check-row input { width: 18px; height: 18px; }

/* Einstellungen */
#settings-body { width: 380px; margin: 0 auto; text-align: left; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.set-row label { font-size: 14px; color: #e8f2fa; }
.set-row input[type="range"] { width: 150px; }
.set-row select {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 1px solid #5a6a78;
  border-radius: 4px;
  padding: 4px 8px;
}
.set-control { display: flex; align-items: center; gap: 8px; }
.set-val { font-size: 12px; color: #9fc3dd; width: 70px; }
.key-btn {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 1px solid #5a6a78;
  border-radius: 4px;
  padding: 5px 12px;
  min-width: 110px;
  cursor: pointer;
  font-size: 13px;
}
.key-btn:hover { border-color: #9fb8cc; }

#controls-help { margin-top: 18px; }
#controls-help p { margin: 4px; color: #cfe3f5; font-size: 13px; }

/* Inventar */
#inv-screen {
  position: fixed; inset: 0;
  background: rgba(10, 15, 22, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
}
#inv-panel {
  background: #2b2f36;
  border: 2px solid #555c66;
  border-radius: 8px;
  padding: 14px 18px;
  color: #fff;
  max-height: 92vh;
  overflow-y: auto;
}
#inv-panel h3 { margin-bottom: 10px; font-size: 16px; color: #cfe3f5; }
#craft-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.craft-grid { display: grid; gap: 3px; }
.craft-grid.g2 { grid-template-columns: repeat(2, 44px); }
.craft-grid.g3 { grid-template-columns: repeat(3, 44px); }
.craft-arrow { font-size: 26px; color: #cfe3f5; }
.inv-grid {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 3px;
}
.inv-grid.hotrow { margin-top: 10px; }
.inv-grid.chest-grid { margin-bottom: 14px; }
.islot {
  width: 44px; height: 44px;
  background: #1d2127;
  border: 1px solid #4a525c;
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}
.islot:hover { border-color: #9fb8cc; }
.islot.result { width: 52px; height: 52px; border-color: #7a9c58; }
.islot canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.islot .cnt, #cursor-item .cnt {
  position: absolute;
  bottom: 0; right: 3px;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
#cursor-item {
  position: fixed;
  width: 40px; height: 40px;
  pointer-events: none;
  z-index: 20;
}
#cursor-item canvas { width: 100%; height: 100%; image-rendering: pixelated; }

/* Rüstungs-Slots */
.armor-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-right: 14px;
}
.islot.armor { border-color: #6a7a8a; background: #232a32; }

/* Rezeptbuch */
.book-btn {
  margin-left: 8px;
  background: #3a4250;
  border: 1px solid #5a6a78;
  border-radius: 4px;
  color: #fff;
  font-size: 16px;
  padding: 8px 10px;
  cursor: pointer;
}
.book-btn:hover { border-color: #9fb8cc; }
#recipe-book {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 3px;
  margin-bottom: 14px;
  max-height: 150px;
  overflow-y: auto;
  padding: 6px;
  background: #232830;
  border: 1px solid #4a525c;
  border-radius: 4px;
}
.islot.recipe.craftable { border-color: #7a9c58; box-shadow: inset 0 0 6px rgba(122, 216, 56, 0.25); }
.islot.recipe.known { opacity: 0.55; }
.islot.recipe.needs-table { opacity: 0.3; }

/* Kreativ-Katalog */
#creative-list {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 3px;
  margin-bottom: 10px;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  background: #232830;
  border: 1px solid #4a525c;
  border-radius: 4px;
}
.creative-hint { font-size: 11px; color: #9fc3dd; margin-bottom: 10px; }

/* Ofen */
#furnace-area {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}
.furnace-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.furnace-flame { font-size: 18px; opacity: 0.15; filter: grayscale(1); }
.furnace-flame.lit { filter: none; }
.furnace-progress {
  width: 90px; height: 10px;
  background: #1d2127;
  border: 1px solid #4a525c;
  border-radius: 3px;
  overflow: hidden;
}
.furnace-progress div { height: 100%; background: #e0e0e0; }

/* Handel */
#trade-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}
.trade-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #232830;
  border: 1px solid #4a525c;
  border-radius: 4px;
  padding: 5px 8px;
}
.trade-row .islot { cursor: default; }
.trade-row .islot:hover { border-color: #4a525c; }
.trade-btn {
  margin-left: auto;
  padding: 8px 14px;
  background: #57a64e;
  color: #fff;
  border: 1px solid #2d5c28;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.trade-btn:hover:not(:disabled) { background: #4c9344; }
.trade-btn:disabled { background: #4a525c; border-color: #38404a; opacity: 0.6; cursor: not-allowed; }

/* Boss-Bar */
#bossbar {
  position: fixed;
  top: 18px; left: 50%;
  transform: translateX(-50%);
  width: min(560px, 70vw);
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
#bossbar .bb-name {
  color: #e8c2ff;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
  margin-bottom: 4px;
}
#bossbar .bb-track {
  height: 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  overflow: hidden;
}
#bossbar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(#c95ce8, #8a2bb5);
  transition: width 0.2s;
}

/* Toast */
#toast {
  position: fixed;
  top: 64px; left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 20, 30, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  padding: 8px 18px;
  pointer-events: none;
  z-index: 15;
  text-shadow: 1px 1px 0 #000;
}

/* Multiplayer-Chat */
#chat-log {
  position: fixed;
  left: 10px;
  bottom: 110px;
  width: min(46vw, 520px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
  z-index: 14;
  font-size: 14px;
}
#chat-log .chat-line {
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 2px 8px;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #000;
  word-break: break-word;
  animation: chatIn 0.12s ease-out;
}
#chat-log .chat-line.system { color: #ffd75e; font-style: italic; }
#chat-log .chat-line.fading { opacity: 0; transition: opacity 1s; }
#chat-log .chat-line .chat-name { color: #8fd3ff; font-weight: bold; }
@keyframes chatIn { from { transform: translateX(-8px); opacity: 0; } }
#chat-input-row {
  position: fixed;
  left: 10px;
  bottom: 84px;
  width: min(46vw, 520px);
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  color: #fff;
  font-size: 14px;
  padding: 4px 8px;
  z-index: 15;
  text-shadow: 1px 1px 0 #000;
  word-break: break-word;
}
#chat-caret { animation: caretBlink 1s steps(1) infinite; }
@keyframes caretBlink { 50% { opacity: 0; } }
