:root {
  --paper: #F4F1E8; --card: #FFFDF7; --ink: #1F2A22; --muted: #66705F; --rule: #DDD8C8;
  --moss: #2F5D45; --moss-ink: #FFFFFF; --leaf: #5E9C5B; --wash: #E6EEDD;
  --ok: #2F7A4B; --ok-bg: #E1F0E2; --bad: #B5452F; --bad-bg: #F8E4DE; --sun: #E0A526; --sun-bg: #FBF0D2;
  --soil: #8A6A48; --soil2: #A07E58; --trunk: #7A5A3C; --shadow: rgba(60, 70, 40, .16);
  --sky: linear-gradient(#EAF1E2, #F4F1E8 70%);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141A16; --card: #1C241E; --ink: #E9EDE3; --muted: #9AA596; --rule: #2E3A31;
    --moss: #7DBB6C; --moss-ink: #10160F; --leaf: #7DBB6C; --wash: #22301F;
    --ok: #8ED29A; --ok-bg: #1D3324; --bad: #F0957F; --bad-bg: #3A211B; --sun: #F0C255; --sun-bg: #3A3117;
    --soil: #6B5237; --soil2: #7E6344; --trunk: #8A6A48; --shadow: rgba(0, 0, 0, .35);
    --sky: linear-gradient(#18221B, #141A16 70%);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans);
  min-height: 100dvh; overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; text-wrap: balance; }
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

.boot { display: grid; place-items: center; min-height: 100dvh; font: 4rem var(--serif); color: var(--leaf); }
.page {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.page.sky { background: var(--sky); min-height: 100dvh; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 14px; }

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .kanji { font: 1.5rem var(--serif); color: var(--leaf); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px;
  border-radius: 14px; border: 1.5px solid var(--rule); background: var(--card); font-weight: 600; width: 100%;
}
.btn.primary { background: var(--moss); border-color: var(--moss); color: var(--moss-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost { background: transparent; }
.btn.slim { min-height: 40px; padding: 0 14px; width: auto; font-size: .9rem; border-radius: 12px; }
.btn:disabled { opacity: .55; }
.link { background: none; border: 0; padding: 8px 0; color: var(--moss); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.back { background: none; border: 0; padding: 10px 10px 10px 0; color: var(--muted); font-weight: 600; }

/* Anmeldung */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; }
.auth .hero { text-align: center; margin-bottom: 22px; }
.auth .hero svg { width: 150px; }
.auth .hero h1 { font-size: 2.6rem; }
.field label { display: block; font-size: .86rem; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--rule);
  background: var(--card); font-size: 16px;
}
.error { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: 12px; font-size: .92rem; }

/* Wald */
.forest { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.plot {
  position: relative; display: block; text-align: left; padding: 8px 12px 12px; border-radius: var(--r);
  border: 1.5px solid var(--rule); background: var(--card); width: 100%;
}
.plot .tree { display: block; width: 64%; margin: 0 auto; }
.plot h3 { font-size: 1.02rem; margin-top: 2px; }
.plot .meta { font-size: .8rem; color: var(--muted); margin-top: 3px; min-height: 2.4em; }
.plot .pill { position: absolute; top: 10px; right: 10px; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; background: var(--sun-bg); color: var(--ink); font-size: .74rem; font-weight: 700; }
.tree { aspect-ratio: 120 / 134; overflow: visible; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary div { background: var(--card); border: 1.5px solid var(--rule); border-radius: 14px; padding: 10px 6px; text-align: center; }
.summary b { display: block; font: 600 1.4rem var(--serif); }
.summary span { font-size: .76rem; color: var(--muted); }

/* Thema */
.bigtree { background: var(--wash); border-radius: var(--r); padding: 10px; }
.bigtree .tree { width: min(78%, 300px); display: block; margin: 0 auto; }
.bigtree.hang .tree { cursor: crosshair; }
.bar { height: 10px; border-radius: 999px; background: var(--rule); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--leaf); border-radius: 999px; }
.notice { background: var(--sun-bg); border-radius: 14px; padding: 12px 14px; font-weight: 600; }

/* Quiz */
.qhead { position: sticky; top: 0; z-index: 2; background: var(--paper); padding: calc(env(safe-area-inset-top) + 8px) 0 10px; margin-top: calc(-1 * env(safe-area-inset-top) - 18px); }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--wash); font-size: .78rem; font-weight: 700; }
.question { font-size: 1.12rem; line-height: 1.45; font-weight: 500; text-wrap: pretty; }
.fig { background: var(--card); border: 1.5px solid var(--rule); border-radius: 14px; padding: 8px; color: var(--ink); }
.fig svg { display: block; width: 100%; height: auto; }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 13px 14px; min-height: 52px;
  border-radius: 14px; border: 1.5px solid var(--rule); background: var(--card); line-height: 1.4;
}
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--wash); font-weight: 700; font-size: .82rem; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .k { background: var(--ok); color: var(--card); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .k { background: var(--bad); color: var(--card); }
.opt.dim { opacity: .6; }
.feedback { border-radius: var(--r); padding: 14px; background: var(--card); border: 1.5px solid var(--rule); }
.feedback h3 { font-size: 1.15rem; }
.feedback.ok h3 { color: var(--ok); }
.feedback.no h3 { color: var(--bad); }
details.steps { border-top: 1.5px solid var(--rule); padding-top: 10px; }
details.steps summary { font-weight: 700; color: var(--moss); padding: 6px 0; cursor: pointer; }
details.steps ol { margin: 6px 0 0; padding-left: 22px; }
details.steps li + li { margin-top: 6px; }
.source { font-size: .78rem; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 700; background: var(--wash); color: var(--ink); margin-right: 6px; }
.badge.ergaenzt { background: var(--sun-bg); }
.badge.neu { background: var(--rule); }
.reward { display: flex; gap: 12px; align-items: center; background: var(--sun-bg); border-radius: var(--r); padding: 10px 14px; font-weight: 600; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.reward .tree { width: 64px; flex: none; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .reward { animation: none; } }
.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px); background: linear-gradient(transparent, var(--paper) 30%); }
.dock .btn { max-width: 528px; margin: 0 auto; display: flex; }
.score { font: 600 3.2rem/1 var(--serif); }

/* Leute */
.people { display: grid; gap: 10px; }
.person { width: 100%; text-align: left; padding: 12px 14px; border-radius: var(--r); border: 1.5px solid var(--rule); background: var(--card); }
.person .name { font-weight: 700; overflow-wrap: anywhere; }
.mini { display: flex; gap: 2px; margin-top: 6px; }
.mini .tree { width: calc((100% - 18px) / 10); max-width: 30px; }
.adminrow { display: flex; gap: 8px; margin-top: 10px; }
.card { padding: 14px; border-radius: var(--r); border: 1.5px solid var(--rule); background: var(--card); }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(var(--n, 3), 1fr);
  background: var(--card); border-top: 1.5px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs button { background: none; border: 0; padding: 9px 0 8px; font-size: .74rem; font-weight: 700; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--moss); }

