:root {
  --bg: #1b1b1b;
  --panel: #c6c6c6;
  --panel-dark: #8b8b8b;
  --slot: #8b8b8b;
  --slot-hi: #b5b5b5;
  --text: #fff;
  --accent: #5b8f3a;
  --font: 'Courier New', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
#game canvas { display: block; width: 100vw; height: 100vh; image-rendering: pixelated; }
img { image-rendering: pixelated; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); mix-blend-mode: difference; }
#crosshair::before, #crosshair::after { content: ''; position: absolute; background: #fff; }
#crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
#crosshair::after { top: 10px; left: 0; height: 2px; width: 22px; }
#bottom { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; }
#stats { width: 364px; display: flex; justify-content: space-between; }
#stats .row { display: flex; flex-direction: column; gap: 1px; }
#stats .row.right { align-items: flex-end; justify-content: flex-end; }
#hearts, #food, #air { display: flex; height: 18px; }
#hearts img, #food img, #air img { width: 18px; height: 18px; margin-right: -1px; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.4)); }
#xpbar { width: 364px; height: 6px; background: #222; border: 1px solid #000; position: relative; }
#xpfill { height: 100%; background: #7cfc00; width: 0; }
#xplevel { position: absolute; left: 50%; top: -15px; transform: translateX(-50%); color: #7cfc00; font-weight: bold; font-size: 15px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }
#hotbar { display: flex; background: rgba(0,0,0,.45); border: 2px solid #111; padding: 1px; }
#hotbar .slot { width: 40px; height: 40px; background: rgba(139,139,139,.35); border: 2px solid transparent; margin: 0; pointer-events: auto; }
#hotbar .slot.sel { border-color: #fff; outline: 2px solid #000; z-index: 1; }
#itemname { position: absolute; bottom: 106px; left: 50%; transform: translateX(-50%); font-weight: bold; text-shadow: 2px 2px 0 #3f3f3f; opacity: 0; font-size: 16px; }
#itemname.fade { animation: fadename 2.5s forwards; }
@keyframes fadename { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
#minimapbox { position: absolute; right: 10px; top: 10px; border: 3px solid #333; background: #000; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
#minimap { display: block; width: 150px; height: 150px; image-rendering: pixelated; }
#coords { font-size: 12px; text-align: center; background: rgba(0,0,0,.7); padding: 2px; }
#debug { position: absolute; left: 6px; top: 6px; margin: 0; font-size: 13px; line-height: 1.35; background: rgba(0,0,0,.45); padding: 6px 8px; white-space: pre; }
#chat { position: absolute; left: 6px; bottom: 90px; width: min(520px, 60vw); }
#chatlog { max-height: 40vh; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
#chatlog div { background: rgba(0,0,0,.45); padding: 2px 6px; font-size: 14px; transition: opacity 1s; word-wrap: break-word; }
#chatlog div.old { opacity: 0; }
#chatinput { display: none; width: 100%; background: rgba(0,0,0,.65); color: #fff; border: none; font: 15px var(--font); padding: 6px; outline: none; pointer-events: auto; }
#chat.open #chatinput { display: block; }
#chat.open #chatlog { overflow-y: auto; pointer-events: auto; }
#hurt { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 40%, rgba(255,0,0,.55)); opacity: 0; }
#hurt.on { animation: hurt .5s; }
@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }
#underwater { position: fixed; inset: 0; pointer-events: none; background: rgba(20,50,160,.25); display: none; }
#fire { position: fixed; inset: 0; pointer-events: none; display: none; background: linear-gradient(to top, rgba(255,110,0,.55), rgba(255,200,0,.15) 30%, transparent 50%); animation: flicker .2s infinite alternate; }
@keyframes flicker { from { opacity: .7; } to { opacity: 1; } }

