/* Die Oberflaeche haelt sich bewusst zurueck: Das Bild gehoert dem
   Spielfeld, alles andere sitzt als schmale Leiste am Rand. */

:root {
  --ink: #0d1117;
  --ink-soft: rgba(13, 17, 23, 0.72);
  --paper: #e9edf2;
  --lamp: #e8c37a;
  --moss: #4f7a34;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  /* dvh berücksichtigt die ein- und ausfahrende Browserleiste auf Tablets */
  height: 100dvh;
  outline: none;
  cursor: crosshair;
  touch-action: none;
}

/* --- HUD ------------------------------------------------------------- */

#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  padding: 6px 10px;
  background: var(--ink-soft);
  border-left: 3px solid var(--lamp);
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: pre;
  pointer-events: none;
}

/* --- Chat ------------------------------------------------------------ */

#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(420px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#chat-log {
  max-height: 30vh;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.5;
  scrollbar-width: thin;
}

.chat-line {
  padding: 2px 8px;
  background: var(--ink-soft);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  word-break: break-word;
}

.chat-line.system {
  color: #9fb3c8;
  font-style: italic;
}

.chat-name {
  color: var(--lamp);
}

#chat-input {
  display: none;
  padding: 8px 10px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid rgba(232, 195, 122, 0.5);
  color: var(--paper);
  font: inherit;
  font-size: 13px;
}

#chat-input.active {
  display: block;
}

#chat-input:focus {
  outline: 2px solid var(--lamp);
  outline-offset: 1px;
}

/* --- Beitritts-Overlay ----------------------------------------------- */

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #12212f, #0d1117);
}

#overlay.hidden {
  display: none;
}

.panel {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
  background: rgba(9, 13, 18, 0.9);
  border-top: 4px solid var(--moss);
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.panel p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.6;
  color: #9fb3c8;
}

.panel label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: #9fb3c8;
}

.panel input {
  width: 100%;
  padding: 10px;
  margin-bottom: 14px;
  background: #0d1117;
  border: 1px solid #2b3947;
  color: var(--paper);
  font: inherit;
}

.panel input:focus {
  outline: 2px solid var(--lamp);
  outline-offset: 1px;
}

.panel button {
  width: 100%;
  padding: 11px;
  background: var(--moss);
  border: none;
  color: #f2f5f8;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.panel button:hover {
  background: #5d8f3e;
}

.panel button:focus-visible {
  outline: 2px solid var(--lamp);
  outline-offset: 2px;
}

/* --- Touch-Steuerung -------------------------------------------------- */
/* Standardmäßig unsichtbar. body.touch schaltet sie frei, body.playing
   blendet sie erst nach dem Beitritt ein. */

#touch-controls {
  display: none;
}

body.touch.playing #touch-controls {
  display: flex;
  position: fixed;
  inset: auto 0 0 0;
  padding: 0 max(16px, env(safe-area-inset-left))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.pad {
  display: flex;
  gap: 14px;
  align-items: flex-end;
}

.pad.right {
  align-items: center;
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid rgba(232, 195, 122, 0.45);
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.55);
  color: var(--paper);
  backdrop-filter: blur(2px);
}

.tbtn svg {
  width: 34px;
  height: 34px;
  fill: currentColor;
  opacity: 0.9;
}

.tbtn.jump {
  width: 100px;
  height: 100px;
  border-color: rgba(79, 122, 52, 0.75);
  background: rgba(38, 60, 26, 0.6);
}

.tbtn.jump svg {
  width: 40px;
  height: 40px;
}

.tbtn.small {
  width: 60px;
  height: 60px;
  align-self: flex-end;
  margin-bottom: 10px;
}

.tbtn.small svg {
  width: 26px;
  height: 26px;
  fill: none;
}

/* Gedrückter Zustand: sofortige Rückmeldung, ohne Übergangsanimation. */
.tbtn.pressed {
  background: rgba(232, 195, 122, 0.3);
  border-color: var(--lamp);
}

/* Auf Touchgeräten rückt der Chat über die linke Bedientaste. */
body.touch #chat {
  bottom: 124px;
  width: min(360px, calc(100vw - 24px));
}

body.touch #chat-log {
  max-height: 22vh;
}

/* Hinweistext im Overlay je nach Eingabegerät. */
.hint-touch {
  display: none;
}

body.touch .hint-keyboard {
  display: none;
}

body.touch .hint-touch {
  display: block;
}

/* Bei niedrigen Querformat-Fenstern die Tasten etwas verkleinern. */
@media (max-height: 480px) {
  .tbtn {
    width: 68px;
    height: 68px;
  }
  .tbtn.jump {
    width: 82px;
    height: 82px;
  }
  body.touch #chat {
    bottom: 104px;
  }
}

/* Während der Chat offen ist, blockieren die Bedientasten die Tastatur. */
body.chatting #touch-controls {
  display: none;
}
