:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e4e4e2;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --accent: #1f7a5c;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --surface: #1e1e1a;
    --border: #33332d;
    --text: #ececE6;
    --muted: #9a9a92;
    --accent: #4fb58c;
    --accent-text: #0c0c08;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button { touch-action: manipulation; }
button:active { transform: translateY(1px); }

.wrap {
  max-width: 720px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           64px max(16px, env(safe-area-inset-left));
}

header.app {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 2px 18px;
}
header.app .brand { font-weight: 650; font-size: 1.15rem; letter-spacing: -0.01em; flex: 0 0 auto; }
header.app .brand span { color: var(--accent); }
header.app > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
header.app .who {
  font-size: 0.85rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42vw;
}
header.app button.link {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 0.85rem; text-decoration: underline;
  padding: 6px 2px; flex: 0 0 auto;
}
@media (max-width: 380px) { header.app .who { display: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

label.file {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center;
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 36px 16px; cursor: pointer; color: var(--muted);
}
label.file:hover { border-color: var(--accent); color: var(--text); }
label.file input { display: none; }

.cam-btn {
  width: 100%; min-height: 44px; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
/* nur auf Touch/kleinen Screens sinnvoll — auf dem Desktop ist "auswählen" genug */
@media (hover: hover) and (pointer: fine) { .cam-btn { display: none; } }

.preview { margin-top: 14px; }
.preview canvas {
  max-width: 100%; max-height: 46vh; width: auto; height: auto;
  border-radius: var(--radius); border: 1px solid var(--border); display: block; margin: 0 auto;
}
.preview.placeholder::before {
  content: "Vorschau nicht verfügbar – Analyse läuft trotzdem.";
  display: block; text-align: center; color: var(--muted); font-size: 0.85rem;
  padding: 24px; border: 1.5px dashed var(--border); border-radius: var(--radius);
}
.preview.placeholder canvas { display: none; }

.modes { display: flex; gap: 8px; margin: 14px 0; }
.modes button {
  flex: 1 1 0; min-width: 0; min-height: 44px;
  padding: 8px 6px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
}
.modes button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

button.primary {
  width: 100%; min-height: 48px; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: default; }

input[type="text"], input[type="email"], input[type="password"], input.code {
  width: 100%; min-height: 44px; padding: 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* ≥16px: kein iOS-Zoom */
}

.result { margin-top: 20px; }

/* --- "Übersicht mit KI" (Google-Lens-Stil) --- */
.ai-overview {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  background: var(--surface);
}
.ai-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.05rem; font-weight: 550; margin-bottom: 12px;
}
.ai-spark {
  color: var(--accent); font-size: 1.1rem; line-height: 1;
}
.ai-overview .body p { margin: 0 0 10px; }
.ai-overview .body p:last-child { margin-bottom: 0; }
.ai-overview .body ul { margin: 0 0 10px; padding-left: 20px; }
.ai-overview .body pre { white-space: pre-wrap; word-break: break-word; }
.ai-overview .body > div { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.ai-foot { font-size: 0.78rem; color: var(--muted); margin-top: 14px; }

/* --- "Visuelle Übereinstimmungen" grid --- */
.matches { margin-top: 26px; }
.matches h3 { font-size: 1.15rem; font-weight: 500; margin: 0 0 2px; }
.matches-note { font-size: 0.8rem; color: var(--muted); margin: 0 0 14px; }
.matches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px 12px;
}
@media (max-width: 560px) {
  .matches-grid { grid-template-columns: repeat(3, 1fr); gap: 14px 8px; }
}
.match { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text); }
.match-img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  transition: filter .12s;
}
.match:hover .match-img { filter: brightness(0.92); }
.match-src {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.75rem; color: var(--muted);
  overflow: hidden; white-space: nowrap;
}
.match-src span { overflow: hidden; text-overflow: ellipsis; }
.match-fav { width: 14px; height: 14px; border-radius: 3px; flex: 0 0 auto; }
.match-title {
  font-size: 0.82rem; line-height: 1.3; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted { color: var(--muted); }
.fu-answer { color: var(--muted); font-size: 0.92rem; padding: 4px 0; }

.followup { display: flex; gap: 8px; margin-top: 12px; }
.followup input { flex: 1; min-width: 0; }
.followup button {
  flex: 0 0 auto; min-width: 84px; min-height: 44px;
  padding: 0 16px; border: 1px solid var(--accent); border-radius: 8px;
  background: var(--surface); color: var(--accent); font: inherit; cursor: pointer;
}
.followup button:disabled { opacity: 0.7; cursor: default; }
.followup input:disabled { opacity: 0.6; }

.msg { padding: 10px 12px; border-radius: 8px; margin-top: 12px; font-size: 0.92rem; }
.msg.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.msg.info { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }

.login { max-width: 380px; margin: max(24px, 6vh) auto 0; }
.login h1 { font-size: 1.3rem; }
.login button.primary { margin-top: 4px; }
.login .field { margin-bottom: 12px; }
.login .hint { font-size: 0.87rem; color: var(--muted); margin-top: 14px; }

footer.app {
  max-width: 720px; margin: 40px auto 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  text-align: center; font-size: 0.85rem; color: var(--muted);
}
footer.app a { display: inline-block; margin: 4px 8px; padding: 4px; color: var(--muted); }

/* --- kleinere Screens: engere Ränder, kompaktere Karten --- */
@media (max-width: 480px) {
  .card { padding: 14px; }
  .ai-overview { padding: 15px 16px; border-radius: 14px; }
  .matches h3 { font-size: 1.05rem; }
  label.file { padding: 30px 14px; }
}

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
