/* Kisium Light – Design 2.0: dunkel, ruhig, große Zahlen, klare Hierarchie. */

:root {
  --bg: #080d16;
  --surface: #121a2a;
  --surface-2: #18223a;
  --line: #26324b;
  --ink: #f2f6ff;
  --muted: #93a3bd;
  --dim: #6d7c96;
  --mint: #4be3b0;
  --mint-ink: #052b21;
  --amber: #ffc53d;
  --red: #ff6f7d;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh;
  background:
    radial-gradient(90% 45% at 50% -8%, #1d2c47 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 460px; margin: 0 auto; }

/* ---------- Start / Hero ---------- */
.hero { text-align: center; padding: 30px 8px 24px; }
.hero-logo {
  width: 76px; height: 76px;
  margin: 0 auto 18px;
  border-radius: 23px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #ffd86b, #ffb300);
  box-shadow: 0 14px 34px -8px rgba(255, 179, 0, 0.55);
}
.hero-logo svg { width: 50px; height: 50px; }
.hero h1 {
  font-size: 1.9rem;
  font-weight: 760;
  letter-spacing: -0.025em;
  margin: 0 0 8px;
}
.hero-sub {
  color: var(--muted);
  margin: 0 auto;
  max-width: 30ch;
  font-size: 0.95rem;
}

/* ---------- Karten ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  margin: 0 0 12px;
  box-shadow: 0 20px 44px -30px #000;
}

h3 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 12px;
}

.muted { color: var(--muted); font-size: 0.92rem; margin: 0 0 6px; }
.tip { color: var(--dim); font-size: 0.83rem; text-align: center; margin: 6px 12px 0; }
.tip strong { color: var(--muted); }

/* ---------- Topbar der Mess-Ansicht ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 14px;
}
.eyebrow {
  margin: 0 0 2px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mint);
}
.title { font-size: 1.5rem; font-weight: 750; letter-spacing: -0.02em; margin: 0; }

#calStatus {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 197, 61, 0.12);
  border: 1px solid rgba(255, 197, 61, 0.3);
  color: var(--amber);
  white-space: nowrap;
}

/* ---------- Kamera ---------- */
#videoContainer {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #04070d;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}
#videoContainer video { width: 100%; height: 100%; object-fit: cover; display: block; }
#videoContainer::after {
  content: "Diffusor über die Linse – dann Raster scannen";
  position: absolute;
  bottom: 12px; left: 12px; right: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  text-align: center;
  color: #dbe6f7;
  background: rgba(6, 10, 18, 0.62);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

#canvas { display: none; }

#camError {
  background: rgba(255, 111, 125, 0.1);
  border: 1px solid rgba(255, 111, 125, 0.32);
  border-radius: var(--r-md);
  color: #ffc4ca;
  font-size: 0.9rem;
  padding: 12px 14px;
  margin: 0 0 12px;
}

/* ---------- Messwerte ---------- */
#results {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: grid;
  gap: 2px;
  min-width: 0;
}
.metric-label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.metric-value {
  font-size: 1.35rem;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.metric-unit { font-size: 0.63rem; color: var(--dim); }

.metric-hero {
  background: linear-gradient(155deg, rgba(75, 227, 176, 0.16), rgba(75, 227, 176, 0.04));
  border-color: rgba(75, 227, 176, 0.35);
}
.metric-hero .metric-value { font-size: 2.1rem; color: var(--mint); }
.metric-hero .metric-label { color: #8ff2d4; }

/* ---------- Buttons ---------- */
button { font: inherit; }

button,
.btn-primary,
.btn-quiet,
.btn-danger {
  min-height: 50px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 650;
  padding: 0 18px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}
button:active { transform: scale(0.98); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--mint);
  border-color: var(--mint);
  color: var(--mint-ink);
  box-shadow: 0 12px 26px -14px rgba(75, 227, 176, 0.85);
}
.btn-primary:hover { background: #6ceec2; }

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-quiet:hover { color: var(--ink); }

.btn-danger {
  background: transparent;
  border-color: rgba(255, 111, 125, 0.3);
  color: #ffb3ba;
}

.btn-block { display: block; width: 100%; margin-top: 10px; }

.actions { display: flex; gap: 10px; }
.actions > * { flex: 1; }
.btn-row { display: flex; gap: 10px; margin-top: 4px; }
.btn-row > * { flex: 1; }

/* ---------- Ergebnis-Listen ---------- */
.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--muted);
}
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv strong {
  color: var(--ink);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.prose { font-size: 0.92rem; color: var(--ink); margin: 10px 0 0; }
.prose strong { color: #fff; }

/* ---------- Aufklapp-Karten ---------- */
details.card { padding: 0; overflow: hidden; }
details.card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  min-height: 56px;
  font-weight: 650;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary small {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--dim);
}
details.card > summary::after {
  content: "+";
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--dim);
  margin-left: 4px;
  line-height: 1;
}
details.card[open] > summary::after { content: "–"; }
details.card[open] > summary { border-bottom: 1px solid var(--line); }
.details-body { padding: 16px 18px 18px; }

