:root {
  --bg: #ffffff;
  --bg-secondary: rgba(120,120,128,0.10);
  --primary: #000000;
  --primary-07: rgba(0,0,0,0.7);
  --primary-02: rgba(0,0,0,0.2);
  --blue: #007aff;
  --blue-08: rgba(0,122,255,0.8);
  --blue-03: rgba(0,122,255,0.3);
  --green: #34c759;
  --red: #ff3b30;
  --indigo: rgba(88,86,214,0.8);
  --purple: rgba(175,82,222,0.8);
  --gray: #8e8e93;
  --cell: 80px; /* updated at runtime via --cell */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-secondary: rgba(120,120,128,0.18);
    --primary: #ffffff;
    --primary-07: rgba(255,255,255,0.7);
    --primary-02: rgba(255,255,255,0.2);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--primary);
  overflow: hidden;
}
#app {
  display: flex; flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg); gap: 8px;
}
#toolbar h1 { font-size: 1.4rem; font-weight: 500; color: var(--primary-07); margin: 0; text-align: center; flex: 1; }
.toolbar-left, .toolbar-right { display: flex; gap: 12px; }
.icon-btn {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  padding: 4px; line-height: 1; opacity: 0.85; color: var(--primary-07);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:disabled { opacity: 0.25; cursor: default; }
.icon-btn svg { width: 26px; height: 26px; display: block; }
#viz {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#controls {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; padding: 16px; border-top: 1px solid var(--primary-02);
  flex-wrap: wrap;
}
.ctrl-block { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.ctrl-texts { flex: 1; min-width: 200px; align-items: center; text-align: center; }
.ctrl-row { display: flex; align-items: center; gap: 6px; }
.ctrl-label { font-size: 1.4rem; }
.step-btn {
  font-size: 2rem; border: none; background: none; cursor: pointer; line-height: 1;
  width: 48px; height: 48px; border-radius: 50%;
}
.step-btn.minus { color: var(--indigo); }
.step-btn.plus { color: var(--purple); }
.zahlpicker { font-size: 1.4rem; font-weight: 700; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
#cover-overlay { position: absolute; inset: 0; background: var(--gray); z-index: 5; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 50; }
@media (max-width: 640px) {
  #controls { flex-direction: column; align-items: stretch; }
  .ctrl-block { flex-direction: row; justify-content: center; }
}
.aufgabe-row { display: flex; align-items: center; gap: 8px; justify-content: center; }
.aufgabe { font-size: 2rem; font-weight: 700; cursor: pointer; }
.aufgabe.green { color: var(--green); }
.aufgabe.red { color: var(--red); }
.teiler-satz { font-size: 2rem; font-weight: 700; cursor: pointer; }
.teiler-satz.green { color: var(--green); }
.teiler-satz.red { color: var(--red); }
.beschreibung { font-size: 1.4rem; text-align: center; cursor: pointer; }
.beschreibung.red { color: var(--red); }
.grouping-outer { display: flex; align-items: center; gap: 8px; }
.grouping-wrap { display: flex; flex-direction: column; align-items: center; }
.g-row { display: flex; align-items: center; }
.g-cols { display: flex; align-items: flex-start; }
.g-col { display: flex; flex-direction: column; align-items: center; }
.g-label { display: flex; align-items: center; justify-content: center; color: var(--primary); }
.tile {
  border-radius: 50%; background: var(--blue); border: solid var(--primary);
  display: flex; align-items: center; justify-content: center; color: #fff;
  transition: width .3s, height .3s, transform .3s;
}
.tile.faded { background: var(--blue-08); color: rgba(255,255,255,0.5); }
.g-row.grouped, .g-cols.grouped { background: var(--blue-03); border-radius: 999px; padding: 2px; }
.separator { width: 40px; background: var(--primary); opacity: 0.55; border-radius: 8px; cursor: ew-resize; touch-action: none; }
.b-scroll { width: 100%; height: 100%; overflow: auto; display: flex; justify-content: center; }
.b-stack { display: flex; flex-direction: column; align-items: center; padding: 16px; }
.b-groups { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; }
.b-group { display: flex; flex-direction: column; align-items: center; padding: 8px; border-radius: 16px; }
.b-group.grouped { background: var(--blue-03); }
.b-grid { display: flex; flex-direction: column; }
.b-row { display: flex; }
.b-rest { display: flex; flex-direction: column; align-items: center; padding: 8px; border-radius: 16px; background: rgba(255,59,48,0.2); }
.b-lbl { color: var(--primary); text-align: center; }
.b-lbl.red { color: var(--red); }
.nl-scroll { width: 100%; height: 100%; overflow: auto; padding: 16px; }
.nl-stack { display: flex; flex-direction: column; gap: 30px; }
.nl-line { display: flex; align-items: flex-start; gap: 8px; padding-left: 40px; position: relative; }
.nl-circle { width: 48px; height: 48px; border: 2px solid var(--primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; flex: none; }
.nl-circle.good { background: rgba(52,199,89,0.1); }
.nl-circle.bad { background: rgba(255,59,48,0.1); border-color: var(--red); }
.nl-del { position: absolute; left: 8px; top: -8px; border: none; background: #fff; color: var(--gray);
  border-radius: 50%; font-size: 16px; cursor: pointer; }
.nl-lane { position: relative; }
.nl-nums { display: flex; align-items: flex-end; font-size: 12px; height: 16px; }
.nl-nums > div { text-align: left; }
.nl-ticks { display: flex; align-items: flex-end; height: 12px; }
.nl-tickcell { display: flex; flex-direction: column; align-items: flex-start; }
.nl-vtick { width: 1px; background: var(--primary); }
.nl-htick { height: 1px; background: var(--primary); }
.nl-bars { display: flex; align-items: flex-end; height: 12px; }
.nl-bar { height: 12px; }
.nl-dots { display: flex; }
.nl-dotcell { display: flex; align-items: center; justify-content: flex-start; position: relative; }
.nl-dotcell.boundary::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 1px; background: var(--primary); }
.nl-dot { border-radius: 50%; }
.nl-cover { position: absolute; top: 0; bottom: 0; background: var(--gray); transition: left .3s, width .3s; }
.nl-add { background: none; border: none; color: var(--blue); font-size: 1.2rem; cursor: pointer; padding: 12px 0; }
.nl-add:disabled { color: var(--primary-02); cursor: default; }
.popover { background: var(--bg); border: 1px solid var(--primary-02); border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25); padding: 16px; z-index: 100; }
.zahlpicker-pop { width: 240px; }
.zp-head { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.zp-display { font-size: 2rem; min-width: 60px; text-align: right; }
.zp-ok { width: 56px; height: 56px; border-radius: 50%; border: none; font-size: 1.6rem;
  background: var(--blue); color: #fff; cursor: pointer; }
.zp-ok:disabled { background: var(--red); cursor: default; }
.zp-hint { font-size: .8rem; color: var(--gray); margin: 8px 0; }
.zp-pad { display: flex; flex-direction: column; gap: 8px; }
.zp-row { display: flex; gap: 8px; justify-content: center; }
.zp-key { width: 60px; height: 60px; font-size: 1.4rem; border: none; border-radius: 10px;
  background: var(--bg-secondary); cursor: pointer; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90;
  display: flex; align-items: center; justify-content: center; }
.sheet { background: var(--bg); border-radius: 16px; max-width: 480px; width: 92%;
  max-height: 86vh; overflow: auto; padding: 24px; position: relative; }
.sheet-close { position: absolute; top: 12px; right: 12px; border: none; background: none;
  font-size: 1.3rem; cursor: pointer; color: var(--primary-07); line-height: 0; padding: 4px; }
.sheet-close svg { width: 24px; height: 24px; display: block; }
.set-group { margin-bottom: 18px; border: 1px solid var(--primary-02); border-radius: 12px; padding: 12px; }
.set-group h3 { margin: 0 0 10px; font-size: 1rem; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.set-row input[type=checkbox] { width: 42px; height: 26px; }
.seg { display: inline-flex; border: 1px solid var(--primary-02); border-radius: 8px; overflow: hidden; }
.seg-btn { border: none; background: none; padding: 6px 12px; cursor: pointer; color: var(--primary); }
.seg-btn.active { background: var(--blue); color: #fff; }
.max-input { width: 80px; padding: 6px; border: 1px solid var(--primary-02); border-radius: 6px;
  background: var(--bg); color: var(--primary); }
@media (max-width: 640px) { .sheet { width: 100%; height: 100%; max-height: 100dvh; border-radius: 0; } }
.arch-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; background: var(--bg); padding-bottom: 12px; }
.arch-actions { display: flex; align-items: center; gap: 10px; }
.arch-actions button { cursor: pointer; }
.arch-empty { color: var(--gray); text-align: center; padding: 40px; }
.arch-section { padding: 12px 0; border-bottom: 1px solid var(--primary-02); }
.arch-formula { font-size: 1.8rem; }
.arch-sentence { font-size: 1rem; margin: 6px 0; }
.arch-more { color: #ff9500; }
.arch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; margin-top: 12px; }
.arch-card { background: var(--bg-secondary); border-radius: 12px; padding: 8px; cursor: pointer; text-align: center; }
.arch-card-label { font-size: 1.6rem; font-weight: 700; }
.arch-card-ts { font-size: .7rem; color: var(--gray); }
.arch-thumb { overflow: hidden; border-radius: 8px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; transform: scale(0.9); }
.arch-edit-list { display: flex; flex-direction: column; gap: 12px; }
.arch-check { line-height: 0; background: var(--bg); border-radius: 50%; }
.arch-check svg { width: 26px; height: 26px; display: block; }
.info-body { font-size: 1rem; line-height: 1.5; }
.info-body h2 { font-size: 1.25rem; margin: 1.2em 0 .4em; }
.info-body h3 { font-size: 1.1rem; margin: 1.1em 0 .3em; }
.info-body p { margin: .5em 0; }
.info-body ul { margin: .5em 0; padding-left: 1.3em; }
.info-body li { margin: .35em 0; }
.info-body a { color: var(--blue); }
.max-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 16px; }
.btn-primary { background: var(--blue); color: #fff; border: none; border-radius: 8px; padding: 8px 16px; cursor: pointer; }
.btn-secondary { background: var(--bg-secondary); border: none; border-radius: 8px; padding: 8px 16px; cursor: pointer; color: var(--primary); }
.tile.scatter { position: absolute; transition: left .3s, top .3s; pointer-events: none; }
#multitouch-panel { margin: 8px 16px; min-height: 120px; border-radius: 24px;
  background: var(--bg-secondary); display: flex; align-items: center; justify-content: center;
  color: var(--primary-02); text-align: center; padding: 16px; cursor: pointer; }
/* `display: flex` above would otherwise override the `hidden` attribute. */
#multitouch-panel[hidden] { display: none; }
#viz.no-anim .tile { transition: none; }
@media (max-width: 760px) {
  #toolbar h1 { font-size: 1.1rem; }
  .aufgabe, .teiler-satz { font-size: 1.5rem; }
  .beschreibung { font-size: 1.1rem; }
  .ctrl-label { font-size: 1.1rem; }
}
@media (orientation: portrait) and (max-width: 760px) {
  #controls { gap: 6px; padding: 10px; }
  .step-btn { width: 40px; height: 40px; font-size: 1.6rem; }
}
