/* =========================================================================
   Systemchen · Modul wasser · Minispiele (Futter, Ordnen, Lupe)
   Ergänzt style.css (Holz/Papier-Tokens). Alle Klassen mit Präfix .mg-
   ========================================================================= */
.mg-root {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  background: radial-gradient(ellipse at center, rgba(20,25,10,.35), rgba(12,15,6,.7));
  animation: fadeIn .35s ease both;
}
.mg-frame {
  position: relative;
  width: min(1240px, 100%); height: min(880px, 100%);
  border-radius: 26px; padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
  animation: cardIn .45s cubic-bezier(.2,.9,.25,1.1) both;
}
.mg-head { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 2px; }
.mg-head h2 {
  flex: 1; margin: 0 0 0 6px;
  font-family: var(--font-title); font-weight: 600; font-size: clamp(1.15rem, 2.6vw, 1.7rem);
  color: #fff8ea; text-shadow: 0 1px 0 rgba(50,25,5,.7); line-height: 1.15;
}
.mg-head .btn { --tap: 56px; }
.mg-head .btn .ico { width: 30px; height: 30px; }
.mg-stage {
  position: relative; flex: 1; min-height: 0;
  border-radius: 16px; overflow: hidden;
  background: #3d5236;
  box-shadow: inset 0 0 0 3px rgba(50,28,10,.55), 0 0 0 2px rgba(255,235,200,.18);
}
.mg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.mg-canvas.grab { cursor: grab; }
.mg-canvas.grabbing { cursor: grabbing; }
.mg-inset {
  position: absolute; inset: 0; pointer-events: none; border-radius: 16px;
  box-shadow: inset 0 8px 22px rgba(0,0,0,.38), inset 0 0 0 3px rgba(50,28,10,.45);
}
.mg-layer {
  position: absolute; inset: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  padding: 14px; pointer-events: none;
}
.mg-layer > * { pointer-events: auto; }
.mg-layer.dim { background: rgba(20,24,12,.28); pointer-events: auto; }
.mg-layer .card { width: min(640px, 100%); max-height: 100%; }
.mg-layer .card.wide { width: min(760px, 100%); }
.mg-pic { display: flex; justify-content: center; margin: 2px 0 8px; }
.mg-pic canvas { width: min(300px, 62vw); height: auto; aspect-ratio: 3 / 2; border-radius: 18px; background: #e8efe0; box-shadow: inset 0 0 0 2px var(--paper-edge); }


/* Ergebnis-Kette (Ursache -> Wirkung) */
.mg-chain { display: flex; align-items: flex-start; justify-content: center; flex-wrap: wrap; gap: 2px; margin: 8px 0 2px; }
.mg-chain .mg-link {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 104px;
  font-size: .95rem; font-weight: 800; color: var(--ink-soft); text-align: center; line-height: 1.15;
  opacity: 0; animation: chainIn .5s ease forwards;
}
.mg-chain .mg-link canvas { width: 84px; height: 84px; border-radius: 50%; background: #fffaf0; border: 2px solid var(--paper-edge); }
.mg-chain .mg-arr { width: 26px; height: 84px; display: flex; align-items: center; opacity: 0; animation: chainIn .4s ease forwards; color: var(--brown-light); }
.mg-chain .mg-arr svg { width: 26px; height: 26px; }

/* Fundleiste (Lupe) */
.mg-foot { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; min-height: 72px; }
.mg-slot {
  position: relative; width: 66px; height: 66px; border-radius: 16px;
  background: rgba(248,241,226,.92); border: 2px solid var(--paper-edge);
  box-shadow: inset 0 2px 4px rgba(60,40,10,.15);
}
.mg-slot canvas { width: 100%; height: 100%; display: block; }
.mg-slot.found { background: #f2f8e6; border-color: var(--green-light); }
.mg-slot.found::after {
  content: ''; position: absolute; right: -6px; top: -6px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  animation: mgPop .4s cubic-bezier(.2,.9,.3,1.6) both;
}
.mg-foot .btn.mg-done { margin-left: 10px; }
.mg-foot .btn.mg-done.ready { animation: mgReady 1.6s ease-in-out infinite; }
@keyframes mgPop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes mgReady { 0%, 100% { box-shadow: 0 0 0 0 rgba(140,191,90,.0), 0 4px 10px rgba(20,30,5,.35); } 50% { box-shadow: 0 0 0 8px rgba(140,191,90,.45), 0 4px 10px rgba(20,30,5,.35); } }

@media (max-width: 640px) {
  .mg-root { padding: 4px; }
  .mg-frame { padding: 6px 6px 8px; border-radius: 18px; }
  .mg-head .btn { --tap: 48px; }
  .mg-slot { width: 52px; height: 52px; }
  .mg-chain .mg-link { width: 80px; }
  .mg-chain .mg-link canvas { width: 64px; height: 64px; }
  .mg-chain .mg-arr { height: 64px; width: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .mg-chain .mg-link, .mg-chain .mg-arr { opacity: 1; }
}


/* "Das hast du gelernt" */
.mg-learned {
  margin: 14px 0 2px; padding: 10px 14px 10px 16px;
  background: #f1f6e6; border: 2px solid #cfe0b4; border-left: 8px solid var(--green-light);
  border-radius: 14px;
}
.mg-learned-h { font-family: var(--font-title); font-weight: 600; color: var(--green-dark); font-size: 1.15rem; margin-bottom: 2px; }
.mg-learned p { margin: 0; font-size: 1.05rem; line-height: 1.4; color: var(--ink); }
.mg-curr { margin-top: 6px; font-size: .85rem; font-weight: 700; color: var(--ink-soft); letter-spacing: .02em; }

/* Was frisst es? Wer frisst es? */
.mg-eat { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 2px; }
.mg-eat-row { background: #fffaf0; border: 2px solid var(--paper-edge); border-radius: 14px; padding: 8px 10px; }
.mg-eat-h { font-weight: 800; color: var(--green-dark); margin-bottom: 6px; font-size: 1.02rem; }
.mg-eat-items { display: flex; flex-wrap: wrap; gap: 8px; }
.mg-eat-it { display: flex; flex-direction: column; align-items: center; width: 84px; text-align: center; font-size: .85rem; font-weight: 700; color: var(--ink-soft); line-height: 1.15; gap: 3px; }
.mg-eat-it canvas { width: 60px; height: 60px; border-radius: 50%; border: 2px solid var(--paper-edge); }

/* breites, animiertes Bild (Wasserkreislauf) */
.mg-wide-pic { display: flex; justify-content: center; margin: 4px 0 6px; }
.mg-wide-pic canvas { width: min(460px, 100%); height: auto; aspect-ratio: 460 / 230; border-radius: 18px; box-shadow: inset 0 0 0 2px var(--paper-edge); }

/* Anleitung echtes Experiment */
.mg-steps { margin: 4px 0 0 0; padding-left: 1.6em; font-size: 1.1rem; line-height: 1.5; font-weight: 700; color: var(--ink); }
.mg-steps li { margin: 2px 0; }
.mg-steps li::marker { color: var(--green); font-weight: 800; }

/* Bild-Auswahl in Karten */
.mg-choices .choice { max-width: 230px; }
.mg-choices .choice span { font-size: 1rem; }

@media (max-width: 640px) {
  .mg-eat { grid-template-columns: 1fr; }
  .mg-eat-it { width: 70px; }
}

@media (orientation: portrait) { .mg-frame { height: min(1120px, 100%); } }


/* Mengen-Anzeige (Bild + Zahl) und Reihe der gefundenen Tiere */
.mg-count { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 2px 0 6px; }
.mg-count canvas { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--paper-edge); }
.mg-count b { font-size: 1.5rem; font-weight: 800; color: var(--green-dark); }
.mg-found-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0 6px; }
.mg-pic.big canvas { width: min(480px, 100%); aspect-ratio: 3 / 2; background: #f7efd9; }
.mg-wide-pic.info canvas { width: min(480px, 100%); aspect-ratio: 3 / 2; }
/* Bilder in Karten nicht zu hoch, damit die Knöpfe sichtbar bleiben */
.mg-pic canvas { width: auto; height: min(200px, 22vh); max-width: 100%; }
.mg-pic.big canvas { width: auto; height: min(320px, 30vh); max-width: 100%; }
.mg-wide-pic.info canvas { width: auto; height: min(300px, 28vh); max-width: 100%; }
.mg-pic.big canvas { height: auto; width: min(480px, 100%); max-height: 26vh; object-fit: contain; aspect-ratio: auto; }
/* Karten im Minispiel etwas kompakter, damit alles ohne Scrollen passt */
.mg-layer .card { padding: 20px 24px 18px; }
.mg-layer .card h2 { font-size: clamp(1.25rem, 2.8vw, 1.8rem); margin-bottom: .25rem; }
.mg-layer .card p.say { font-size: clamp(1rem, 2.1vw, 1.22rem); margin-bottom: .5rem; }
.mg-layer .card .actions { margin-top: 10px; }
.mg-pic.big canvas { max-height: 22vh; }
@media (max-height: 700px) { .mg-pic canvas, .mg-pic.big canvas, .mg-wide-pic.info canvas { max-height: 18vh; } }
.mg-pic.story canvas { max-height: 38vh; width: min(480px, 100%); border-radius: 16px; }
/* echtes Foto: klein an die Ecke des Bildes gesteckt, Nachweis winzig darunter */
.mg-pic-in { position: relative; display: inline-block; line-height: 0; }
/* echtes Foto gleich groß neben der Zeichnung (nicht mehr darüber), antippen = groß */
.mg-pic.with-photo { gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.mg-photo { position: relative; margin: 0; padding: 5px 5px 4px; background: #fff; border-radius: 10px; display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 3px 10px rgba(20,15,5,.2); cursor: zoom-in; aspect-ratio: 4 / 3.25; height: min(200px, 22vh); line-height: 1; }
.mg-photo img { display: block; flex: 1 1 auto; min-height: 0; width: 100%; object-fit: cover; border-radius: 6px; }
.mg-photo figcaption { font-size: 10px; line-height: 1.15; color: #8a8a80; text-align: left; overflow-wrap: anywhere; }

/* Verdunstungs-Labor */
.mg-shelf { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 6px 0 4px;
  padding: 12px; border-radius: 14px; background: linear-gradient(180deg, #c08b57, #9a6738); box-shadow: inset 0 3px 0 rgba(255,235,200,.3), inset 0 -4px 0 rgba(40,20,5,.25); }
.mg-shelf-it { position: relative; max-width: none; min-height: 0; padding: 8px 6px 10px; font-size: 1rem; }
.mg-shelf-it canvas { width: 100%; height: auto; aspect-ratio: 150 / 96; border-radius: 10px; }
.mg-shelf-it.done { border-color: var(--green); background: #f3f9e8; }
.mg-stamp { position: absolute; top: -8px; right: -8px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #4a7c23; color: #fff; font-style: normal; font-weight: 800; font-size: 1.4rem; transform: rotate(-12deg); box-shadow: 0 2px 6px rgba(0,0,0,.3); border: 3px solid #fff; }
.mg-real { margin: 6px 0 2px; padding: 10px 14px; border-radius: 14px; background: #fff6df; border: 2px dashed #d9b86a; }
.mg-real-h { font-family: var(--font-title); font-weight: 600; color: #8a5a1c; font-size: 1.15rem; }
.mg-real p { margin: 4px 0 0; font-weight: 700; color: var(--ink); line-height: 1.4; }
.mg-factors { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; }
.mg-factor { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100px; font-weight: 800; font-size: .92rem; color: var(--ink-soft); opacity: .45; text-align: center; }
.mg-factor canvas { width: 90px; height: 72px; border-radius: 12px; border: 2px solid var(--paper-edge); }
.mg-factor.on { opacity: 1; color: var(--green-dark); }
.mg-factor.on canvas { border-color: var(--green-light); }
@media (max-width: 640px) { .mg-shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Lupe: Noch zu finden + Tipp */
.mg-tofind { position: absolute; z-index: 2; top: 8px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px;
  padding: 4px 12px 4px 14px; border-radius: 30px; background: rgba(248,241,226,.92); border: 1px solid var(--paper-edge); box-shadow: 0 3px 10px rgba(20,15,5,.25); pointer-events: none; }
.mg-tofind b { font-weight: 800; color: var(--ink); font-size: .95rem; margin-right: 4px; white-space: nowrap; }
.mg-tofind canvas { width: 40px; height: 40px; }
.mg-tip { gap: 6px; }
.mg-tip .ico { width: 30px; height: 30px; }
@media (max-width: 640px) { .mg-tofind b { display: none; } .mg-tofind canvas { width: 32px; height: 32px; } }
