/* Kinder-Mal-App – Gestaltung. Ruhige Flächen, klare Gruppen, große Touch-Ziele, gute Kontraste. */
@font-face { font-family: 'Fredoka'; src: url('../fonts/Fredoka.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }

:root {
  --bg: #f6f2ea; --panel: #ffffff; --ink: #24283b; --muted: #5d6275; --line: #e7e0d2; --soft: #f3eee4;
  --accent: #ff6a3d; --accent-soft: #fff0ea; --blue: #2f6fec; --ok: #16a34a; --danger: #c2410c;
  --stage: #ebe5d8;
  --shadow: 0 1px 2px rgba(36,40,59,.06), 0 6px 18px rgba(36,40,59,.08);
  --shadow-sm: 0 1px 2px rgba(36,40,59,.08), 0 2px 6px rgba(36,40,59,.06);
  --tap: 54px; --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Fredoka', system-ui, sans-serif; color: var(--ink); background: var(--bg);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
input, select, textarea { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.grow { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.small { font-size: .95rem; color: var(--muted); }
.center { text-align: center; }
.warn { color: var(--danger); font-weight: 600; }
.err { color: var(--danger); min-height: 1.2em; margin: 4px 0; }

#app { min-height: 100dvh; }
.screen { min-height: 100dvh; padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 16px); }

/* ---------- Symbole und Knöpfe ---------- */
.ico { display: inline-flex; width: 32px; height: 32px; pointer-events: none; flex: 0 0 auto; }
.ico svg { width: 100%; height: 100%; }
.ico.md { width: 40px; height: 40px; }
.ico.big { width: 72px; height: 72px; }
.ico.xl { width: 64px; height: 64px; }
.ico.logo { width: 48px; height: 48px; }

.btn {
  position: relative; min-width: var(--tap); height: var(--tap); padding: 0 8px; border: 0; border-radius: 14px;
  background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform .08s, background .15s;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(.93); }
.btn:disabled { opacity: .3; cursor: default; background: transparent; }
.bar > .btn, .modal .btn.xl, .modal .btn.huge, .tile-del, .tile-restore { background: var(--panel); box-shadow: var(--shadow-sm); }
.btn:focus-visible, .tool:focus-visible, .color:focus-visible, .tile:focus-visible, .profile-card:focus-visible, .btn-text:focus-visible, .cat:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn.xl { width: 96px; height: 96px; border-radius: 26px; }
.btn.xl .ico { width: 64px; height: 64px; }
.btn.huge { width: 168px; height: 168px; border-radius: 32px; border: 3px solid var(--line); }
.btn.huge:hover { border-color: var(--accent); }
.btn.huge .ico { width: 112px; height: 112px; }
.btn .badge { position: absolute; top: 6px; right: 6px; width: 13px; height: 13px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; }
.btn .count { position: absolute; top: -5px; right: -5px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 13px; line-height: 22px; padding: 0 6px; }

.btn-text {
  min-height: 46px; padding: 8px 18px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 1rem; font-weight: 500; transition: background .15s, border-color .15s;
}
.btn-text:hover { border-color: #cfc5b1; }
.btn-text.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-text.danger { color: var(--danger); border-color: #f1c6ad; }
.btn-text:disabled { opacity: .45; }

.bar { display: flex; align-items: center; gap: 10px; min-height: 60px; margin-bottom: 16px; }
.bar h1, .bar .title { font-size: 1.45rem; margin: 0; font-weight: 600; }
.pname { font-size: 1.25rem; font-weight: 600; }
.brand { max-width: 1100px; margin-left: auto; margin-right: auto; }
.brand-t { display: flex; flex-direction: column; line-height: 1.15; }
.brand-t strong { font-size: 1.5rem; letter-spacing: .2px; }
.brand-t span { color: var(--muted); font-size: 1rem; }

.avatar { display: inline-flex; align-items: center; justify-content: center; font-size: 30px; line-height: 1;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }
.avatar.md { font-size: 36px; }
.avatar.xl { font-size: 78px; }

/* ---------- Profile ---------- */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 20px; max-width: 1100px; margin: 3vh auto 0; }
.profile-card {
  aspect-ratio: 1; border: 2px solid transparent; border-radius: 28px; background: var(--panel); cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; transition: transform .12s, border-color .15s;
}
.profile-card:hover { border-color: var(--accent); }
.profile-card:active { transform: scale(.96); }
.profile-card.add { background: transparent; border: 3px dashed #d9cfbb; box-shadow: none; }
.profile-card.add:hover { border-color: var(--ok); background: #f1fbf4; }
.hint-card { max-width: 1100px; margin: 28px auto 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border-radius: 18px; padding: 14px 18px; box-shadow: var(--shadow-sm); border-left: 6px solid var(--accent); }
.hint-card p { flex: 1 1 260px; margin: 0; }

.profile-edit { display: flex; flex-direction: column; gap: 14px; width: min(540px, 86vw); }
.avatar-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.av { font-size: 36px; aspect-ratio: 1; border-radius: 16px; border: 3px solid transparent; background: var(--soft); cursor: pointer;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }
.av.on { border-color: var(--blue); background: #e8f0ff; }
.field input, .field select { min-height: 48px; border-radius: 12px; border: 1.5px solid var(--line); padding: 6px 12px; background: #fff; }
.field input { width: 100%; font-size: 1.15rem; }
.field.row { flex-wrap: wrap; }

/* ---------- Galerie und Vorlagen ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 18px; }
.tile { position: relative; aspect-ratio: 1; border: 2px solid transparent; border-radius: 20px; background: var(--panel); padding: 10px; cursor: pointer;
  box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; transition: transform .1s, border-color .15s; }
.tile:hover { border-color: var(--accent); }
.tile:active { transform: scale(.97); }
.tile.add { background: transparent; border: 3px dashed #d9cfbb; box-shadow: none; }
.tile.add:hover { border-color: var(--ok); background: #f1fbf4; }
.tpl-tile { aspect-ratio: auto; height: 190px; }
.tile-open { border: 0; background: none; padding: 0; width: 100%; height: 100%; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.thumb { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; box-shadow: 0 0 0 1px #ece6da; background: #fff; min-height: 0; }
.tpl-img { box-shadow: none; flex: 1; width: 100%; }
.tile-l { font-size: .9rem; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-del, .tile-restore { position: absolute; right: -6px; top: -6px; min-width: 44px; height: 44px; border-radius: 14px; padding: 0; }
.tile-del .ico, .tile-restore .ico { width: 26px; height: 26px; }
.tile-restore { min-width: 56px; height: 56px; }
.tile.trashed .thumb { opacity: .55; }
.empty-note { grid-column: 1 / -1; display: flex; justify-content: center; padding: 40px; opacity: .4; }

.cats { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 14px; scrollbar-width: thin; }
.cat { flex: 0 0 auto; width: 104px; border-radius: 20px; border: 2px solid transparent; background: var(--panel); box-shadow: var(--shadow-sm); cursor: pointer;
  padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: border-color .15s; }
.cat-i { width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; }
.cat-i img { max-width: 100%; max-height: 100%; }
.cat-l { font-size: .82rem; color: var(--muted); text-align: center; line-height: 1.1; }
.cat.on { border-color: var(--accent); background: var(--accent-soft); }
.cat.on .cat-l { color: var(--ink); font-weight: 600; }
.subs { display: flex; gap: 10px; overflow-x: auto; padding: 0 2px 16px; }
.sub { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 16px; border: 2px solid transparent; background: var(--panel); box-shadow: var(--shadow-sm); cursor: pointer; padding: 6px;
  display: flex; align-items: center; justify-content: center; }
.sub img { max-width: 100%; max-height: 100%; }
.sub.on { border-color: var(--accent); background: var(--accent-soft); }

.choice { display: flex; gap: 24px; padding: 22px 8px 8px; flex-wrap: wrap; justify-content: center; }
.formats { display: grid; grid-template-columns: repeat(3, minmax(110px, 1fr)); gap: 14px; width: min(460px, 86vw); padding-top: 22px; }
.fmt { height: 140px; border-radius: 20px; border: 3px solid transparent; background: var(--soft); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 10px; padding-bottom: 14px; }
.fmt.on { border-color: var(--accent); background: var(--accent-soft); }
.sheet { display: block; background: #fff; border: 2px solid var(--ink); border-radius: 3px; box-shadow: 2px 2px 0 rgba(0,0,0,.08); }
.fmt-l { font-weight: 600; font-size: 1.15rem; }
.fmt-note { grid-column: 1 / -1; margin: 4px 0 0; text-align: center; }

/* ---------- Malen ---------- */
body[data-screen="s-paint"] { overflow: hidden; }
#s-paint { height: 100dvh; min-height: 0; display: flex; flex-direction: column; gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 10px); }
.paint-top { margin: 0; min-height: 0; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.grp { display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-sm); flex: 0 0 auto; }
.grp .btn { height: 50px; min-width: 50px; }
.grp .btn .ico { width: 30px; height: 30px; }
.fmt-chip { padding: 0 12px 0 10px; gap: 8px; font-weight: 600; font-size: 1.1rem; }
.mini-sheet { display: inline-block; background: #fff; border: 2px solid var(--ink); border-radius: 2px; }
.mini-sheet.portrait { width: 18px; height: 25px; }
.mini-sheet.landscape { width: 25px; height: 18px; }
.btn.mode { margin-right: 10px; } /* Abstand, damit der Umschalter nicht aus Versehen getroffen wird */
.work { flex: 1; min-height: 0; display: flex; gap: 10px; }
body.left-hand .work { flex-direction: row-reverse; }
.tools { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; padding: 8px; scrollbar-width: none;
  background: var(--panel); border-radius: 22px; box-shadow: var(--shadow-sm); }
.tool { width: 72px; height: 72px; flex: 0 0 auto; border-radius: 18px; border: 3px solid transparent; background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform .08s, background .15s; }
.tool:hover { background: var(--soft); }
.tool .ico { width: 54px; height: 54px; }
.tool.on { border-color: var(--accent); background: var(--accent-soft); }
.stage { position: relative; flex: 1; min-width: 0; border-radius: 22px; overflow: hidden; touch-action: none;
  background-color: var(--stage); background-image: radial-gradient(rgba(36,40,59,.07) 1px, transparent 1px); background-size: 18px 18px; }
.stage canvas { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }

.bottom { display: flex; align-items: center; gap: 12px; overflow-x: auto; scrollbar-width: none; min-height: 72px;
  padding: 8px 12px; background: var(--panel); border-radius: 22px; box-shadow: var(--shadow-sm); }
.sizes { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; padding-right: 12px; border-right: 1.5px solid var(--line); }
.size { width: 56px; height: 56px; border-radius: 50%; border: 3px solid transparent; background: var(--soft);
  cursor: pointer; display: flex; align-items: center; justify-content: center; }
.size.on { border-color: var(--accent); background: var(--accent-soft); }
.size-dot { width: var(--d); height: var(--d); border-radius: 50%; background: var(--ink); display: block; flex: 0 0 auto; }
.sizes.adv { gap: 10px; }
.size-range { width: 160px; height: 40px; accent-color: var(--accent); }
.colors { display: flex; gap: 8px; flex: 0 0 auto; flex-wrap: nowrap; align-items: center; }
.colors.adv { display: grid; grid-template-rows: repeat(2, 38px); grid-auto-flow: column; grid-auto-columns: 38px; gap: 6px; }
.color { width: 52px; height: 52px; border-radius: 50%; border: 3px solid #fff; background: var(--c); cursor: pointer;
  box-shadow: 0 0 0 1.5px var(--line); flex: 0 0 auto; position: relative; transition: transform .1s; }
.colors.adv .color { width: 38px; height: 38px; }
.color.on { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.08); }
.color.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.color.custom .ico { width: 22px; height: 22px; }
.color-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.shapes { display: flex; gap: 6px; flex: 0 0 auto; padding-right: 12px; border-right: 1.5px solid var(--line); }
.shape { width: 54px; height: 54px; border-radius: 14px; border: 3px solid transparent; background: var(--soft); cursor: pointer; padding: 4px; }
.shape.on { border-color: var(--accent); background: var(--accent-soft); }
.shape canvas { width: 100%; height: 100%; }

/* Kleine Bildschirme (Handy): kompakter, Kopfleiste darf umbrechen */
@media (max-width: 760px), (max-height: 560px) {
  :root { --tap: 46px; }
  .tool { width: 56px; height: 56px; border-radius: 14px; }
  .tool .ico { width: 40px; height: 40px; }
  .tools { padding: 5px; }
  .color { width: 44px; height: 44px; }
  .size { width: 46px; height: 46px; }
  .ico { width: 28px; height: 28px; }
  .grp .btn { height: 44px; min-width: 44px; }
  .grp .btn .ico { width: 26px; height: 26px; }
  .profiles { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
  .paint-top { flex-wrap: wrap; }
  .paint-top .grow { display: none; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .tpl-tile { height: 160px; }
}

/* ---------- Dialoge ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(36,40,59,.42); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { position: relative; background: var(--panel); border-radius: 28px; padding: 30px 26px 24px; max-width: 94vw; max-height: 92dvh; overflow: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.25); animation: pop .18s; -webkit-user-select: text; user-select: text; }
.modal-x { position: absolute; top: 8px; right: 8px; min-width: 44px; height: 44px; }
.modal-x .ico { width: 30px; height: 30px; }
.confirm { display: flex; flex-direction: column; align-items: center; gap: 16px; max-width: 460px; text-align: center; font-size: 1.25rem; }
.confirm p { margin: 0; }
.gate { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; min-width: min(360px, 84vw); }
.gate h2 { margin: 0; }
.gate-in { width: 110px; min-height: 52px; font-size: 1.5rem; text-align: center; border-radius: 12px; border: 1.5px solid var(--line); }
.gate-msg { color: var(--danger); min-height: 1.2em; margin: 0; }
.guide { max-width: 620px; }
.guide h3 { margin: 16px 0 4px; }
.guide li { margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 14px; z-index: 60; max-width: 90vw; transition: opacity .3s; box-shadow: var(--shadow); }
.toast.out { opacity: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

/* ---------- Elternbereich ---------- */
.parents { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; -webkit-user-select: text; user-select: text; }
.psec { background: var(--panel); border-radius: 20px; padding: 18px 22px; box-shadow: var(--shadow-sm); }
.psec h2 { margin: 0 0 10px; font-size: 1.2rem; }
.psec p { margin: 6px 0; }
.psec a { color: var(--blue); font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plist li { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plist li:last-child { border-bottom: 0; }
.plist li.deleted { opacity: .65; }

/* ---------- Druck ---------- */
#print-area { display: none; }
@media print {
  body { background: #fff; }
  #app, .modal-bg, .toast { display: none !important; }
  #print-area { display: flex; align-items: center; justify-content: center; width: 100%; height: 100vh; }
  #print-area img { max-width: 100%; max-height: 100%; object-fit: contain; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Malen nach Zahlen ---------- */
/* Farben mit Nummern in der Farbleiste (1–3 Reihen je nach Anzahl, waagerecht scrollbar) */
/* zeilenweise nummeriert: 1 2 3 … in der ersten Reihe */
.colors.num { display: grid; grid-auto-flow: row; gap: 6px; }
.colors.num.r1 { grid-template-columns: repeat(var(--cols), 52px); grid-auto-rows: 52px; }
.colors.num.r2 { grid-template-columns: repeat(var(--cols), 42px); grid-auto-rows: 42px; }
.colors.num.r3 { grid-template-columns: repeat(var(--cols), 34px); grid-auto-rows: 34px; gap: 4px; }
.color.num-color { width: 100%; height: 100%; color: var(--t); font: 700 1.1rem/1 inherit; font-family: inherit;
  display: flex; align-items: center; justify-content: center; padding: 0; }
.colors.num.r2 .num-color { font-size: .95rem; }
.colors.num.r3 .num-color { font-size: .8rem; border-width: 2px; }
.num-preview { width: 66px; height: 50px; padding: 0; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: #fff; flex: 0 0 auto; }
.num-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.num-toggle { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.num-toggle .ico { width: 24px; height: 24px; }
.num-preview-big { display: flex; flex-direction: column; gap: 10px; align-items: center; max-width: min(720px, 86vw); }
.num-preview-big img { max-width: 100%; max-height: 62dvh; border-radius: 14px; display: block; }
.tpl-tile { position: relative; }
.tpl-img.photo { object-fit: cover; border-radius: 12px; }
.num-badge { position: absolute; top: 10px; right: 10px; background: var(--accent); color: #fff; font-weight: 700; font-size: .8rem;
  padding: 3px 8px; border-radius: 999px; box-shadow: var(--shadow-sm); letter-spacing: .5px; }
/* Stufen-Auswahl */
.level-box { display: flex; flex-direction: column; gap: 10px; width: min(980px, 86vw); }
.level-box h2 { margin: 0; }
.levels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .levels { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.level { position: relative; display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left; padding: 8px 8px 10px;
  border: 3px solid transparent; border-radius: 18px; background: var(--soft); cursor: pointer; font: inherit; color: inherit; }
.level:hover { border-color: var(--line); }
.level.rec { border-color: var(--accent); background: var(--accent-soft); }
.level img { width: 100%; aspect-ratio: 1.414; object-fit: cover; border-radius: 12px; background: #fff; }
.level-t { font-size: 1.05rem; }
.level-d { font-size: .85rem; opacity: .75; }
.level-rec { position: absolute; top: 14px; left: 14px; background: var(--accent); color: #fff; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.level-dots { display: flex; gap: 4px; }
.level-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: block; }
.level-dots i.on { background: var(--accent); }
@media (max-width: 760px), (max-height: 560px) {
  .colors.num.r1 { grid-template-columns: repeat(var(--cols), 44px); grid-auto-rows: 44px; }
  .colors.num.r2 { grid-template-columns: repeat(var(--cols), 36px); grid-auto-rows: 36px; }
  .colors.num.r3 { grid-template-columns: repeat(var(--cols), 30px); grid-auto-rows: 30px; }
  .num-preview { width: 50px; height: 38px; }
  .levels { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
