:root {
  --ink: #1f2430;
  --muted: #5d6474;
  --paper: #fbf7f1;
  --accent: #e07a1f;
  --accent-dark: #b85f10;
  --glass: rgba(24, 28, 38, 0.82);
  --glass-line: rgba(255, 255, 255, 0.12);
  --on-glass: #f3f1ec;
  --on-glass-muted: #b9bcc6;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b3140; font-family: var(--font); color: var(--ink); }
.hidden { display: none !important; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }

button { font: inherit; cursor: pointer; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; margin: 0 2px;
  border: 1px solid #c9c4ba; border-bottom-width: 2px; border-radius: 5px;
  background: #fff; font: 600 12px/1.5 var(--font); text-align: center;
}

/* ---------- Vollbild-Ebenen ---------- */
.screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#login {
  background:
    linear-gradient(180deg, rgba(31, 36, 48, 0.55), rgba(31, 36, 48, 0.85)),
    var(--login-bg, none) center / cover no-repeat, #2b3140;
}
.login-card, .help-card, .loading-card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border-radius: 18px; padding: 26px 28px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.field { display: block; border: 0; padding: 0; margin: 0 0 16px; }
.field > span, .field > legend { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; padding: 0; }
.field input {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 16px;
  border: 1.5px solid #d8d2c7; border-radius: 10px; background: #fff; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 122, 31, 0.2); }

#figure-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; }
.fig {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px; border: 1.5px solid #e2dccf; border-radius: 10px; background: #fff;
  font-size: 11px; color: var(--muted); line-height: 1.2; text-align: center;
}
.fig:hover { border-color: #cfc5b4; }
.fig[aria-checked="true"] { border-color: var(--accent); background: #fff4e8; color: var(--ink); box-shadow: 0 0 0 3px rgba(224, 122, 31, 0.18); }
.fig:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fig .sprite {
  width: 48px; height: 72px; image-rendering: pixelated;
  background-repeat: no-repeat; background-size: 96px 72px; background-position: 0 0;
}

button.primary {
  width: 100%; padding: 12px 16px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px;
}
button.primary:hover { background: var(--accent-dark); }
.fineprint { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ---------- Laden ---------- */
#loading { background: #2b3140; }
.loading-card { width: min(360px, 100%); text-align: center; }
.bar { height: 8px; background: #e9e3d8; border-radius: 99px; overflow: hidden; }
#loading-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
#loading-text { margin: 12px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px; pointer-events: none;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 6px; pointer-events: auto; flex-wrap: wrap; }
.hud-brand { color: #fff; font-weight: 800; letter-spacing: -0.01em; margin-right: 4px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.chip, #hud button {
  background: var(--glass); color: var(--on-glass); border: 1px solid var(--glass-line);
  border-radius: 99px; padding: 6px 12px; font-size: 13px; backdrop-filter: blur(6px);
}
#hud button.icon { width: 32px; height: 32px; padding: 0; font-size: 17px; font-weight: 700; }
#hud button:hover { background: rgba(40, 46, 60, 0.95); }

/* ---------- Hinweis / Meldung ---------- */
#hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 20;
  background: var(--glass); color: var(--on-glass); border: 1px solid var(--glass-line);
  padding: 10px 16px; border-radius: 99px; font-size: 14px; max-width: calc(100vw - 32px);
  backdrop-filter: blur(6px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hint b { color: #ffb36b; font-weight: 700; }
#toast {
  position: fixed; left: 50%; top: 58px; transform: translateX(-50%); z-index: 1000;   /* auch über Hauptmenü und Fenstern */
  background: var(--paper); color: var(--ink); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px);
}
#conn {
  position: fixed; left: 50%; top: 58px; transform: translateX(-50%); z-index: 31;
  background: #b3261e; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
}

/* ---------- Chat ---------- */
#chat {
  position: fixed; left: 12px; bottom: 12px; z-index: 20; width: min(360px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
#chat-log {
  max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 3px;
  pointer-events: auto; scrollbar-width: thin;
  mask-image: linear-gradient(to bottom, transparent 0, #000 24px);
}
.msg {
  align-self: flex-start; max-width: 100%;
  background: var(--glass); color: var(--on-glass); border-radius: 10px; padding: 5px 9px;
  font-size: 13.5px; line-height: 1.35; overflow-wrap: anywhere;
}
.msg .who { font-weight: 700; color: #ffb36b; margin-right: 6px; }
.msg.me .who { color: #8fd3a8; }
.msg.system { background: rgba(24, 28, 38, 0.6); color: var(--on-glass-muted); font-style: italic; }
.msg .time { color: var(--on-glass-muted); font-size: 11px; margin-left: 6px; }
#chat-form { pointer-events: auto; }
#chat-input {
  width: 100%; padding: 9px 12px; border-radius: 10px; font: inherit; font-size: 14px;
  background: var(--glass); color: var(--on-glass); border: 1px solid var(--glass-line); backdrop-filter: blur(6px);
}
#chat-input::placeholder { color: var(--on-glass-muted); }
#chat-input:focus { outline: none; border-color: var(--accent); background: rgba(24, 28, 38, 0.95); }

/* ---------- Seitenfenster ---------- */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 70vw; z-index: 25;
  display: flex; flex-direction: column; background: #111; box-shadow: -10px 0 30px rgba(0,0,0,.35);
}
.panel-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px 8px 14px; background: var(--glass); color: var(--on-glass); font-size: 14px; font-weight: 600;
}
.panel-bar a, .panel-bar button {
  color: var(--on-glass); background: transparent; border: 1px solid var(--glass-line); border-radius: 8px;
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; font-size: 16px; margin-left: 4px;
}
#panel-frame { flex: 1; border: 0; width: 100%; background: #111; }

/* ---------- Agent: großes Fenster mit Quellen-Ansicht ---------- */
#agent {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 40;
  width: min(1180px, calc(100vw - 32px)); height: min(84vh, 820px); display: flex; flex-direction: column;
  background: rgba(24, 28, 38, 0.96); color: var(--on-glass); border: 1px solid var(--glass-line); border-radius: var(--radius);
  box-shadow: 0 0 0 100vmax rgba(10, 12, 18, 0.45), 0 18px 50px rgba(0,0,0,.45);
}
.agent-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 10px 10px 18px; font-weight: 600; font-size: 16px; color: #9fe0ff; border-bottom: 1px solid var(--glass-line); }
.agent-bar-rechts { display: flex; gap: 6px; align-items: center; }
.agent-bar button { color: var(--on-glass); background: transparent; border: 1px solid var(--glass-line); border-radius: 8px; height: 32px; padding: 0 10px; font-size: 13px; font-weight: 500; }
.agent-bar button.icon { width: 32px; padding: 0; font-size: 18px; }
.agent-body { flex: 1; min-height: 0; display: flex; }
.agent-gespraech { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
#agent-log { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
.agent-msg { font-size: 15px; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; padding: 10px 14px; border-radius: 12px; max-width: 88%; }
.agent-msg.frage { align-self: flex-end; background: rgba(224, 122, 31, 0.3); }
.agent-msg.antwort { align-self: flex-start; background: rgba(159, 224, 255, 0.12); }
.agent-msg.denkt { color: var(--on-glass-muted); font-style: italic; }
.agent-msg b { color: #fff; }
.agent-msg .punkt { display: block; padding-left: 1.1em; text-indent: -1.1em; }
.agent-msg .kasten { display: block; padding: 7px 10px; margin-bottom: 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.07); border-left: 3px solid #9fe0ff; }
.agent-msg .kasten.rot { border-left-color: #ff6b6b; } .agent-msg .kasten.gelb { border-left-color: #ffd400; } .agent-msg .kasten.gruen { border-left-color: #5fd38d; }
.agent-msg .kasten.warn { border-left-color: #ff9f43; } .agent-msg .kasten.notfall { border-left-color: #ff6b6b; background: rgba(255, 80, 80, 0.14); }
.agent-msg .zusatz { display: block; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--glass-line); color: var(--on-glass-muted); font-size: 13.5px; }
.agent-msg.schreibt::after { content: '▍'; animation: blinkt 1s steps(2) infinite; color: #9fe0ff; }
@keyframes blinkt { 50% { opacity: 0; } }
.agent-bewertung { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--on-glass-muted); }
.agent-bewertung button { background: transparent; border: 1px solid var(--glass-line); border-radius: 999px; padding: 2px 9px; font-size: 14px; cursor: pointer; }
.agent-bewertung button:hover, .agent-bewertung button.aktiv { background: rgba(159, 224, 255, 0.18); border-color: #9fe0ff; }
#agent-vorschlaege { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
#agent-vorschlaege button { font-size: 13px; color: var(--on-glass); background: rgba(255, 255, 255, 0.06); border: 1px solid var(--glass-line); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
#agent-vorschlaege button:hover, #agent-vorschlaege button:focus-visible { border-color: #9fe0ff; background: rgba(159, 224, 255, 0.14); }
.agent-msg.denkt::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: denkt 1.2s steps(4) infinite; }
@keyframes denkt { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.agent-quellen { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.agent-quellen button {
  font-size: 12.5px; color: #9fe0ff; background: transparent; border: 1px solid rgba(159, 224, 255, 0.4);
  border-radius: 999px; padding: 4px 10px; text-align: left;
}
.agent-quellen button:hover, .agent-quellen button.aktiv { background: rgba(159, 224, 255, 0.18); }
.agent-seite { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; padding: 6px; width: 292px; max-width: 100%; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--glass-line); border-radius: 10px; color: var(--on-glass-muted); font-size: 12px; text-align: left; cursor: zoom-in; }
.agent-seite canvas { width: 100%; height: auto; background: #fff; border-radius: 6px; }
.agent-seite:hover { border-color: #9fe0ff; }
#agent-form { display: flex; gap: 8px; padding: 10px 14px 14px; border-top: 1px solid var(--glass-line); align-items: flex-end; }
#agent-input {
  flex: 1; min-width: 0; resize: none; background: rgba(255,255,255,0.08); color: var(--on-glass); border: 1px solid var(--glass-line);
  border-radius: 10px; padding: 10px 12px; font: 15px/1.4 var(--font);
}
#agent-input::placeholder { color: var(--on-glass-muted); }
#agent-input:focus { outline: none; border-color: #9fe0ff; }
#agent-input:disabled { opacity: .6; }
#agent-form .primary { width: auto; margin: 0; padding: 10px 16px; font-size: 15px; }
#agent-quelle { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; border-left: 1px solid var(--glass-line); }
.agent-quelle-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; font-size: 13px; color: var(--on-glass-muted); }
#agent-quelle-titel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-quelle-bar a { color: #9fe0ff; text-decoration: none; font-size: 16px; }
.agent-quelle-bar button { color: var(--on-glass); background: transparent; border: 1px solid var(--glass-line); border-radius: 8px; width: 28px; height: 28px; }
#agent-quelle-frame { flex: 1; border: 0; width: 100%; background: #fff; border-radius: 0 0 var(--radius) 0; }
#agent-meldung {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 35;
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px;
  background: var(--paper); color: var(--ink); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35); font-size: 14px;
  max-width: calc(100vw - 32px); animation: hoch .25s ease-out;
}
#agent-meldung .primary { width: auto; margin: 0; padding: 7px 12px; font-size: 14px; }
#agent-meldung .icon { background: transparent; border: 0; font-size: 18px; color: var(--muted); }
@keyframes hoch { from { transform: translate(-50%, 20px); opacity: 0; } }
@media (max-width: 900px) {
  .agent-body.mit-quelle .agent-gespraech { display: none; }
  #agent { width: calc(100vw - 16px); height: calc(100vh - 16px); }
}
#panel-frame.hell { background: #fffdf9; }

/* ---------- Hilfe ---------- */
#help { background: rgba(20, 24, 32, 0.6); z-index: 60; }
.help-card h2 { margin: 0 0 12px; font-size: 21px; }
.help-card table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 6px; }
.help-card td { padding: 7px 4px; border-bottom: 1px solid #eae4d9; vertical-align: middle; }
.help-card td:first-child { white-space: nowrap; padding-right: 14px; }
.help-card .primary { margin-top: 14px; }

@media (max-width: 720px) {
  #panel { width: 100vw !important; }
  .hud-brand { display: none; }
  #btn-leave { display: none; }
}
#hud #btn-waende[aria-pressed="true"] { background: #ffd400; color: #141414; }

/* ---- Barrierefreiheit (js/barriere.js, Einstellungen → Barrierefreiheit) ---------------------------------- */
/* Schriftgröße: Textfenster werden mit zoom vergrößert, Breiten in vw werden durch den Faktor geteilt, damit nichts aus dem Bild ragt */
html { --bf-zoom: 1; }
html.schrift-gross { --bf-zoom: 1.2; }
html.schrift-sehrgross { --bf-zoom: 1.4; }
html:is(.schrift-gross, .schrift-sehrgross) :is(#dialog, #aufgabe, #hint, #toast, #intro-text, #agent-log, #agent-vorschlaege, #agent-form, #chat-log, #chat-form, #agent-meldung, .einst-inhalt, #kapitel-geschafft > *, #kapitel-uebersicht > *) { zoom: var(--bf-zoom); }
html:is(.schrift-gross, .schrift-sehrgross) #dialog { width: min(700px, calc((100vw - 24px) / var(--bf-zoom))); }
html:is(.schrift-gross, .schrift-sehrgross) #aufgabe { max-width: min(320px, calc((100vw - 24px) / var(--bf-zoom))); }
html:is(.schrift-gross, .schrift-sehrgross) :is(#hint, #toast) { max-width: calc((100vw - 32px) / var(--bf-zoom)); }
html:is(.schrift-gross, .schrift-sehrgross) #chat-log { max-height: calc(34vh / var(--bf-zoom)); }

/* Hoher Kontrast: schwarzer Grund, weiße Schrift, gelber Rahmen um das Gewählte */
html.kontrast :focus-visible { outline: 4px solid #ffd400 !important; outline-offset: 2px; }
html.kontrast #dialog { background: #000; color: #fff; border-color: #fff; }
html.kontrast #dialog.erzaehler #dialog-text { color: #fff; }
html.kontrast #dialog-name { color: #000; }
html.kontrast .dialog-wahl button { background: #000; color: #fff; border-color: #fff; }
html.kontrast .dialog-wahl button:is(:hover, :focus, :focus-visible) { background: #ffd400; color: #000; }
html.kontrast .dialog-wahl button .nr { background: #ffd400; color: #000; }
html.kontrast :is(#aufgabe, #hint, #toast, .msg, #agent, #rucksack) { background: #000 !important; color: #fff !important; border: 2px solid #fff !important; }
html.kontrast .msg .time, html.kontrast .agent-msg.denkt, html.kontrast .agent-msg .zusatz, html.kontrast .fineprint, html.kontrast .ml-fenster .fineprint { color: #fff !important; opacity: 1; }
html.kontrast .agent-msg.antwort { background: #111; border: 1px solid #fff; }
html.kontrast .agent-msg.frage { background: #3a2400; border: 1px solid #ffd400; }
html.kontrast #chat-input, html.kontrast #agent-input { background: #fff; color: #000; border: 2px solid #000; }
html.kontrast #intro-text { text-shadow: 0 0 6px #000, 0 0 2px #000, 3px 3px 0 #000; background: rgba(0, 0, 0, .7); padding: 6px 12px; }
html.kontrast .ml-fenster { background-color: #000; }

/* Weniger Bewegung: keine Kamerafahrten, kein Blinken und Wackeln, Übergänge sofort */
html.wenig-bewegung *, html.wenig-bewegung *::before, html.wenig-bewegung *::after {
  animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
  transition-duration: 1ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important;
}
#hud #btn-waende[aria-pressed="true"], #hud #btn-dach[aria-pressed="true"] { background: #ffd400; color: #141414; }
