/* Werkstatt auf Millimeterpapier: kräftige Tinte, Filament-Orange, goldenes PEI-Druckbett.
   Bewusst ein einziges helles Thema, damit das Spiel im Klassenzimmer überall gleich aussieht. */
:root {
  color-scheme: light;
  --paper: #eef3f1;
  --paper-line: rgba(29, 43, 79, 0.06);
  --paper-line-strong: rgba(29, 43, 79, 0.11);
  --card: #fffdf8;
  --ink: #1d2b4f;
  --ink-soft: #4a587c;
  --filament: #ff7a3d;
  --filament-dark: #c4501b;
  --pei: #d9b56a;
  --teal: #2ec4b6;
  --good: #1f9e6e;
  --bad: #e0244a;
  --warn: #d9822b;
  --overhang: #ffd23f;
  --bridge: #4cc9f0;
  --floating: #ff3b5c;
  --falls: #ff8c42;
  --support: #d9dde8;

  --font-display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius: 14px;
  --shadow: 0 3px 0 var(--ink);
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--paper-line-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line-strong) 1px, transparent 1px),
    linear-gradient(var(--paper-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 50px 50px, 50px 50px, 10px 10px, 10px 10px;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.1; margin: 0; text-wrap: balance; letter-spacing: 0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--filament); outline-offset: 2px; }
.eyebrow { font-family: var(--font-mono); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--filament-dark); }
.small { font-size: 14px; color: var(--ink-soft); }
.note { font-size: 14px; background: #fff4d6; border: 2px dashed var(--warn); border-radius: 10px; padding: 8px 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px;
  border: 2px solid var(--ink); border-radius: 12px;
  background: var(--card); color: var(--ink);
  font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.btn:hover:not(:disabled) { background: #fff; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--filament); color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); }
.btn-primary:hover:not(:disabled) { background: #ff8b55; }
.btn-ghost { box-shadow: none; background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: rgba(29, 43, 79, 0.06); }
.btn-small { min-height: 38px; padding: 6px 12px; font-size: 15px; }
.btn-big { min-height: 56px; padding: 12px 28px; font-size: 20px; font-family: var(--font-display); font-weight: 400; letter-spacing: 0.02em; }
.btn-round { width: 42px; padding: 0; }
.btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 10px;
  padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  background: rgba(238, 243, 241, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 2px solid var(--ink);
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 10px; }
.brand-name { font-family: var(--font-display); font-size: 26px; letter-spacing: 0.02em; }
.brand-mark { display: grid; gap: 2px; }
.brand-mark i { display: block; height: 6px; border-radius: 3px; border: 2px solid var(--ink); }
.brand-mark i:nth-child(1) { width: 14px; margin-left: 7px; background: var(--overhang); }
.brand-mark i:nth-child(2) { width: 22px; margin-left: 3px; background: var(--teal); }
.brand-mark i:nth-child(3) { width: 28px; background: var(--filament); }
.topnav { display: flex; gap: 8px; align-items: center; }
body[data-screen="title"] #nav-map, body[data-screen="title"] #nav-lexikon { display: none; }

main { padding-left: var(--gutter-l); padding-right: var(--gutter-r); padding-block: 20px 40px; }

/* ---------- Startbildschirm ---------- */
.hero { max-width: 980px; margin: 0 auto; display: grid; gap: 22px; padding-top: 12px; }
.hero-title { font-size: clamp(64px, 14vw, 132px); line-height: 0.9; color: var(--ink); text-shadow: 4px 4px 0 var(--filament); }
.hero-title span { display: block; font-size: clamp(22px, 4vw, 36px); color: var(--ink-soft); text-shadow: none; margin-top: 10px; letter-spacing: 0.03em; }
.hero-lead { font-size: 19px; max-width: 62ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.title-creatures { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }
.title-creature { width: clamp(64px, 12vw, 104px); animation: hop 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * -0.4s); }
.how { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; counter-reset: how; }
.how li { counter-increment: how; background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: 14px 16px 14px 56px; position: relative; font-size: 15px; }
.how li::before { content: counter(how); position: absolute; left: 14px; top: 14px; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: #fff; font-family: var(--font-display); display: grid; place-items: center; }
.how b { display: block; font-family: var(--font-display); font-weight: 400; font-size: 20px; }

@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.creature { display: block; width: 100%; height: auto; overflow: visible; }
.creature .creature-body { transform-origin: 50% 90%; animation: squish 3s ease-in-out infinite; }
@keyframes squish { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.03, 0.97); } }
.creature.mood-cheer .creature-body { animation: cheer 0.7s ease-in-out infinite; }
@keyframes cheer { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-6px) scale(0.97, 1.04); } }

