/* KI-Adventkalender – Basis: Tokens, Reset, Kopfzeile, Dorf-Einpassung, Tuerchen-Overlay */

:root {
  --ak-night: #0B1D3A;
  --ak-night-2: #16305C;
  --ak-snow: #F4F7FB;
  --ak-gold: #FFC857;
  --ak-warm: #FFE9A8;
  --ak-wood: #7A4E2D;
  --ak-ink: #1B2A41;
  --ak-card: #FFFFFF;
  --ak-w1: #2E7D4F;
  --ak-w2: #B3263B;
  --ak-w3: #D4A017;
  --ak-w4: #6EC1E4;
  --ak-ok: #3BA66B;
  --ak-warn: #E0A526;
  --ak-font: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --hdr-h: 64px;
}

[hidden] { display: none !important; }
dialog:not([open]) { display: none; }

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  font-family: var(--ak-font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ak-snow);
  background: linear-gradient(180deg, var(--ak-night) 0%, var(--ak-night-2) 100%) fixed;
  background-color: var(--ak-night);
  min-height: 100vh;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 3px solid var(--ak-gold); outline-offset: 2px; }

/* ------------------------------------------------------------ Kopfzeile */
#hdr {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: var(--hdr-h); padding: 8px 20px;
  background: rgba(11, 29, 58, .85);
  border-bottom: 1px solid rgba(255, 200, 87, .25);
}
#hdr h1 { font-size: 1.25rem; line-height: 1.2; color: var(--ak-gold); }
#subtitle { font-size: .875rem; opacity: .8; }
.hdr-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
#progress {
  padding: 4px 12px; border-radius: 999px; font-weight: 600;
  background: rgba(255, 200, 87, .15); color: var(--ak-warm);
}
#langSwitch { display: inline-flex; border: 1px solid rgba(244, 247, 251, .35); border-radius: 8px; overflow: hidden; }
#langSwitch button { background: transparent; border: 0; padding: 6px 12px; min-height: 36px; }
#langSwitch button[aria-pressed="true"] { background: var(--ak-gold); color: var(--ak-ink); font-weight: 700; }
#soundBtn, #musicBtn {
  background: transparent; border: 1px solid rgba(244, 247, 251, .35); border-radius: 8px;
  padding: 6px 12px; min-height: 36px;
}
#musicBtn[data-state="ready"] { border-style: dashed; }
#musicBtn[data-state="off"] { opacity: .75; }

/* --------------------------------------------------------------- Buttons */
.btn {
  border: 2px solid transparent; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  font-weight: 600; background: var(--ak-night-2); color: var(--ak-snow);
}
.btn-primary { background: var(--ak-w1); color: #fff; }
.btn-gold { background: var(--ak-gold); color: var(--ak-ink); }
.btn-ghost { background: transparent; border-color: rgba(27, 42, 65, .3); color: var(--ak-ink); }
.btn:hover:not(:disabled) { filter: brightness(1.1); }
#hdr .btn-gold { min-height: 36px; padding: 6px 14px; }

/* ------------------------------------------------------ Dorf (16:9 einpassen) */
#village {
  position: relative;
  width: min(100%, calc((100vh - var(--hdr-h)) * 16 / 9));
  aspect-ratio: 16 / 9;
  margin: 0 auto;
}
#village > svg { display: block; width: 100%; height: 100%; }
#village .door { cursor: pointer; }
#village .door.locked { cursor: not-allowed; }
#countdown {
  position: absolute; z-index: 2; top: 12px; left: 50%; transform: translateX(-50%);
  padding: 8px 20px; border-radius: 999px; font-weight: 700; text-align: center;
  background: rgba(11, 29, 58, .88); color: var(--ak-gold); border: 1px solid var(--ak-gold);
}
.village-error { padding: 24px; color: var(--ak-warm); }
#doorTip {
  position: fixed; z-index: 50; max-width: 280px; padding: 8px 12px; border-radius: 8px;
  background: var(--ak-card); color: var(--ak-ink); font-size: .9rem; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
  display: flex; flex-direction: column; gap: 2px;
}
body.show-cert #village { display: none; }

/* ------------------------------------------------------- Tuerchen-Overlay */
#door, #finale {
  border: 0; padding: 0; background: transparent; color: var(--ak-ink);
  max-width: 960px; width: calc(100% - 32px); max-height: calc(100vh - 32px);
}
#door::backdrop, #finale::backdrop { background: rgba(5, 12, 28, .75); }
#door[open] { display: block; }

.door-card {
  --week: var(--ak-w1);
  background: var(--ak-card); border-radius: 16px; overflow: hidden;
  border-top: 8px solid var(--week);
  display: flex; flex-direction: column; max-height: calc(100vh - 32px);
}
.door-card[data-week="2"] { --week: var(--ak-w2); }
.door-card[data-week="3"] { --week: var(--ak-w3); }
.door-card[data-week="4"] { --week: var(--ak-w4); }

