:root {
  --bg: #0f172a;
  --bg-strong: #030712;
  --panel: rgba(15, 23, 42, 0.82);
  --panel-alt: #172033;
  --surface: #f8fafc;
  --text: #e2e8f0;
  --muted: #a5b4cf;
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(245, 158, 11, 0.18), transparent 25%),
    radial-gradient(circle at 85% 80%, rgba(59, 130, 246, 0.12), transparent 30%),
    var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
}

button, img { display: block; }

button {
  font: inherit;
}

/* ------------------------------------------------------------------
   Grundlayout: Die App füllt genau den sichtbaren Bereich (dvh).
   Foto, Antworten und Buttons teilen sich den Platz, damit nichts
   gescrollt werden muss. Nur wenn der Platz wirklich zu klein ist,
   wächst die Seite (min-height) und scrollt als Notlösung.
   ------------------------------------------------------------------ */
.app-shell {
  display: flex;
  flex-direction: column;
  width: min(1100px, calc(100% - 2rem));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(0.6rem, env(safe-area-inset-top))
    0
    max(0.75rem, env(safe-area-inset-bottom));
}

main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.topbar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
  min-height: 48px;
}

.brand { display: flex; align-items: center; gap: 0.8rem; min-width: 0; }

.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 42px;
  height: 48px;
  filter: drop-shadow(0 6px 14px rgba(255, 134, 127, 0.35));
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.9rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

h1 span { color: var(--primary); }

.score-pill {
  flex: none;
  padding: 0.5rem 0.9rem;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.09);
  color: var(--primary);
  font-weight: 800;
  white-space: nowrap;
}

