/* Grundlayout: kein Zoomen, kein Scrollen, keine Textmarkierung */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #1c2a20 0%, #08100b 100%);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Spielfläche: Canvas füllt das Fenster, Pixel bleiben scharf */
#game-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  border-radius: 6px;
  box-shadow: 0 0 0 3px #0a120d, 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* Hinweis im Hochformat */
#rotate-hint {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1c2a20 0%, #08100b 100%);
  color: #f2e6c4;
  font-size: 6vmin;
  font-family: "Trebuchet MS", -apple-system, sans-serif;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 2em;
  z-index: 100;
}

/* Hinweis nur auf Touch-Geräten im Hochformat; die Klasse 'touch'
   setzt JavaScript nur auf Touch-Geräten (siehe js/input.js) */
@media (orientation: portrait) {
  body.touch #rotate-hint {
    display: flex;
  }
}

/* Touch-Steuerung: nur auf Touch-Geräten sichtbar (JS setzt hidden zurück) */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#touch-controls button {
  pointer-events: auto;
  position: absolute;
  border: none;
  font-family: "Trebuchet MS", -apple-system, sans-serif;
  font-weight: bold;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease;
}

/* Steuerkreuz links unten, Safe-Area beachten.
   Das ganze Feld nimmt Berührungen an (auch die Ecken = schräg laufen). */
#dpad {
  pointer-events: auto;
  position: absolute;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 192px;
  height: 192px;
}

/* runde Glas-Grundfläche hinter dem Kreuz */
#dpad::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 28, 40, 0.35), rgba(20, 28, 40, 0.12));
  border: 2px solid rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Mittelstück des Kreuzes */
#dpad::after {
  content: "";
  position: absolute;
  left: 64px;
  top: 64px;
  width: 64px;
  height: 64px;
  background: rgba(16, 20, 32, 0.6);
}

.dpad-btn {
  width: 64px;
  height: 64px;
  background: rgba(16, 20, 32, 0.6);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14);
  z-index: 1;
}

.dpad-btn.up    { left: 64px; top: 0;     border-radius: 14px 14px 0 0; }
.dpad-btn.left  { left: 0;    top: 64px;  border-radius: 14px 0 0 14px; }
.dpad-btn.right { left: 128px; top: 64px; border-radius: 0 14px 14px 0; }
.dpad-btn.down  { left: 64px; top: 128px; border-radius: 0 0 14px 14px; }

/* Pfeile als CSS-Dreiecke */
.dpad-btn::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border: 10px solid transparent;
}
.dpad-btn.up::after    { border-bottom: 13px solid rgba(255, 255, 255, 0.8); border-top: 0; }
.dpad-btn.down::after  { border-top: 13px solid rgba(255, 255, 255, 0.8); border-bottom: 0; }
.dpad-btn.left::after  { border-right: 13px solid rgba(255, 255, 255, 0.8); border-left: 0; }
.dpad-btn.right::after { border-left: 13px solid rgba(255, 255, 255, 0.8); border-right: 0; }

.dpad-btn.lit {
  background: rgba(110, 200, 100, 0.75);
}

/* Aktionstasten rechts unten */
#action-buttons {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(36px + env(safe-area-inset-bottom));
  width: 160px;
  height: 236px;
}

.action-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 28px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  border: 3px solid rgba(255, 255, 255, 0.55) !important;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), inset 0 -5px 0 rgba(0, 0, 0, 0.18), inset 0 4px 0 rgba(255, 255, 255, 0.3);
  opacity: 0.9;
}

/* A links unten (rot), B rechts oben (blau) */
.action-btn[data-btn="a"] {
  left: 0;
  bottom: 0;
  background: radial-gradient(circle at 35% 30%, #ff8a7a, #c8302e);
}

.action-btn[data-btn="b"] {
  right: 0;
  bottom: 48px;
  background: radial-gradient(circle at 35% 30%, #8fd0ff, #3b7fc4);
}

.action-btn.lit {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.18), inset 0 4px 0 rgba(255, 255, 255, 0.3);
  filter: brightness(1.15);
}

/* Aktuelle Aktion unter A und B (z. B. „Reden“, „Weiter“) */
.btn-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 8px);
  font-size: 14px;
  font-weight: bold;
  white-space: nowrap;
  color: #f2e6c4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* Merkbuch- und Schwert-Taste: kleiner, oben in der Tastengruppe */
.item-btn {
  top: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(16, 20, 32, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.4) !important;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.14);
}
.item-btn[data-btn="book"]  { left: 8px; }
.item-btn[data-btn="sword"] { right: 8px; }
.item-btn.lit { transform: translateY(3px); filter: brightness(1.3); }

