:root {
  --grund: #f4efe4;
  --karte: #fffdf8;
  --tinte: #1d2230;
  --gedaempft: #6a6e79;
  --rand: #e3dac7;
  --akzent: #27467f;
  --akzent-hell: #e3e9f5;
  --akzent-text: #ffffff;
  --fehler: #b3261e;
  --schatten: 0 1px 2px rgba(40, 32, 15, .06), 0 8px 28px rgba(40, 32, 15, .08);
  --blatt-schatten: 0 2px 6px rgba(40, 32, 15, .10), 0 18px 40px rgba(40, 32, 15, .14);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --grund: #15171c;
    --karte: #1e2128;
    --tinte: #ece7dc;
    --gedaempft: #9a9ea8;
    --rand: #30343d;
    --akzent: #8eaaf0;
    --akzent-hell: #263049;
    --akzent-text: #10131a;
    --fehler: #ff8a80;
    --schatten: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
    --blatt-schatten: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 40px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--grund); color: var(--tinte); font: 16px/1.5 var(--sans); min-height: 100dvh; }
h1 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* --- Sperrbildschirm --- */
.sperre { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.sperre-karte {
  width: min(400px, 100%); background: var(--karte); border: 1px solid var(--rand); border-radius: 22px;
  box-shadow: var(--schatten); padding: 32px 28px; display: grid; gap: 14px; text-align: center;
}
.sperre-logo { margin: 0 auto 4px; border-radius: 18px; }
.sperre-karte h1 { font-size: 30px; }
.sperre-karte p { margin: 0; color: var(--gedaempft); }
.sperre-karte input[type=password] { text-align: center; }
.haken { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--gedaempft); font-size: 15px; }
.haken input { width: 18px; height: 18px; accent-color: var(--akzent); }
.fehler { color: var(--fehler) !important; min-height: 1.5em; font-size: 15px; }

/* --- Obere Leiste: Aktionen immer erreichbar, Teilen-Menü öffnet direkt daneben --- */
.app { min-height: 100dvh; }
.leiste {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--grund) 85%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--rand);
}
.marke { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marke img { border-radius: 9px; box-shadow: var(--schatten); }
.marke h1 { font-size: 22px; white-space: nowrap; }
.aktionen { display: flex; align-items: center; gap: 8px; }
@media (max-width: 900px) {
  .aktionen .beschriftung { display: none; }       /* schmal: nur Symbole für die Nebenknöpfe */
  .aktionen .knopf:not(.primaer) { padding: 0; width: 44px; }
}
@media (max-width: 520px) { .marke h1 { display: none; } }

/* --- Einstellungen --- */
.einstellungen {
  max-width: 1320px; margin: 0 auto; padding: 16px 16px 4px;
  display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end;
}
.gruppe { display: grid; gap: 6px; }
.etikett { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--gedaempft); }

.umschalter { display: flex; gap: 3px; padding: 3px; background: var(--karte); border: 1px solid var(--rand); border-radius: 13px; box-shadow: var(--schatten); }
.umschalter button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 6px 14px;
  border: 0; border-radius: 10px; background: transparent; color: var(--gedaempft); font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.umschalter button svg { width: 17px; height: 17px; stroke-width: 1.5; }
.umschalter button[aria-checked=true] { background: var(--akzent); color: var(--akzent-text); font-weight: 600; }
.umschalter button:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }

.layout-zeile { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.layout-zeile .knopf { min-height: 46px; box-shadow: var(--schatten); }
#anpassen[aria-expanded=true] { border-color: var(--akzent); color: var(--akzent); }
.feinheiten {
  max-width: 1288px; margin: 10px auto 0; padding: 16px;
  display: grid; gap: 18px 28px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
@media (max-width: 1320px) { .feinheiten { margin: 10px 16px 0; } }
.spalte { display: grid; gap: 10px; align-content: start; }
.schalter .text { font-style: normal; display: grid; line-height: 1.3; }
.schalter small { color: var(--gedaempft); font-size: 13px; }
.feinheiten .schalter { box-shadow: none; }
.regel-liste { margin: -2px 0 0; padding: 4px 0 0 14px; border: 0; border-left: 2px solid var(--rand); display: grid; gap: 2px; transition: opacity .15s; }
.regel-liste:disabled { opacity: .45; }
.regel-liste label { display: flex; align-items: center; gap: 9px; min-height: 34px; font-size: 14.5px; cursor: pointer; user-select: none; }
.regel-liste:disabled label { cursor: default; }
.regel-liste input { width: 18px; height: 18px; margin: 0; accent-color: var(--akzent); flex: none; }
.unsichtbar { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.umschalter.klein { box-shadow: none; }
.umschalter.klein button { min-height: 38px; flex: 1; }
.regler { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 15px; }
.regler output { color: var(--akzent); font-weight: 600; font-variant-numeric: tabular-nums; }
.regler input { grid-column: 1 / -1; width: 100%; accent-color: var(--akzent); height: 28px; }
.schalter {
  display: inline-flex; align-items: center; gap: 10px; min-height: 46px; padding: 6px 14px 6px 8px;
  background: var(--karte); border: 1px solid var(--rand); border-radius: 13px; box-shadow: var(--schatten);
  font-size: 15px; cursor: pointer; user-select: none;
}
.schalter input { position: absolute; opacity: 0; pointer-events: none; }
.schalter span { width: 38px; height: 22px; border-radius: 11px; background: var(--rand); position: relative; transition: background .15s; flex: none; }
.schalter span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s;
}
.schalter input:checked + span { background: var(--akzent); }
.schalter input:checked + span::after { transform: translateX(16px); }
.schalter input:focus-visible + span { outline: 2px solid var(--akzent); outline-offset: 2px; }

/* --- Arbeitsfläche --- */
.werkbank {
  max-width: 1320px; margin: 0 auto; padding: 14px 16px max(24px, env(safe-area-inset-bottom));
  display: grid; gap: 18px;
}
@media (min-width: 900px) {
  .werkbank { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: start; }
  .ausgabe { position: sticky; top: 76px; }
}
.karte { background: var(--karte); border: 1px solid var(--rand); border-radius: var(--radius); box-shadow: var(--schatten); }
.eingabe { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 900px) { .eingabe { min-height: calc(100dvh - 210px); } }

input[type=text], input[type=password], textarea {
  width: 100%; border: 1px solid var(--rand); border-radius: 12px; background: var(--grund);
  padding: 12px 14px; font-size: 17px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--akzent); box-shadow: 0 0 0 3px var(--akzent-hell); }
.titel { font-family: var(--serif); font-size: 19px !important; font-weight: 600; background: transparent !important; border-color: transparent !important; padding: 6px 4px !important; }
.titel:focus { border-color: var(--akzent) !important; }
textarea { flex: 1; min-height: 300px; resize: vertical; line-height: 1.6; }
.titel-zeile { display: flex; align-items: center; gap: 2px; }
.titel-zeile .titel { flex: 1; min-width: 0; }
.titel-zeile .knopf { color: var(--gedaempft); }
#zurueckholen { color: var(--akzent); }

/* --- Knöpfe --- */
.knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  padding: 8px 16px; border-radius: 12px; border: 1px solid var(--rand); background: var(--karte);
  font-weight: 600; cursor: pointer; white-space: nowrap; transition: transform .08s, background .15s, opacity .15s;
}
.knopf:active:not(:disabled) { transform: scale(.97); }
.knopf:disabled { opacity: .4; cursor: default; }
.knopf.primaer { background: var(--akzent); border-color: var(--akzent); color: var(--akzent-text); box-shadow: 0 4px 14px color-mix(in srgb, var(--akzent) 35%, transparent); }
.knopf.leise { background: transparent; border-color: transparent; }
.knopf.rund { min-height: 40px; width: 40px; padding: 0; border-radius: 50%; }
.knopf:focus-visible { outline: 2px solid var(--akzent); outline-offset: 2px; }

