:root {
  --ink: #2b2b3a;
  --panel: #fffaf0;
  --accent: #ffcc33;
  --accent-dark: #d99a00;
  --grass: #4f9e2f;
  --slot: min(52px, calc((100vw - 64px) / 9));
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8fd3ff; color: var(--ink);
  font-family: var(--font);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

button {
  font: inherit; font-weight: 800; font-size: 18px; color: var(--ink);
  border: 0; border-radius: 16px; padding: 14px 20px; cursor: pointer;
  background: #ece5d6; box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
  touch-action: manipulation;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
button.primary { background: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); }
button.small { font-size: 15px; padding: 10px 14px; }
button.ghost { background: rgba(255, 255, 255, .7); }

/* ---------- Menü ---------- */
#menu {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(#5fc2ff, #b9ecff 58%, #5cae3a 58%, #4a9a2e 70%, #8a5a3a 70%, #6e4529);
  overflow: auto;
}
#menu.overlay { background: rgba(10, 20, 45, .55); }
.screen {
  background: var(--panel); border-radius: 26px; padding: 24px; width: min(620px, 100%);
  max-height: 100%; overflow: auto; text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .18), 0 20px 50px rgba(0, 0, 0, .25);
}
h1 { margin: 0; font-size: clamp(34px, 8vw, 58px); color: var(--grass); letter-spacing: -1px; text-shadow: 0 4px 0 #2f6b18; }
h1 span { color: #c9772f; text-shadow: 0 4px 0 #7a4519; }
h2 { margin: 0 0 12px; font-size: 30px; }
h3 { margin: 0 0 8px; }
.sub { margin: 6px 0 0; color: #6b6b7b; font-size: 16px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; max-width: 360px; margin: 0 auto; }

#slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.slot {
  background: #fff; border-radius: 20px; padding: 14px 10px; border: 3px solid #efe7d6;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.slot-icon { font-size: 40px; line-height: 1; }
.slot-name { font-weight: 800; font-size: 20px; }
.slot-info { font-size: 13px; color: #7b7b8b; min-height: 2.4em; }
.slot-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
@media (max-width: 560px) {
  #slots { grid-template-columns: 1fr; }
  .slot { flex-direction: row; flex-wrap: wrap; justify-content: space-between; text-align: left; }
  .slot-info { min-height: 0; flex: 1; }
}

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; font-weight: 800; font-size: 18px; flex-wrap: wrap; }
.seg { display: flex; gap: 6px; }
.seg button { font-size: 15px; padding: 10px 14px; background: #ece5d6; }
.seg button.on { background: var(--grass); color: #fff; box-shadow: 0 4px 0 #2f6b18; }

.help { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; text-align: left; margin-bottom: 8px; }
.help ul { margin: 0; padding-left: 18px; line-height: 1.6; }
@media (max-width: 560px) { .help { grid-template-columns: 1fr; } }

#lan { background: #e6f6ff; border: 3px solid #9bd6f7; border-radius: 20px; padding: 14px; margin-top: 18px; }
.lan-title { font-weight: 800; font-size: 20px; }
.lan-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
#lan-name {
  font: inherit; font-weight: 700; font-size: 18px; padding: 12px 14px; border-radius: 14px; border: 3px solid #cfe7f5;
  width: 170px; user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#lan-name.shake { animation: shake .4s; border-color: #e53935; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#lan-colors { display: flex; gap: 6px; }
.swatch { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, .2); }
.swatch.on { outline: 3px solid var(--ink); }

/* ---------- Im Spiel ---------- */
#players {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  max-width: 60vw; padding: 8px 12px; border-radius: 12px; background: rgba(0, 0, 0, .35);
  color: #fff; font-weight: 800; font-size: 15px;
}
#water-tint { position: fixed; inset: 0; background: rgba(30, 90, 200, .35); pointer-events: none; display: none; }
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hotbar, #joy { pointer-events: auto; }

#crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px rgba(0, 0, 0, .8); }
#crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
#crosshair::after { top: 10px; left: 0; height: 2px; width: 22px; }

#hotbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 5px; background: rgba(0, 0, 0, .35); border-radius: 14px;
}
.hs {
  width: var(--slot); height: var(--slot); border-radius: 10px; position: relative;
  background: rgba(255, 255, 255, .15); border: 3px solid transparent;
  display: flex; align-items: center; justify-content: center;
}
.hs.sel { border-color: #fff; background: rgba(255, 255, 255, .4); }
.hs img { width: 82%; height: 82%; image-rendering: pixelated; pointer-events: none; }
.hs span { position: absolute; top: 0; left: 3px; font-size: 11px; color: #fff; font-weight: 800; text-shadow: 0 1px 2px #000; }
body.touch .hs span { display: none; }

#toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--slot) + 36px + env(safe-area-inset-bottom));
  color: #fff; font-weight: 800; font-size: 22px; text-shadow: 0 2px 4px rgba(0, 0, 0, .7);
  opacity: 0; transition: opacity .3s; white-space: nowrap;
}
#toast.show { opacity: 1; }

#topbar { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: none; gap: 8px; }
#topbar button { width: 54px; height: 54px; padding: 0; font-size: 26px; background: rgba(255, 255, 255, .85); }

#touch { display: none; }
body.touch #touch, body.touch #topbar { display: flex; }
body.touch #crosshair { display: none; }

#joy {
  position: absolute; left: max(24px, env(safe-area-inset-left));
  bottom: calc(var(--slot) + 36px + env(safe-area-inset-bottom));
  width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255, 255, 255, .18); border: 3px solid rgba(255, 255, 255, .55); touch-action: none;
}
#knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255, 255, 255, .8); pointer-events: none; }

#actions {
  position: absolute; right: max(20px, env(safe-area-inset-right));
  bottom: calc(var(--slot) + 32px + env(safe-area-inset-bottom));
  display: grid; grid-template-areas: "fly down" "mode jump"; gap: 12px; align-items: center; justify-items: center;
}
.tb { width: 62px; height: 62px; border-radius: 50%; padding: 0; font-size: 26px; background: rgba(255, 255, 255, .82); }
.tb.big { width: 82px; height: 82px; font-size: 32px; }
#btn-fly { grid-area: fly; }
#btn-down { grid-area: down; visibility: hidden; }
body.flying #btn-down { visibility: visible; }
#btn-fly.on { background: #8fe07a; }
#btn-mode { grid-area: mode; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
#btn-mode small { font-size: 11px; margin-top: 3px; }
#btn-mode.build { background: #ffd966; }
#btn-jump { grid-area: jump; }

@media (max-height: 430px) {
  :root { --slot: min(44px, calc((100vw - 64px) / 9)); }
  #joy { width: 118px; height: 118px; }
  .tb { width: 52px; height: 52px; font-size: 22px; }
  .tb.big { width: 68px; height: 68px; font-size: 28px; }
  #topbar button { width: 46px; height: 46px; font-size: 22px; }
}

/* ---------- Block-Auswahl ---------- */
#blocks {
  position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#blocks .panel {
  background: var(--panel); border-radius: 24px; padding: 20px; width: min(760px, 100%); max-height: 100%;
  overflow: auto; text-align: center; box-shadow: 0 8px 0 rgba(0, 0, 0, .18);
}
#block-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; margin: 16px 0; }
.bk { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; font-size: 13px; background: #fff; }
.bk img { width: 48px; height: 48px; image-rendering: pixelated; }
