:root {
  --green-900: #1b5e20;
  --green-700: #2e7d32;
  --green-500: #43a047;
  --green-100: #e8f5e9;
  --amber: #f9a825;
  --amber-bg: #fff8e1;
  --red: #c62828;
  --red-bg: #ffebee;
  --dark-red: #8e0000;
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1d231d;
  --text-dim: #5c6b5c;
  --line: #e4e9e4;
  --chip-bg: var(--green-100);
  --chip-text: var(--green-900);
  --warn-text: #7a4a00;
  /* Haupt-Aktionsbutton: muss der auffälligste Punkt der Seite sein */
  --cta-bg: var(--green-900);
  --cta-text: #ffffff;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

/* Das hidden-Attribut darf nie durch display-Regeln (z.B. #loadingSection)
   überschrieben werden */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: #fff;
}

.logo { font-size: 34px; }

.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.3px;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  opacity: 0.9;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/* --- Buttons --- */

.btn {
  border: none;
  border-radius: 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active { transform: scale(0.97); }

.btn-big {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  font-size: 17px;
  min-height: 56px;
}

.btn-icon { font-size: 22px; }

.btn-primary { background: var(--green-700); color: #fff; }
.btn-primary:active { background: var(--green-900); }

.btn-secondary { background: var(--green-100); color: var(--chip-text); }

.btn-analyze {
  width: 100%;
  margin-top: 12px;
  padding: 16px;
  min-height: 56px;
  font-size: 17px;
  background: var(--cta-bg);
  color: var(--cta-text);
}

.btn-analyze:disabled {
  background: var(--line);
  color: var(--text-dim);
  cursor: not-allowed;
}

.btn-small {
  padding: 8px 14px;
  font-size: 13.5px;
}

.btn-ghost { background: var(--line); color: var(--text-dim); }

.btn-overlay {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  backdrop-filter: blur(4px);
}

/* Sichtbarer Fokus für Tastatur- und Switch-Bedienung */
.btn:focus-visible,
.history-item:focus-visible,
.merkmale summary:focus-visible {
  outline: 3px solid var(--green-500);
  outline-offset: 2px;
}

.capture-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

/* --- Vorschau --- */

#previewWrap {
  position: relative;
  margin-bottom: 12px;
}

#preview {
  width: 100%;
  max-height: 320px;
  /* contain statt cover: der Nutzer soll genau das sehen, was die KI bekommt */
  object-fit: contain;
  background: var(--line);
  border-radius: 12px;
  display: block;
}

#previewWrap .btn {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* --- Ladezustand --- */

#loadingSection {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px;
}

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid var(--green-100);
  border-top-color: var(--green-700);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.loading-text {
  margin: 14px 0 0;
  font-weight: 600;
  text-align: center;
}

#btnCancel { margin-top: 14px; }

/* --- Ergebnis --- */

.result-card { overflow: hidden; }

.result-head { margin-bottom: 6px; }

.result-head h2 {
  margin: 0;
  font-size: 22px;
}

.latin {
  font-style: italic;
  color: var(--text-dim);
  font-size: 14px;
}

.kurz {
  margin: 10px 0 0;
  font-size: 14.5px;
}

.confidence { margin: 14px 0 4px; }

.confidence-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.confidence-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 999px;
  width: 0;
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.conf-high { background: var(--green-500); }
.conf-mid { background: var(--amber); }
.conf-low { background: var(--red); }

.conf-warning {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--red);
  font-weight: 600;
}

.verdicts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.verdict {
  border-radius: 12px;
  padding: 12px;
  font-size: 13.5px;
}

.verdict .animal {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.verdict .urteil {
  display: inline-block;
  margin: 8px 0 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}

.verdict p { margin: 0; }

.v-ok { background: var(--green-100); }
.v-ok .urteil { background: var(--green-700); color: #fff; }

.v-warn { background: var(--amber-bg); }
.v-warn .urteil { background: var(--amber); color: #4e3c00; }

.v-bad { background: var(--red-bg); }
.v-bad .urteil { background: var(--red); color: #fff; }

.v-toxic { background: var(--red-bg); outline: 2px solid var(--red); }
.v-toxic .urteil { background: var(--dark-red); color: #fff; }

.section-title {
  margin: 18px 0 8px;
  font-size: 15px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--chip-bg);
  color: var(--chip-text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.warnings {
  margin: 0;
  padding-left: 20px;
  font-size: 13.5px;
  color: var(--warn-text);
}

.warnings li { margin-bottom: 4px; }

.error-card {
  background: var(--red-bg);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--red);
  font-weight: 600;
}

/* --- Verlauf --- */

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.history-header h2 {
  margin: 0;
  font-size: 17px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--card);
  border: none;
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px 12px 8px 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.history-item:active { transform: scale(0.99); }

.h-text { min-width: 0; }

.history-item .h-name,
.history-item .h-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
}

.history-item .h-name { font-weight: 700; font-size: 14.5px; }
.history-item .h-meta { font-size: 12px; color: var(--text-dim); }
.history-item .h-badges { margin-left: auto; font-size: 15px; }

.app-footer {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 4px 10px 0;
}

/* --- Giftalarm --- */

.toxic-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--dark-red);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.toxic-icon { font-size: 22px; }

.result-card.has-toxic {
  outline: 2px solid var(--dark-red);
  outline-offset: -2px;
}

/* --- Fütterungs-Fakten --- */

.familie {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.facts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fact {
  background: var(--chip-bg);
  border-radius: 12px;
  padding: 10px 12px;
}

.fact-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--chip-text);
  opacity: 0.85;
  margin-bottom: 2px;
}

.fact-value { font-size: 14px; }

/* --- Verwechselbare Arten --- */

.alts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alt {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.alt-toxic {
  border-color: var(--red);
  background: var(--red-bg);
}

.alt-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 700;
  font-size: 14px;
}

.alt-badge {
  background: var(--dark-red);
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 700;
}

.alt-diff {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* --- Erkannte Merkmale --- */

.merkmale {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.merkmale summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  border-radius: 6px;
}

.merkmale p {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

@media (min-width: 480px) {
  .capture-buttons { flex-direction: row; }
  .facts { flex-direction: row; }
  .facts .fact { flex: 1; }
}

/* Sehr schmale Geräte: Urteile untereinander statt gequetscht */
@media (max-width: 360px) {
  .verdicts { grid-template-columns: 1fr; }
}

/* Bewegung reduzieren, wenn das System es verlangt */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner {
    animation: none !important;
    border-top-color: var(--green-700);
  }
}