/* --- Vorschau --- */
.ausgabe { display: grid; gap: 12px; }
.blatt-rahmen { position: relative; display: grid; place-items: center; }
#blatt { width: 100%; height: auto; border-radius: 4px; box-shadow: var(--blatt-schatten); background: #fff; display: block; }
.leer {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px; text-align: center;
  color: #8a8578; font-family: var(--serif); font-size: 18px; font-style: italic; pointer-events: none;
}
.seiten { display: flex; align-items: center; justify-content: center; gap: 16px; color: var(--gedaempft); font-size: 15px; }
.seiten .knopf { border-color: var(--rand); font-size: 22px; }
.status { margin: 0; min-height: 1.5em; color: var(--gedaempft); font-size: 14px; text-align: center; }
.status.warnung { color: var(--fehler); }

/* --- Fenster (Training, Regelblatt) --- */
.fenster {
  width: min(980px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--rand);
  border-radius: 20px; background: var(--karte); color: var(--tinte); box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.fenster::backdrop { background: rgba(20, 18, 12, .45); backdrop-filter: blur(3px); }
#training, #training * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }   /* nie markieren */
body.training-offen { -webkit-user-select: none; user-select: none; overflow: hidden; }
.fenster-kopf, .fenster-fuss { display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.fenster-kopf { border-bottom: 1px solid var(--rand); justify-content: space-between; }
.fenster-kopf h2 { margin: 0; font-family: var(--serif); font-size: 22px; }
.fenster-fuss { border-top: 1px solid var(--rand); color: var(--gedaempft); font-size: 14px; }
.fenster-inhalt { padding: 16px 18px; display: grid; gap: 12px; }
.fenster-knoepfe { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.abstand { flex: 1; }
.hinweis { margin: 0; color: var(--gedaempft); }
.vorlage { margin: 0; white-space: pre-line; line-height: 1.25; text-align: center; font-family: var(--serif); font-size: clamp(28px, 5vw, 44px); letter-spacing: .06em; }
.schreibfeld {
  width: 100%; height: 170px; border-radius: 14px; border: 1px solid var(--rand); background: #fffefb;
  touch-action: none; cursor: crosshair; display: block;
}
.kacheln { display: flex; flex-wrap: wrap; gap: 10px; }
.tr-kachel {
  display: grid; justify-items: center; gap: 2px; padding: 6px 6px 4px; border: 2px solid var(--akzent); border-radius: 12px;
  background: #fffefb; color: #1d2230; cursor: pointer; transition: opacity .15s, border-color .15s;
}
.tr-kachel canvas { width: 60px; height: 60px; }
.tr-kachel span { font-weight: 700; }
.tr-kachel[aria-pressed=false] { opacity: .35; border-color: var(--rand); border-style: dashed; }
.regeln {
  margin: 0; max-height: 52dvh; overflow: auto; white-space: pre-wrap; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--grund); border: 1px solid var(--rand); border-radius: 12px; padding: 14px;
}

.tipps { color: var(--gedaempft); font-size: 15px; border-top: 1px solid var(--rand); padding-top: 10px; }
.tipps summary { cursor: pointer; font-weight: 600; }
.tipps dl { margin: 10px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; align-items: baseline; }
.tipps dt { white-space: nowrap; }
.tipps dd { margin: 0; }
@media (max-width: 700px) { .tipps dl { grid-template-columns: 1fr; } .tipps dd { margin-bottom: 6px; } }
.tipps code { font-size: 13.5px; background: var(--grund); border: 1px solid var(--rand); border-radius: 6px; padding: 1px 6px; }