.screen { display: none; }
.screen.visible {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.loading-card,
.question-card,
.result-card,
.error-card {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.loading-card,
.error-card {
  width: min(560px, 100%);
  margin: auto;
  padding: clamp(1.5rem, 6vw, 3.5rem);
  text-align: center;
}

.loading-card h2,
.error-card h2,
.result-card h2 { margin: 0 0 0.75rem; }

.loading-card p,
.error-card p,
.result-summary { color: var(--muted); }

.spinner {
  width: 52px;
  height: 52px;
  margin: 0 auto 1.25rem;
  border: 4px solid rgba(245, 158, 11, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  flex: none;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
}

.progress-bar {
  width: 20%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #fb923c);
  transition: width 220ms ease;
}

.question-meta {
  display: flex;
  flex: none;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.round-label,
.category-label {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.11);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.category-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Karte füllt den restlichen Platz */
.question-card {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding: clamp(0.6rem, 1.5vw, 1.1rem);
}

.question-layout {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  grid-template-rows: minmax(0, 1fr);
  gap: clamp(0.6rem, 1.6vw, 1.25rem);
  min-height: 0;
}

/* Foto-Spalte: Foto nimmt den Platz, Copyright-Zeile steht darunter */
.photo-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.photo-frame {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 140px;
  overflow: hidden;
  border-radius: 18px;
  background: #0b1220;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.12);
}

.photo-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.photo-frame img.is-hidden { display: none; }

.photo-credit {
  flex: none;
  margin: 0.4rem 0.25rem 0;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.photo-credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(165, 180, 207, 0.5);
  text-underline-offset: 2px;
}

.photo-credit a:hover,
.photo-credit a:focus-visible {
  color: var(--primary);
  text-decoration-color: currentColor;
}

.photo-credit a:not([href]) {
  text-decoration: none;
  cursor: default;
}

/* Antwort-Spalte: vertikal zentriert, scrollt nur im Notfall in sich selbst */
.answer-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.answer-panel h2 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.05rem, 2.2vw, 1.7rem);
  line-height: 1.25;
}

.answers {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.answer-button {
  position: relative;
  width: 100%;
  min-height: 52px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--primary-dark);
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #1f2937;
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  font-weight: 700;
  line-height: 1.25;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

.answer-button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.answer-button:focus-visible,
.primary-button:focus-visible,
.photo-credit a:focus-visible { outline: 3px solid rgba(245, 158, 11, 0.7); outline-offset: 3px; }

.answer-button:disabled { cursor: default; }

/* Nach der Antwort: nicht gewählte Buttons abdunkeln, damit richtig/falsch hervorstechen */
.answer-button:disabled:not(.correct):not(.wrong) {
  opacity: 0.45;
}

.answer-button.correct {
  border-color: #16a34a;
  background: var(--success);
  color: #052e16;
}

.answer-button.wrong {
  border-color: #b91c1c;
  background: var(--danger);
  color: #fff;
}

.feedback {
  flex: none;
  margin-top: 0.5rem;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.3;
}

.feedback.success {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}

.feedback.error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.primary-button {
  flex: none;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #1f2937;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.primary-button:hover { transform: translateY(-1px); filter: brightness(1.05); }

.result-card {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 620px;
  min-height: 340px;
  margin: auto;
  padding: clamp(1.25rem, 6vw, 3.5rem);
  text-align: center;
}

.error-card { max-width: 620px; }

.result-badge {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.result-score {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  margin: 1rem 0 1.5rem;
  color: var(--primary);
  font-weight: 900;
}

.result-score span:first-child {
  font-size: clamp(2.6rem, 10vw, 4.2rem);
  line-height: 1;
}

/* ------------------------------------------------------------------
   Tablet & Handy im Hochformat: Foto oben (nimmt den Restplatz),
   Antworten kompakt darunter, beides ohne Scrollen sichtbar.
   ------------------------------------------------------------------ */
@media (max-width: 820px) and (orientation: portrait), (max-width: 680px) {
  .app-shell {
    width: calc(100% - 1rem);
  }

  .question-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .answer-panel {
    justify-content: flex-start;
    overflow: visible;
  }

  .answer-panel h2 {
    margin-bottom: 0.45rem;
    font-size: clamp(0.95rem, 4vw, 1.2rem);
  }

  /* Antworten als 2x2-Raster spart Höhe */
  .answers {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }

  .answer-button {
    min-height: 46px;
    padding: 0.45rem 0.6rem;
    border-radius: 14px;
    font-size: clamp(0.78rem, 3.3vw, 0.95rem);
  }

  .question-card { border-radius: 20px; }
  .photo-frame { border-radius: 14px; min-height: 120px; }
}

/* Sehr schmale Handys: Antworten untereinander, damit Namen lesbar bleiben */
@media (max-width: 340px) {
  .answers { grid-template-columns: 1fr; }
}

/* Niedrige Bildschirme (kleine Handys, Browserleisten): Kopf verdichten */
@media (max-height: 740px) {
  .topbar { min-height: 40px; margin-bottom: 0.25rem; }
  .brand-mark { width: 34px; height: 40px; }
  h1 { font-size: clamp(0.95rem, 2.4vw, 1.4rem); }
  .score-pill { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
  .question-meta { margin: 0.35rem 0; }
  .round-label, .category-label { padding: 0.2rem 0.6rem; font-size: 0.7rem; }
  .feedback { margin-top: 0.35rem; padding: 0.4rem 0.7rem; font-size: 0.8rem; }
  .primary-button { margin-top: 0.35rem; padding: 0.6rem 1rem; }
}

/* Querformat auf Handys: Foto und Antworten nebeneinander */
@media (max-height: 520px) and (orientation: landscape) {
  .app-shell {
    width: calc(100% - 1rem);
    padding-top: max(0.3rem, env(safe-area-inset-top));
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
  }

  .topbar { min-height: 32px; margin-bottom: 0.2rem; }
  .brand-mark { width: 26px; height: 30px; }
  h1 { font-size: 1rem; }
  .score-pill { padding: 0.25rem 0.65rem; font-size: 0.8rem; }

  .progress { height: 4px; }
  .question-meta { margin: 0.25rem 0; }
  .round-label, .category-label { padding: 0.15rem 0.55rem; font-size: 0.65rem; }

  .question-card { padding: 0.4rem; border-radius: 16px; }

  .question-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 0.5rem;
  }

  .photo-frame { min-height: 90px; border-radius: 12px; }
  .photo-credit { margin-top: 0.2rem; font-size: 0.62rem; }

  .answer-panel { justify-content: center; overflow-y: auto; }
  .answer-panel h2 { margin-bottom: 0.35rem; font-size: 0.85rem; }
  .answers { grid-template-columns: 1fr; gap: 0.3rem; }
  .answer-button { min-height: 34px; padding: 0.3rem 0.6rem; border-radius: 10px; font-size: 0.78rem; }

  .feedback { margin-top: 0.25rem; padding: 0.3rem 0.6rem; font-size: 0.72rem; }
  .primary-button { margin-top: 0.25rem; padding: 0.45rem 0.8rem; border-radius: 10px; font-size: 0.85rem; }
}

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