/* ---------- Slots & Bildschirme ---------- */
.slot { position: relative; width: 40px; height: 40px; background: var(--slot); border: 2px solid; border-color: #373737 #fff #fff #373737; display: flex; align-items: center; justify-content: center; }
.slot img { width: 32px; height: 32px; pointer-events: none; }
.slot .cnt { position: absolute; right: 1px; bottom: -1px; font-size: 14px; font-weight: bold; color: #fff; text-shadow: 2px 2px 0 #3f3f3f; pointer-events: none; }
.slot .dur { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; background: #000; pointer-events: none; }
.slot .dur i { display: block; height: 100%; }
#screen .slot:hover { background: var(--slot-hi); }
.slot.big { width: 52px; height: 52px; }
#screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.55); z-index: 10; }
#screen.show { display: flex; }
.panel { background: var(--panel); color: #3f3f3f; border: 3px solid; border-color: #fff #555 #555 #fff; padding: 12px; box-shadow: 0 0 0 2px #000; max-height: 96vh; overflow: auto; }
.panel .title { font-weight: bold; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.cols { display: flex; gap: 14px; }
.grid9 { display: grid; grid-template-columns: repeat(9, 40px); gap: 0; }
.grid9.hot { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 40px); }
.grid3 { display: grid; grid-template-columns: repeat(3, 40px); }
.craftrow { display: flex; align-items: center; gap: 14px; margin: 4px 0 8px 40px; }
.arrow { font-size: 30px; color: #555; }
.sep { margin: 8px 0; display: flex; gap: 6px; }
.tab { font: bold 12px var(--font); background: #a0a0a0; border: 2px solid; border-color: #fff #555 #555 #fff; padding: 3px 8px; cursor: pointer; color: #222; }
.tab:hover { background: #b8b8ff; }
.book { width: 250px; background: #b0b0b0; border: 2px solid; border-color: #555 #fff #fff #555; padding: 6px; display: flex; flex-direction: column; }
.bookhead { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.bookgrid { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 2px; overflow-y: auto; max-height: 340px; align-content: start; flex: 1; }
.slot.rec { cursor: pointer; }
.slot.rec.dim { opacity: .35; }
.hint { font-size: 11px; margin-top: 6px; color: #444; }
.creative { display: grid; grid-template-columns: repeat(9, 40px); max-height: 240px; overflow-y: auto; margin: 6px 0; }
#csearch { width: 100%; font: 14px var(--font); padding: 4px; border: 2px solid #555; background: #eee; }
.furnace { display: flex; align-items: center; gap: 20px; margin: 8px 0 12px 80px; }
.fcol { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.flame { width: 20px; height: 22px; background: #555; display: flex; align-items: flex-end; }
.flame i { display: block; width: 100%; background: linear-gradient(#ffd23a, #ff6a00); }
.progress { width: 60px; height: 14px; background: #555; }
.progress i { display: block; height: 100%; background: #fff; }
#cursorstack { position: fixed; pointer-events: none; z-index: 30; transform: translate(-50%, -50%); }
#cursorstack img { width: 32px; height: 32px; display: block; }
#cursorstack .cnt { position: absolute; right: -4px; bottom: -4px; font-weight: bold; text-shadow: 2px 2px 0 #3f3f3f; }
#tooltip { position: fixed; display: none; z-index: 40; background: rgba(16,0,16,.94); border: 2px solid #2d0a63; color: #fff; padding: 4px 8px; font-size: 14px; pointer-events: none; max-width: 260px; }

/* ---------- Menüs ---------- */
#menu, #loading, #pause, #death, #help { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; }
#menu { background: linear-gradient(rgba(0,0,0,.35), rgba(0,0,0,.6)), repeating-linear-gradient(45deg, #5d4430 0 16px, #6b4f38 16px 32px); }
#loading { display: none; flex-direction: column; gap: 14px; background: #2a1e14; }
#pause, #death { display: none; background: rgba(0,0,0,.6); }
#death { background: rgba(120,0,0,.45); }
#help { display: none; z-index: 50; background: rgba(0,0,0,.7); }
#help.show { display: flex; }
.menubox { background: rgba(0,0,0,.6); border: 2px solid #555; padding: 24px 28px; text-align: center; max-width: 94vw; max-height: 94vh; overflow: auto; }
h1 { font-size: 64px; margin: 0; color: #ddd; text-shadow: 4px 4px 0 #3f3f3f; letter-spacing: 2px; }
h2 { margin: 0 0 14px; }
.sub { color: #ff5; margin-top: 4px; }
.small { font-size: 12px; color: #bbb; max-width: 420px; margin: 14px auto 0; }
#name { display: block; margin: 18px auto 10px; width: 260px; font: 18px var(--font); padding: 8px; background: #000; color: #fff; border: 2px solid #a0a0a0; text-align: center; }
.btn { display: block; margin: 8px auto; width: 260px; font: bold 17px var(--font); padding: 10px; background: #6f6f6f; color: #fff; border: 2px solid; border-color: #aaa #333 #333 #aaa; cursor: pointer; text-shadow: 2px 2px 0 #333; }
.btn:hover { background: #7c86c9; }
.btn.secondary { background: #555; font-size: 14px; }
.settings { display: grid; gap: 10px; margin: 16px 0; text-align: left; width: 320px; }
.settings label { display: flex; flex-direction: column; font-size: 14px; }
.settings label span { float: right; color: #ff5; }
.settings input[type=range] { width: 100%; }
.checks { display: flex; gap: 12px; flex-wrap: wrap; }
.checks label { flex-direction: row; gap: 4px; align-items: center; }
#help table { text-align: left; border-collapse: collapse; font-size: 14px; }
#help td { padding: 3px 10px; border-bottom: 1px solid #333; }
#help td:first-child { color: #ff5; white-space: nowrap; }
.spinner { width: 48px; height: 48px; background: #68aa3e; animation: spin 1s infinite steps(4); box-shadow: inset 0 -30px 0 #866043; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Touch ---------- */
#touch { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#touch button { pointer-events: auto; background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.5); color: #fff; font-size: 22px; border-radius: 10px; }
#touch button.on { background: rgba(255,255,100,.45); }
#joy { position: absolute; left: 24px; bottom: 90px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.15); border: 2px solid rgba(255,255,255,.4); pointer-events: auto; }
#joyknob { position: absolute; left: 40px; top: 40px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.5); }
#tbtns { position: absolute; right: 18px; bottom: 90px; display: grid; grid-template-columns: 64px 64px; gap: 10px; }
#tbtns button { width: 64px; height: 64px; }
#tjump { grid-column: 1 / span 2; width: 100% !important; }
#ttop { position: absolute; right: 180px; top: 10px; display: flex; gap: 8px; }
#ttop button { width: 46px; height: 46px; font-size: 18px; }

@media (max-width: 700px) {
  #stats, #xpbar { width: 300px; }
  #hotbar .slot { width: 34px; height: 34px; }
  .slot img { width: 26px; height: 26px; }
  #minimapbox { transform: scale(.7); transform-origin: top right; }
  .grid9, .creative { grid-template-columns: repeat(9, 34px); }
  .grid9 .slot, .creative .slot { width: 34px; height: 34px; }
  .cols { flex-direction: column; }
  .book { width: 100%; }
  h1 { font-size: 40px; }
}
