/* Zahlenstrahl Webapp — portiert von AR Zahlenstrahl (iOS) */
:root {
  --tint: rgb(85, 110, 141);        /* tintColor */
  --red: rgb(225, 107, 121);        /* redColor (Standard-Pin) */
  --draw: rgb(63, 140, 129);        /* drawColor */
  --green: #2e9e44;
  --green-dark: #1f7a33;
  --orange: #e08a00;
  --orange-text: #8a5200;           /* AA-konform auf Weiß (≥4.5:1) */
  --error: #b3261e;
  --error-bg: #fdecea;
  --bg: #fafafa;
  --card: #ffffff;
  --text: #1c1c1e;
  --text2: #515156;                /* abgedunkelt für Kontrast */
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px;
  --shadow-1: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-2: 0 6px 24px rgba(0,0,0,0.18);
  --dur-micro: 160ms; --dur-small: 280ms; --dur-medium: 450ms;
  --ease-spring-sm: cubic-bezier(.34,1.56,.64,1);
  --ease-spring-md: cubic-bezier(.22,1.4,.36,1);
  --ease-out: cubic-bezier(.2,.8,.2,1);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; border-radius: 8px; }
.skip-link { position: absolute; left: -9999px; top: 0; background: #fff; padding: 10px 16px; z-index: 999; border-radius: 0 0 12px 0; font-weight: 700; }
.skip-link:focus { left: 0; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button { font-family: inherit; }

/* ---------- generic screen layout ---------- */
.screen { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.navbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: var(--card); border-bottom: 1px solid #e3e3e6;
  min-height: 52px; flex-wrap: wrap;
}
.navbar .title { font-weight: 700; font-size: 18px; flex: 1; text-align: center; }
.navbar .title:focus { outline: none; }
.navbar .spacer { flex: 1; }
.nav-btn {
  border: none; background: rgba(85,110,141,0.12); color: var(--tint);
  border-radius: 10px; padding: 8px 14px; font-size: 15px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
}
.nav-btn:hover { background: rgba(85,110,141,0.22); }
.nav-btn.icon { font-size: 18px; padding: 8px 10px; }

/* ---------- Matheforscher-Protokoll v3: Profil-Adoption ---------- */
/* Übernimmt der Host ein Kind-Profil (siehe js/matheforscher.js, js/app.js:mfOnContext),
   wird die App-eigene Benutzerverwaltung ausgeblendet — Auswahl/Anlegen/Wechseln/Löschen
   sind dann für das Kind nicht mehr erreichbar (Regel B.2). */
body.mf-profile-adopted .mf-user-btn { display: none; }

/* ---------- main menu ---------- */
.menu-scroll { overflow-y: auto; flex: 1; padding: 16px clamp(12px, 4vw, 48px) 40px; }
.menu-section-title { font-size: 14px; font-weight: 600; color: var(--text2); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: 0.4px; }
.range-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.range-chip {
  border: 1.5px solid var(--tint); background: var(--card); color: var(--tint);
  border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 44px;
}
.range-chip.active { background: var(--tint); color: #fff; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.tile {
  background: var(--card); border-radius: 18px; padding: 18px 12px 14px; text-align: center;
  cursor: pointer; border: none; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative;
  transition: transform var(--dur-micro) var(--ease-spring-md), box-shadow var(--dur-micro) var(--ease-out);
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.tile:active { transform: scale(0.96); }
.tile .tile-icon { font-size: 34px; line-height: 1; }
.tile .tile-icon img { width: 64px; height: 64px; object-fit: contain; border-radius: 12px; display: block; }
.tile.wide .tile-icon img { width: 54px; height: 54px; }
.tile .tile-title { font-weight: 700; font-size: 15px; }
.tile .tile-sub { font-size: 12px; color: var(--text2); }
.tile .tile-stars { font-size: 12px; color: #f5b400; min-height: 14px; letter-spacing: 1px; }
.tile .tile-check { position: absolute; top: 8px; right: 10px; color: var(--green); font-size: 16px; }
.tile.wide { flex-direction: row; justify-content: flex-start; gap: 14px; padding: 16px 18px; text-align: left; }
.tile.wide .tile-text { display: flex; flex-direction: column; gap: 2px; }

/* ---------- game shell ---------- */
.game-header { padding: 10px 16px 4px; min-height: 58px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start; }
.game-header .game-info { grid-column: 1 / -1; }
.read-task { font-size: 14px; }
.game-question { margin: 0; text-wrap: balance; font-size: clamp(18px, 2.6vw, 26px); font-weight: 700; min-height: 30px; line-height: 1.35; }
.game-info { color: var(--orange-text); font-weight: 600; font-size: 15px; min-height: 22px; margin-top: 2px; }
.game-canvas-wrap { flex: 1; position: relative; min-height: 200px; contain: size layout paint; background: #fbfbf9; }
.game-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.game-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid #e3e3e6;
}
.footer-btn {
  border: none; background: rgba(85,110,141,0.12); color: var(--tint); cursor: pointer;
  border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600; min-height: 44px;
}
.footer-btn.primary { background: var(--tint); color: #fff; }
.footer-btn:disabled { opacity: 0.4; cursor: default; }

/* score display */
.score-display { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 16px; }
.score-box { width: 26px; height: 26px; border-radius: 7px; border: 2px solid #c8c8cc; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; color: #fff; }
.score-box.done { background: var(--green); border-color: var(--green); }
.score-box.pop { animation: score-pop var(--dur-small) var(--ease-spring-sm); }
@keyframes score-pop { from { transform: scale(0.4); } to { transform: scale(1); } }

/* tutor */
.tutor-btn {
  width: 72px; height: 72px; border-radius: 16px; border: none; cursor: pointer;
  background: rgba(85,110,141,0.15) center/cover no-repeat; font-size: 38px; position: relative; flex-shrink: 0;
  background-image: url('../assets/tutor.png');
}
.tutor-btn.speaking, .tutor-btn.loading { background-image: url('../assets/tutor_sprechend.png'); }
.tutor-btn.loading::after {
  content: ""; position: absolute; inset: 6px; border-radius: 12px;
  border: 3px solid rgba(85,110,141,0.25); border-top-color: var(--tint);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.speech-bubble {
  position: fixed; left: 12px; top: 12px; width: min(360px, calc(100vw - 32px)); z-index: 40;
  background: #fff; border-radius: 16px; padding: 14px 52px 14px 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18); font-size: 15px; line-height: 1.45;
}
.speech-bubble .close { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; border: none; border-radius: 12px; background: none; font-size: 18px; color: var(--text2); cursor: pointer; }
.speech-bubble::after {
  content: ""; position: absolute; bottom: -10px; left: var(--tail-x, 50%); transform: translateX(-50%);
  border: 10px solid transparent; border-top-color: #fff; border-bottom: none;
}

/* ---------- overlays ---------- */
.overlay-dim { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card {
  background: #fff; border-radius: 20px; padding: 24px; max-width: 520px; width: 100%;
  max-height: 86dvh; overflow-y: auto; box-shadow: 0 12px 48px rgba(0,0,0,0.25);
}
.modal-card h2 { margin-top: 0; }
.celebration-title { font-size: 42px; font-weight: 800; color: var(--green); text-align: center; margin: 6px 0; }
.celebration-sub { text-align: center; font-size: 20px; margin-bottom: 14px; }
.diff-chart { display: flex; align-items: flex-end; gap: 5px; height: 90px; justify-content: center; margin: 12px 0; }
.diff-chart .bar { width: 20px; border-radius: 4px 4px 0 0; }
.confetti-piece { position: absolute; font-size: 26px; animation: confetti-fall 2.6s ease-in forwards; }
@keyframes confetti-fall {
  from { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  to { transform: translateY(70vh) rotate(540deg); opacity: 0; }
}

/* number pad */
.numpad { display: flex; flex-direction: column; gap: 8px; width: 250px; }
.numpad .np-display {
  font-size: 32px; font-weight: 700; text-align: right; padding: 8px 12px;
  background: #f2f2f6; border-radius: 10px; min-height: 50px;
}
.numpad .np-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad button {
  font-size: 22px; font-weight: 600; padding: 12px 0; border: none; border-radius: 10px;
  background: rgba(85,110,141,0.10); color: var(--text); cursor: pointer;
}
.numpad .np-actions { display: flex; gap: 8px; }
.numpad .np-actions button { flex: 1; font-size: 16px; }
.numpad .np-ok { background: var(--tint) !important; color: #fff !important; }
.numpad-popover {
  position: absolute; z-index: 50; background: #fff; border-radius: 16px; padding: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.22);
}

/* settings + forms */
.settings-list { overflow-y: auto; flex: 1; padding: 12px clamp(10px, 4vw, 40px) 50px; max-width: 720px; width: 100%; margin: 0 auto; }
.settings-group { background: var(--card); border-radius: 14px; margin: 14px 0; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.settings-group .group-title { font-size: 13px; font-weight: 600; color: var(--text2); padding: 10px 16px 4px; text-transform: uppercase; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid #f0f0f2; min-height: 48px; }
.settings-row:first-child, .group-title + .settings-row { border-top: none; }
.settings-row .row-label { flex: 1; min-width: 0; font-size: 16px; overflow-wrap: anywhere; }
.settings-toggle-row { cursor: pointer; min-height: 64px; }
.settings-row[hidden] { display: none; }
.settings-field-row { flex-wrap: wrap; }
.settings-field-row .row-label { flex-basis: 130px; }
.settings-row .row-note { font-size: 12px; color: var(--text2); padding: 0 16px 10px; }
.settings-note, .settings-group > .row-note {
  margin: 0; padding: 12px 16px; color: var(--text2); font-size: 14px; line-height: 1.5;
}
.settings-row input[type="range"] { flex: 1; min-width: 100px; max-width: 220px; min-height: 48px; }
.settings-row select, .settings-row input[type="number"], .settings-row input[type="text"], .settings-row input[type="password"] {
  font-size: 16px; padding: 8px; border-radius: 8px; border: 1px solid #d6d6da;
  min-height: 48px; min-width: 48px; max-width: min(220px, 100%);
}
.toggle { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.toggle input { position: absolute; inset: -9px 0; width: 100%; height: 48px; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.toggle input:focus-visible + .knob { outline: 3px solid var(--tint); outline-offset: 3px; }
.toggle .knob { position: absolute; inset: 0; background: #d6d6da; border-radius: 15px; cursor: pointer; transition: background .15s; }
.toggle .knob::after { content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.toggle input:checked + .knob { background: var(--green); }
.toggle input:checked + .knob::after { left: 22px; }

/* user list */
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid #f0f0f2; cursor: pointer; background: none; border-left: none; border-right: none; border-bottom: none; width: 100%; text-align: left; font-size: 16px; }
.user-row .avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff; flex-shrink: 0; }
.user-row.selected { background: rgba(85,110,141,0.08); }

/* experiment toolbar */
.exp-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid #e3e3e6; flex-wrap: wrap; }
.exp-toolbar .tool-btn {
  border: none; background: rgba(85,110,141,0.12); color: var(--tint); cursor: pointer;
  border-radius: 10px; padding: 9px 12px; font-size: 17px; font-weight: 600;
}
.exp-toolbar .tool-btn.active { background: var(--tint); color: #fff; }
.exp-toolbar input[type="range"] { width: 130px; }
.interactive-label {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: rgba(255,255,255,0.92); border-radius: 12px; padding: 8px 16px;
  font-size: 20px; font-weight: 700; color: var(--tint); cursor: pointer; max-width: 90%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12); white-space: nowrap; overflow-x: auto;
}

/* coach marks */
.coach-card {
  position: fixed; z-index: 220; width: min(340px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
  overflow-y: auto; background: rgba(255,255,255,0.98);
  border-radius: 14px; padding: 14px; box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.coach-card h3 { margin: 0 0 6px; font-size: 17px; }
.coach-card p { margin: 0 0 10px; font-size: 15px; }
.coach-card .coach-hint { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.coach-card .coach-actions { display: flex; justify-content: space-between; gap: 8px; }
.coach-card .coach-actions button { min-height: 48px; }
.coach-card .coach-close { min-width: 48px; min-height: 48px; flex-shrink: 0; }
.coach-card .coach-progress { color: var(--text2); font-size: 13px; margin: 0 0 8px; }
.coach-card button:disabled { opacity: 0.4; cursor: default; }
.coach-spot { position: fixed; z-index: 210; border: 3px solid #b25f00; border-radius: 10px; pointer-events: none; animation: pulse-ring 0.9s ease-in-out 3; }
@keyframes pulse-ring { 0%,100% { transform: scale(0.98); opacity: 0.95; } 50% { transform: scale(1.04); opacity: 0.5; } }
.coach-dim { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.55); }
body.calm .coach-spot { animation: none; border-color: var(--tint); }
body.calm .confetti-canvas { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  .coach-spot, .confetti-piece, .success-check, .tutor-btn.loading::after { animation: none !important; }
  .tile, .footer-btn, .nav-btn { transition: none !important; }
}
@media (prefers-contrast: more) {
  :root { --text2: #1c1c1e; --orange-text: #5f3a00; }
  .score-box, .num-chip, .range-chip { border-width: 3px; }
}

/* assign-number chips */
.chip-row { display: flex; gap: 10px; flex-wrap: wrap; padding: 8px 16px; justify-content: center; }
.num-chip {
  border: 2px solid var(--tint); background: #fff; color: var(--tint); border-radius: 12px;
  padding: 10px 16px; font-size: 20px; font-weight: 700; cursor: grab; user-select: none; touch-action: none;
}
.num-chip.used { opacity: 0.25; pointer-events: none; }
.num-chip.selected { background: var(--tint); color: #fff; }
.num-chip.correct { border-color: var(--green); color: var(--green); }
.num-chip.wrong { border-color: #d33; color: #d33; }
.num-chip.missed { border-color: var(--orange); color: var(--orange); }
.num-chip.locked { cursor: default; }
.range-choices .num-chip {
  position: relative; min-width: 64px; min-height: 48px; padding-inline: 24px;
  cursor: pointer; touch-action: manipulation;
}
.range-choices .num-chip.locked { cursor: default; }
.range-choices .num-chip.correct { background: #e6f6ea; color: #17672a; border-color: #17672a; }
.range-choices .num-chip.wrong { background: #fff0f0; color: #a31f1f; border-color: #a31f1f; }
.range-choices .num-chip.correct::after, .range-choices .num-chip.wrong::after {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%); font-size: 14px;
}
.range-choices .num-chip.correct::after { content: '✓'; }
.range-choices .num-chip.wrong::after { content: '×'; }

/* teleporter command buttons */
.cmd-rows { display: flex; flex-direction: column; gap: 6px; padding: 6px 12px; }
.cmd-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.cmd-btn { border: none; border-radius: 10px; padding: 10px 13px; font-size: 17px; font-weight: 700; cursor: pointer; color: #fff; min-width: 56px; min-height: 48px; }
.cmd-btn.pos { background: var(--green); }
.cmd-btn.neg { background: #c75050; }
.cmd-btn.mul { background: #7a5fb5; }
.cmd-btn:disabled { opacity: 0.35; cursor: default; }
.cmd-history { display: flex; gap: 4px; overflow-x: auto; padding: 4px 12px; font-size: 15px; font-weight: 600; color: var(--tint); align-items: center; min-height: 30px; }

/* misc */
.success-check {
  position: absolute; z-index: 30; font-size: 60px; color: var(--green);
  transform: translate(-50%, -50%); animation: pop-in var(--dur-small) var(--ease-spring-sm); pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
@keyframes pop-in { from { transform: translate(-50%,-50%) scale(0.2); opacity: 0; } to { transform: translate(-50%,-50%) scale(1); opacity: 1; } }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.a11y-panel { padding: 8px 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.a11y-panel .stepper { display: flex; gap: 6px; align-items: center; }
.a11y-panel button { min-height: 44px; min-width: 44px; border-radius: 10px; border: 1.5px solid var(--tint); background: #fff; color: var(--tint); font-weight: 700; font-size: 16px; padding: 6px 12px; cursor: pointer; }
.offline-badge { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px; background: #fff3cd; color: #664d03; border: 1px solid #ffecb5; }
.offline-badge.online { display: none; }
.countdown-ring { width: 44px; height: 44px; margin: 8px auto; display: block; }
.hidden { display: none !important; }
.neighbor-table { display: flex; gap: 0; justify-content: center; margin: 4px auto; border: 1px solid #d6d6da; border-radius: 10px; overflow: hidden; width: fit-content; }
.neighbor-table .nb-cell { padding: 6px 14px; text-align: center; border-left: 1px solid #d6d6da; min-width: 76px; }
.neighbor-table .nb-cell:first-child { border-left: none; }
.neighbor-table .nb-head { font-size: 13px; color: var(--text2); display: block; overflow-wrap: anywhere; }
.neighbor-table .nb-val { font-size: 20px; font-weight: 700; }
.neighbor-table .nb-val.found { color: var(--green); }
.neighbor-table .nb-cell.target { background: rgba(85,110,141,0.12); }
.neighbor-sidebar, .neighbor-stage { display: contents; }
.riddle-sidebar, .riddle-stage, .section-sidebar, .section-stage, .range-sidebar, .range-stage, .finderror-sidebar, .finderror-stage, .name-sidebar, .name-stage { display: contents; }
.riddle-zoom { position: absolute; top: 8px; right: 8px; display: flex; gap: 8px; }
.riddle-zoom button { display: grid; place-items: center; width: 48px; height: 48px;
  border: 1px solid #d6d6da; border-radius: 12px; background: rgba(255,255,255,.94); color: var(--tint); cursor: pointer; }
@media (min-width: 700px) and (max-height: 500px) {
  :is(.riddle-screen, .section-screen, .range-screen, .finderror-screen, .name-screen) { display: grid; grid-template-columns: minmax(240px, 34%) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
  :is(.riddle-screen, .section-screen, .range-screen, .finderror-screen, .name-screen) > :is(.navbar, .game-footer) { grid-column: 1 / -1; }
  :is(.riddle-sidebar, .section-sidebar, .range-sidebar, .finderror-sidebar, .name-sidebar) { display: flex; flex-direction: column; min-height: 0; overflow-y: auto;
    border-right: 1px solid #d6d6da; }
  :is(.riddle-sidebar, .section-sidebar, .range-sidebar, .finderror-sidebar, .name-sidebar) .game-header { grid-template-columns: 1fr; }
  :is(.riddle-sidebar, .section-sidebar, .range-sidebar, .finderror-sidebar, .name-sidebar) .game-question { font-size: 18px; }
  :is(.riddle-sidebar, .section-sidebar, .range-sidebar, .finderror-sidebar, .name-sidebar) .read-task { justify-self: start; }
  :is(.riddle-stage, .section-stage, .range-stage, .finderror-stage, .name-stage) { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  :is(.riddle-stage, .section-stage, .range-stage, .finderror-stage, .name-stage) .game-canvas-wrap { min-height: 0; }
  :is(.riddle-stage, .finderror-stage, .name-stage) .a11y-panel { flex-shrink: 0; }
  :is(.riddle-stage, .finderror-stage, .name-stage) .position-controls-label { flex-basis: 100%; }
  .neighbor-screen { display: grid; grid-template-columns: minmax(260px, 34%) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
  .neighbor-screen > .navbar, .neighbor-screen > .game-footer { grid-column: 1 / -1; }
  .neighbor-sidebar { display: flex; flex-direction: column; min-height: 0; overflow-y: auto;
    border-right: 1px solid #d6d6da; }
  .neighbor-sidebar .game-header { grid-template-columns: 1fr; }
  .neighbor-sidebar .score-display { order: 0; }
  .neighbor-sidebar .neighbor-summary { order: 1; }
  .neighbor-sidebar .game-header { order: 2; }
  .neighbor-sidebar .game-question { font-size: 18px; }
  .neighbor-sidebar .read-task { justify-self: start; }
  .neighbor-sidebar .neighbor-table { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    width: calc(100% - 16px); }
  .neighbor-sidebar .nb-cell { min-width: 0; padding: 4px 6px; grid-row: var(--neighbor-row); }
  .neighbor-sidebar .lower { grid-column: 1; }
  .neighbor-sidebar .upper { grid-column: 3; }
  .neighbor-sidebar .target { grid-column: 2; grid-row: 1 / span var(--neighbor-rows); align-content: center; }
  .neighbor-stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  .neighbor-stage .game-canvas-wrap { min-height: 0; }
  .neighbor-stage .a11y-panel { flex-shrink: 0; }
  .neighbor-stage .position-controls-label { flex-basis: 100%; }
}

/* Keep task and controls reachable on phones and in short landscape windows. */
.screen { overflow-y: auto; }
.navbar, .game-header, .game-footer, .score-display, .exp-toolbar { flex-shrink: 0; }
@media (max-width: 600px) {
  .game-header { grid-template-columns: 1fr; }
  .read-task { justify-self: start; }
  .game-footer { gap: 8px; padding-inline: 10px; }
  .game-footer > div { flex-wrap: wrap; }
  .game-footer > div:last-child { margin-left: auto; }
  .footer-btn { padding-inline: 12px; }
  .navbar { padding-inline: 10px; }
  .navbar .title { min-width: 120px; }
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .neighbor-table { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: calc(100% - 24px); }
  .neighbor-table .nb-cell { min-width: 0; grid-row: var(--neighbor-row); }
  .neighbor-table .lower { grid-column: 1; }
  .neighbor-table .upper { grid-column: 3; }
  .neighbor-table .target { grid-column: 2; grid-row: 1 / span var(--neighbor-rows); align-content: center; }
}
body.calm .score-box.pop, body.calm .success-check { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .score-box.pop { animation: none; }
}

.range-notice { max-width: 560px; padding: 24px; margin: auto; line-height: 1.5; }
.range-notice button { margin: 8px 8px 0 0; }

.numpad-popover { max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow: auto; }
.numpad { width: min(250px, calc(100vw - 44px)); }
.numpad button:disabled { opacity: 0.4; cursor: default; }

.navbar span.nav-btn { cursor: default; }

.report-explanation { line-height: 1.5; max-width: 70ch; padding-inline: 8px; }
.report-profile { font-size: 20px; padding-inline: 8px; overflow-wrap: anywhere; }
.report-downloads { flex-wrap: wrap; }
.report-downloads .footer-btn { flex: 1 1 220px; min-height: 48px; white-space: normal; overflow-wrap: anywhere; }
.report-game { align-items: flex-start; flex-direction: column; gap: 8px; }
.report-game small { color: var(--text2); line-height: 1.5; }

.storage-notice { background: #fff4d4; color: #503c00; padding: 10px 16px; max-height: 36dvh; overflow: auto; }
.storage-notice p { margin: 0 0 8px; line-height: 1.4; }
.storage-notice > div { display: flex; flex-wrap: wrap; gap: 8px; }
body.storage-problem { display: flex; flex-direction: column; height: 100dvh; }
body.storage-problem #app { flex: 1; min-height: 0; height: auto; }
.storage-notice { flex-shrink: 0; }

.archive-notice { margin: 0; padding: 12px 16px; background: #fff4d4; color: #503c00; line-height: 1.4; flex-shrink: 0; }

/* Labeled, keyboard-accessible forms for ranges and profiles. */
.form-dialog { padding: 0; border: 0; border-radius: 24px; width: min(480px, calc(100vw - 24px));
  max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow: auto;
  color: var(--text); background: var(--card); box-shadow: 0 4px 12px #0002, 0 20px 60px #0003; }
.form-dialog::backdrop { background: rgb(20 30 45 / 40%); }
.form-dialog form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.form-dialog h2 { margin: 0; font-size: 24px; line-height: 1.2; text-wrap: balance; }
.form-description { margin: 0; color: var(--text2); line-height: 1.45; text-wrap: pretty; }
.form-fields { display: flex; flex-direction: column; gap: 18px; }
.form-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.form-field-label, .form-dialog legend { font-weight: 600; }
.form-field input, .form-field select { width: 100%; min-width: 0; min-height: 48px; padding: 10px 12px;
  font: inherit; font-size: 18px; border: 1.5px solid #a6afbb; border-radius: 10px; color: var(--text); background: #fff; }
.form-field [aria-invalid="true"] { border-color: var(--error); }
.form-error { margin: 0; min-height: 1.4em; line-height: 1.4; color: var(--error); font-weight: 600; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.footer-btn.danger { background: var(--error); color: #fff; }
.range-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.signed-field { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: end; gap: 4px; }
.signed-field > button { min-height: 48px; padding: 8px; font-size: 20px; }
.avatar-picker, .reset-choices { padding: 0; margin: 0; border: 0; min-width: 0; }
.form-dialog legend { padding: 0; margin-bottom: 10px; }
.avatar-choices { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.avatar-option { position: relative; cursor: pointer; }
.avatar-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.avatar-symbol { display: flex; align-items: center; justify-content: center; min-height: 48px; font-size: 28px;
  border: 2px solid transparent; border-radius: 12px; background: #f2f3f6; }
.avatar-option input:checked + .avatar-symbol { border-color: var(--tint); background: #e4ebf4; }
.avatar-option:focus-within .avatar-symbol { outline: 3px solid var(--tint); outline-offset: 2px; }
.reset-option { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; margin: 8px 0; padding: 12px;
  border: 1px solid #cbd1da; border-radius: 12px; line-height: 1.4; }
.reset-option input { margin: 4px 0 0; width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--tint); }
.reset-option b, .reset-option small { display: block; }
.reset-option small { color: var(--text2); margin-top: 4px; }
.profile-name { overflow-wrap: anywhere; }
.profile-progress { color: var(--text2); }
.user-row > span:not(.avatar) { min-width: 0; }
@media (max-width: 420px) {
  .form-dialog form { padding: 20px; }
  .range-fields { grid-template-columns: 1fr; gap: 12px; }
  .form-actions > button { flex: 1 1 130px; }
}

button.interactive-label { border: none; font-family: inherit; min-height: 44px; color: var(--text); }
@media (max-height: 480px) {
  .form-dialog form { padding: 12px; gap: 8px; }
  .form-dialog h2 { font-size: 22px; }
  .form-description { font-size: 14px; }
  .form-fields { gap: 12px; }
  .form-field { gap: 4px; }
  .form-dialog legend { margin-bottom: 6px; }
  .avatar-symbol { min-height: 44px; font-size: 26px; }
  .form-error:empty { display: none; }
}

/* Pong keeps room for the brick field and pauses explicitly after a resize. */
.pong-single-canvas { min-height: 360px; }
.pong-two-canvas { min-height: 420px; }
.pong-two-controls { display: flex; justify-content: center; gap: 10px; padding: 8px 16px; flex-wrap: wrap; }
.pong-pause-layer { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center;
  justify-content: center; padding: 16px; background: rgba(251,251,249,.88); }
.pong-pause-layer[hidden] { display: none; }
.pong-pause-card { width: min(100%, 360px); padding: 22px; border-radius: 20px; background: var(--card, white);
  text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.pong-pause-card h2 { margin: 0 0 12px; }
.pong-pause-card p { margin: 0 0 20px; line-height: 1.5; }

.position-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
.position-controls button { min-height: 48px; min-width: 48px; }
.position-controls button:disabled { opacity: .4; cursor: default; }
.position-controls-label { font-size: 14px; font-weight: 600; color: var(--text2); }
.position-controls .position-fine[aria-pressed="true"] { background: var(--tint); color: white; }
.position-controls .position-check { margin-left: auto; background: var(--tint); color: white; }
@media (max-width: 500px) { .position-controls-label { flex-basis: 100%; } }

.backup-actions { flex-wrap: wrap; }
.backup-actions button { flex: 1 1 200px; }
.backup-file { max-width: 100%; }
.backup-preview ul { max-height: 180px; overflow-y: auto; padding-left: 24px; overflow-wrap: anywhere; }

.jump-intro-list { margin: 0; padding-left: 22px; line-height: 1.45; }
.jump-intro-list li + li { margin-top: 10px; }

.assignment-controls { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.assignment-caption { font-size: 14px; font-weight: 600; color: var(--text2); }
.assignment-markers { display: flex; gap: 8px; flex-wrap: wrap; }
.a11y-panel .assignment-marker { min-width: 56px; min-height: 48px; font-size: 18px; }
.a11y-panel .assignment-marker.correct { border-color: var(--green); color: var(--green); background: #eef8ef; }

/* Archived work is opened by real buttons, with separate, non-overlapping deletion. */
.archive-dialog { width: min(620px, calc(100vw - 24px)); }
.archive-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.archive-item { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.archive-picture { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px;
  border: 1px solid #d6d6da; border-radius: 14px; background: white; color: var(--text); font: inherit;
  cursor: pointer; min-height: 100px; }
.archive-picture img { width: 100%; height: 180px; object-fit: contain; }
.archive-delete { min-height: 44px; border: 1px solid #c75050; border-radius: 12px; background: white;
  color: #a53131; font: inherit; cursor: pointer; padding: 8px; }
.archive-notice .footer-btn { margin-left: 12px; min-height: 44px; }

.archive-numbers { font-size: 16px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.archive-dialog .form-error:empty, .archive-dialog [role="status"]:empty { display: none; }

.experiment-option { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.experiment-option input, .experiment-color input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--tint); }
.experiment-colors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  padding: 0; margin: 0; border: 0; }
.experiment-color { display: flex; align-items: center; gap: 8px; padding: 8px; min-height: 48px;
  border: 1px solid #cbd1da; border-radius: 12px; cursor: pointer; }
.experiment-color-dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }
.experiment-color:focus-within { outline: 3px solid var(--tint); outline-offset: 2px; }

.experiment-settings-dialog form, .profile-dialog form { max-height: calc(100dvh - 24px); }
.experiment-settings-dialog .form-fields, .profile-dialog .form-fields { min-height: 0; overflow-y: auto; padding: 4px; margin: -4px; }
.experiment-settings-dialog h2, .experiment-settings-dialog .form-description,
.experiment-settings-dialog .form-actions, .experiment-settings-dialog .form-error,
.profile-dialog h2, .profile-dialog .form-description, .profile-dialog .form-actions, .profile-dialog .form-error { flex-shrink: 0; }
.experiment-settings-dialog .form-error:empty, .profile-dialog .form-error:empty { display: none; }

.drawing-controls, .experiment-general-tools { display: contents; }
.drawing-actions { display: inline-flex; gap: 6px; }
.exp-toolbar .tool-btn { min-width: 48px; min-height: 48px; }
.drawing-palette { border: 0; padding: 0; margin: 0; width: 248px; max-width: 100%; min-width: 0; }
.drawing-palette legend { font-size: 12px; line-height: 1.3; color: var(--text2); padding: 0 0 3px; }
.drawing-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.drawing-option { position: relative; cursor: pointer; min-width: 0; }
.drawing-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drawing-choice { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 52px; padding: 5px 2px; border: 2px solid transparent; border-radius: 10px; background: #f0f2f5; }
.drawing-option-name { font-size: 11px; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.drawing-swatch { width: 18px; height: 18px; border-radius: 50%; }
.drawing-width-preview { display: flex; align-items: center; height: 18px; }
.drawing-width-preview > span { display: block; width: 28px; border-radius: 10px; background: var(--tint); }
.drawing-check { display: none; position: absolute; right: 2px; top: 0; font-size: 12px; font-weight: 800; }
.drawing-option input:checked + .drawing-choice { border-color: var(--tint); background: #e1e9f2; }
.drawing-option input:checked + .drawing-choice .drawing-check { display: block; }
.drawing-option input:focus-visible + .drawing-choice { outline: 3px solid var(--tint); outline-offset: 2px; }

.exp-toolbar .tool-btn:disabled { opacity: 0.4; cursor: default; }

.pin-separation { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); min-height: 44px; z-index: 2; }

.operation-steps { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: 8px; padding: 6px 12px;
  background: var(--card); border-top: 1px solid #e3e3e6; flex-shrink: 0; }
.operation-steps[hidden] { display: none; }
.operation-steps > button { min-height: 48px; }
.operation-steps > button:not(.operation-current) { min-width: 48px; padding-inline: 12px; }
.operation-current { min-width: 0; max-width: 360px; flex: 1; }
.operation-group { flex-basis: 100%; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  max-width: 480px; font-size: 14px; white-space: normal; }
.operation-group strong { font-size: 16px; }
.operation-group[hidden] { display: none; }
@media (min-width: 700px) { .operation-group { flex-basis: auto; max-width: 360px; } }
.operation-step-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.finderror-instructions { margin: 8px 16px; font-size: 15px; text-align: center; }
.finderror-selectors { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 0 12px 8px; }
.finderror-selectors button { min-width: 48px; min-height: 48px; padding: 8px 14px; border: 2px solid var(--tint);
  border-radius: 12px; background: white; color: var(--tint); font-size: 19px; font-weight: 700; cursor: pointer; }
.finderror-selectors button[aria-pressed="true"] { background: var(--tint); color: white; }
.finderror-selectors button:disabled { opacity: .5; cursor: default; }
.finderror-stage .a11y-panel { padding-top: 4px; padding-bottom: 4px; }
.finderror-stage .position-controls { row-gap: 4px; }
@media (min-width: 700px) and (max-height: 500px) {
  .finderror-choices { order: -1; }
  .finderror-instructions { display: none; }
  .finderror-sidebar .game-info:empty { display: none; }
  .finderror-sidebar .score-display { order: 1; }
  .finderror-selectors { padding-top: 8px; }
}
.finderror-stage .game-canvas-wrap { min-height: var(--finderror-min-height, 200px); }
@media (min-width: 700px) and (max-height: 500px) {
  .finderror-stage .game-canvas-wrap { min-height: 0; }
}

.numpad .np-entry { display: flex; align-items: stretch; gap: 8px; }
.numpad .np-display { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.numpad button { min-height: 48px; min-width: 48px; }
.numpad .np-delete { width: 48px; flex-shrink: 0; }
.numpad .np-error { color: #9b2435; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.numpad .np-error:empty { display: none; }
.numpad .np-actions button { min-width: 0; overflow-wrap: anywhere; }
.name-screen .footer-btn { min-height: 48px; }

.celebration-summary { display: grid; gap: 10px; text-align: left; margin: 18px 0; }
.celebration-summary-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 12px; background: rgba(85,110,141,.08); }
.celebration-summary .summary-count { font-size: 28px; min-width: 1.3em; text-align: center; color: var(--tint); }
.celebration-summary-row span { font-size: 16px; overflow-wrap: anywhere; }
.celebration-chart-title { margin: 16px 0 4px; font-size: 17px; }
.celebration-chart-note { margin: 0; color: var(--text2); font-size: 14px; }
.celebration-card { display: flex; flex-direction: column; gap: 12px; overflow: hidden;
  max-height: calc(100dvh - 40px); }
.celebration-content { min-height: 0; overflow-y: auto; }
.celebration-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; flex-shrink: 0; }
.celebration-actions button { flex: 1; min-width: 96px; }
@media (min-width: 700px) and (max-height: 500px) {
  .celebration-card { max-width: 740px; padding: 16px; }
  .celebration-content { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 20px; }
  .celebration-content .celebration-title { grid-column: 1 / -1; font-size: 32px; margin: 0; }
  .celebration-content .celebration-sub { grid-column: 1; margin: 0; }
  .celebration-content .celebration-summary { grid-column: 1; margin: 0; }
  .celebration-content .celebration-chart { grid-column: 2; grid-row: 2 / span 2; }
  .celebration-chart-title { margin-top: 0; }
  .celebration-chart .diff-chart { margin-bottom: 0; }
}
.celebration-content .celebration-title:focus-visible { outline-offset: -3px; }
