:root {
  --fenster: #202024; --feld: #2b2b31; --knopf: #34343b; --knopf-hover: #40404a; --rand: #4a4a52;
  --text: #ececf1; --gedimmt: #9a9aa6; --akzent: #1e88e5; --gold: #f2b705;
  --hintergrund: #3a3a3a;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --fenster: #f3f3f6; --feld: #ffffff; --knopf: #e8e8ee; --knopf-hover: #dcdce4; --rand: #c4c4cc;
          --text: #1f1f24; --gedimmt: #6a6a74; --hintergrund: #c9c9d0; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fenster); color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
[hidden] { display: none !important; }
button { font: inherit; color: var(--text); background: var(--knopf); border: 1px solid var(--rand);
  border-radius: 10px; padding: 8px 14px; min-height: 44px; cursor: pointer; touch-action: manipulation; }
button:hover { background: var(--knopf-hover); }
button.haupt { background: var(--akzent); border-color: var(--akzent); color: #fff; font-weight: 600; }
button:disabled { opacity: .4; }
button svg { width: 24px; height: 24px; vertical-align: middle; stroke: currentColor; fill: none; stroke-width: 6;
  stroke-linecap: round; stroke-linejoin: round; }

.kopf { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--rand); }
.kopf h1 { font-size: 22px; margin: 0; flex: 1; }
.malkopf { padding: 6px 10px; }
.malkopf #titel { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.malkopf #fortschritt { color: var(--gedimmt); white-space: nowrap; }
.abstand { flex: 1; }
.hinweis-text { color: var(--gedimmt); margin: 10px 16px; }

/* Galerie */
#galerie { height: 100%; overflow: auto; }
#karten { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; padding: 14px; }
.karte { background: var(--feld); border: 1px solid var(--rand); border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column; }
.karte .bild { aspect-ratio: 4 / 3; background: #fff center / contain no-repeat; cursor: pointer; }
.karte .text { padding: 10px 12px 4px; }
.karte .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.karte .klein { color: var(--gedimmt); font-size: 14px; }
.karte .balken { height: 6px; background: var(--rand); border-radius: 3px; margin: 8px 0 4px; overflow: hidden; }
.karte .balken div { height: 100%; background: var(--akzent); }
.karte .aktionen { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 12px; }
.karte .aktionen button { flex: 1 1 auto; min-width: 0; padding: 6px 8px; min-height: 40px; font-size: 14px; }
.karte .sichern { color: var(--gold); font-size: 13px; }
#speicher-info { color: var(--gedimmt); font-size: 13px; padding: 4px 16px 20px; }
.leer { text-align: center; color: var(--gedimmt); padding: 60px 20px; }

/* Malen */
#malen { height: 100%; display: flex; flex-direction: column; }
.arbeitsflaeche { flex: 1; display: flex; min-height: 0; }
#leinwand { flex: 1; min-width: 0; touch-action: none; display: block; background: var(--hintergrund); }
#werkzeuge { width: 76px; display: flex; flex-direction: column; gap: 6px; padding: 8px 6px; overflow-y: auto;
  border-right: 1px solid var(--rand); }
#werkzeuge button { padding: 4px; min-height: 52px; display: flex; flex-direction: column; align-items: center;
  font-size: 11px; gap: 2px; }
#werkzeuge button.an { background: var(--akzent); border-color: var(--akzent); color: #fff; }
#werkzeuge .groesse { font-size: 12px; text-align: center; color: var(--gedimmt); }
#werkzeuge input[type=range] { writing-mode: vertical-lr; direction: rtl; width: 30px; height: 120px; margin: 0 auto; }
#palette { width: 170px; display: flex; flex-direction: column; border-left: 1px solid var(--rand); }
#farbe-aktuell { margin: 8px; padding: 10px; border-radius: 10px; text-align: center; font-weight: 700;
  border: 2px solid var(--rand); }
#farben { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px; padding: 4px 8px 12px; align-content: start; }
.farbfeld { min-height: 56px; padding: 2px; border-radius: 9px; border: 2px solid rgba(128,128,128,.6);
  font-weight: 700; line-height: 1.1; font-size: 15px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; }
.farbfeld small { font-weight: 600; font-size: 12px; opacity: .9; }
.farbfeld.an { border: 4px solid var(--akzent); }
.farbfeld.fertig { opacity: .55; }

/* Schublade (Menü) */
.schublade { position: fixed; right: 10px; top: 62px; width: min(340px, calc(100vw - 20px)); max-height: calc(100% - 80px);
  overflow: auto; background: var(--feld); border: 1px solid var(--rand); border-radius: 14px; padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 10; }
.schublade h3 { margin: 12px 0 6px; font-size: 14px; color: var(--gedimmt); text-transform: uppercase; letter-spacing: .04em; }
.schublade label { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.schublade input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--akzent); }
.schublade input[type=range] { flex: 1; accent-color: var(--akzent); }
.schublade button { width: 100%; margin: 4px 0; text-align: left; }

.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: rgba(30,30,34,.95); color: #fff;
  border: 2px solid var(--gold); border-radius: 14px; padding: 10px 22px; font-weight: 700; z-index: 20;
  pointer-events: none; max-width: 90vw; text-align: center; }
.warten { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 30; color: #fff; }
.kreisel { width: 46px; height: 46px; border: 5px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: drehen 1s linear infinite; }
@keyframes drehen { to { transform: rotate(360deg); } }

/* schmal (Handy hochkant): Palette unten */
@media (max-width: 700px) {
  .arbeitsflaeche { flex-direction: column; }
  #werkzeuge { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--rand); overflow-x: auto; }
  #werkzeuge button { min-width: 48px; min-height: 48px; }
  #werkzeuge button span { display: none; }
  #werkzeuge .groesse { align-self: center; }
  .malkopf button { padding: 6px 10px; }
  #werkzeuge input[type=range] { writing-mode: horizontal-tb; direction: ltr; width: 110px; height: auto; }
  #palette { width: auto; height: 150px; border-left: 0; border-top: 1px solid var(--rand); flex-direction: row; }
  #farbe-aktuell { width: 90px; display: flex; align-items: center; justify-content: center; }
  .malkopf #titel, .malkopf .breit { display: none; }
}
