@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=Nunito:wght@600;800&display=swap");

:root {
  --gold: #ffd98a;
  --gold-deep: #e9a84a;
  --cyan: #8fe8ff;
  --violet: #b99bff;
  --ink: #1d1638;
  --panel: rgba(28, 22, 58, 0.78);
  --panel-edge: rgba(255, 220, 150, 0.45);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0e0b1f;
  font-family: "Nunito", system-ui, sans-serif; color: #fff;
  user-select: none; -webkit-user-select: none;
}
#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud-crystals {
  position: absolute; left: 24px; top: 18px; display: flex; align-items: center; gap: 8px;
  font-size: 30px; font-weight: 800; text-shadow: 0 2px 8px rgba(40, 20, 90, 0.8);
}
#hud-crystals img { height: 44px; filter: drop-shadow(0 0 10px rgba(120, 220, 255, 0.9)); }
#hud-crystals small { font-size: 18px; opacity: 0.75; margin-left: -4px; }
#hud-crystals.pop span { animation: pop 0.35s ease-out; display: inline-block; }
@keyframes pop { 0% { transform: scale(1.5); color: var(--cyan); } 100% { transform: scale(1); } }

#hud-abilities { position: absolute; right: 22px; top: 16px; display: flex; gap: 12px; }
.ability {
  width: 58px; height: 58px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 50% 40%, rgba(70, 50, 140, 0.85), rgba(20, 14, 48, 0.9));
  border: 2px solid rgba(255, 255, 255, 0.18); transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  display: grid; place-items: center;
}
.ability svg { width: 32px; height: 32px; }
.ability .key {
  position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; background: rgba(15, 10, 35, 0.9); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px; padding: 1px 6px; white-space: nowrap;
}
.ability .cd { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(10,6,25,0.75) var(--p, 0%), transparent 0); }
.ability.ready { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 210, 120, 0.8); transform: scale(1.08); }
.ability.active { border-color: var(--cyan); box-shadow: 0 0 22px rgba(120, 230, 255, 0.95); }
.ability.locked { opacity: 0.25; }

#hud-echo { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  font-weight: 800; color: var(--cyan); text-shadow: 0 0 10px rgba(100, 220, 255, 0.9); letter-spacing: 2px; }
#hud-echo svg { width: 38px; height: 38px; transform: rotate(-90deg); }
#hud-echo circle { fill: none; stroke-width: 4; }
#hud-echo .bg { stroke: rgba(255, 255, 255, 0.2); }
#hud-echo .fg { stroke: var(--cyan); stroke-dasharray: 100.5; stroke-linecap: round; }

#hint {
  position: absolute; left: 50%; top: 96px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 14px;
  padding: 10px 20px; font-size: 20px; max-width: min(760px, 90vw); text-align: center;
  box-shadow: 0 6px 30px rgba(10, 5, 30, 0.5); animation: fadein 0.3s ease-out;
}
#banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; animation: bannerIn 3.2s ease-in-out forwards; }
#banner .title { font-family: "Cinzel", serif; font-size: clamp(34px, 5vw, 72px); font-weight: 700; color: #fff4d8;
  text-shadow: 0 0 24px rgba(255, 200, 110, 0.95), 0 4px 18px rgba(60, 20, 110, 0.8); }
#banner .sub { font-family: "Cinzel", serif; font-size: clamp(18px, 2vw, 28px); color: var(--gold); letter-spacing: 6px; margin-top: 6px; }
@keyframes bannerIn { 0% { opacity: 0; transform: translateY(12px); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } }

#dialog {
  position: absolute; left: 50%; bottom: 36px; transform: translateX(-50%); width: min(880px, 92vw);
  display: flex; gap: 16px; align-items: center; background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 20px; padding: 14px 22px 14px 14px; box-shadow: 0 10px 40px rgba(10, 5, 30, 0.55);
  animation: fadein 0.25s ease-out;
}
#dialog .portrait { width: 84px; height: 84px; flex: none; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle, rgba(255, 220, 150, 0.35), rgba(80, 60, 160, 0.4)); border: 2px solid var(--gold); }
#dialog .portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 60% 20%; }
#dialog .name { font-family: "Cinzel", serif; color: var(--gold); font-size: 18px; letter-spacing: 2px; }
#dialog .text { font-size: 22px; line-height: 1.35; min-height: 30px; }
kbd {
  display: inline-block; font-family: inherit; font-weight: 800; font-size: 0.8em; padding: 1px 8px; margin: 0 2px;
  border-radius: 7px; background: #fff6df; color: var(--ink); box-shadow: 0 2px 0 var(--gold-deep); vertical-align: 2px;
}

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; }
#title-screen { background: #120d28; }
.title-art { position: absolute; inset: 0; background: url("../01_Concept/keyart.webp") center / cover no-repeat;
  animation: drift 30s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.02); } to { transform: scale(1.08) translate(-1%, -1%); } }
