/* Rechenfeld-Web — Grundlayout nach iOS-Vorbild (erzwungener Light Mode,
   schwarze Nav-/Toolbar, vertikaler Darstellungs-Stack). */

@font-face {
  font-family: 'Grundschrift';
  src: url('Grundschrift-Regular.otf') format('opentype');
  font-display: swap;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fff;
  color: #000;
  color-scheme: light; /* erzwungener Light Mode wie iOS */
}

body {
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Navigationsleiste ---------- */
#navbar {
  flex: 0 0 auto;
  min-height: 48px;
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top, 0);
  z-index: 40;
}
#navbar.hidden { display: none; }
#navTitle { font-size: 17px; font-weight: 600; }
.nav-group { display: flex; gap: 4px; }

/* Reveal-Button für die Navigationsleiste (Web-Ersatz für iOS-Systemeinstellungen).
   Runde Matheforscher-Reveal-Optik, aber oben rechts: dort ist bei ausgeblendeter Navbar
   frei, während unten rechts die Aktions-Buttons + Fuß-Werkzeugleiste sitzen. */
#navReveal {
  position: fixed; right: 10px; z-index: 45;
  top: calc(8px + env(safe-area-inset-top, 0));
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid rgba(0,0,0,0.2);
  background: rgba(255,255,255,0.85); color: #333;
  font-size: 18px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: background 0.2s;
}
#navReveal:hover { background: #fff; }
#navReveal.hidden { display: none; }
.nav-btn {
  width: 42px; height: 42px;
  background: none; border: none; color: #fff;
  display: grid; place-items: center;
  cursor: pointer; border-radius: 8px;
}
.nav-btn:active { background: rgba(255,255,255,0.2); }
.nav-btn svg { width: 24px; height: 24px; fill: currentColor; }
.nav-btn.recording { color: rgb(255,135,135); }

/* ---------- Darstellungs-Stack ---------- */
#stack {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 20px 8px;
  min-height: 0;
  overflow: hidden;
}
.collapsible {
  flex: 0 0 auto;
  overflow: hidden;
  position: relative;
  transition: height 0.5s, flex-basis 0.5s, opacity 0.5s;
}
.collapsible.versteckt { display: none; }
.feld-flex { flex: 1 1 0; min-height: 0; }

/* Storyboard-Höhen des vertikalen Stacks (schrumpfen bei knapper Höhe mit) */
#sachrechnenView { flex: 0 1 100px; min-height: 56px; }
#rechenlinieView { flex: 0 1 180px; min-height: 120px; }
#actionCollectionView { flex: 0 1 200px; min-height: 110px; }
#aufgabenfamilieView { flex: 0 1 120px; min-height: 64px; }
#aufgabenView { flex: 0 1 200px; min-height: 110px; }
#actionViewContainer { flex: 0 1 150px; min-height: 84px; }

/* Sachaufgabe */
.sach-zeile { display: flex; align-items: stretch; gap: 8px; height: 100%; }
#sachaufgabenLabel {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-size: clamp(16px, 2.6vmin, 28px);
  background: #F2F2F2;
  border-radius: 8px;
  padding: 6px 14px;
  transition: opacity 0.5s;
  cursor: pointer;
}
#nextSachaufgabenButton {
  flex: 0 0 45px;
  border: none; border-radius: 8px;
  background: #0a7bff; color: #fff;
  opacity: 0.6;
  cursor: pointer;
  display: grid; place-items: center;
}
#nextSachaufgabenButton svg { width: 26px; height: 26px; fill: currentColor; }

/* Aufgabenfamilie */
#aufgabenfamilieLabel {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  white-space: pre;
  font-size: clamp(20px, 4.4vmin, 45px);
  background: #F2F2F2;
  border-radius: 8px;
}
.familie-inner { white-space: pre; text-align: center; line-height: 1.45; }

/* Rechenaufgabe (Rechenterm + Soundknopf) */
.aufgaben-zeile { display: flex; align-items: center; height: 100%; gap: 4px; }
#rechentermContainer { flex: 1; height: 100%; min-width: 0; }
#btnSound {
  flex: 0 0 38px; height: 38px;
  align-self: center;
  border: none; background: none; cursor: pointer; opacity: 0.5;
}
#btnSound img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Toolbar ---------- */
#toolbar {
  flex: 0 0 auto;
  background: #000;
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 40;
}
.toolbar-inner {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 3px 20px;
}
.tb-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; color: #fff;
  font-size: 15px;
  height: 40px;
  min-width: 44px;
  cursor: pointer;
  border-radius: 8px;
  justify-content: center;
}
.tb-btn:active { background: rgba(255,255,255,0.2); }
.tb-btn img { height: 28px; max-width: 52px; object-fit: contain; filter: invert(1); }
.tb-icon img { height: 30px; }
#btnBlitzblick.selected { background: rgba(255,255,255,0.32); }

.segmented {
  display: flex;
  background: rgba(255,255,255,0.52);
  border-radius: 7px;
  padding: 2px;
  height: 34px;
}
.segmented button {
  border: none; background: transparent;
  border-radius: 5px;
  width: 36px;
  display: grid; place-items: center;
  cursor: pointer;
}
.segmented button img { height: 22px; }
.segmented button.selected { background: #fff; }

.tb-farben { display: flex; gap: 10px; }
.color-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid #fff;
  cursor: pointer;
}