/* ---------- Formulare ---------- */
label {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--muted);
  margin-bottom: 12px;
}

input, select {
  width: 100%;
  min-height: 48px;
  background: #0d1420;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
input::placeholder { color: #56657f; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 359px) { .field-row { grid-template-columns: 1fr; gap: 0; } }

input[type="file"] {
  padding: 10px;
  font-size: 0.9rem;
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  padding: 9px 16px;
  margin-right: 12px;
  cursor: pointer;
}

/* ---------- Kleingeräte ---------- */
@media (max-width: 359px) {
  #results { grid-template-columns: 1fr 1fr; }
  .metric-hero { grid-column: 1 / -1; }
}

/* ================= Animationen ================= */

/* Karten gleiten beim Öffnen der Mess-Ansicht gestaffelt ein */
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
#measure.enter .card,
#measure.enter #results .metric {
  animation: cardIn 0.42s cubic-bezier(0.22, 0.8, 0.3, 1) both;
  animation-delay: var(--delay, 0ms);
}

/* Hero beim Laden */
@keyframes heroIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}
#permission .hero,
#permission .card,
#permission .tip {
  animation: heroIn 0.5s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}
#permission .card { animation-delay: 80ms; }
#permission .tip { animation-delay: 160ms; }

@keyframes logoGlow {
  0%, 100% { box-shadow: 0 14px 34px -8px rgba(255, 179, 0, 0.5); transform: translateY(0); }
  50%      { box-shadow: 0 18px 44px -6px rgba(255, 179, 0, 0.75); transform: translateY(-3px); }
}
.hero-logo { animation: logoGlow 4.5s ease-in-out infinite; }

/* Sonnenstrahlen drehen sich langsam */
@keyframes sunSpin { to { transform: rotate(90deg); } }
.hero-logo svg g { transform-origin: 50% 50%; animation: sunSpin 24s linear infinite; }

/* PPFD-Wert pulsiert kurz nach einer neuen Messung */
@keyframes valuePulse {
  0%   { transform: scale(1);    text-shadow: 0 0 0 rgba(75, 227, 176, 0); }
  35%  { transform: scale(1.06); text-shadow: 0 0 26px rgba(75, 227, 176, 0.65); }
  100% { transform: scale(1);    text-shadow: 0 0 0 rgba(75, 227, 176, 0); }
}
.metric-value { display: inline-block; transform-origin: left center; }
.metric-value.pulse { animation: valuePulse 0.55s ease-out; }

/* Ergebnis-Karten leuchten kurz auf, wenn sie erscheinen */
@keyframes revealCard {
  0%   { opacity: 0; transform: translateY(10px) scale(0.99); box-shadow: 0 0 0 1px rgba(75, 227, 176, 0); }
  60%  { opacity: 1; box-shadow: 0 0 0 1px rgba(75, 227, 176, 0.55), 0 0 34px -8px rgba(75, 227, 176, 0.5); }
  100% { opacity: 1; transform: none; box-shadow: 0 20px 44px -30px #000; }
}
.card.reveal { animation: revealCard 0.6s ease-out both; }

/* Werte, die sich ändern, blitzen kurz auf */
@keyframes valueFlash {
  0%   { color: var(--mint); }
  100% { color: var(--ink); }
}
.flash { animation: valueFlash 0.7s ease-out; }

/* Scanlinie über dem Kamerabild während des Rasters */
@keyframes scanSweep {
  0%   { transform: translateY(-10%); opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(760%); opacity: 0; }
}
#videoContainer.scanning::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 14%;
  background: linear-gradient(180deg, transparent, rgba(75, 227, 176, 0.45), transparent);
  box-shadow: 0 0 26px rgba(75, 227, 176, 0.5);
  pointer-events: none;
  z-index: 2;
  animation: scanSweep 1.15s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Aufklapp-Karten: Inhalt fährt auf */
@keyframes detailsIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
details.card[open] > .details-body { animation: detailsIn 0.28s ease-out; }
details.card > summary::after { transition: transform 0.25s ease; }
details.card[open] > summary::after { transform: rotate(180deg); }

/* Buttons: leichtes Anheben beim Hover, Druck-Feedback */
button { transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease; }
@media (hover: hover) {
  button:hover { transform: translateY(-1px); }
  .btn-primary:hover { box-shadow: 0 16px 30px -14px rgba(75, 227, 176, 0.95); }
}

/* Barrierearm: alles aus, wenn der Nutzer das so will */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
