:root {
  --paper: #F3F6FF;
  --card: #FFFFFF;
  --ink: #221E4F;
  --ink-soft: #5D5A8A;
  --mist: #C9CEEE;
  --pink: #FF5C9A;
  --pink-deep: #E23E7E;
  --lamp: #FFC940;
  --mint: #2FCB9B;
  --danger: #D8344F;

  --display: 'Fredoka', 'Avenir Next Rounded', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }

/* ---------- Grundbausteine ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px;
  border: 0; border-radius: 16px;
  font: 600 17px/1 var(--display);
}
.btn-primary { background: var(--pink); color: #fff; box-shadow: 0 4px 0 var(--pink-deep); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--pink-deep); }
.btn-primary:disabled { background: var(--mist); box-shadow: 0 4px 0 #AEB4DC; color: #fff; }
.btn-quiet { background: transparent; color: var(--ink-soft); border: 2px solid var(--mist); }
.btn-danger { background: transparent; color: var(--danger); border: 2px solid #F2C3CC; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 13px 14px;
  background: var(--card); color: var(--ink);
  border: 2px solid var(--mist); border-radius: 14px;
  font: 17px/1.3 var(--body);
}
.field input:focus, .field textarea:focus { border-color: var(--ink); outline: none; }
.field textarea { resize: none; min-height: 72px; }

.form-error { color: var(--danger); font-weight: 700; min-height: 1.5em; margin: 0 0 10px; }

.seg { display: flex; background: #E3E7FA; border-radius: 14px; padding: 4px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 11px;
  padding: 10px 8px; font: 600 15px/1.2 var(--display); color: var(--ink-soft);
}
.seg button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(34, 30, 79, .15); }

/* Sticker: das Wiedererkennungszeichen der App */
.sticker {
  background: #fff;
  border: 5px solid #fff;
  border-radius: 18px;
  box-shadow: 0 1px 0 #E4E7F7, 0 6px 14px rgba(34, 30, 79, .18);
  overflow: hidden;
  transform: rotate(var(--tilt, 0deg));
}
.sticker img { width: 100%; height: 100%; object-fit: cover; border-radius: 13px; }

/* ---------- Login ---------- */

.auth {
  min-height: 100%;
  padding: calc(var(--safe-top) + 32px) 24px calc(var(--safe-bottom) + 32px);
  display: flex; justify-content: center;
}
.auth-inner { width: 100%; max-width: 380px; }
.auth-logo { margin: 12px auto 4px; transform: rotate(-4deg); }
.wordmark {
  font: 700 46px/1 var(--display);
  text-align: center; margin: 8px 0 10px;
  letter-spacing: -.5px;
}
.auth-lead { text-align: center; color: var(--ink-soft); margin: 0 0 26px; }
.auth .seg { margin-bottom: 22px; }
.auth .btn-primary { width: 100%; }

/* ---------- App-Rahmen ---------- */

.app { height: 100%; }
.view {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 18px) 18px calc(var(--safe-bottom) + var(--tabbar-h) + 34px);
}
.view-head { margin-bottom: 18px; }
.view-title { font: 700 32px/1.1 var(--display); margin: 0; }
.view-sub { margin: 6px 0 0; color: var(--ink-soft); font-weight: 700; }
.section-title { font: 600 21px/1.2 var(--display); margin: 30px 0 12px; }

.empty {
  text-align: center; color: var(--ink-soft);
  padding: 48px 12px;
}
.empty strong { display: block; font: 600 20px/1.3 var(--display); color: var(--ink); margin-bottom: 6px; }

/* Tab-Leiste mit großem Fang-Knopf */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
  display: grid; grid-template-columns: 1fr 1fr 96px 1fr 1fr; align-items: end;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 6px var(--safe-bottom);
  background: var(--card);
  border-top: 2px solid #E3E7FA;
}
.tab {
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--ink-soft);
  font: 600 12px/1 var(--display);
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { stroke-width: 2.6; }

.catch-btn {
  justify-self: center;
  width: 84px; height: 84px; margin-bottom: 14px;
  border-radius: 50%; border: 5px solid var(--card);
  background: var(--pink); color: #fff;
  box-shadow: 0 5px 0 var(--pink-deep), 0 8px 20px rgba(226, 62, 126, .35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: 700 12px/1 var(--display);
}
.catch-btn svg { width: 38px; height: 38px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.catch-btn svg circle { fill: #fff; stroke: none; }
.catch-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--pink-deep); }

/* ---------- Feed ---------- */

.feed { display: grid; gap: 14px; }
.feed-item {
  display: grid; grid-template-columns: 92px 1fr; gap: 16px; align-items: center;
  width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: 20px;
  padding: 12px 16px 12px 12px;
}
.feed-item .sticker { width: 92px; height: 92px; }
.feed-line { margin: 0 0 2px; color: var(--ink-soft); font-size: 15px; }
.feed-line b { color: var(--ink); }
.feed-name { font: 600 21px/1.2 var(--display); margin: 0 0 4px; }
.feed-meta { font-size: 14px; color: var(--ink-soft); }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: #FFF1C9; color: #6B4E00; font-weight: 700; font-size: 13px;
}

/* ---------- Karte ---------- */

.view-map { padding: 0; position: relative; }
.map { position: absolute; inset: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom)); background: #E9ECF7; }
.map-toggle {
  position: absolute; z-index: 450;
  top: calc(var(--safe-top) + 12px); left: 50%; transform: translateX(-50%);
  width: min(260px, calc(100% - 36px));
  box-shadow: 0 4px 14px rgba(34, 30, 79, .2);
}
.cat-pin { background: none; border: 0; }
.cat-pin .sticker { width: 58px; height: 58px; border-width: 4px; }
.cat-pin.mine .sticker { border-color: var(--pink); }
.cat-pin .sticker img { border-radius: 12px; }
.leaflet-container { font-family: var(--body); }
.leaflet-control-attribution { font-size: 11px; }
.leaflet-bottom { bottom: 6px; }

