:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #dfe4ee;
  --text: #16202f;
  --muted: #5d6b83;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #e8efff;
  --danger: #b42318;
  --ok: #067647;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

/*
 * Muss vor allen Layoutregeln stehen: Klassenselektoren mit display-Angabe
 * (z.B. .stage-fallback { display: grid }) schlagen sonst die Browser-Regel
 * fuer [hidden]. Ein "verstecktes" Overlay bliebe dann sichtbar bzw. laege
 * unsichtbar ueber dem App-Iframe und wuerde alle Klicks abfangen.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

.layout { display: flex; flex-direction: column; height: 100%; }

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.65rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

.progress { display: flex; align-items: center; gap: 0.75rem; flex: 1; max-width: 460px; }
.progress-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }
.progress-label { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.timer { font-variant-numeric: tabular-nums; font-size: 0.9rem; color: var(--muted); }
.timer strong { color: var(--text); }

/* --- Layout --- */
.main { flex: 1; display: flex; min-height: 0; }

.panel {
  flex: 1 1 100%;
  overflow-y: auto;
  padding: 2rem clamp(1rem, 4vw, 3rem) 4rem;
  /* Spalte, damit neben der Schrittkarte auch die Zugangsdaten-Karte passt. */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.main.split .panel {
  flex: 0 0 clamp(380px, 38%, 620px);
  align-items: stretch;
  padding: 1.5rem 1.5rem 3rem;
}

.card-credentials {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1.25rem;
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
}
.card-credentials .bar-label { text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.68rem; color: var(--muted); }
.card-credentials .cred b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; user-select: all; }

.stage {
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--border);
  background: #0b1220;
  position: relative;
  display: flex;
  flex-direction: column;
}
.stage iframe { flex: 1; width: 100%; min-height: 0; border: 0; display: block; background: var(--surface); }

/* Zugangsdaten-Leiste: waehrend der Aufgaben immer sichtbar ueber der App. */
.stage-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1.25rem;
  padding: 0.5rem 0.9rem;
  background: #101a2c;
  color: #c8d3e6;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.stage-bar .bar-label { text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.68rem; color: #8ea1bf; }
.stage-bar .cred { display: inline-flex; align-items: baseline; gap: 0.35rem; }
.stage-bar .cred b {
  font-weight: 600;
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: all; /* ein Klick markiert den ganzen Wert */
}
.stage-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 2rem; color: #fff; text-align: center; }
.stage-fallback code { background: rgba(255,255,255,0.12); padding: 0.15rem 0.4rem; border-radius: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3vw, 2.25rem);
  width: 100%;
  max-width: 720px;
}
.main.split .card { max-width: none; }

h1 { font-size: clamp(1.4rem, 2.5vw, 1.85rem); margin: 0 0 1rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; }
p { margin: 0 0 1rem; }
.prose { color: var(--text); }
.prose strong { font-weight: 650; }
.prose code {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.92em;
}
.muted { color: var(--muted); font-size: 0.9rem; }

/* --- Aufgaben --- */
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; font-weight: 700; color: var(--accent); margin-bottom: 0.4rem; }
.scenario {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.goal { border: 1px solid var(--border); border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1rem; }
.goal-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.25rem; }
.hint { background: #fff8e6; border: 1px solid #f3dfae; border-radius: 8px; padding: 0.75rem 0.9rem; margin-bottom: 1rem; }

/* Rueckmeldung, sobald die App das Aufgabenziel meldet. */
.goal-reached {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: #e7f6ec;
  border: 1px solid #a7d8b8;
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  margin: 1rem 0 0;
  color: #14532d;
  animation: goal-pop 0.25s ease-out;
}
.goal-reached.compact { margin: 0 0 1.25rem; }
.goal-reached strong { display: block; }
.goal-check {
  flex: 0 0 auto;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  line-height: 1;
}
.goal-detail { font-size: 0.88rem; }
@keyframes goal-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.goal-missing {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.btn-success { background: var(--ok); border-color: var(--ok); }
.btn-success:hover { background: #05603a; }

@media (prefers-color-scheme: dark) {
  .goal-reached { background: #12301f; border-color: #245c39; color: #b7e8c8; }
}

/* --- Formularelemente --- */
fieldset { border: 0; padding: 0; margin: 0 0 1.75rem; }
legend { font-weight: 600; padding: 0; margin-bottom: 0.6rem; }
.field-hint { color: var(--muted); font-size: 0.88rem; margin: -0.35rem 0 0.6rem; }
.required-star { color: var(--danger); }

.options { display: flex; flex-direction: column; gap: 0.4rem; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.option:hover { border-color: #b9c4da; }
.option input { margin: 0.25rem 0 0; accent-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

textarea, input[type='text'] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
textarea:focus, input:focus-visible, .option:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- Likert --- */
.likert { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.likert.invalid { border-color: var(--danger); }
.likert-question { font-weight: 550; margin-bottom: 0.75rem; }
.likert-question .num { color: var(--muted); font-weight: 600; margin-right: 0.4rem; }
.likert-scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.35rem; }
.likert-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.25rem;
  transition: border-color 0.15s, background 0.15s;
}
.likert-option input { accent-color: var(--accent); margin: 0; }
.likert-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.likert-endlabels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }

/* --- SEQ --- */
.seq-scale { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.3rem; }
.seq-scale .likert-option { font-size: 0.85rem; font-weight: 600; }

/* --- Buttons --- */
.actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 1.5rem; }
.actions .spacer { flex: 1; }
.btn {
  font: inherit;
  font-weight: 550;
  border-radius: 8px;
  padding: 0.6rem 1.15rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: #b9c4da; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); font-size: 0.85rem; padding: 0.4rem 0.75rem; }
.btn-ghost:hover { color: var(--text); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { border-color: #f0c4bf; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-box { color: var(--danger); background: #fef3f2; border: 1px solid #f6cfc9; border-radius: 8px; padding: 0.6rem 0.85rem; margin-top: 1rem; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #16202f;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 20;
}

.footnote { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.78rem; color: var(--muted); }

/* --- Schmale Fenster: App unter die Aufgabe --- */
@media (max-width: 900px) {
  .main.split { flex-direction: column; }
  .main.split .panel { flex: 0 0 auto; max-height: 45%; }
  .stage { border-left: 0; border-top: 1px solid var(--border); min-height: 55%; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #161d29;
    --border: #2a3546;
    --text: #e7ecf5;
    --muted: #98a5ba;
    --accent: #6d9bff;
    --accent-dark: #8fb2ff;
    --accent-soft: #1d2940;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
  .hint { background: #2a2313; border-color: #4a3d1c; }
  .error-box { background: #2a1614; border-color: #5c2a24; color: #ffb4a8; }
}