/* Dialog & Toast */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 15, .5); display: grid; place-items: end center; z-index: 20; padding: 16px; padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
.dialog { width: 100%; max-width: 480px; background: var(--card); border-radius: 20px; padding: 18px; }
#toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -160%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600; transition: transform .25s; z-index: 30; max-width: 90vw; text-align: center; }
#toast.show { transform: translate(-50%, 0); }
@media (min-width: 620px) { .forest { grid-template-columns: repeat(3, 1fr); } }

/* Tablet und größer: Seitenleiste statt Fußleiste, mehr Spalten, größere Schrift */
@media (min-width: 768px) {
  body { font-size: 17.5px; }
  h1 { font-size: 2.3rem; }
  .page { max-width: 980px; padding: calc(env(safe-area-inset-top) + 32px) 32px calc(env(safe-area-inset-bottom) + 48px); }
  .page.narrow { max-width: 720px; }
  .tabs {
    top: 0; right: auto; bottom: 0; width: 92px; grid-template-columns: 1fr; grid-auto-rows: min-content; align-content: center; gap: 10px;
    border-top: 0; border-right: 1.5px solid var(--rule); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .tabs button { padding: 14px 0; font-size: .8rem; }
  .tabs button svg { width: 28px; height: 28px; }
  #app:has(.tabs) .page { margin-left: max(92px, calc((100vw - 980px) / 2)); margin-right: auto; }
  #app:has(.tabs) .page.narrow { margin-left: max(92px, calc((100vw - 720px) / 2)); }
  .forest { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .summary { max-width: 560px; }
  .page > .btn { max-width: 420px; }
  .page.narrow > .btn, .auth .btn { max-width: none; }
  .people { grid-template-columns: 1fr 1fr; gap: 14px; }
  .question { font-size: 1.3rem; }
  .opt { padding: 16px 18px; min-height: 60px; font-size: 1.05rem; }
  .opt .k { width: 30px; height: 30px; }
  .fig { max-width: 560px; }
  .bigtree .tree { width: min(60%, 340px); }
  .qhead { margin-top: calc(-1 * env(safe-area-inset-top) - 32px); padding-top: calc(env(safe-area-inset-top) + 16px); }
  .dock { position: static; padding: 8px 0 0; background: none; }
  .dock .btn { max-width: none; }
  .overlay { place-items: center; }
  .auth .hero svg { width: 190px; }
}
@media (min-width: 1100px) { .forest { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 768px) and (orientation: landscape) {
  .page.quiz:has(.fig) { max-width: 1040px; }
}

/* Skript-Zusammenfassung */
details.sec { border: 1.5px solid var(--rule); border-radius: var(--r); background: var(--card); }
details.sec > summary { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px; cursor: pointer; font: 600 1.08rem var(--serif); list-style: none; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: "+"; flex: none; width: 1em; color: var(--moss); font-family: var(--sans); }
details.sec[open] > summary::before { content: "–"; }
details.sec > summary > span:first-of-type { flex: 1; }
details.sec > summary .small { font-family: var(--sans); font-weight: 400; white-space: nowrap; }
.secbody { padding: 0 14px 16px; border-top: 1.5px solid var(--rule); padding-top: 14px; }
.secbody ul, .secbody ol { margin: 0; padding-left: 22px; }
.secbody li + li { margin-top: 4px; }
.formel { background: var(--wash); border-radius: 12px; padding: 10px 14px; }
.formel b { display: block; font: 600 1.12rem var(--serif); overflow-wrap: anywhere; }
.formel > span { display: block; font-size: .84rem; color: var(--muted); margin-top: 4px; }
.note { border-left: 4px solid var(--leaf); padding: 2px 0 2px 12px; }
.note .tag { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.note > * + * { margin-top: 6px; }
.note.beispiel { border-color: var(--rule); }
.note.skizze { border-color: var(--rule); border-left-style: dashed; }
.note.extra { border-color: var(--sun); }
.note.korrektur { border-color: var(--bad); }
.tablewrap { overflow-x: auto; }
.tablewrap table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.tablewrap th, .tablewrap td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
@media (min-width: 768px) { .tabs { grid-template-columns: 1fr; } }
.counts { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: .92rem; }
.counts b { font: 600 1.15rem var(--serif); }
.vec { position: relative; display: inline-block; }
.vec::after { content: "\2192"; position: absolute; left: 0; right: 0; top: -.58em; font-size: .62em; line-height: 1; text-align: center; font-weight: 400; }