.item-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 2px);
  font-size: 11px;
  color: rgba(242, 230, 196, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* Symbole als reine CSS-Formen (keine Bilddateien) */
.icon-book {
  position: absolute;
  left: 50%; top: 50%;
  width: 22px; height: 26px;
  transform: translate(-50%, -50%);
  background: #e8dcc0;
  border: 3px solid #7a3a2a;
  border-left-width: 6px;
  border-radius: 2px;
}
.icon-sword {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 30px;
  transform: translate(-50%, -55%) rotate(45deg);
  background: linear-gradient(#eef2f8, #c8ccd8);
  border-radius: 3px 3px 1px 1px;
}
.icon-sword::after {
  content: "";
  position: absolute;
  left: -5px; top: 21px;
  width: 16px; height: 4px;
  background: #b8863a;
  border-radius: 2px;
}

/* Steuerkreuz ausblenden, solange Aufgabe, Dialog oder Merkbuch offen sind */
body.dpad-off #dpad {
  display: none;
}

/* Kompakte Touch-Tasten, wenn neben dem Spielbild wenig Platz ist
   (render.js setzt die Klasse). Gleiche Anordnung, kleinere Maße;
   alle Tasten bleiben mindestens 44 px groß. */
body.compact-controls #dpad {
  left: calc(4px + env(safe-area-inset-left));
  width: 120px;
  height: 120px;
}
body.compact-controls #dpad::after {
  left: 40px;
  top: 40px;
  width: 40px;
  height: 40px;
}
body.compact-controls .dpad-btn {
  width: 40px;
  height: 40px;
}
body.compact-controls .dpad-btn.up    { left: 40px; top: 0; }
body.compact-controls .dpad-btn.left  { left: 0;    top: 40px; }
body.compact-controls .dpad-btn.right { left: 80px; top: 40px; }
body.compact-controls .dpad-btn.down  { left: 40px; top: 80px; }
body.compact-controls .dpad-btn::after { border-width: 8px; }
body.compact-controls .dpad-btn.up::after    { border-bottom-width: 10px; border-top: 0; }
body.compact-controls .dpad-btn.down::after  { border-top-width: 10px; border-bottom: 0; }
body.compact-controls .dpad-btn.left::after  { border-right-width: 10px; border-left: 0; }
body.compact-controls .dpad-btn.right::after { border-left-width: 10px; border-right: 0; }

body.compact-controls #action-buttons {
  right: calc(4px + env(safe-area-inset-right));
  width: 120px;
  height: 200px;
}
body.compact-controls .action-btn {
  width: 60px;
  height: 60px;
  font-size: 24px;
}
body.compact-controls .action-btn[data-btn="b"] { bottom: 44px; }
body.compact-controls .item-btn {
  width: 48px;
  height: 48px;
}
body.compact-controls .item-btn[data-btn="book"]  { left: 4px; }
body.compact-controls .item-btn[data-btn="sword"] { right: 4px; }

/* --- Spielstand-Code (js/codepanel.js) -------------------------------- */
#code-panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 16, 0.85);
  /* Safe-Area auf dem iPad beachten */
  padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
           calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  box-sizing: border-box;
}
#code-panel[hidden] { display: none; }
.code-box {
  width: min(92vw, 560px);
  max-height: 92vh;
  overflow-y: auto;
  background: #1c1828;
  color: #f6f0e2;
  border: 2px solid #efe4c4;
  border-radius: 8px;
  padding: 12px 14px;
  box-sizing: border-box;
  font-size: 16px;
}
.code-title { font-weight: bold; font-size: 18px; margin-bottom: 8px; }
#code-panel textarea {
  width: 100%;
  min-height: 76px;
  margin: 6px 0;
  padding: 8px;
  box-sizing: border-box;
  background: #14121a;
  color: #f6f0e2;
  border: 1px solid #55506a;
  border-radius: 4px;
  font-size: 13px;
  word-break: break-all;
  resize: vertical;
}
#code-panel textarea.error { border-color: #e8344a; }
.code-row { display: flex; gap: 8px; margin: 8px 0; }
.code-box button {
  flex: 1;
  padding: 10px 12px;
  font-size: 16px;
  background: #2e2a3e;
  color: #f6f0e2;
  border: 1px solid #efe4c4;
  border-radius: 6px;
  cursor: pointer;
}
.code-box button:active { background: #3a3450; }
.code-hint { color: #8a8496; font-size: 14px; margin-top: 10px; }
#code-msg { min-height: 1.2em; color: #e8344a; font-size: 14px; }