/* ---------- Dex ---------- */

.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.dex-slot {
  position: relative;
  border: 0; border-radius: 20px; background: var(--card);
  padding: 14px 12px 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.dex-slot .sticker { width: 104px; height: 104px; margin: 6px 0 12px; }
.dex-no { position: absolute; top: 10px; left: 12px; font: 600 13px/1 var(--display); color: var(--ink-soft); }
.dex-count {
  position: absolute; top: 8px; right: 10px;
  background: var(--lamp); color: var(--ink);
  font: 700 13px/1 var(--display); padding: 5px 8px; border-radius: 999px;
}
.dex-name { font: 600 17px/1.2 var(--display); }
.dex-hint { font-size: 13px; color: var(--ink-soft); line-height: 1.35; margin-top: 4px; }
.dex-slot.empty-slot { background: transparent; border: 2px dashed var(--mist); }
.dex-unknown {
  width: 104px; height: 104px; margin: 6px 0 12px;
  display: grid; place-items: center;
  border-radius: 18px; background: #E3E7FA;
  font: 700 30px/1 var(--display); color: #A3A9D6;
}

/* ---------- Ich ---------- */

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border-radius: 20px; padding: 16px; }
.stat b { display: block; font: 700 38px/1 var(--display); }
.stat span { color: var(--ink-soft); font-weight: 700; font-size: 14px; }
.ranking { list-style: none; margin: 0 0 30px; padding: 0; display: grid; gap: 8px; }
.ranking li {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  background: var(--card); border-radius: 16px; padding: 12px 16px;
}
.ranking .place { font: 700 18px/1 var(--display); color: var(--ink-soft); }
.ranking .who { font-weight: 700; }
.ranking .me-row { box-shadow: inset 0 0 0 2px var(--pink); }
.ranking .score { font-size: 14px; color: var(--ink-soft); text-align: right; }
#logout { width: 100%; }

/* ---------- Kamera ---------- */

.camera { position: fixed; inset: 0; z-index: 1000; background: #000; overflow: hidden; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-frame {
  position: absolute;
  left: 15%; top: 26%; width: 70%; height: 38%;
  transition: left .18s, top .18s, width .18s, height .18s;
  --c: var(--lamp);
}
.cam-frame.found { --c: var(--mint); }
.cam-frame i { position: absolute; width: 38px; height: 38px; border: 5px solid var(--c); }
.cam-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 16px; }
.cam-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 16px; }
.cam-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 16px; }
.cam-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 16px; }
.cam-status {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 138px);
  margin: 0; text-align: center; color: #fff;
  font: 600 20px/1.3 var(--display);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .6);
  padding: 0 24px;
}
.cam-close {
  position: absolute; top: calc(var(--safe-top) + 12px); left: 14px;
  width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .45); display: grid; place-items: center;
}
.cam-close svg { width: 24px; height: 24px; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; }
.cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 20px 0 calc(var(--safe-bottom) + 26px);
  display: flex; justify-content: center;
}
.shutter {
  width: 86px; height: 86px; border-radius: 50%;
  border: 6px solid #fff; background: var(--pink);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .25);
}
.shutter:disabled { background: rgba(255, 255, 255, .25); }
.shutter:not(:disabled) { animation: ready .9s ease-out 1; }
@keyframes ready { 0% { transform: scale(.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
.cam-fallback {
  position: absolute; inset: auto 20px calc(var(--safe-bottom) + 40px);
  background: var(--card); border-radius: 22px; padding: 20px; text-align: center;
}
.cam-fallback p { margin: 0 0 14px; }

/* ---------- Bottom-Sheet ---------- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 1100; background: rgba(34, 30, 79, .45); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
  max-height: 92%; overflow-y: auto;
  background: var(--paper);
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  animation: sheet-in .22s ease-out;
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--mist); margin: 0 auto 14px; }
.sheet-hero { display: flex; justify-content: center; margin: 6px 0 20px; }
.sheet-hero .sticker { width: 190px; height: 190px; --tilt: -3deg; }
.sheet h2 { font: 700 28px/1.15 var(--display); margin: 0 0 4px; text-align: center; }
.sheet .sheet-sub { text-align: center; color: var(--ink-soft); margin: 0 0 20px; }
.sheet .btn { width: 100%; margin-top: 10px; }
.sheet .photo-full { border-radius: 18px; margin: 4px 0 16px; width: 100%; }

.species-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.species-pick button {
  border: 2px solid var(--mist); background: var(--card); border-radius: 14px;
  padding: 10px 12px; text-align: left; font: 600 15px/1.2 var(--display);
}
.species-pick button small { display: block; font: 400 12px/1.3 var(--body); color: var(--ink-soft); margin-top: 2px; }
.species-pick button[aria-pressed="true"] { border-color: var(--ink); background: #FFF1C9; }
.pick-label { font-weight: 700; font-size: 14px; margin: 0 0 8px; }

.geo {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 6px;
  font-size: 15px;
}
.geo::before { content: ''; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--lamp); }
.geo.ok::before { background: var(--mint); }
.geo.bad::before { background: var(--danger); }

.detail-list { margin: 0 0 12px; display: grid; gap: 8px; }
.detail-list div { display: flex; justify-content: space-between; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; }
.detail-list dt { color: var(--ink-soft); font-weight: 700; }
.detail-list dd { margin: 0; text-align: right; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 1500; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-top) + 14px);
  max-width: calc(100% - 32px);
  background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 16px;
  font-weight: 700; box-shadow: 0 8px 20px rgba(34, 30, 79, .3);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
