:root {
  color-scheme: light;
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #1c2230;
  --muted: #6b7385;
  --line: #e6e8ef;
  --soft: #f0f1f6;
  --rose: #e11d48;
  --rose-2: #ff5c86;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #ea6c0c;
  --warn-soft: #ffedd5;
  --hint: #d99a00;
  --hint-soft: #fef3c7;

  --t: #8b5cf6; --t-dark: #5b21b6; --t-tint: #f5f3ff;
  --h: #f43f5e; --h-dark: #9f1239; --h-tint: #fff1f2;
  --z: #3b82f6; --z-dark: #1e40af; --z-tint: #eff6ff;
  --e: #22c55e; --e-dark: #166534; --e-tint: #effcf4;

  --radius: 22px;
  --radius-sm: 16px;
  --gap: 14px;
  --shadow: 0 1px 2px rgba(20, 27, 45, .05), 0 12px 32px -14px rgba(20, 27, 45, .2);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 6% -12%, #ffe3ea 0, transparent 62%),
    radial-gradient(820px 520px at 104% 112%, #ebe6ff 0, transparent 60%),
    var(--bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
output { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

svg { display: block; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Grundgerüst ---------- */

.app {
  display: grid;
  grid-template-columns: clamp(150px, 15vw, 230px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gap);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: var(--gap);
  padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.app.is-dragging,
.app.is-dragging * { cursor: grabbing !important; }

/* ---------- Kopfzeile ---------- */

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand {
  display: block;
  flex: none;
  border-radius: 50%;
  line-height: 0;
  transition: transform .15s;
}

.brand:hover { transform: rotate(-4deg) scale(1.04); }

.brand-logo {
  width: clamp(44px, 7.4vh, 60px);
  height: auto;
  border-radius: 50%;
  box-shadow: 0 4px 12px -4px rgba(225, 29, 72, .35);
}

.segmented {
  display: inline-flex;
  flex: none;
  padding: 4px;
  border-radius: 999px;
  background: var(--soft);
}

.segmented button {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 750;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}

.segmented button[aria-pressed="true"] {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 27, 45, .14);
}

.task {
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.6vw, 22px);
}

.task-text {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.task-label {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.target,
.target-input {
  min-width: 2ch;
  margin: 0;
  padding: 0 .12em;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  font-size: clamp(2.2rem, 8vh, 5.2rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  line-height: 1.02;
}

.target { display: inline-flex; transition: background .15s; }
.target:hover { background: var(--soft); }

.target-input {
  width: 4.6ch;
  border-bottom: 4px solid var(--rose);
  border-radius: 10px 10px 0 0;
  background: #fff5f7;
  text-align: center;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.digit { display: inline-block; transition: color .2s; }
.digit.d-t { margin-right: .2em; }

.target.is-flip .digit { animation: rise .42s cubic-bezier(.2, .9, .3, 1.2) both; animation-delay: calc(var(--i) * 45ms); }

.hints-on .digit.d-t { color: var(--t); }
.hints-on .digit.d-h { color: var(--h); }
.hints-on .digit.d-z { color: var(--z); }
.hints-on .digit.d-e { color: var(--e); }

.dice {
  display: grid;
  flex: none;
  place-items: center;
  width: clamp(48px, 7vh, 60px);
  height: clamp(48px, 7vh, 60px);
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: #fff;
  box-shadow: none;
  transition: transform .15s;
}

.dice svg { width: 100%; height: 100%; }
.dice:hover { transform: translateY(-1px) rotate(-6deg); }
.dice.is-rolling svg { animation: roll .45s ease-out; }

.tools {
  display: flex;
  justify-self: end;
  gap: 8px;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 750;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}

.chip-btn svg { width: 25px; height: 25px; }
.chip-btn[data-hints][aria-pressed="true"] { --bulb-fill: #fbbf24; --bulb-rays: 1; }
.chip-btn:hover { background: var(--soft); }
.chip-btn.icon-only { justify-content: center; width: 46px; padding: 0; }
.chip-btn[aria-pressed="true"] { border-color: #f5c542; background: #fff7d6; color: #7a5200; }

/* ---------- Blöcke links ---------- */

.palette {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  transition: box-shadow .2s, background .2s;
}

.palette.is-target {
  background: #fff6f8;
  box-shadow: var(--shadow), inset 0 0 0 3px #fda4b8;
}

.palette-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 850;
}

.palette-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 650;
}

.palette.is-target .palette-head p { color: var(--rose); }

.palette-list {
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
}

.tile {
  --c: var(--e); --c-dark: var(--e-dark); --tint: var(--e-tint);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 6px;
  min-height: 0;
  padding: 10px 8px 9px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--tint);
  cursor: grab;
  touch-action: none;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}

.tile:hover {
  border-color: color-mix(in srgb, var(--c) 35%, transparent);
  box-shadow: 0 12px 22px -14px var(--c);
  transform: translateY(-2px);
}

.tile:active { transform: scale(.97); }

.tile-t { --c: var(--t); --c-dark: var(--t-dark); --tint: var(--t-tint); }
.tile-h { --c: var(--h); --c-dark: var(--h-dark); --tint: var(--h-tint); }
.tile-z { --c: var(--z); --c-dark: var(--z-dark); --tint: var(--z-tint); }

.tile-art {
  position: relative;
  align-self: stretch;
  justify-self: stretch;
  min-height: 0;
  pointer-events: none;
}

.tile-art svg {
  position: absolute;
  inset: 0;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  filter: drop-shadow(0 4px 4px rgba(20, 27, 45, .16));
}

.tile-t .tile-art svg { height: clamp(40px, 11vh, 92px); aspect-ratio: 1; }
.tile-h .tile-art svg { height: clamp(36px, 9.5vh, 80px); aspect-ratio: 1; }
.tile-z .tile-art svg { height: clamp(56px, 13vh, 108px); aspect-ratio: 15 / 105; }
.tile-e .tile-art svg { height: clamp(18px, 4.4vh, 36px); aspect-ratio: 1; }

.tile-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--c-dark);
  font-size: .92rem;
  font-weight: 800;
  pointer-events: none;
}

.tile-label small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.app[data-range="10"] .tile-t,
.app[data-range="10"] .col-t,
.app[data-range="10"] .tile-h,
.app[data-range="10"] .col-h,
.app[data-range="20"] .tile-t,
.app[data-range="20"] .col-t,
.app[data-range="20"] .tile-h,
.app[data-range="20"] .col-h,
.app[data-range="100"] .tile-t,
.app[data-range="100"] .col-t { display: none; }

/* ---------- Stellenwerttafel rechts ---------- */

.board {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap);
  min-width: 0;
  min-height: 0;
}

.mat {
  position: relative;
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 12px;
  min-height: 0;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  transition: box-shadow .2s;
}

.mat.is-target { box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--drag-c, var(--rose)) 45%, transparent); }

.col {
  --c: var(--e); --c-dark: var(--e-dark); --tint: var(--e-tint);
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-sm);
  background: var(--tint);
  transition: box-shadow .2s, background .2s;
}

.col-t { --c: var(--t); --c-dark: var(--t-dark); --tint: var(--t-tint); }
.col-h { --c: var(--h); --c-dark: var(--h-dark); --tint: var(--h-tint); }
.col-z { --c: var(--z); --c-dark: var(--z-dark); --tint: var(--z-tint); }

.col.is-hot { background: color-mix(in srgb, var(--c) 16%, #fff); }

.col-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 14px 4px;
}

.col-letter {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--c);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 850;
  box-shadow: 0 8px 16px -8px var(--c);
}

.col-name {
  overflow: hidden;
  color: var(--c-dark);
  font-size: clamp(.8rem, 1.7vh, 1rem);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-body {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--per, 1), var(--bw, 40px));
  align-content: center;
  justify-content: center;
  gap: var(--gap-b, 8px);
  min-width: 0;
  min-height: 0;
  padding: 10px;
  overflow: hidden;
}

