:root {
  --bg: #000;
  --sci: #1f1f21;       /* wissenschaftliche Tasten (dunkel) */
  --sci-p: #4c4c4f;
  --fn: #5c5c5e;        /* graue Funktionstasten */
  --fn-p: #8e8e92;
  --num: #2c2c2e;       /* Zifferntasten */
  --num-p: #5a5a5d;
  --op: #ff9f0a;        /* orange Operatoren */
  --op-p: #ffc77d;
  --muted: #8e8e93;
  /* Breite des Tastenfelds: Tastenfeld-Höhe ≈ 1,34 × Breite (7 Reihen, Tasten 1,35 : 1) */
  --w: min(calc(100vw - 32px), 440px, calc((100vh - 190px) / 1.34));
  --w: min(calc(100vw - 32px), 440px, calc((100dvh - 190px) / 1.34));
  --gap: calc(var(--w) * 0.022);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; background: var(--bg); color: #fff;
  font-family: var(--font);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  /* fest über den ganzen Bildschirm: als Home-Bildschirm-App rechnet iOS 100vh/100dvh ohne
     Statusleiste, dann blieb unten eine Lücke */
  position: fixed; inset: 0; height: auto;
  /* unten: Home-Balken-Bereich + 5px Luft */
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 5px);
}

[hidden] { display: none !important; }

/* ---------- Rechner ---------- */

#calc { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }

.display {
  width: var(--w); flex: 1; min-height: 120px;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 0 calc(var(--w) * 0.03) calc(var(--w) * 0.02);
}


.sub {
  min-height: 1.4em; text-align: right; color: var(--muted);
  font-size: calc(var(--w) * 0.058); font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl;
}

/* Formel: 3/4 der früheren Größe; wird bei Bedarf kleiner und mehrzeilig (Umbruch nach
   Rechenzeichen, mitten in Zahlen nur wenn es nicht anders geht), nie abgeschnitten */
.main {
  text-align: right; white-space: normal; overflow-wrap: anywhere;
  font-size: calc(var(--w) * 0.1275); font-weight: 300; line-height: 1.12;
  font-variant-numeric: tabular-nums;
}

.keys {
  width: var(--w);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap);
}

.key {
  appearance: none; border: 0; margin: 0; padding: 0; cursor: pointer;
  aspect-ratio: 1.353 / 1; border-radius: 999px;  /* 1,33-mal so hoch wie ursprünglich (1,8 : 1) */
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; font-weight: 400; color: #fff;
  font-size: calc(var(--w) * 0.085);
  background: var(--bg-k); touch-action: manipulation;
  transition: background-color .35s ease;
}
.key:active { background: var(--bg-p); transition: none; }
.key:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.key.sci { --bg-k: var(--sci); --bg-p: var(--sci-p); font-size: calc(var(--w) * 0.068); }
.key.fn  { --bg-k: var(--fn);  --bg-p: var(--fn-p);  font-size: calc(var(--w) * 0.068); }
.key.num { --bg-k: var(--num); --bg-p: var(--num-p); }
.key.op  { --bg-k: var(--op);  --bg-p: var(--op-p);  font-size: calc(var(--w) * 0.11); }
.key.fn.big { font-size: calc(var(--w) * 0.075); }

.key.on { --bg-k: #fff; --bg-p: #d6d6d6; color: #000; }
.key sup { font-size: .62em; line-height: 0; position: relative; top: -.1em; margin-left: .05em; }
.key i { font-family: "Times New Roman", Georgia, serif; font-size: 1.1em; }
.key .pi { font-family: "Times New Roman", Georgia, serif; font-size: 1.15em; }

/* ---------- Zugangscode ---------- */

#lock {
  width: 100%; height: 100%; padding: 0 24px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.login-box { display: grid; gap: 12px; width: 100%; max-width: 340px; }
.login-box h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.login-box p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.4; }
.login-box input[type="password"] {
  min-height: 44px; padding: 9px 12px; border: 1px solid #3a3a3c; border-radius: 10px;
  background: var(--num); color: #fff; font: 16px var(--font);
  -webkit-user-select: text; user-select: text;
}
.login-box input[type="password"]:focus { outline: none; border-color: var(--op); }
.login-box button {
  height: 44px; border: 0; border-radius: 10px; background: var(--op); color: #000;
  font: 600 16px var(--font); cursor: pointer;
}
.login-box button:active { background: var(--op-p); }
.lock-msg { min-height: 1.4em; color: #ff453a !important; }
.visually-hidden { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

/* ---------- Cursor in der Eingabezeile ---------- */
.main { touch-action: none; cursor: text; }
/* Cursor als Rand eines unsichtbaren Zeichens (Wortverbinder): erzeugt keine Umbruchstelle */
.main .caret {
  border-left: 2px solid var(--op); margin: 0 -1px;
  animation: caret-blink 1s steps(1) infinite;
}
.main.dragging .caret { animation: none; }
@keyframes caret-blink { 50% { opacity: 0; } }

/* Löschtaste: Zurückpfeil */
.key svg.back { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