#doorHead { display: flex; align-items: center; gap: 16px; padding: 16px 24px 8px; }
.door-day {
  flex: none; width: 56px; height: 56px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.75rem; font-weight: 800; background: var(--week); color: #fff;
}
.door-card[data-week="3"] .door-day, .door-card[data-week="4"] .door-day { color: var(--ak-ink); }
#doorWeek { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }
#doorTitle { font-size: 1.4rem; line-height: 1.25; }
#doorTeaser { font-size: .95rem; opacity: .75; }

#doorSteps { list-style: none; display: flex; gap: 8px; margin: 0; padding: 8px 24px; }
#doorSteps .step { display: flex; align-items: center; gap: 6px; font-size: .85rem; opacity: .55; }
#doorSteps .step.current { opacity: 1; font-weight: 700; }
#doorSteps .step.past { opacity: .8; }
#doorSteps .dot {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem;
  border: 2px solid var(--week); color: var(--ak-ink);
}
#doorSteps .step.current .dot, #doorSteps .step.past .dot { background: var(--week); color: #fff; }
.door-card[data-week="3"] #doorSteps .step.current .dot, .door-card[data-week="3"] #doorSteps .step.past .dot,
.door-card[data-week="4"] #doorSteps .step.current .dot, .door-card[data-week="4"] #doorSteps .step.past .dot { color: var(--ak-ink); }

#doorBody { flex: 1 1 auto; overflow-y: auto; padding: 8px 24px 16px; min-height: 240px; }
#doorBody p { max-width: 70ch; }