.title-panel { position: absolute; bottom: 7vh; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.chapters { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.chapters button { font-size: 15px; padding: 7px 16px; background: linear-gradient(#f4ecff, #cbb6ff); box-shadow: 0 3px 0 #8d74d6; }
.chapters button.done::after { content: " \2713"; }
.chapters-title { font-family: "Cinzel", serif; color: var(--gold); font-size: 15px; letter-spacing: 0.1em; text-shadow: 0 2px 8px rgba(20, 10, 50, 0.8); }
.title-help { font-size: 15px; text-align: center; line-height: 1.6; background: rgba(20, 14, 48, 0.6); padding: 8px 18px; border-radius: 12px; }
#loading { position: absolute; bottom: 3vh; font-size: 14px; opacity: 0.8; }

button {
  font-family: "Nunito", sans-serif; font-weight: 800; font-size: 20px; color: var(--ink); cursor: pointer;
  background: linear-gradient(#fff4d8, var(--gold)); border: none; border-radius: 14px; padding: 10px 28px;
  box-shadow: 0 4px 0 var(--gold-deep), 0 8px 26px rgba(255, 190, 90, 0.35); transition: transform 0.1s;
}
button:hover, button.focus { transform: translateY(-2px) scale(1.03); }
button:active { transform: translateY(2px); }
button.big { font-size: 30px; padding: 14px 64px; font-family: "Cinzel", serif; }
button:disabled { opacity: 0.4; }

.panel {
  background: var(--panel); backdrop-filter: blur(8px); border: 1px solid var(--panel-edge); border-radius: 22px;
  padding: 24px 34px; display: flex; flex-direction: column; gap: 12px; min-width: 340px; max-width: 92vw; max-height: 92vh; overflow: auto;
}
.panel h2 { font-family: "Cinzel", serif; color: var(--gold); margin: 0 0 6px; text-align: center; }
.panel label { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.panel .controls table { width: 100%; font-size: 14px; border-collapse: collapse; margin-top: 6px; }
.panel .controls td, .panel .controls th { padding: 3px 8px; text-align: left; }
.panel .controls th { color: var(--gold); }
#pause-screen, #end-screen { background: rgba(12, 8, 30, 0.45); }
#end-stats { font-size: 20px; line-height: 1.7; text-align: center; }
#end-stats b { color: var(--gold); }

/* Abspann nach dem Finale: der Text rollt ueber das geheilte Schloss */
#credits { position: fixed; inset: 0; overflow: hidden; background: linear-gradient(rgba(20, 12, 40, 0.15), rgba(20, 12, 40, 0.55) 40%, rgba(20, 12, 40, 0.55) 60%, rgba(20, 12, 40, 0.15));
  animation: credits-in 2.5s ease-out; z-index: 5; }
@keyframes credits-in { from { opacity: 0; } to { opacity: 1; } }
#credits .roll { position: absolute; left: 0; right: 0; top: 100%; text-align: center; color: #fff6e6; text-shadow: 0 2px 12px rgba(40, 20, 80, 0.8);
  animation: credits-roll 42s linear forwards; }
@keyframes credits-roll { from { transform: translateY(0); } to { transform: translateY(calc(-100% - 100vh)); } }
#credits h1 { font-family: "Cinzel", serif; font-size: 54px; color: var(--gold); margin: 0 0 30px; }
#credits h3 { font-family: "Cinzel", serif; font-size: 24px; color: var(--gold); margin: 56px 0 12px; letter-spacing: 0.08em; }
#credits p { font-size: 21px; line-height: 1.7; margin: 0; }
#credits p.lead { font-size: 24px; font-style: italic; }
#credits .skip { position: absolute; right: 22px; bottom: 16px; font-size: 14px; opacity: 0.6; }
@media (max-width: 700px) { #credits h1 { font-size: 34px; } #credits p { font-size: 16px; } #credits p.lead { font-size: 18px; } }

#level-loading { background: rgba(12, 8, 30, 0.75); z-index: 4; }
.load-bar { width: min(60vw, 420px); height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#level-load-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 0.2s; }

#error { position: fixed; left: 20px; right: 20px; bottom: 20px; background: #3a0d1e; border: 1px solid #ff6b8a; color: #ffd6df;
  padding: 14px; border-radius: 10px; font: 14px/1.4 monospace; white-space: pre-wrap; z-index: 10; }
#debug { position: fixed; left: 10px; bottom: 10px; font: 12px/1.3 monospace; background: rgba(0,0,0,0.55); padding: 6px 10px; border-radius: 6px; }

@media (max-width: 700px) {
  #hud-crystals { font-size: 22px; } #hud-crystals img { height: 32px; }
  .ability { width: 44px; height: 44px; } .ability svg { width: 24px; height: 24px; }
  #dialog .text { font-size: 17px; } #dialog .portrait { width: 60px; height: 60px; }
}
.panel .focus, .title-panel .focus { outline: 3px solid var(--cyan); outline-offset: 4px; }
input.focus { outline: 3px solid var(--cyan); }

/* Boss-Anzeige: Name, verbleibende Treffer, aktuelle Aufgabe */
#boss-bar { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); text-align: center; pointer-events: none;
  width: min(760px, 56vw); animation: fadein 0.5s ease-out; }

#boss-bar .row { display: flex; justify-content: center; align-items: center; gap: 14px; }
#boss-bar .name { font-family: "Cinzel", serif; font-size: 22px; font-weight: 700; color: #fff0d0; letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(40, 10, 60, 0.8); }
#boss-bar .hp i { display: inline-block; width: 16px; height: 16px; margin: 0 3px; transform: rotate(45deg);
  background: linear-gradient(135deg, #bff4ff, #6fb8ff); box-shadow: 0 0 10px #8fe8ff; border: 1px solid #fff; }
#boss-bar .hp i.gone { background: rgba(255, 255, 255, 0.12); box-shadow: none; border-color: rgba(255, 255, 255, 0.35); }
#boss-bar .goal { margin-top: 6px; background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 12px;
  padding: 6px 16px; font-size: 17px; display: inline-block; box-shadow: 0 6px 24px rgba(10, 5, 30, 0.45); }
#boss-bar .goal.open { border-color: #ffe08a; color: #fff4c8; box-shadow: 0 0 24px rgba(255, 220, 120, 0.55); }

/* Aktions-Hinweis unten in der Mitte (E: reden / aufheben / werfen) */
#prompt { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 999px; padding: 6px 16px; font-size: 17px; pointer-events: none; animation: fadein 0.2s ease-out; }

/* Schwierigkeit */
.difficulty { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 12px auto 4px; width: fit-content;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 14px; padding: 6px 10px; }
.difficulty span { font-size: 14px; color: #fff0d0; margin-right: 6px; letter-spacing: 1px; text-transform: uppercase; }
.difficulty .diff { min-width: 92px; padding: 8px 14px; font-size: 16px; opacity: 0.7; }
.difficulty .diff.active { opacity: 1; outline: 2px solid var(--gold); box-shadow: 0 0 16px rgba(255, 210, 120, 0.45); }
.diff-info { font-size: 14px; color: #f4ecff; text-align: center; max-width: 520px; margin: 4px auto 10px; line-height: 1.4;
  background: var(--panel); border-radius: 10px; padding: 6px 12px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }

/* ---------- Handy / Tablet (Touch) ---------- */
body.touch { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
.touch-help { display: none; }
body.touch .touch-help { display: block; }
body.touch .key-help { display: none; }
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 3; display: none; }
#touch.on { display: block; }
#t-stick-zone { position: absolute; left: 0; bottom: 0; width: 45vw; height: 70vh; pointer-events: auto; touch-action: none; }
#t-stick { position: absolute; width: 132px; height: 132px; border-radius: 50%; left: calc(22px + env(safe-area-inset-left)); bottom: calc(18px + env(safe-area-inset-bottom));
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.16)); border: 2px solid rgba(255, 255, 255, 0.3); opacity: 0.7; transition: opacity 0.15s; }
#t-stick::before, #t-stick::after { content: ""; position: absolute; left: 50%; top: 50%; background: rgba(255, 255, 255, 0.18); border-radius: 3px; transform: translate(-50%, -50%); }
#t-stick::before { width: 76%; height: 6px; } #t-stick::after { width: 6px; height: 76%; }
#t-stick.on { opacity: 0.9; }
#t-knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; z-index: 1;
  background: radial-gradient(circle at 40% 35%, #fff4d8, var(--gold)); box-shadow: 0 0 18px rgba(255, 210, 120, 0.6); }
.t-btn { pointer-events: auto; touch-action: none; position: absolute; border-radius: 50%; padding: 0; font-size: 22px; font-weight: 900;
  color: #fff; background: radial-gradient(circle at 50% 40%, rgba(90, 70, 170, 0.75), rgba(20, 14, 48, 0.8)); border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); display: grid; place-items: center; transform: none; }
.t-btn.down { transform: scale(0.92); background: radial-gradient(circle at 50% 40%, rgba(255, 220, 140, 0.9), rgba(200, 140, 60, 0.9)); color: #2a1a40; }
#t-buttons { position: absolute; right: calc(16px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom)); width: 210px; height: 190px; }
.t-jump { right: 0; bottom: 0; width: 96px; height: 96px; font-size: 34px; }
.t-dash { right: 108px; bottom: 6px; width: 70px; height: 70px; }
.t-e { right: 18px; bottom: 112px; width: 64px; height: 64px; }
#t-pause { left: calc(12px + env(safe-area-inset-left)); top: calc(62px + env(safe-area-inset-top)); width: 48px; height: 48px; font-size: 18px; }
body.touch #hud-abilities { top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); gap: 10px; pointer-events: auto; z-index: 4; }
body.touch #hud-abilities .ability { width: 56px; height: 56px; }
body.touch #hud-abilities .ability.tapped { transform: scale(0.9); box-shadow: 0 0 22px rgba(140, 220, 255, 0.9); }
body.touch .ability .key { display: none; }
body.touch #hud-crystals { left: calc(12px + env(safe-area-inset-left)); top: calc(8px + env(safe-area-inset-top)); }
/* kleine Bildschirme (Handy quer): Titel, Kapitel und Menues kompakter */
@media (max-height: 520px) {
  .title-panel { bottom: 2vh; gap: 8px; }
  button.big { font-size: 22px; padding: 8px 40px; }
  .chapters { gap: 6px; max-height: 34vh; overflow-y: auto; padding: 2px 8px; }
  .chapters button { font-size: 12px; padding: 5px 10px; }
  .title-help { font-size: 12px; padding: 5px 12px; }
  .panel { padding: 14px 20px; gap: 8px; }
  #dialog .text { font-size: 15px; }
  #credits h1 { font-size: 30px; }
}
/* Handy hochkant: bitte drehen */
#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #rotate-hint { display: grid; place-items: center; align-content: center; gap: 16px; position: fixed; inset: 0; z-index: 20;
    background: #120d28; color: var(--gold); font-family: "Cinzel", serif; font-size: 20px; text-align: center; padding: 30px; }
  body.touch #rotate-hint div { font-size: 64px; animation: spin-hint 2.4s ease-in-out infinite; }
}
@keyframes spin-hint { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }

/* Texte fest oben links neben dem Kristall-Zaehler (Dialog, darunter Tipps) - nichts springt, das Spielfeld bleibt frei.
   Die Spalte reicht bis kurz vor die Faehigkeits-Symbole oben rechts (--abil-w setzt das HUD). */
#messages { position: absolute; left: 150px; top: 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  max-width: min(620px, calc(100vw - 150px - var(--abil-w, 360px) - 44px)); pointer-events: none; }
#messages.below-boss { top: 112px; }
#messages #dialog { position: static; transform: none; width: auto; max-width: 100%; padding: 8px 16px 8px 8px; gap: 12px; border-radius: 16px;
  animation: msgin 0.25s ease-out; }
#messages #dialog .portrait { width: 52px; height: 52px; }
#messages #dialog .name { font-size: 14px; }
#messages #dialog .text { font-size: 17px; line-height: 1.3; min-height: 0; }
#messages #hint { position: static; transform: none; max-width: 100%; text-align: left; font-size: 16px; padding: 7px 14px; border-radius: 12px;
  animation: msgin 0.25s ease-out; }
@keyframes msgin { from { opacity: 0; transform: translateY(-6px); } }
#prompt { bottom: 14px; }
body.touch #messages { left: calc(104px + env(safe-area-inset-left)); top: calc(8px + env(safe-area-inset-top));
  max-width: calc(100vw - 104px - var(--abil-w, 330px) - 30px); }
body.touch #messages #dialog { padding: 5px 10px 5px 5px; gap: 8px; border-radius: 12px; }
body.touch #messages #dialog .portrait { width: 34px; height: 34px; }
body.touch #messages #dialog .name { font-size: 11px; letter-spacing: 1px; }
body.touch #messages #dialog .text { font-size: 13px; }
body.touch #messages #hint { font-size: 13px; padding: 5px 10px; }
body.touch #prompt { bottom: 8px; font-size: 13px; }
@media (max-width: 1000px) { #messages { left: 130px; } #messages #dialog .text { font-size: 15px; } }
/* iPhone: kein Vollbild im Browser - Hinweis auf dem Titelbild */
#ios-hint { display: none; }
body.ios-hint #ios-hint { display: block; position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(20, 14, 48, 0.8); border: 1px solid var(--panel-edge); border-radius: 12px; padding: 6px 14px; font-size: 13px; text-align: center; max-width: 90vw; }

/* Y8: Konto-Kasten auf dem Titelbild (Gaeste spielen ohne Anmeldung) */
#account { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); z-index: 2;
  background: rgba(20, 14, 48, 0.78); border: 1px solid var(--panel-edge); border-radius: 12px; padding: 6px 8px 6px 12px; font-size: 13px; max-width: min(430px, 60vw); }
#account > div { display: flex; align-items: center; gap: 10px; }
#account button { font-size: 13px; padding: 5px 12px; border-radius: 9px; box-shadow: 0 2px 0 var(--gold-deep); flex: none; }
#account b { color: var(--gold); }
#blocked { background: #120d28; z-index: 30; text-align: center; }
#blocked p { font-size: 18px; line-height: 1.6; }

/* Titelbild in kleinen Fenstern (Y8 960x540, 800x450, Handy quer): alles bleibt sichtbar - die Kapitelliste
   scrollt, "Play" und die Schwierigkeit stehen immer im Bild */
.title-panel { top: 2vh; justify-content: flex-end; max-height: 96vh; }
.title-panel > * { flex-shrink: 0; }
.title-panel .chapters { flex-shrink: 1; min-height: 44px; overflow-y: auto; overscroll-behavior: contain; padding: 4px 10px; }
@media (max-height: 700px) {
  .title-panel { bottom: 2vh; gap: 8px; }
  .title-panel .title-help, .title-panel .diff-info { display: none; }
  body.touch .title-panel .touch-help { display: none; }
  .chapters button { font-size: 13px; padding: 5px 12px; }
  button.big { font-size: 24px; padding: 8px 44px; }
  .difficulty button { font-size: 15px; padding: 5px 14px; }
}


/* Handy: keine Escape-Taste - Hinweis im Pausenmenue ausblenden */
body.touch #pause-screen button small { display: none; }