/* ---------- Menüs & Popover ---------- */
.menu, .popover {
  position: fixed;
  z-index: 60;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  padding: 6px;
}
.hidden { display: none !important; }
.menu .menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 14px;
  border: none; background: none;
  font-size: 16px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.menu .menu-item:hover { background: #eee; }
.menu .menu-item img { height: 22px; width: 44px; object-fit: contain; }
.menu .menu-item .check { width: 18px; }
.menu .menu-item:disabled { opacity: 0.35; cursor: default; }

/* Teilen-Popover */
#sharePopover.share { width: min(94vw, 340px); padding: 12px; color: #333; }
.share-toggle { display: flex; gap: 4px; margin-bottom: 10px; }
.share-toggle button {
  flex: 1; padding: 6px 4px;
  font: inherit; font-size: 13px;
  border: 1px solid #ccc; border-radius: 7px;
  background: #f4f4f4; color: #333; cursor: pointer;
}
.share-toggle button.selected { background: #1A4766; border-color: #1A4766; color: #fff; }
.share-row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.share-url {
  flex: 1; min-width: 0;
  font: inherit; font-size: 12px;
  padding: 7px 8px;
  border: 1px solid #ccc; border-radius: 7px;
  background: #fff; color: #333;
}
.share-copy {
  flex: 0 0 auto; padding: 7px 12px;
  font: inherit; font-size: 13px;
  border: none; border-radius: 7px;
  background: #1A4766; color: #fff; cursor: pointer;
  white-space: nowrap;
}
.share-qr { width: min(82vw, 280px); height: min(82vw, 280px); margin: 6px auto 0; }
.share-qr svg { width: 100%; height: 100%; display: block; }
.share-hint { font-size: 11px; color: #888; text-align: center; margin-top: 8px; }

.popover.dark {
  background: #1c1c1e; color: #fff;
  padding: 20px;
  max-height: 70vh; overflow-y: auto;
  min-width: 300px;
}
.popover.dark h3 { font-size: 22px; margin-bottom: 14px; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px;
  padding: 8px 0;
  font-size: 16px;
}

/* iOS-artiger Switch */
.uiswitch {
  position: relative;
  width: 51px; height: 31px;
  flex: 0 0 51px;
  border-radius: 16px;
  border: none;
  background: rgba(120,120,128,0.32);
  cursor: pointer;
  transition: background 0.25s;
}
.uiswitch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  transition: transform 0.25s;
}
.uiswitch.on { background: #34c759; }
.uiswitch.on::after { transform: translateX(20px); }

/* ---------- Sheets & Alerts ---------- */
.sheet {
  position: fixed; inset: 0;
  z-index: 70;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
}
.sheet-card {
  background: #f2f2f7;
  border-radius: 14px;
  width: min(680px, 94vw);
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 8px;
}
.sheet-head h2 { font-size: 34px; font-weight: 700; }
.close-btn {
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: rgba(120,120,128,0.16);
  font-size: 16px;
  cursor: pointer;
}
#settingsBody { overflow-y: auto; padding: 0 20px 20px; }
.settings-section { margin-top: 18px; }
.settings-section > .section-title {
  font-size: 13px; color: #6d6d72;
  text-transform: uppercase;
  padding: 0 16px 6px;
}
.settings-group { background: #fff; border-radius: 10px; overflow: hidden; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  font-size: 16px;
  border-top: 0.5px solid rgba(60,60,67,0.29);
}
.settings-row:first-child { border-top: none; }
.settings-row .row-label { flex: 1; }
.settings-row input[type="range"] { flex: 1; }
.settings-info { font-size: 14px; line-height: 1.45; padding: 12px 16px; color: #333; }
.settings-info a { color: #0a7bff; }
.seg-textual { display: flex; background: rgba(120,120,128,0.16); border-radius: 8px; padding: 2px; flex-wrap: wrap; }
.seg-textual button {
  border: none; background: transparent;
  padding: 5px 10px; border-radius: 6px;
  font-size: 14px; cursor: pointer;
}
.seg-textual button.selected { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

.alert-card {
  background: #f2f2f7;
  border-radius: 14px;
  width: min(320px, 88vw);
  padding: 20px;
  text-align: center;
}
.alert-card h3 { font-size: 17px; margin-bottom: 6px; }
.alert-card p { font-size: 14px; margin-bottom: 12px; }
.alert-card input {
  width: 100%;
  font-size: 20px;
  text-align: center;
  padding: 8px;
  border: 1px solid #ccc; border-radius: 8px;
  margin-bottom: 14px;
  background: #fff;
}
.alert-buttons { display: flex; gap: 10px; }
.alert-buttons button {
  flex: 1;
  padding: 10px;
  border: none; border-radius: 10px;
  background: #e5e5ea;
  font-size: 16px;
  cursor: pointer;
}
.alert-buttons .primary { background: #0a7bff; color: #fff; font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  #stack { padding: 4px 8px 6px; }
  .toolbar-inner { justify-content: center; padding: 3px 8px; }
  #navTitle { display: none; }
}
@media (max-height: 480px) {
  #navbar { min-height: 40px; }
  .nav-btn { width: 36px; height: 36px; }
}

/* Stellenwertmaterial (Dienes) */
#dienesView { position: relative; }
#dienesUmschalter {
  position: absolute; top: 8px; right: 10px; z-index: 2;
  height: 32px;
}
#dienesUmschalter button { width: 38px; }
#dienesUmschalter button svg { width: 26px; height: 26px; display: block; }
