:root {
  --bg: #10161a;
  --panel: rgba(16, 24, 28, 0.92);
  --panel-solid: #131c21;
  --border: rgba(255, 255, 255, 0.12);
  --text: #e9eef2;
  --muted: #93a3ad;
  --accent: #6fcf7f;
  --accent-dark: #3f8a4d;
  --danger: #e8615a;
  --warn: #e8b83a;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* Das hidden-Attribut ist im Browser-Stylesheet nur `display: none` und wird
 * von jeder eigenen display-Regel ueberstimmt. Ohne diese Zeile bleiben
 * #login (.overlay), #game, #battle-ui und #team-panel trotz hidden sichtbar,
 * weil sie alle display:flex setzen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  /* Handy: kein Ueberziehen der Seite (Pull-to-Refresh) und keine blaue
   * Aufblende beim Antippen von Knoepfen */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- Login */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1d2c22 0%, #0c1114 70%);
  z-index: 100;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}

.login-panel {
  width: min(420px, 92vw);
  padding: 32px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 30px;
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}

#login-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }

#login-form label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }

input[type="text"] {
  padding: 11px 13px;
  font-size: 15px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  font-size: 14px;
  color: #0d1418;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: filter 0.12s ease, transform 0.06s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.error { color: var(--danger); font-size: 13px; margin: 14px 0 0; }

.hint {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 2;
}

/* Die Tastenliste nuetzt am Handy nichts und der Fingerhinweis nichts am
 * Rechner - es wird immer genau einer der beiden gezeigt. */
.touch-hint { display: none; text-align: left; line-height: 1.6; }
@media (pointer: coarse) {
  .keys-hint { display: none; }
  .touch-hint { display: block; }
}

/* ---------------------------------------------------------------- Spiel */
/* Das Spiel fuellt das Browserfenster. Die Buehne nimmt allen Platz ausser
 * der Tastenzeile am Fuss; das Canvas passt seine Aufloesung per JS genau an
 * diese Groesse an (siehe resizeCanvas), damit die Pixel nicht verzerren. */
#game {
  display: flex;
  flex-direction: column;
  width: 100vw;
  /* dvh statt vh: auf dem Handy waechst und schrumpft die sichtbare Hoehe mit
   * der ein- und ausfahrenden Adressleiste. Mit vh raegte die Knopfleiste
   * unter den Bildrand. Die vh-Zeile bleibt als Rueckfall fuer aeltere
   * Browser stehen. */
  height: 100vh;
  height: 100dvh;
}

.stage {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #23331f;
  image-rendering: pixelated;
  /* Ohne das wertet der Browser jedes Wischen ueber dem Spielfeld als Scrollen
   * oder Zoomen aus - das Steuerkreuz bekaeme nur den ersten Bruchteil der
   * Bewegung zu sehen. */
  touch-action: none;
}

.footer-hint {
  flex: none;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  background: rgba(6, 10, 13, 0.8);
  border-top: 1px solid var(--border);
}

/* HUD */
.hud-card {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 220px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  pointer-events: none;
}
.hud-card.foe { left: auto; right: 12px; }
/* Boss-Kampf: deutlich hervorgehoben, damit man sofort sieht, dass das kein
 * gewoehnliches wildes Tier ist. */
.hud-card.foe.boss {
  border-color: #c23b3b;
  box-shadow: 0 0 16px rgba(194, 59, 59, 0.4);
}

.hud-title { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 6px; }
.hud-title .level { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 500; }
/* Traegt normalerweise ein Sprite-Vorschaubild als background-image; die
 * Grundfarbe der Art bleibt als Rueckfall, falls ein Raster fehlt. */
.dot {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: #666;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  image-rendering: pixelated;
  flex: none;
}

.bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  overflow: hidden;
}
.bar.xp { height: 4px; margin-top: 5px; }
.bar.stamina { height: 4px; }
.bar-fill { height: 100%; width: 100%; border-radius: 4px; transition: width 0.18s ease, background 0.2s ease; }
.bar-fill.hp { background: linear-gradient(90deg, #4fbf6a, #79dd8c); }
.bar-fill.hp.mid { background: linear-gradient(90deg, #d9a338, #efc75e); }
.bar-fill.hp.low { background: linear-gradient(90deg, #cf4a44, #e8615a); }
.bar-fill.exp { background: #4a8fd4; }
.bar-fill.stamina { background: linear-gradient(90deg, #8a6fd4, #b48fe8); }

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
.bar-label.small { font-size: 10px; }

.status-chip {
  display: inline-block;
  padding: 0 5px;
  margin-left: 3px;
  border-radius: 3px;
  font-size: 10px;
  color: #10161a;
  font-family: inherit;
}

#server-info {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 8px;
  border-radius: 5px;
  pointer-events: none;
}

/* Toasts */
#toasts {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}
.toast {
  padding: 7px 14px;
  background: rgba(10, 16, 20, 0.94);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  animation: toast-in 0.18s ease;
}
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--danger); }
.toast.good { border-left-color: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Chat */
#chat-log {
  position: absolute;
  top: 122px;
  left: 12px;
  width: 268px;
  /* Feste Hoehe statt max-height: zusammen mit justify-content: flex-end
   * haengen die Zeilen dadurch immer an der Unterkante des Feldes, und neue
   * Nachrichten schieben die alten nach oben. Mit max-height waere das Feld
   * so hoch wie sein Inhalt und wuechse nach unten - die Auftragszeile
   * darunter stuende dann bei leerem Chat einsam weit weg. */
  height: 160px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  pointer-events: none;
  z-index: 14;
}
/* Kein Balken hinter dem Chat, sondern weisse Schrift mit schwarzem Rand -
 * so bleibt sie auf hellem Gras und im dunklen Wald gleich gut lesbar.
 * text-shadow in vier Richtungen statt -webkit-text-stroke: letzteres frisst
 * bei kleiner Schrift die Innenflaeche der Buchstaben auf. */
.chat-line {
  padding: 1px 2px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  color: #ffffff;
  word-break: break-word;
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000,
    0 2px 3px rgba(0, 0, 0, 0.8);
  animation: toast-in 0.16s ease;
}
.chat-line .who { color: #8fd0ff; }
.chat-line.self .who { color: #8ff0a4; }
.chat-line.system { color: #c8d2d8; font-style: italic; }

#chat-form {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: 62%;
  display: flex;
  gap: 6px;
  z-index: 40;
}
#chat-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  background: rgba(6, 10, 13, 0.96);
  border: 1px solid var(--accent);
  border-radius: 7px;
  outline: none;
}
.chat-btn {
  flex: none;
  width: 38px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 7px;
  touch-action: manipulation;
}
.chat-btn.cancel { background: #4a5a64; color: var(--text); }

/* PvP-Schalter */
#pvp-toggle {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(10, 16, 20, 0.9);
  border: 1px solid var(--border);
  border-radius: 7px;
  z-index: 12;
}
#pvp-toggle .pvp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
#pvp-toggle.on { border-color: var(--danger); }
#pvp-toggle.on .pvp-dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* Auftragsanzeige: steht unter dem Chatverlauf und zeigt nur den Fortschritt,
 * ausdruecklich nicht die Loesung - das Raetsel selbst hat man beim
 * Faehrtenleser gehoert.
 *
 * Kein Kasten: der lag frueher genau dort, wo der Chat seine Zeilen anzeigt,
 * und beide ueberdeckten sich gegenseitig. Jetzt haengt die Zeile unter dem
 * Chatfeld (122px Oberkante + 160px Hoehe = 282px) und ist wie dieses reine
 * Schrift mit schwarzem Rand - gelb, damit sie sich vom weissen Chat
 * unterscheidet, und mit Sternchen als Aufhaenger.
 *
 * Die 282px sind fest, nicht die tatsaechliche Chathoehe: #chat-log hat eine
 * feste Hoehe und fuellt sich von unten (justify-content: flex-end), die
 * Auftragszeile springt also nicht mit jeder neuen Nachricht - und die
 * juengste Chatzeile steht immer direkt darueber. */
#quest-hud {
  position: absolute;
  top: 290px;
  left: 12px;
  width: 268px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 5px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  color: #ffd75e;
  word-break: break-word;
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000,
    0 2px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 13;
}
#quest-hud .quest-star { flex: none; }
#quest-hud .quest-title { color: #ffd75e; }
/* Trennpunkt in der CSS statt im Markup: ohne Fortschrittstext gibt es
 * nichts zu trennen, und die Anzeige ist in dem Zustand ohnehin verborgen. */
#quest-hud .quest-title::after { content: ' ·'; }
#quest-hud #quest-progress { color: #f2e2ac; font-weight: 500; }
/* Geloest: heller statt gruen - die Zeile soll gelb bleiben. */
#quest-hud.solved #quest-progress { color: #fff3c4; font-weight: 600; }

/* Faehrtenleser: gleiche Bauart wie die Boss-Stufenwahl, nur unten und in
 * warmen Farben - hier droht nichts, hier wird geredet. */
#npc-panel {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100% - 24px));
  padding: 12px 14px;
  background: rgba(22, 18, 12, 0.94);
  border: 1px solid rgba(224, 163, 60, 0.45);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 18;
}
.npc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}
#npc-name { font-weight: 700; font-size: 15px; color: #f0c987; }
#npc-quest { font-size: 11px; color: var(--muted); }
#npc-text {
  min-height: 42px;
  font-size: 13px;
  line-height: 1.5;
  color: #e8e2d4;
}
.npc-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.action.talk { background: #d8a03a; }
.action.quiet { background: #4a5a64; color: var(--text); }

/* Boss-Stufenwahl: erscheint automatisch, sobald man den Arena-Kreis
 * betritt (siehe updateBossPanel), bildschirmfest oben mittig. */
#boss-panel {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  padding: 12px 14px;
  background: rgba(24, 10, 10, 0.92);
  border: 1px solid rgba(210, 60, 60, 0.45);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 18;
}
.boss-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 9px;
}
#boss-panel-title {
  font-weight: 700;
  font-size: 15px;
  color: #f0a8a8;
}
.boss-panel-sub {
  font-size: 11px;
  color: var(--muted);
}
#boss-stage-buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.boss-stage-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(210, 60, 60, 0.35);
}
.boss-stage-btn:hover { border-color: #e0574f; background: rgba(210, 60, 60, 0.18); }
.boss-stage-btn .stage-num { font-weight: 700; font-size: 14px; }
.boss-stage-btn .stage-level { font-size: 10px; color: var(--muted); font-family: var(--mono); }
.boss-stage-btn.cleared { border-color: var(--accent); background: rgba(111, 207, 127, 0.1); }
.boss-stage-btn .stage-check {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  color: var(--accent);
}

/* Brutstaette: erscheint automatisch im Kreis (siehe updateBreedPanel).
 * Anders als die Boss-Stufenwahl braucht sie Platz fuer eine lange Liste -
 * deshalb links am Rand statt oben mittig, mit eigener Bildlaufleiste und in
 * ruhigem Gruen. Das Team-Fenster sitzt rechts, beide koennen also offen sein. */
#breed-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(320px, calc(100% - 28px));
  max-height: min(560px, calc(100% - 28px));
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: rgba(16, 26, 18, 0.94);
  border: 1px solid rgba(143, 208, 122, 0.42);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 19;
}
.breed-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
#breed-title { font-weight: 700; font-size: 15px; color: #b9e3a4; }
#breed-status {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  margin-bottom: 8px;
}
#breed-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}
.breed-species { display: flex; flex-direction: column; gap: 4px; }
.breed-species-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}
.breed-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  text-align: left;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.breed-card:hover:not(:disabled) { border-color: rgba(143, 208, 122, 0.6); }
.breed-card.picked { border-color: #8fd07a; background: rgba(143, 208, 122, 0.16); }
.breed-card.dimmed { opacity: 0.4; }
.breed-card.cooling, .breed-card:disabled { opacity: 0.45; cursor: not-allowed; }
.breed-card-head { font-size: 12px; font-weight: 600; }
.breed-card-iv { font-size: 10px; color: #9c8fd4; font-family: var(--mono); }
.breed-card-cool { font-size: 10px; color: var(--warn); font-family: var(--mono); }
.breed-empty { margin: 0; font-size: 11px; line-height: 1.45; color: var(--muted); }
.breed-foot {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}
#breed-preview {
  min-height: 26px;
  font-size: 10px;
  line-height: 1.4;
  color: #9c8fd4;
  font-family: var(--mono);
  margin-bottom: 7px;
}
#breed-go { width: 100%; background: #5fa863; }
#breed-go:disabled { opacity: 0.4; cursor: not-allowed; }

/* Fach "Breeding" im Team-Fenster */
#breed-babies { display: flex; flex-direction: column; gap: 8px; }
.team-card.baby { border-color: rgba(143, 208, 122, 0.5); background: rgba(143, 208, 122, 0.08); }
.nest-card {
  padding: 9px 10px;
  background: rgba(143, 208, 122, 0.08);
  border: 1px dashed rgba(143, 208, 122, 0.5);
  border-radius: 7px;
  margin-bottom: 8px;
}
.nest-card .row { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.nest-card .row .level { margin-left: auto; font-size: 11px; color: #b9e3a4; font-family: var(--mono); }
.nest-card .stats { margin-top: 3px; font-size: 10px; color: var(--muted); font-family: var(--mono); }

/* Kampf-UI */
/* Auf einem breiten Monitor darf die Kampf-UI nicht ueber die ganze Breite
 * laufen - die Knoepfe waeren dann meterweit auseinander. */
#battle-ui {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 12px;
  width: min(1180px, calc(100% - 24px));
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  gap: 8px;
  z-index: 15;
}

#battle-main { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Wechsel-Buttons rechts neben der Kampf-UI */
#switch-panel {
  width: 168px;
  flex: none;
  padding: 8px;
  background: rgba(8, 12, 15, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.switch-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 6px;
}
#switch-buttons { display: flex; flex-direction: column; gap: 4px; }

.switch-btn {
  display: block;
  width: 100%;
  padding: 5px 8px;
  text-align: left;
  font-size: 12px;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.switch-btn .row { display: flex; align-items: center; gap: 5px; }
.switch-btn .row .level { margin-left: auto; font-size: 10px; color: var(--muted); }
.switch-btn .mini-bar {
  height: 3px;
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 2px;
  overflow: hidden;
}
.switch-btn .mini-bar > div { height: 100%; }
/* Zweiter, schmalerer Balken darunter: Ausdauer des Tiers auf der Bank */
.switch-btn .mini-bar.ap { height: 2px; margin-top: 2px; }
.switch-btn .mini-bar.ap > div { background: #9a7fe0; }
.switch-btn.active { border-color: var(--accent); background: rgba(111, 207, 127, 0.12); }
.switch-btn.ko { opacity: 0.4; cursor: not-allowed; }
.switch-btn:not(.ko):not(.active):hover { border-color: rgba(255, 255, 255, 0.3); }

#switch-hint {
  margin-top: 6px;
  padding: 5px 7px;
  font-size: 11px;
  line-height: 1.4;
  color: #10161a;
  background: var(--warn);
  border-radius: 5px;
}

#battle-log {
  max-height: 88px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(8, 12, 15, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
  color: #cfd9e0;
  font-family: var(--mono);
  scrollbar-width: thin;
}
#battle-log div { opacity: 0.55; }
#battle-log div:last-child { opacity: 1; color: var(--text); }

#battle-actions { display: flex; flex-direction: column; gap: 6px; }

#battle-turn-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 2px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
#battle-turn-status { color: var(--text); }
#battle-turn-status.warn { color: #e0b03e; }
#battle-stages { color: #b06fd4; }
#battle-stamina { color: #b48fe8; }

#skill-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.skill {
  flex: 1 1 0;
  min-width: 120px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 11px;
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  text-align: left;
}
.skill.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-dark); }
.skill.kind-buff { border-left-color: #4a8fd4; }
.skill.kind-debuff { border-left-color: #b06fd4; }
.skill.kind-hybrid { border-left-color: #d4a24a; }
.skill:disabled { opacity: 0.4; cursor: not-allowed; }
.skill .skill-name { font-weight: 600; font-size: 13px; }
.skill .skill-meta { font-size: 10px; color: var(--muted); font-family: var(--mono); }
.skill .key {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
}

.action-row { display: flex; gap: 6px; }
.action {
  flex: 1;
  position: relative;
  padding: 9px 12px;
  font-size: 13px;
}
.action .key { font-family: var(--mono); font-size: 10px; opacity: 0.7; margin-right: 4px; }
.action.catch { background: #d8a03a; }
/* Gegner ist muerbe genug (unter der Fangschwelle) - der Wurf lohnt jetzt */
.action.catch.ready { background: #5fc574; box-shadow: 0 0 0 2px rgba(95, 197, 116, 0.35); }
.action.catch:disabled { opacity: 0.45; cursor: not-allowed; }
.action.flee { background: #4a5a64; color: var(--text); }
.action .cooldown { font-family: var(--mono); font-size: 11px; margin-left: 6px; opacity: 0.8; }

/* Team-Panel */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  display: flex;
  flex-direction: column;
  border-radius: 0 var(--radius) var(--radius) 0;
  z-index: 30;
}

.panel-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.icon-button {
  margin-left: auto;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.panel-body { flex: 1; overflow-y: auto; padding: 10px; }

.section-head {
  display: flex;
  align-items: center;
  margin: 4px 0 7px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}
.section-head:not(:first-child) { margin-top: 16px; }
.section-head .count { margin-left: auto; font-family: var(--mono); letter-spacing: 0; }

#team-list, #stored-list { display: flex; flex-direction: column; gap: 8px; }
#stored-list:empty::after {
  content: 'Noch keine Tiere zuhause.';
  font-size: 12px;
  color: var(--muted);
}

.card-actions { display: flex; gap: 5px; margin-top: 7px; }
.card-actions button {
  flex: 1;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.card-actions button.primary { background: var(--accent); color: #0d1418; border-color: transparent; }
.card-actions button.danger { color: #e8908a; }
.card-actions button.danger:hover:not(:disabled) { border-color: var(--danger); }
.card-actions button.danger.confirm { background: var(--danger); color: #16090a; border-color: transparent; }
.card-actions button:disabled { opacity: 0.35; }

.team-card {
  padding: 9px 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.team-card:hover { border-color: rgba(255, 255, 255, 0.28); }
.team-card.active { border-color: var(--accent); background: rgba(111, 207, 127, 0.09); }
.team-card.ko { opacity: 0.5; }
.team-card .row { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.team-card .row .level { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 500; }
.team-card .skills { margin-top: 5px; font-size: 10px; color: var(--muted); font-family: var(--mono); }
.team-card .stats { margin-top: 3px; font-size: 10px; color: var(--muted); font-family: var(--mono); }
.team-card .iv-row { margin-top: 3px; font-size: 10px; color: #9c8fd4; font-family: var(--mono); }

.train-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 7px;
  padding: 5px 6px;
  background: rgba(111, 207, 127, 0.08);
  border: 1px solid var(--accent-dark);
  border-radius: 5px;
  flex-wrap: wrap;
}
.train-row .train-label { font-size: 10px; color: var(--accent); font-family: var(--mono); margin-right: 2px; }
.train-btn {
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(111, 207, 127, 0.16);
  color: var(--accent);
  border: 1px solid var(--accent-dark);
  border-radius: 4px;
}
.train-btn:hover { background: var(--accent); color: #0d1418; }

.panel-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  line-height: 1.7;
}

/* ------------------------------------------------------ Touch-Steuerung */
/* Knopfleiste rechts unten: dieselben Befehle wie die Tasten I, M, T und
 * Enter, als Ziele in Daumengroesse. Sie blendet sich aus, sobald Kampf,
 * Team-Panel oder Chat den unteren Bildrand brauchen (siehe updateTouchUi). */
#touch-buttons {
  position: absolute;
  right: 10px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 16;
}
.touch-btn {
  width: 56px;
  height: 56px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 50%;
  background: rgba(10, 16, 20, 0.82);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}
.touch-btn .touch-icon { font-size: 21px; line-height: 1; }
.touch-btn .touch-label { font-size: 9px; color: var(--muted); letter-spacing: 0.3px; }
.touch-btn:active { background: rgba(111, 207, 127, 0.28); border-color: var(--accent); }

/* Steuerkreuz. Es erscheint unter dem Finger und faengt selbst keine
 * Beruehrungen ab - die Ereignisse gehoeren dem Canvas darunter. */
#joystick {
  position: absolute;
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: radial-gradient(circle, rgba(159, 212, 255, 0.10), rgba(8, 12, 15, 0.30));
  z-index: 14;
  pointer-events: none;
}
#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(159, 212, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.55);
}

/* ------------------------------------------------------ Verbindungsverlust */
/* Deckt die Buehne ab, solange die Leitung tot ist. Es waere schlimmer, das
 * Spiel offen zu lassen: man laeuft dann durch eine Welt, die niemand mehr
 * mitschreibt, und merkt es erst am naechsten Kampf, der nicht beginnt. */
#conn-panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 13, 0.72);
  backdrop-filter: blur(2px);
  z-index: 60;
}
.conn-box {
  width: min(360px, calc(100% - 32px));
  padding: 20px 22px;
  text-align: center;
  background: var(--panel-solid);
  border: 1px solid rgba(232, 97, 90, 0.5);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.conn-title { font-size: 16px; font-weight: 700; color: #f0a8a8; margin-bottom: 6px; }
#conn-text { font-size: 13px; color: var(--muted); line-height: 1.5; min-height: 38px; }
.conn-actions { display: flex; gap: 8px; margin-top: 14px; }

/* Auf schmalen Fenstern wird der Platz knapp: Tastenzeile weg, Panels enger */
@media (max-width: 720px) {
  .footer-hint { display: none; }
  .side-panel { width: 100%; border-radius: 0; }
  #chat-log { width: 60%; }
}

/* --------------------------------------------------- Handy im Hochformat */
/* Hier ist der Bildschirm hoch und schmal: die Kampf-UI wird gestapelt statt
 * nebeneinander gesetzt, alle Anzeigen ruecken zusammen und jedes Bedienziel
 * waechst auf Daumengroesse. */
@media (max-width: 820px) and (orientation: portrait) {
  .footer-hint { display: none; }

  .hud-card {
    width: 47%;
    max-width: 200px;
    top: 8px;
    left: 8px;
    padding: 7px 9px;
    font-size: 12px;
  }
  .hud-card.foe { right: 8px; }
  .hud-title .level { font-size: 10px; }
  .dot { width: 22px; height: 22px; }

  #chat-log {
    top: 142px;
    left: 8px;
    width: calc(100% - 90px);
    height: 108px;
  }

  /* Auch hier unter den Chat: 142px + 108px = 250px */
  #quest-hud {
    top: 256px;
    left: 8px;
    width: calc(100% - 90px);
    font-size: 12px;
  }
  .chat-line { font-size: 12px; }

  /* Die Eingabezeile gehoert am Handy nicht an den unteren Bildrand: dort
   * steht die Bildschirmtastatur und verdeckt sie vollstaendig. Sie sitzt
   * deshalb im oberen Drittel; den genauen Wert setzt positionChatForm()
   * anhand der Hoehe, die die Tastatur tatsaechlich uebrig laesst.
   * 16px Schriftgroesse im Feld: darunter zoomt iOS beim Antippen hinein. */
  #chat-form {
    top: 34%;
    bottom: auto;
    width: calc(100% - 16px);
    gap: 8px;
  }
  #chat-input { padding: 13px 14px; font-size: 16px; }
  .chat-btn { width: 48px; font-size: 18px; }

  #toasts { width: calc(100% - 24px); }
  .toast { font-size: 12px; padding: 6px 11px; }

  /* Serverzeile weg von der rechten unteren Ecke - dort liegt die Knopfleiste */
  #server-info { right: auto; left: 8px; bottom: 52px; font-size: 10px; }
  #pvp-toggle { left: 8px; bottom: 8px; }

  /* Kampf: gestapelt statt nebeneinander. Die Bank wird zur Zeile, durch die
   * man waagerecht wischt - untereinander waere sie hoeher als das Bild. */
  #battle-ui {
    flex-direction: column;
    align-items: stretch;
    width: calc(100% - 12px);
    bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }
  /* Jede hier gesparte Zeile ist Wiese, auf der man die Tiere sieht - die
   * Leiste steht am Handy vor dem Kampfplatz. Den groesseren Teil erledigt
   * battleFocusShift() im Client, indem es den Bildausschnitt anhebt; hier
   * geht es nur darum, die Leiste nicht unnoetig hoch werden zu lassen. */
  #switch-panel { width: 100%; padding: 5px 6px; }
  .switch-title { margin-bottom: 3px; }
  #switch-buttons {
    flex-direction: row;
    overflow-x: auto;
    gap: 5px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .switch-btn { flex: 0 0 112px; padding: 4px 7px; }
  /* Zwei Zeilen Kampf-Log genuegen - die letzte ist die, die zaehlt */
  #battle-log { max-height: 44px; font-size: 11px; padding: 5px 8px; }
  #battle-turn-bar { flex-wrap: wrap; gap: 2px 8px; font-size: 10px; }
  #skill-buttons { gap: 5px; }
  .skill { flex: 1 1 calc(50% - 3px); min-width: 0; padding: 8px 10px; }
  .skill .skill-meta { font-size: 9px; }
  .action { padding: 12px 10px; font-size: 14px; }

  /* Gespraech und Stufenwahl: volle Breite, groessere Knoepfe */
  #npc-panel {
    width: calc(100% - 16px);
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 11px 12px;
  }
  #npc-text { max-height: 34vh; overflow-y: auto; font-size: 14px; }
  .npc-actions .action { padding: 13px 10px; }
  #boss-panel { top: 8px; width: calc(100% - 16px); }
  .boss-panel-sub { font-size: 10px; }
  .boss-stage-btn { padding: 11px 4px; }

  /* Team-Panel fuellt das Bild; die Karten bekommen groessere Knoepfe */
  .side-panel { width: 100%; border-radius: 0; }
  .panel-head { padding: 10px 12px; }
  .icon-button { width: 34px; height: 34px; font-size: 20px; }
  .card-actions button { padding: 9px 6px; font-size: 11px; }
  .train-btn { padding: 7px 10px; }
}