/* ---------- Karte ---------- */
.map-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; max-width: 1100px; margin: 0 auto 18px; }
.map-head h1 { font-size: clamp(34px, 6vw, 52px); }
.map-head p { color: var(--ink-soft); }
.map-total { font-family: var(--font-display); font-size: 26px; display: flex; align-items: center; gap: 6px; color: var(--ink); }
.map-total .star svg { width: 30px; height: 30px; }
#map-worlds, #teacher-note { max-width: 1100px; margin: 0 auto; }
#teacher-note { margin-bottom: 14px; }
.world { margin-bottom: 26px; }
.world-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; padding-bottom: 6px; border-bottom: 2px dashed var(--paper-line-strong); }
.world-head h2 { font-size: 28px; }
.world-head p { font-family: var(--font-mono); font-size: 13px; color: var(--ink-soft); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.level-card {
  position: relative; display: grid; justify-items: center; gap: 4px;
  padding: 14px 10px 12px; border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); cursor: pointer; text-align: center;
  transition: transform 0.12s;
}
.level-card:hover:not(:disabled) { transform: translateY(-3px) rotate(-1deg); }
.level-card.done { background: #f2fbf6; }
.level-card.locked { background: #e6e9ee; cursor: not-allowed; }
.level-card.locked .level-creature { filter: grayscale(1); opacity: 0.45; }
.level-num { position: absolute; top: 8px; left: 10px; font-family: var(--font-display); font-size: 20px; color: var(--ink-soft); }
.level-creature { width: 78px; }
.level-title { font-weight: 700; font-size: 15px; line-height: 1.25; min-height: 2.5em; display: grid; align-items: center; }
.level-stars { display: flex; gap: 2px; }
.star svg { width: 22px; height: 22px; fill: #d4d8e0; stroke: var(--ink); stroke-width: 1.4; }
.star.on svg { fill: #ffc83d; }
.lock { position: absolute; top: 10px; right: 10px; }
.lock svg { width: 22px; height: 22px; fill: var(--ink-soft); stroke: var(--ink-soft); }

/* ---------- Lexikon ---------- */
.lex-list { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.lex-card { background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: 14px 16px; }
.lex-card dt { font-family: var(--font-display); font-size: 22px; margin-bottom: 4px; }
.lex-card dd { margin: 0; font-size: 15px; }

/* ---------- Level ---------- */
#screen-level { max-width: 1320px; margin: 0 auto; }
.level-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-bottom: 14px; }
.level-who { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.level-who-creature { width: 46px; flex: none; }
.level-who h1 { font-size: clamp(22px, 3vw, 30px); }
.stepper { list-style: none; display: flex; gap: 4px; margin: 0; padding: 0; }
.stepper li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--ink-soft); border: 2px solid transparent; }
.stepper li span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: #dfe4ea; font-family: var(--font-display); font-size: 14px; color: var(--ink); }
.stepper li.active { border-color: var(--ink); background: var(--card); color: var(--ink); }
.stepper li.active span { background: var(--filament); color: #fff; }
.stepper li.done span { background: var(--teal); color: #fff; }

.level-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.stage {
  position: relative; height: clamp(420px, calc(100vh - 190px), 820px);
  border: 2px solid var(--ink); border-radius: 18px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #ffffff 0%, #e3ecf0 70%);
  touch-action: none;
  scroll-margin-top: 76px;
}
.stage[data-phase="slice"] { touch-action: auto; }
.stage[data-phase="print"] { background: #1b2647; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage canvas[hidden] { display: none; }
.panel .mini {
  width: 100%; height: 170px; display: block;
  background: radial-gradient(ellipse at 50% 35%, #ffffff 0%, #dde6ea 80%);
  border: 2px solid var(--ink); border-radius: 12px;
}
.hint {
  position: absolute; left: 12px; top: 12px; right: 12px; max-width: 520px;
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 2px solid var(--ink); border-radius: 14px;
  padding: 8px 14px 8px 8px; box-shadow: var(--shadow); pointer-events: none;
}
.hint-filo { width: 52px; flex: none; }
.hint p { font-size: 15px; line-height: 1.35; min-width: 0; }
.stage[data-phase="print"] .hint { top: auto; bottom: 12px; }
.toast {
  position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 24px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); }
.stage[data-phase="print"] .toast { bottom: auto; top: 14px; }

.panel {
  background: var(--card); border: 2px solid var(--ink); border-radius: 18px; padding: 16px;
  display: grid; gap: 14px; align-content: start; min-width: 0;
}
.panel-title { display: flex; align-items: center; gap: 10px; font-size: 28px; }
.step-num { width: 34px; height: 34px; border-radius: 50%; background: var(--filament); color: #fff; display: grid; place-items: center; font-size: 20px; border: 2px solid var(--ink); }
.panel-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.panel-actions .btn-primary { flex: 1 1 auto; }

.tilt-pad { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tilt-pad .btn { justify-content: flex-start; font-size: 15px; padding: 8px 10px; }
.tilt-pad .span2 { grid-column: span 2; justify-content: center; }
.view-row { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.view-row span { margin-right: auto; }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; padding: 12px; background: var(--paper); border-radius: 12px; font-size: 15px; }
.stats dt { color: var(--ink-soft); }
.stats dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.stats dd.good { color: var(--good); }
.stats dd.bad { color: var(--bad); }
.stats dd.warnc { color: var(--warn); }
.warn { background: #ffe3e8; border: 2px solid var(--bad); border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 14px; color: #8f1230; }
.txt-red { color: var(--bad); }
.txt-orange { color: var(--warn); }
.cell-info { font-size: 14px; padding: 8px 12px; border-radius: 10px; background: var(--paper); border-left: 6px solid #9aa3b5; }
.cell-info[data-status="overhang"] { border-left-color: var(--overhang); }
.cell-info[data-status="bridge"] { border-left-color: var(--bridge); }
.cell-info[data-status="floating"] { border-left-color: var(--floating); }
.cell-info[data-status="falls"] { border-left-color: var(--falls); }
.cell-info[data-status="solid"], .cell-info[data-status="bed"] { border-left-color: var(--good); }

.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--ink); flex: none; }
.sw-solid { background: #9aa3b5; }
.sw-overhang { background: var(--overhang); }
.sw-bridge { background: var(--bridge); }
.sw-floating { background: var(--floating); }
.sw-falls { background: var(--falls); }
.sw-support { background: repeating-linear-gradient(45deg, var(--support) 0 3px, #aab0c0 3px 5px); }

.gcode { margin: 0; padding: 10px 12px; background: #111a33; color: #b8f5d0; border-radius: 10px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; overflow-x: auto; white-space: pre; }
.ticker { min-height: calc(7 * 1.55em + 20px); }
.layer-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 17px; }
.pill { font-size: 12px; font-family: var(--font-mono); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 9px; border-radius: 999px; border: 2px solid var(--ink); }
.pill-you { background: var(--filament); color: #fff; }
.pill-auto { background: var(--bridge); }
.progress { height: 14px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--paper); }
.progress span { display: block; height: 100%; width: 0; background: var(--teal); transition: width 0.15s; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { margin: 8px 0 0; padding-left: 20px; font-size: 14px; display: grid; gap: 4px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: start center;
  padding: max(16px, env(safe-area-inset-top, 0px)) var(--gutter-r) max(16px, env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  background: rgba(29, 43, 79, 0.55); overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(560px, 100%); background: var(--card); border: 3px solid var(--ink); border-radius: 22px;
  padding: 22px; box-shadow: 0 6px 0 var(--ink); animation: pop 0.25s ease-out; margin: auto;
}
.modal-card.wide { width: min(760px, 100%); }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.intro { display: grid; gap: 18px; }
.intro-request { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; align-items: center; }
.bubble { position: relative; background: #fff; border: 2px solid var(--ink); border-radius: 16px; padding: 12px 16px; font-size: 17px; }
.bubble::before { content: ""; position: absolute; left: -12px; top: 50%; width: 18px; height: 18px; background: #fff; border-left: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: translateY(-50%) rotate(45deg); }
.bubble strong { display: block; font-family: var(--font-display); font-weight: 400; font-size: 22px; }
.lesson { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; background: #e6f8f5; border: 2px solid var(--teal); border-radius: 16px; padding: 14px; }
.lesson h3 { font-size: 24px; margin: 2px 0 6px; }
.lesson p:last-child { max-width: 62ch; }

.result { display: grid; gap: 16px; }
.result-head { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 16px; align-items: center; }
.result-head h2 { font-size: 30px; margin: 2px 0 6px; }
.big-stars { display: flex; gap: 6px; margin-bottom: 8px; }
.big-star svg { width: 46px; height: 46px; fill: #d4d8e0; stroke: var(--ink); stroke-width: 1.4; }
.big-star.on svg { fill: #ffc83d; animation: starpop 0.5s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: var(--d); }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
.small-bubble { font-size: 15px; padding: 8px 12px; }
.small-bubble::before { display: none; }
.points { margin-top: 8px; font-family: var(--font-display); font-size: 22px; }
.points span { font-family: var(--font-body); font-size: 13px; color: var(--ink-soft); }
.tip { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; background: #e6f8f5; border: 2px solid var(--teal); border-radius: 14px; padding: 10px 14px; }
.res-grid { display: grid; gap: 0; border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; }
.res-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 2px 12px; padding: 10px 14px; border-top: 1px solid var(--paper-line-strong); }
.res-row:first-child { border-top: 0; }
.res-row:nth-child(even) { background: var(--paper); }
.res-label { font-weight: 700; grid-row: span 2; }
.res-value { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-weight: 700; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.res-expl { font-size: 14px; color: var(--ink-soft); }
.grade { font-size: 12px; font-family: var(--font-mono); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; border: 2px solid var(--ink); white-space: nowrap; }
.grade-good { background: #c9f2dd; }
.grade-ok { background: #fff0b8; }
.grade-bad { background: #ffd0d9; }
.grade-neutral { background: #e6e9ee; }
.best-preview { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: center; background: var(--paper); border-radius: 14px; padding: 8px 12px; }
.best-preview canvas { width: 220px; height: 170px; max-width: 100%; }
.fact { font-size: 15px; background: #fff4d6; border-radius: 12px; padding: 10px 14px; }
.finale { font-family: var(--font-display); font-size: 22px; color: var(--filament-dark); }

/* ---------- schmal ---------- */
@media (max-width: 980px) {
  .level-body { grid-template-columns: minmax(0, 1fr); }
  .level-head { grid-template-columns: 1fr; }
  .stepper { overflow-x: auto; }
  .stage { height: clamp(380px, 62vh, 640px); }
}
@media (max-width: 560px) {
  .stepper li { font-size: 0; gap: 0; padding: 4px; }
  .stepper li span { font-size: 14px; }
  .hint-filo { width: 40px; }
  .hint p { font-size: 13.5px; }
  .intro-request, .result-head { grid-template-columns: 84px minmax(0, 1fr); }
  .lesson { grid-template-columns: 56px minmax(0, 1fr); }
  .res-row { grid-template-columns: minmax(0, 1fr); }
  .res-label { grid-row: auto; }
  .best-preview { grid-template-columns: minmax(0, 1fr); }
  .modal-card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