.col-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 10px 12px;
}

.step {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--c-dark);
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(20, 27, 45, .12);
  transition: transform .12s, opacity .15s;
}

.step:active { transform: scale(.92); }
.step:disabled { opacity: .35; cursor: default; }

.count {
  min-width: 1.6em;
  color: var(--c-dark);
  font-size: 1.7rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  visibility: hidden;
}

.hints-on .count { visibility: visible; }

.bundle {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 62px;
  left: 0;
  width: max-content;
  margin-inline: auto;
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: .82rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 8px 18px -8px rgba(28, 34, 48, .7);
  animation: pop .25s ease-out;
}

.bundle svg { display: inline-block; width: 22px; height: 22px; vertical-align: middle; --art-color: #fff; }
.bundle[hidden] { display: none; }

.col-mark {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  display: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
}

.col-mark svg { display: none; width: 100%; height: 100%; }
.col.is-right .mark-right { display: block; }
.col.is-wrong .mark-wrong { display: block; }

.col.is-right { box-shadow: inset 0 0 0 3px var(--ok); }
.col.is-right .col-mark { display: grid; background: #fff; }

.col.is-wrong { box-shadow: inset 0 0 0 3px var(--warn); animation: shake .42s; }
.col.is-wrong .col-mark { display: grid; background: #fff; }

.col.is-bundle { box-shadow: inset 0 0 0 3px var(--hint); }

.mat-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: var(--muted);
  font-size: clamp(.9rem, 2vh, 1.1rem);
  font-weight: 750;
  white-space: nowrap;
  box-shadow: 0 6px 20px -10px rgba(20, 27, 45, .35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.mat-empty svg { width: 22px; height: 22px; animation: nudge 1.6s ease-in-out infinite; }
.mat-empty[hidden] { display: none; }

/* ---------- Blöcke ---------- */

.blk {
  width: var(--bw, 40px);
  aspect-ratio: 1;
  cursor: grab;
  touch-action: none;
  /* 28.09.2026 (Alex): gelegte Blöcke ohne Schatten; nur das Ziehbild (.ghost) behält ihn. */
}

.blk-z { aspect-ratio: 15 / 105; }
.blk svg { width: 100%; height: 100%; pointer-events: none; }
.blk.is-new { animation: pop .3s cubic-bezier(.2, .9, .3, 1.35); }
.blk.is-lifted { opacity: .22; }
.blk.is-leaving { animation: leave .18s ease-in forwards; pointer-events: none; }

.ghost {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  pointer-events: none;
  transform-origin: 0 0;
  filter: drop-shadow(0 14px 16px rgba(20, 27, 45, .3));
  transition: opacity .15s;
  will-change: transform;
}

.ghost svg { width: 100%; height: 100%; }
.ghost.is-removing { opacity: .4; }

/* ---------- Leiste unten ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 10px 10px 16px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.feedback {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
  margin: 0;
  color: var(--ink);
  font-size: clamp(.92rem, 2.1vh, 1.2rem);
  font-weight: 700;
  line-height: 1.25;
}

.feedback b { font-weight: 900; }

.fb-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--muted);
}

.fb-icon svg { width: 24px; height: 24px; }
.feedback.is-hint { --bulb-fill: #fbbf24; --bulb-rays: 1; }

.feedback.is-right .fb-icon { background: var(--ok-soft); color: var(--ok); }
.feedback.is-wrong .fb-icon { background: var(--warn-soft); color: var(--warn); }
.feedback.is-hint .fb-icon { background: var(--hint-soft); color: var(--hint); }
.feedback.is-right,
.feedback.is-wrong,
.feedback.is-hint { animation: slide .3s ease-out; }
.feedback.is-right { color: #11632f; }

.btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
  transition: transform .12s, box-shadow .15s, background .2s;
}

.btn svg { width: 22px; height: 22px; }
.btn:active { transform: scale(.97); }

.btn-ghost { background: var(--soft); color: var(--ink); }
.btn-ghost:hover { background: #e7e9f0; }

.btn-primary {
  --art-color: #fff;
  height: 58px;
  padding: 0 30px 0 24px;
  background: linear-gradient(135deg, var(--rose-2), var(--rose));
  color: #fff;
  font-size: 1.2rem;
  box-shadow: 0 12px 24px -12px rgba(225, 29, 72, .8);
}

.btn-primary:hover { box-shadow: 0 14px 28px -10px rgba(225, 29, 72, .85); }
.btn-primary.is-next { background: var(--ink); box-shadow: 0 12px 24px -12px rgba(28, 34, 48, .8); }
.btn-primary.is-nudge { animation: shake .4s; }

.confetti {
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  pointer-events: none;
}
.confetti svg { width: 100%; height: 100%; }

/* ---------- Animationen ---------- */

@keyframes pop { from { opacity: 0; transform: scale(.55); } to { opacity: 1; transform: scale(1); } }
@keyframes leave { to { opacity: 0; transform: scale(.4); } }
@keyframes rise { from { opacity: 0; transform: translateY(.35em); } to { opacity: 1; transform: none; } }
@keyframes roll { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes slide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-6px); } }

/* ---------- Kleinere Bildschirme ---------- */

@media (max-width: 1400px) {
  .segmented .bis { display: none; }
  .segmented button { padding: 0 12px; }
}

@media (max-width: 900px) {
  :root { --gap: 10px; }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    row-gap: 8px;
    padding: 8px 8px 10px;
  }
  .left { display: contents; }
  .brand { grid-column: 1; grid-row: 1; }
  .segmented { grid-column: 2; grid-row: 1; justify-self: center; }
  .tools { grid-column: 3; grid-row: 1; }
  .task { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
  .chip-btn .label { display: none; }
  .chip-btn { justify-content: center; width: 42px; height: 42px; padding: 0; }
  .brand-logo { width: 44px; }
  .target, .target-input { font-size: clamp(2.2rem, 6.5vh, 3.6rem); }
}

@media (max-width: 640px) {
  .app { grid-template-columns: 84px minmax(0, 1fr); }
  .task { grid-column: 2; grid-row: 1; }
  .segmented { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .segmented button { flex: 1; min-height: 34px; padding: 0 4px; font-size: .8rem; }
  .task-label { font-size: .62rem; }
  .target, .target-input { font-size: 2.3rem; }
  .dice { width: 42px; height: 42px; border-radius: 14px; }
  .palette { gap: 8px; padding: 8px; border-radius: 18px; }
  .palette-head h2 { font-size: .85rem; text-align: center; }
  .palette-head p { display: none; }
  .palette-list { gap: 8px; }
  .tile { padding: 8px 4px 6px; border-radius: 14px; }
  .tile-label { font-size: .66rem; }
  .tile-label small { display: none; }
  .actions { flex-wrap: wrap; gap: 8px; padding: 10px; border-radius: 18px; }
  .feedback { flex: 1 1 100%; gap: 8px; font-size: .86rem; }
  .btn-primary { flex: 1; justify-content: center; }
  .fb-icon { width: 30px; height: 30px; }
  .btn-ghost { width: 46px; height: 46px; padding: 0; justify-content: center; }
  .btn-ghost .label { display: none; }
  .btn-primary { height: 50px; padding: 0 18px 0 14px; font-size: 1rem; }
  .mat, .palette, .actions, .topbar { border-radius: 18px; }
}

/* Hochformat: Spalten werden zu Bahnen, damit die Zehner nebeneinander passen */
@media (orientation: portrait) and (max-width: 900px) {
  .mat {
    grid-auto-columns: auto;
    grid-auto-flow: row;
    grid-auto-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }
  .col {
    grid-template-columns: 40px 34px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "letter count body" ". . body" "minus plus body";
  }
  .col-head { grid-area: letter; justify-content: center; padding: 8px 0 0 6px; }
  .col-name { display: none; }
  .col-letter { width: 30px; height: 30px; border-radius: 9px; font-size: 1rem; }
  .col-body { grid-area: body; padding: 8px; }
  .col-foot { display: contents; }
  .col-foot [data-minus] { grid-area: minus; justify-self: end; margin-bottom: 8px; }
  .col-foot [data-plus] { grid-area: plus; justify-self: center; margin-bottom: 8px; }
  .count { grid-area: count; align-self: end; min-width: 0; padding-bottom: 3px; font-size: 1.15rem; }
  .step { width: 30px; height: 30px; font-size: 1.1rem; }
  .bundle { right: 8px; bottom: 8px; left: auto; margin: 0; padding: 6px 10px; font-size: .74rem; }
  .col-mark { top: 6px; right: 6px; width: 24px; height: 24px; font-size: .8rem; }
}

/* Querformat mit wenig Höhe (Handy quer) */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --gap: 8px; }
  .topbar { grid-template-columns: auto auto minmax(0, 1fr) auto; grid-template-rows: auto; padding: 6px 8px; }
  .brand { grid-column: 1; grid-row: 1; }
  .segmented { grid-column: 2; grid-row: 1; }
  .task { grid-column: 3; grid-row: 1; justify-self: center; }
  .tools { grid-column: 4; grid-row: 1; }
  .task-text { grid-auto-flow: column; align-items: center; gap: 10px; }
  .task-label { font-size: .66rem; }
  .target, .target-input { font-size: clamp(1.6rem, 11vh, 2.6rem); }
  .dice { width: 42px; height: 42px; border-radius: 14px; }
  .chip-btn { height: 40px; }
  .chip-btn.icon-only { width: 40px; }
  .segmented button { min-height: 32px; }
  .brand-logo { width: 38px; }
  .palette { grid-template-rows: minmax(0, 1fr); padding: 8px; }
  .palette-head { display: none; }
  .palette-list { gap: 6px; }
  .tile { padding: 4px; gap: 2px; }
  .tile-label { font-size: .7rem; }
  .tile-label small { display: none; }
  .col-head { padding: 6px 8px 0; }
  .col-letter { width: 28px; height: 28px; font-size: .95rem; border-radius: 9px; }
  .col-foot { padding: 2px 6px 6px; }
  .step { width: 30px; height: 30px; }
  .count { font-size: 1.2rem; }
  .bundle { bottom: 42px; }
  .actions { padding: 6px 6px 6px 12px; }
  .btn { height: 42px; }
  .btn-primary { height: 44px; font-size: 1rem; }
}

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

/* ==========================================================================
   28.09.2026 (Claude): Schriften und gezeichnete Kästen wie in „Zahl des Tages“.
   Nur Ergänzungen, die bestehenden Regeln oben bleiben unverändert.
   ========================================================================== */

@font-face {
  font-family: "Baloo Tamma 2";
  src: url("assets/fonts/baloo-tamma-2.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Rubik";
  src: url("assets/fonts/rubik.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

/* Erzeugt von _grafiken/zeichne.py: gezeichnete Kastenrahmen als Daten-URIs (border-image, slice 34). */
:root {
  --frame: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M31.30 4.80Q60.70 5.05 90.50 4.80Q117.50 4.80 117.50 31.80Q117.98 61.22 117.50 90.80Q117.50 117.80 90.50 117.80Q61.15 117.91 31.30 117.80Q4.30 117.80 4.30 90.80Q3.90 61.05 4.30 31.80Q4.30 4.80 31.30 4.80Z%22 fill=%22%23fff%22/%3E%3Cpath d=%22M30.00 3.00Q59.93 2.28 90.00 3.00Q117.00 3.00 117.00 30.00Q117.06 59.53 117.00 90.00Q117.00 117.00 90.00 117.00Q60.56 117.56 30.00 117.00Q3.00 117.00 3.00 90.00Q3.65 59.89 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%231c2230%22 stroke-width=%222.9%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-ok: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M31.30 4.80Q60.61 4.32 90.50 4.80Q117.50 4.80 117.50 31.80Q116.91 61.30 117.50 90.80Q117.50 117.80 90.50 117.80Q60.37 117.75 31.30 117.80Q4.30 117.80 4.30 90.80Q3.84 60.71 4.30 31.80Q4.30 4.80 31.30 4.80Z%22 fill=%22%23fff%22/%3E%3Cpath d=%22M30.00 3.00Q61.09 3.52 90.00 3.00Q117.00 3.00 117.00 30.00Q117.63 60.86 117.00 90.00Q117.00 117.00 90.00 117.00Q60.14 117.32 30.00 117.00Q3.00 117.00 3.00 90.00Q2.08 59.68 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%2316a34a%22 stroke-width=%224.4%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-warn: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M31.30 4.80Q61.22 4.59 90.50 4.80Q117.50 4.80 117.50 31.80Q117.33 61.67 117.50 90.80Q117.50 117.80 90.50 117.80Q60.38 117.42 31.30 117.80Q4.30 117.80 4.30 90.80Q4.62 60.84 4.30 31.80Q4.30 4.80 31.30 4.80Z%22 fill=%22%23fff%22/%3E%3Cpath d=%22M30.00 3.00Q60.08 3.05 90.00 3.00Q117.00 3.00 117.00 30.00Q118.01 58.93 117.00 90.00Q117.00 117.00 90.00 117.00Q58.97 116.91 30.00 117.00Q3.00 117.00 3.00 90.00Q4.08 60.36 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%23ea6c0c%22 stroke-width=%224.4%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-open: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M31.30 4.80Q61.15 5.02 90.50 4.80Q117.50 4.80 117.50 31.80Q117.41 61.48 117.50 90.80Q117.50 117.80 90.50 117.80Q61.29 118.05 31.30 117.80Q4.30 117.80 4.30 90.80Q4.49 61.76 4.30 31.80Q4.30 4.80 31.30 4.80Z%22 fill=%22%23fff%22/%3E%3Cpath d=%22M30.00 3.00Q60.16 3.92 90.00 3.00Q117.00 3.00 117.00 30.00Q117.82 59.48 117.00 90.00Q117.00 117.00 90.00 117.00Q60.61 117.10 30.00 117.00Q3.00 117.00 3.00 90.00Q3.96 59.50 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%23a3abbb%22 stroke-width=%223.4%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-soft: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M30.00 3.00Q59.28 2.66 90.00 3.00Q117.00 3.00 117.00 30.00Q118.05 59.47 117.00 90.00Q117.00 117.00 90.00 117.00Q59.06 116.54 30.00 117.00Q3.00 117.00 3.00 90.00Q2.52 59.12 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%23c3c9d6%22 stroke-width=%222.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-soft-ok: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M30.00 3.00Q59.19 4.04 90.00 3.00Q117.00 3.00 117.00 30.00Q116.16 60.16 117.00 90.00Q117.00 117.00 90.00 117.00Q60.92 116.82 30.00 117.00Q3.00 117.00 3.00 90.00Q2.64 60.40 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%2316a34a%22 stroke-width=%223.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
  --frame-soft-warn: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22120%22 height=%22120%22 viewBox=%220 0 120 120%22%3E%3Cpath d=%22M30.00 3.00Q60.61 3.19 90.00 3.00Q117.00 3.00 117.00 30.00Q116.44 60.41 117.00 90.00Q117.00 117.00 90.00 117.00Q61.06 116.10 30.00 117.00Q3.00 117.00 3.00 90.00Q2.01 59.34 3.00 30.00Q3.00 3.00 30.00 3.00Z%22 fill=%22none%22 stroke=%22%23ea6c0c%22 stroke-width=%223.8%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22/%3E%3C/svg%3E");
}

:root {
  --font: "Rubik", ui-rounded, "SF Pro Rounded", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Baloo Tamma 2", ui-rounded, "SF Pro Rounded", "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

/* Baloo für die Zahl, große Ziffern und Überschriften; Rubik für den Rest */
.task-label,
.target,
.target-input,
.palette-head h2,
.col-letter,
.count { font-family: var(--font-display); }
.task-label { font-size: .95rem; font-weight: 800; letter-spacing: .04em; line-height: 1; }
.target, .target-input { font-weight: 800; line-height: .95; padding-top: .06em; }
.palette-head h2 { font-size: 1.2rem; font-weight: 800; }
.col-letter, .count { font-weight: 800; line-height: 1; padding-top: .1em; }
.segmented button, .tile-label, .col-name, .bundle, .btn, .palette-head p { font-weight: 600; }
.feedback { font-weight: 500; }
.feedback b { font-weight: 700; }

/* Gezeichnete Rahmen (border-image aus _grafiken/zeichne.py, Ecken bleiben unverzerrt) */
.palette,
.mat,
.actions {
  border: 2px solid transparent;
  border-image: var(--frame) 34 fill / 24px / 0 stretch;
  border-radius: 20px;
  background: none;
}

.palette.is-target { background: none; box-shadow: var(--shadow), 0 0 0 4px #fda4b8; }

/* Die Bahnen bleiben reine Farbflächen ohne eigenen Rahmen (Alex, 28.09.). */

@media (max-width: 1100px) {
  /* Tablet: Kachelbeschriftung darf umbrechen, damit die Kacheln in der Leiste bleiben. */
  .tile-label { flex-direction: column; align-items: center; gap: 0; white-space: normal; text-align: center; line-height: 1.1; }
}

@media (max-width: 640px) {
  .task-label { font-size: .7rem; }
  .palette, .mat, .actions { border-radius: 18px; }
}

/* ==========================================================================
   29.09.2026 (Claude, Nachtschicht Teil B): Geheimschrift.
   Punkt = 1, Strich = 10, Viereck = 100, Würfel = 1000. Legen, selbst zeichnen, lesen.
   Nur Ergänzungen; im Blöcke-Modus sind alle neuen Teile ausgeblendet.
   ========================================================================== */

.mode-switch { flex: none; }
.mode-switch button { font-weight: 600; }

.code-tabs,
.code-list,
.code-key,
.keypad,
.pad,
.reader,
.btn-undo { display: none; }

.app[data-mode="code"] { grid-template-columns: clamp(160px, 16vw, 240px) minmax(0, 1fr); }
.app[data-mode="code"] .blocks-list { display: none; }
.app[data-mode="code"] .palette { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
.app[data-mode="code"][data-code="read"] .palette { grid-template-rows: auto auto auto minmax(0, 1fr); }

/* Legen | Zeichnen | Lesen */
.app[data-mode="code"] .code-tabs {
  display: grid;
  gap: 3px;
  padding: 4px;
  border-radius: 18px;
  background: var(--soft);
}

.code-tabs button {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}

.code-tabs button[aria-pressed="true"] {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 27, 45, .14);
}

/* Zeichen in der Leiste und in den Spalten: Bleistiftlinie in der Stellenwertfarbe */
.tile,
.col,
.key-row { --code-ink: var(--c-dark); }

.app[data-mode="code"][data-code="lay"] .code-list { display: grid; }
.code-list .tile-art svg { filter: none; }
.code-list .tile-t .tile-art svg { height: clamp(38px, 9.5vh, 80px); }
.code-list .tile-h .tile-art svg { height: clamp(34px, 8.5vh, 72px); }
.code-list .tile-z .tile-art svg { height: clamp(40px, 10vh, 84px); aspect-ratio: 16 / 80; }
.code-list .tile-e .tile-art svg { height: clamp(28px, 6.5vh, 52px); }

.app[data-mode="code"] .blk { filter: none; }
.app[data-mode="code"] .blk-z { aspect-ratio: 16 / 80; }
.app[data-mode="code"] .ghost { filter: none; }

/* Schlüssel: So geht die Geheimschrift */
.app[data-mode="code"][data-code="draw"] .code-key,
.app[data-mode="code"][data-code="read"] .code-key { display: grid; }

.code-key {
  grid-auto-rows: minmax(0, 118px);
  align-content: start;
  gap: 10px;
  min-height: 0;
  margin: 0;
}

.key-row {
  --c: var(--e); --c-dark: var(--e-dark); --tint: var(--e-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--tint);
}

.key-t { --c: var(--t); --c-dark: var(--t-dark); --tint: var(--t-tint); }
.key-h { --c: var(--h); --c-dark: var(--h-dark); --tint: var(--h-tint); }
.key-z { --c: var(--z); --c-dark: var(--z-dark); --tint: var(--z-tint); }

.key-row dt { display: flex; flex: none; align-items: center; justify-content: center; width: clamp(26px, min(3.2vw, 7vh), 56px); height: clamp(26px, min(3.2vw, 7vh), 56px); }
.key-row dt svg { width: 100%; height: 100%; }
.key-z dt svg { width: auto; aspect-ratio: 16 / 80; }
.key-e dt svg { width: 70%; height: 70%; }
.key-row dd {
  min-width: 2.9em;
  margin: 0;
  color: var(--c-dark);
  font-family: var(--font-display);
  font-size: clamp(.95rem, min(1.55vw, 2.8vh), 1.6rem);
  white-space: nowrap;
  font-weight: 800;
  line-height: 1;
  padding-top: .12em;
}

.key-row dd::before { content: "= "; color: var(--muted); font-weight: 700; }

.app[data-range="10"] .key-t,
.app[data-range="10"] .key-h,
.app[data-range="20"] .key-t,
.app[data-range="20"] .key-h,
.app[data-range="100"] .key-t { display: none; }

/* Lesen: kleiner Schlüssel über dem Ziffernfeld */
.app[data-code="read"] .code-key { grid-auto-rows: auto; gap: 4px; }
.app[data-code="read"] .key-row { padding: 2px 8px; border-radius: 12px; }
.app[data-code="read"] .key-row dt { width: clamp(20px, 3.4vh, 30px); height: clamp(20px, 3.4vh, 30px); }
.app[data-code="read"] .key-row dd { font-size: clamp(.85rem, 2vh, 1.1rem); }

/* Ziffernfeld */
.app[data-mode="code"][data-code="read"] .keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 78px);
  align-content: center;
  gap: 8px;
  min-height: 0;
}

.keypad button {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px #d5d9e4, 0 2px 0 #d5d9e4;
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 3.6vh, 2.1rem);
  font-weight: 800;
  line-height: 1;
  padding-top: .1em;
  transition: transform .1s, background .15s;
}

.keypad button:hover { background: var(--soft); }
.keypad button:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px #d5d9e4; }
.keypad .key-zero { grid-column: span 2; }
.keypad .key-back { padding-top: 0; background: var(--soft); }
.keypad .key-back svg { width: 26px; height: 26px; }

/* Zeichenfeld und Lesefeld: gleicher gezeichneter Rahmen wie die Stellenwerttafel */
.app[data-mode="code"][data-code="draw"] .mat,
.app[data-mode="code"][data-code="read"] .mat { display: none; }
.app[data-mode="code"][data-code="draw"] .pad { display: block; }
.app[data-mode="code"][data-code="read"] .reader { display: grid; }
.app[data-mode="code"][data-code="draw"] .btn-undo { display: inline-flex; }
.app[data-mode="code"][data-code="read"] [data-clear] { display: none; }
.btn-undo:disabled { opacity: .4; cursor: default; }

.pad,
.reader {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  border: 2px solid transparent;
  border-image: var(--frame) 34 fill / 24px / 0 stretch;
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pad { cursor: crosshair; touch-action: none; }
.pad.is-right, .reader.is-right { border-image-source: var(--frame-ok); }
.pad.is-wrong, .reader.is-wrong { border-image-source: var(--frame-warn); animation: shake .42s; }
.pad.is-unknown { border-image-source: var(--frame-warn); }

.pad-ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }

.pad .ink { fill: none; stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; transition: stroke .2s; }
.pad .ink-e { stroke: var(--e-dark); stroke-width: 8; }
.pad .ink-z { stroke: var(--z-dark); }
.pad .ink-h { stroke: var(--h-dark); }
.pad .ink-t { stroke: var(--t-dark); }
.pad .ink-q { stroke: #a3abbb; stroke-dasharray: 1 7; }

.tag { --c: var(--e); --c-dark: var(--e-dark); }
.tag-z { --c: var(--z); --c-dark: var(--z-dark); }
.tag-h { --c: var(--h); --c-dark: var(--h-dark); }
.tag-t { --c: var(--t); --c-dark: var(--t-dark); }
.tag-q { --c: var(--warn); --c-dark: var(--warn); }
.tag rect { fill: #fff; stroke: var(--c); stroke-width: 2; }
.tag text { fill: var(--c-dark); font-family: var(--font-display); font-size: 15px; font-weight: 800; text-anchor: middle; dominant-baseline: central; }
.pad.is-unknown .tag-q rect { fill: var(--warn-soft); }

.pad-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 20px;
  color: #9aa1b2;
  font-size: clamp(.95rem, 2.2vh, 1.2rem);
  font-weight: 500;
  text-align: center;
  pointer-events: none;
}

.pad.has-ink .pad-empty { display: none; }

.pad-sum {
  position: absolute;
  bottom: 14px;
  left: 16px;
  margin: 0;
  padding: 5px 14px 3px;
  border-radius: 999px;
  background: var(--hint-soft);
  color: #7a5200;
  font-family: var(--font-display);
  font-size: clamp(.95rem, 2.2vh, 1.2rem);
  font-weight: 800;
  pointer-events: none;
}

.pad-sum[hidden] { display: none; }

.reader { place-items: center; padding: 14px; }

.reader-row {
  --s: 60px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: calc(var(--s) * .45) calc(var(--s) * .6);
  max-width: 100%;
}

.rd-group { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 100%; }
.rd-items { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: calc(var(--s) * .22); max-width: 100%; }
.rd svg { display: block; }
.rd-t svg { width: calc(var(--s) * 1.15); height: calc(var(--s) * 1.15); }
.rd-h svg { width: var(--s); height: var(--s); }
.rd-z svg { width: calc(var(--s) * .26); height: calc(var(--s) * 1.3); }
.rd-e svg { width: calc(var(--s) * .5); height: calc(var(--s) * .5); }

.rd-group-t { --c-dark: var(--t-dark); }
.rd-group-h { --c-dark: var(--h-dark); }
.rd-group-z { --c-dark: var(--z-dark); }
.rd-group-e { --c-dark: var(--e-dark); }
.hints-on .rd-group { --code-ink: var(--c-dark); }

.rd-count {
  display: none;
  color: var(--c-dark);
  font-family: var(--font-display);
  font-size: clamp(.9rem, calc(var(--s) * .3), 1.3rem);
  font-weight: 800;
  line-height: 1;
}

.hints-on .rd-count { display: block; }

/* Antwortfeld oben (Lesen) */
.target.is-answer { min-width: 2.2ch; border-bottom: 4px solid var(--rose); border-radius: 10px 10px 0 0; background: #fff5f7; cursor: default; justify-content: center; }
.target.is-answer:hover { background: #fff5f7; }
.target .answer-mark { color: #c3c9d6; }

@media (max-width: 1180px) {
  /* Platz für den Umschalter: Hilfen nur als Glühbirne */
  .tools .chip-btn[data-hints] .label { display: none; }
  .tools .chip-btn[data-hints] { justify-content: center; width: 46px; padding: 0; }
  .mode-switch button { padding: 0 12px; }
}

@media (max-width: 900px) {
  .tools .chip-btn[data-hints] { width: 42px; }
  .mode-switch button { min-height: 34px; padding: 0 10px; font-size: .85rem; }
  .code-tabs button { min-height: 34px; font-size: .86rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .code-tabs { grid-auto-flow: column; }
  .code-tabs button { min-height: 30px; padding: 0 6px; font-size: .78rem; }
}

/* Zurück zur Übersicht (Alex, 28.09.2026) */
a.chip-btn { color: var(--ink); text-decoration: none; }
.back-btn svg { transform: scaleX(-1); }