.scene { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.speaker { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.speaker .avatar { width: 56px; height: 56px; }
.scene-text { font-size: 1.15rem; }
.scene-img, .card-img { width: 100%; max-width: 640px; height: auto; border-radius: 12px; background: var(--ak-night-2); }
.card { display: flex; flex-direction: column; gap: 10px; }
.card h3 { font-size: 1.2rem; }
.card-count { margin-top: 8px; font-size: .85rem; opacity: .65; }
.task-prompt { font-weight: 600; margin-bottom: 12px; }
.missing { padding: 12px 16px; border-radius: 8px; background: #fff3cd; color: #5c4400; font-weight: 600; }
.takeaway { padding: 16px 20px; border-radius: 12px; background: var(--ak-warm); border-left: 6px solid var(--ak-gold); }
.takeaway h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.takeaway-text { font-size: 1.2rem; font-weight: 600; }
.badge-done { margin-top: 10px; font-weight: 700; color: #1f6b43; }

#doorNav { display: flex; align-items: center; gap: 10px; padding: 12px 24px 18px; border-top: 1px solid rgba(27, 42, 65, .12); }
#doorNav .spacer { flex: 1; }

/* ----------------------------------------------------------------- Finale */
.finale-card { background: var(--ak-card); border-radius: 16px; padding: 28px; border-top: 8px solid var(--ak-gold); display: flex; flex-direction: column; gap: 12px; }
.finale-card h2 { font-size: 1.5rem; }
.finale-card label { font-weight: 600; }
.finale-card input { font: inherit; padding: 10px 12px; border: 2px solid var(--ak-night-2); border-radius: 8px; color: var(--ak-ink); }
.finale-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#finale { max-width: 520px; }

/* ------------------------------------------------------------- Zertifikat */
#certificate { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
#certMount { width: min(100%, 1100px); background: #fff; border-radius: 8px; overflow: hidden; }
#certMount svg { display: block; width: 100%; height: auto; }
#certNote { padding: 8px 14px; border-radius: 8px; background: #fff3cd; color: #5c4400; font-weight: 600; text-align: center; }
#certActions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#certActions .btn-ghost { border-color: rgba(244, 247, 251, .5); color: var(--ak-snow); }

/* ----------------------------------------------------------------- Mobil */
@media (max-width: 700px) {
  #hdr { flex-direction: column; align-items: stretch; padding: 8px 12px; }
  #hdr h1 { font-size: 1.05rem; }
  .hdr-tools { justify-content: space-between; gap: 6px; flex-wrap: wrap; width: 100%; }
  #progress { padding: 2px 8px; font-size: .9rem; }
  #langSwitch button, #soundBtn, #musicBtn { padding: 4px 8px; min-height: 36px; }
  #soundBtn, #musicBtn { font-size: .85rem; }
  #subtitle { display: none; }
  /* Dorf scrollt in eigenem Container horizontal; Seite und Kopfzeile bleiben Viewport-breit */
  #village { width: 100%; max-width: 100%; aspect-ratio: auto; margin: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  #village > svg { width: 800px; max-width: none; height: auto; }
  body { overflow-x: hidden; }
  #door, #finale { width: 100%; max-width: none; max-height: none; height: 100%; margin: 0; }
  #door[open] { height: 100%; }
  .door-card { max-height: none; height: 100%; border-radius: 0; }
  #doorHead { padding: 12px 16px 4px; }
  #doorTitle { font-size: 1.2rem; }
  #doorSteps { padding: 8px 16px; }
  #doorSteps .lbl { display: none; }
  #doorSteps .step.current .lbl { display: inline; }
  #doorBody { padding: 8px 16px 12px; }
  #doorNav { padding: 10px 16px 14px; flex-wrap: wrap; }
  #finale { height: auto; margin: auto; width: calc(100% - 24px); }
}

/* ------------------------------------------------ Hochformat am Smartphone (WP8)
   Klasse body.layout-portrait setzt app.js (Hochformat und Breite <= 700 px); das Dorf-SVG
   wechselt dann per js/village-layout.js auf das 900x1860-Layout. */
#village > svg .door { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body.layout-portrait { overflow-x: hidden; }
body.layout-portrait #village { width: 100%; max-width: 100%; aspect-ratio: auto; margin: 0; overflow: visible; }
body.layout-portrait #village > svg { width: 100%; max-width: none; height: auto; }
body.layout-portrait #countdown { top: 8px; width: calc(100% - 24px); max-width: 420px; font-size: 1rem; }
body.layout-portrait #hdr { gap: 6px; }
body.layout-portrait .hdr-tools { gap: 8px; }
body.layout-portrait #progress { font-size: 1rem; padding: 6px 12px; }
body.layout-portrait #langSwitch button { min-height: 44px; min-width: 44px; font-size: 1rem; }
body.layout-portrait #soundBtn, body.layout-portrait #musicBtn, body.layout-portrait #hdr .btn-gold { min-height: 44px; font-size: 1rem; padding: 6px 12px; }
/* Tuerchen-Overlay: Vollbild, Schrittleiste oben, Inhalt scrollt, Buttons unten */
body.layout-portrait #door, body.layout-portrait #finale { max-width: none; }
body.layout-portrait #door, body.layout-portrait #door[open] { width: 100%; height: 100%; max-height: none; margin: 0; }
body.layout-portrait .door-card { max-height: none; height: 100%; border-radius: 0; border-top-width: 6px; }
body.layout-portrait #doorHead { padding: 10px 16px 4px; gap: 12px; }
body.layout-portrait .door-day { width: 48px; height: 48px; font-size: 1.5rem; }
body.layout-portrait #doorWeek { font-size: 1rem; }
body.layout-portrait #doorTitle { font-size: 1.25rem; }
body.layout-portrait #doorTeaser { font-size: 1rem; }
body.layout-portrait #doorSteps { justify-content: space-between; align-items: center; padding: 8px 16px; gap: 6px; border-bottom: 1px solid rgba(27, 42, 65, .12); }
body.layout-portrait #doorSteps .step { font-size: 1rem; }
body.layout-portrait #doorSteps .dot { width: 32px; height: 32px; font-size: 1rem; }
body.layout-portrait #doorBody { min-height: 0; padding: 12px 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
body.layout-portrait .scene-text { font-size: 1.1rem; }
/* Touch-Ziele in Aufgaben >= 44 px (Chips; Hotspot-Flaechen auf Bildern bekommen eine unsichtbare Vergroesserung) */
body.layout-portrait .ak-item { min-height: 44px; }
body.layout-portrait .ak-spot::before { content: ""; position: absolute; inset: -14px -6px; }
body.layout-portrait .card-count, body.layout-portrait .takeaway h3, body.layout-portrait .recap-item { font-size: 1rem; }
body.layout-portrait #doorNav { position: sticky; bottom: 0; background: var(--ak-card); gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); flex-wrap: nowrap; }
body.layout-portrait #doorNav .spacer { display: none; }
body.layout-portrait #doorNav .btn { flex: 1 1 0; min-width: 0; min-height: 48px; padding: 8px 10px; font-size: 1rem; }
body.layout-portrait #doorNav .btn[hidden] { display: none; }
/* Finale: passt ohne Zoom, Buttons untereinander */
body.layout-portrait #finale { height: auto; max-height: calc(100% - 24px); margin: auto; width: calc(100% - 24px); overflow-y: auto; }
body.layout-portrait .finale-card { padding: 20px 16px; }
body.layout-portrait .finale-card input { min-height: 48px; font-size: 1rem; }
body.layout-portrait .finale-actions { flex-direction: column-reverse; align-items: stretch; }
body.layout-portrait .finale-actions .btn { width: 100%; min-height: 48px; }
/* Zertifikat: auf Bildschirmbreite skaliert, Buttons darunter */
body.layout-portrait #certificate { padding: 8px; gap: 12px; }
body.layout-portrait #certMount { width: 100%; }
body.layout-portrait #certNote { font-size: 1rem; }
body.layout-portrait #certActions { flex-direction: column; align-items: stretch; width: 100%; }
body.layout-portrait #certActions .btn { width: 100%; min-height: 48px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* Tag 24: Rueckblick */
.recap { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 6px; }
.recap-item { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; }
.recap-ball {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: .75rem; font-weight: 700; background: var(--ak-w1); color: #fff;
}
.recap-item.week-2 .recap-ball { background: var(--ak-w2); }
.recap-item.week-3 .recap-ball { background: var(--ak-w3); color: var(--ak-ink); }
.recap-item.week-4 .recap-ball { background: var(--ak-w4); color: var(--ak-ink); }
