:root {
  --papier: #fff8ef;
  --karte: #fff;
  --text: #2d2a26;
  --leise: #7a726a;
  --akzent: #ff7a59;
  --akzent-dunkel: #d9502e;
  --akzent-hell: #fff1ec;
  --blau: #2f7de1;
  --rand: #eadfd2;
  --rund: 18px;
  --schatten: 0 2px 12px rgba(80, 50, 20, 0.08);
}

* { box-sizing: border-box; }
/* Eigene display-Regeln heben sonst das hidden-Attribut auf. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--papier);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }

.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
}
.kopf h1 { display: flex; align-items: center; gap: 10px; font-size: 1.45rem; margin: 0; letter-spacing: -0.01em; }
.kopf h1 img { border-radius: 9px; }
.rund {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--rand);
  background: #fff;
  font-size: 20px;
  line-height: 1;
}

.hinweis {
  max-width: 1068px;
  margin: 0 auto 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #eaf3ff;
  color: #1d4f91;
  cursor: pointer;
}
.hinweis[data-art="fehler"] { background: #ffeceb; color: #a1281b; }
.hinweis + .haupt { padding-top: 0; }

.haupt {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 0 16px 16px;
  max-width: 1100px;
  margin: 0 auto;
}
@media screen and (min-width: 820px) {
  .haupt { grid-template-columns: 390px minmax(0, 1fr); align-items: start; }
  .ergebnis { position: sticky; top: 16px; }
}

.steuerung, .ergebnis {
  background: var(--karte);
  border-radius: var(--rund);
  box-shadow: var(--schatten);
  padding: 16px;
}

.reiter {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #f6eee5;
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 16px;
}
.reiter button {
  border: 0;
  background: transparent;
  padding: 10px 4px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--leise);
}
.reiter button[aria-selected="true"] { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }

label, .label { display: block; font-weight: 600; margin: 0 0 6px; }
textarea, input[type="text"], input[type="password"] {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--rand);
  border-radius: 12px;
  background: #fffdfa;
  color: var(--text);
}
textarea { resize: vertical; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chips:empty { display: none; }
@media screen and (max-width: 600px) {
  #ideen { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; }
  #ideen::-webkit-scrollbar { display: none; }
  #ideen button { flex: none; }
}
.chips button {
  border: 1px solid var(--rand);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
}

.haupt-knopf {
  width: 100%;
  border: 0;
  background: var(--akzent);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  padding: 14px;
  border-radius: 14px;
}
.haupt-knopf:disabled { opacity: 0.45; }
.haupt-knopf.schmal { width: auto; padding: 12px 22px; }
.leise-knopf {
  border: 1px solid var(--rand);
  background: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
}

.klein { font-size: 13px; color: var(--leise); margin: 8px 0 0; }
.klein a { color: var(--blau); }

.umschalter {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  margin: 0 0 14px;
  border: 0;
  padding: 0;
}
.umschalter legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.umschalter button {
  border: 1px solid var(--rand);
  background: #fff;
  border-radius: 12px;
  padding: 10px 6px;
  font-weight: 600;
}
.umschalter button small { display: block; font-weight: 400; font-size: 12px; color: var(--leise); }
.umschalter button[aria-pressed="true"] { border-color: var(--akzent); background: var(--akzent-hell); color: var(--akzent-dunkel); }

.foto-wahl {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 2px dashed var(--rand);
  border-radius: 14px;
  background: #fffdfa;
  margin-bottom: 12px;
  cursor: pointer;
  text-align: center;
  padding: 10px;
  color: var(--akzent-dunkel);
}
.foto-wahl input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.foto-vorschau { display: block; max-width: 100%; max-height: 180px; margin: 0 auto 14px; border-radius: 10px; }

.musterwahl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.musterwahl button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--rand);
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  font-weight: 600;
}
.musterwahl button span { font-size: 22px; }
.musterwahl button[aria-pressed="true"] { border-color: var(--akzent); background: var(--akzent-hell); }

.regler { border-top: 1px solid var(--rand); margin-top: 18px; padding-top: 16px; }
.regler label b { font-weight: 600; color: var(--akzent-dunkel); }
input[type="range"] { width: 100%; accent-color: var(--akzent); height: 32px; margin: 0; }
.skala { display: flex; justify-content: space-between; font-size: 12px; color: var(--leise); margin: -2px 0 14px; }
.regler .umschalter { margin-bottom: 0; }

.blatt {
  position: relative;
  width: min(100%, calc(76vh * 210 / 297));
  aspect-ratio: 210 / 297;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--rand);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(60, 40, 20, 0.12);
}
.blatt img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.leer { position: absolute; inset: 0; display: grid; place-items: center; color: var(--leise); padding: 20px; text-align: center; }
.laden {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
}
.kreisel {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 5px solid #f6dcd2;
  border-top-color: var(--akzent);
  animation: dreh 0.9s linear infinite;
}
@keyframes dreh { to { transform: rotate(360deg); } }

.aktionen { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px auto 0; max-width: 560px; }
.aktionen button {
  padding: 13px;
  font-weight: 700;
  border-radius: 14px;
  border: 0;
  background: var(--blau);
  color: #fff;
}
.aktionen button.zweit { background: #fff; color: var(--blau); border: 1px solid #b9d2f3; }
.aktionen button:disabled { opacity: 0.4; }

.zuletzt { max-width: 1100px; margin: 0 auto; padding: 4px 16px 28px; }
.zuletzt h2 { font-size: 1.1rem; margin: 8px 0 12px; }
.galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.kachel { position: relative; margin: 0; }
.kachel-bild {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--rand);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  aspect-ratio: 210 / 297;
}
.kachel-bild img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kachel-weg {
  position: absolute;
  top: 4px; right: 4px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  line-height: 1;
}
.kachel figcaption { font-size: 12px; color: var(--leise); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }

dialog {
  border: 0;
  border-radius: 20px;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  color: var(--text);
}
dialog::backdrop { background: rgba(40, 30, 20, 0.35); }
dialog form { padding: 20px; }
dialog h2 { margin: 0 0 14px; }
dialog input { margin-bottom: 4px; }
dialog label { margin-top: 12px; }
.zeile { display: flex; gap: 8px; align-items: center; }
.zeile input { flex: 1; margin: 0; }
.pruefen { margin-top: 14px; }
.guthaben input[type="text"] { flex: 0 0 6.5em; }
.guthaben input[type="date"] { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 9px 10px; border: 1px solid var(--rand); border-radius: 12px; background: #fffdfa; color: var(--text); }
.guthaben .einheit { white-space: nowrap; color: var(--leise); }
.dialog-knoepfe { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }

#druckbereich { display: none; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; padding: 0; }
  body > *:not(#druckbereich) { display: none !important; }
  #druckbereich { display: block !important; }
  #druckbereich img { display: block; width: 100%; height: 99vh; object-fit: contain; }
}
