/*
 * Calcumeter – Grafit mit Bernstein-Akzent.
 * Vollbild: Anzeige oben wächst, Tastenfelder füllen den Rest.
 * Bewusst nur dunkel – wie ein Messinstrument.
 */
:root {
  --ground: #0E0F11;
  --panel: #121316;
  --raise: #18191D;
  --raise-2: #2B2C32;
  --key: #1F2025;
  --key-util: #34353C;
  --key-op: #271F14;
  --fn: #16171B;
  --line: #1F2024;
  --text: #F4F4F5;
  --text-2: #C9CAD0;
  --muted: #8A8B94;
  --accent: #FFB547;          /* Akzent als Schrift-/Linienfarbe */
  --accent-fill: #FFB547;     /* Akzent als Fläche (=, aktive Knöpfe) */
  --accent-hover: #FFC671;
  --accent-ink: #1C1407;
  --error: #FF8A7A;
  --key-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  --sheet-shadow: 0 -8px 40px rgba(0, 0, 0, .5);
  --backdrop: rgba(0, 0, 0, .55);
  --plot-1: #FFB547;
  --plot-2: #7CC4FF;
  --plot-3: #8BE3A6;

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --gap: 12px;
  --kh: clamp(54px, 9.4dvh, 84px);   /* Höhe Zifferntasten */
  --fh: clamp(36px, 5.4dvh, 48px);   /* Höhe Funktionstasten */
  --maxw: 520px;
  color-scheme: dark;
}

/* Hell: warmes Hellgrau, weiße Tasten, Bernstein als Schrift etwas dunkler für Kontrast */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ground: #EFEEEA;
    --panel: #F8F7F4;
    --raise: #E4E2DD;
    --raise-2: #FFFFFF;
    --key: #FFFFFF;
    --key-util: #DCDAD4;
    --key-op: #FBE8C6;
    --fn: #E6E4DF;
    --line: #D9D7D1;
    --text: #17181B;
    --text-2: #3A3B40;
    --muted: #66676E;
    --accent: #A65F00;
    --accent-fill: #FFB547;
    --accent-hover: #FFC671;
    --accent-ink: #1C1407;
    --error: #C23A2B;
    --key-shadow: 0 1px 2px rgba(30, 25, 15, .10), inset 0 -1px 0 rgba(30, 25, 15, .05);
    --sheet-shadow: 0 -8px 40px rgba(30, 25, 15, .18);
    --backdrop: rgba(20, 18, 14, .35);
    --plot-1: #D98A00;
    --plot-2: #2F7FD6;
    --plot-3: #1F9D55;
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --ground: #EFEEEA;
  --panel: #F8F7F4;
  --raise: #E4E2DD;
  --raise-2: #FFFFFF;
  --key: #FFFFFF;
  --key-util: #DCDAD4;
  --key-op: #FBE8C6;
  --fn: #E6E4DF;
  --line: #D9D7D1;
  --text: #17181B;
  --text-2: #3A3B40;
  --muted: #66676E;
  --accent: #A65F00;
  --accent-fill: #FFB547;
  --accent-hover: #FFC671;
  --accent-ink: #1C1407;
  --error: #C23A2B;
  --key-shadow: 0 1px 2px rgba(30, 25, 15, .10), inset 0 -1px 0 rgba(30, 25, 15, .05);
  --sheet-shadow: 0 -8px 40px rgba(30, 25, 15, .18);
  --backdrop: rgba(20, 18, 14, .35);
  --plot-1: #D98A00;
  --plot-2: #2F7FD6;
  --plot-3: #1F9D55;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible + *,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] { display: none !important; }

/* ---------- Grundgerüst ---------- */

.app {
  display: flex;
  height: 100vh;
  height: calc(100dvh - var(--ad-h, 0px));   /* Platz für das Werbebanner der Store-App */
}

.calculator {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.calculator > * {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
}

.calculator.sci-on { --maxw: 1080px; }

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tabs, .seg {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--raise);
}

.tabs button {
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  transition: background-color .15s, color .15s;
}

.seg button {
  padding: 8px 12px;
  border-radius: 999px;
  font: 600 12px var(--mono);
  color: var(--muted);
}

.tabs button[aria-selected="true"],
.seg button[aria-checked="true"] {
  background: var(--raise-2);
  color: var(--text);
}

.tabs button:hover, .seg button:hover { color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--raise);
  color: var(--text-2);
  transition: background-color .15s, color .15s;
}

.icon-btn:hover { background: var(--raise-2); color: var(--text); }

.sci-btn { padding: 0 12px; font: italic 500 15px var(--mono); }
.sci-btn[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-ink); }
.sci-btn[aria-pressed="true"]:hover { background: var(--accent-hover); color: var(--accent-ink); }

.calculator:not(.sci-on) .sci-only,
.calculator:not(.sci-on) .pad.sci { display: none; }

/* ---------- Rechner ---------- */

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.display {
  flex: 1;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 6px 2px;
  overflow: hidden;
}

.indicators {
  display: flex;
  gap: 12px;
  margin-bottom: auto;
  font: 600 12px var(--mono);
  letter-spacing: .06em;
  color: var(--muted);
}

.indicators .on { color: var(--accent); }

.ind-btn {
  font: inherit;
  letter-spacing: inherit;
  color: var(--text-2);
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 8px;
}

.ind-btn:hover { background: var(--raise); }

.expression {
  min-height: 1.4em;
  font: 400 clamp(17px, 2.7dvh, 24px) var(--mono);
  letter-spacing: -0.01em;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.expression::-webkit-scrollbar { display: none; }

.expression .caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1.1s steps(1) infinite;
}

.expression .ghost { opacity: .35; }

@keyframes blink { 50% { opacity: 0; } }

.result {
  display: block;
  width: 100%;
  text-align: right;
  font-size: var(--result-size, clamp(56px, 11dvh, 104px));
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  color: var(--text);
  cursor: copy;
}

.result.preview { color: var(--muted); }
.result.error { color: var(--error); font-size: clamp(24px, 4dvh, 34px); font-weight: 500; letter-spacing: 0; }

.memory-row { display: flex; gap: 8px; }

.chip {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background-color .15s, color .15s;
}

.chip:hover:not(:disabled) { background: var(--raise); color: var(--text); }
.chip:disabled { opacity: .4; cursor: default; }

/* ---------- Tasten ---------- */

.pads { display: grid; gap: var(--gap); }

.pad { display: grid; gap: var(--gap); }
.pad.num, .pad.fxpad { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: var(--kh); }
.pad.sci { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: var(--fh); gap: 8px; }

.key {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-radius: min(24px, 30%);
  background: var(--key);
  box-shadow: var(--key-shadow);
  font-size: clamp(22px, 3.5dvh, 32px);
  font-weight: 400;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  transition: background-color .12s, transform .08s, filter .12s;
}

.key svg { width: 1.05em; height: 1.05em; }
.key:hover { filter: brightness(1.15); }
.key:active, .key.pressed { transform: scale(.95); filter: brightness(1.3); }

.key.util { background: var(--key-util); font-size: clamp(18px, 2.8dvh, 24px); font-weight: 500; }
.key.op { background: var(--key-op); color: var(--accent); font-size: clamp(24px, 3.8dvh, 34px); }
.key.accent-text { color: var(--accent); }
.key.small { font-size: clamp(20px, 3dvh, 26px); }
.key.label { font-size: clamp(14px, 2.1dvh, 17px); font-weight: 600; }

.key.equals {
  background: var(--accent-fill);
  color: var(--accent-ink);
  box-shadow: none;
  font-size: clamp(26px, 4dvh, 36px);
  font-weight: 500;
}

.key.equals.label { font-size: clamp(14px, 2.1dvh, 17px); font-weight: 600; }

.key.fn {
  border-radius: min(16px, 30%);
  background: var(--fn);
  box-shadow: none;
  font-size: clamp(14px, 2.1dvh, 17px);
  font-weight: 500;
  color: var(--text-2);
}

.key.fn.toggle[aria-pressed="true"] { background: var(--raise-2); color: var(--accent); }

/* ---------- Währung ---------- */

.fx-info {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fx-pair { position: relative; display: flex; flex-direction: column; gap: 6px; }

.fx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  border-radius: 22px;
  background: var(--panel);
}

.fx-row.from { background: var(--raise); box-shadow: inset 0 0 0 1.5px var(--accent); }

.fx-cur {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -6px;
  padding: 6px;
  border-radius: 14px;
  text-align: left;
  transition: background-color .15s;
}

.fx-cur:hover { background: var(--raise-2); }

.fx-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 600 15px var(--mono);
  color: #141518; /* dunkle Schrift auf hellen Pastell-Plaketten, in beiden Designs */
  background: var(--text-2);
}

.unit-badge {
  width: auto;
  min-width: 40px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--accent-fill);
}

.fx-badge.long { font-size: 11px; }

.fx-cur-text { display: flex; flex-direction: column; line-height: 1.25; }

.fx-cur-text strong {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 600;
}

.fx-cur-text strong::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
}

.fx-cur-text small { font-size: 13px; color: var(--muted); max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fx-amount {
  flex: 1;
  min-width: 0;
  text-align: right;
  font-size: var(--fit-size, clamp(28px, 5dvh, 42px));
  font-weight: 300;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

#fx-amount:focus { outline: none; }
#fx-amount.invalid { color: var(--error); }
#fx-result { color: var(--text-2); }

.fx-swap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 4px solid var(--ground);
  background: var(--raise-2);
  color: var(--accent);
  transition: transform .2s;
}

.fx-swap:hover { transform: translate(-50%, -50%) rotate(180deg); }

.fx-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 0 4px;
  font: 400 12.5px var(--mono);
  color: var(--muted);
}

.fx-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 4px;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

.fx-list li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.fx-list li:last-child { border-bottom: 0; }

.fx-list .fx-li {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 4px;
  text-align: left;
  font-size: 15px;
}

.fx-list .fx-li:hover .fx-li-code { color: var(--accent); }
.fx-li > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fx-star {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: 4px;
  border-radius: 10px;
  color: var(--accent);
}

.fx-star:hover { background: var(--raise); }

.fx-add {
  width: 100%;
  padding: 12px 4px;
  text-align: left;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
}
.fx-li-name { color: var(--muted); margin-left: 6px; }
.fx-li-val { font-variant-numeric: tabular-nums; white-space: nowrap; }

.pad.fxpad { --kh: clamp(48px, 7.4dvh, 66px); gap: 10px; }

/* ---------- Verlauf ---------- */

.history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  padding:
    max(20px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 8px 14px;
}

.history-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-actions { display: flex; align-items: center; gap: 6px; }

.text-btn { padding: 8px 10px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--accent); }
.text-btn:hover { background: var(--raise); }

.history-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.history-list button {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: right;
}

.history-list button:hover { background: var(--raise); }
.h-expr { font: 400 13px var(--mono); color: var(--muted); overflow-wrap: anywhere; }
.h-res { font-size: 22px; font-weight: 400; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.history-list:empty { display: none; }
.history-empty { margin: 32px 0; text-align: center; color: var(--muted); font-size: 14px; }

/* Handy: Verlauf als Vollbild-Ebene */
@media (max-width: 899px) {
  .history {
    position: fixed;
    inset: 0;
    z-index: 10;
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* Breit: Verlauf als Seitenleiste */
@media (min-width: 900px) {
  .history {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid var(--line);
  }
  .history-close { display: none; }
}

/* ---------- Hinweis ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--raise-2);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Varianten ---------- */

/* Hochformat mit eingeblendeten Funktionen: kompaktere Ziffern */
@media (orientation: portrait) {
  .calculator.sci-on { --gap: 8px; }
  .calculator.sci-on .display { flex: 0 0 auto; min-height: 0; height: clamp(80px, 15dvh, 160px); gap: 2px; }
  .calculator.sci-on .pads { flex: 1; min-height: 0; grid-template-rows: minmax(0, 6fr) minmax(0, 8fr); }
  .calculator.sci-on .pad.sci { grid-template-rows: repeat(6, minmax(0, 1fr)); grid-auto-rows: auto; gap: 6px; }
  .calculator.sci-on .pad.num { grid-template-rows: repeat(5, minmax(0, 1fr)); grid-auto-rows: auto; }
  .calculator.sci-on .result { font-size: var(--result-size, clamp(34px, 6.5dvh, 60px)); }
  .calculator.sci-on .expression { font-size: clamp(15px, 2.2dvh, 20px); }
  .calculator.sci-on .chip { padding: 5px 0; }
  .calculator.sci-on .view { gap: 10px; }
}

/* ---------- Bereichsschalter, Menü, Auswahlblatt ---------- */

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  background: var(--raise);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  transition: background-color .15s;
}

.view-switch:hover { background: var(--raise-2); }
.view-switch svg:first-child { color: var(--accent); }
.view-switch .chev { color: var(--muted); }

.sheet {
  width: min(560px, 100%);
  max-width: 100%;
  max-height: min(86dvh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--sheet-shadow);
  overflow: hidden;
}

.sheet[open] { display: flex; animation: sheet-in .22s ease-out; }
.sheet::backdrop { background: var(--backdrop); }

@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

.sheet-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-left: 4px;
}

.sheet-head h2, .sheet-sub {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet-sub { margin: 12px 0 2px 4px; }

@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 24px; }
}

.view-list { display: grid; gap: 4px; }

.view-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border-radius: 16px;
  text-align: left;
  transition: background-color .15s;
}

.view-item:hover { background: var(--raise); }
.view-item[aria-current="page"] { background: var(--raise); box-shadow: inset 0 0 0 1.5px var(--accent); }

.vi-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--key-op);
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
}

.vi-icon.mono { font: 600 15px var(--mono); }
.vi-text { display: flex; flex-direction: column; min-width: 0; }
.vi-text strong { font-size: 16px; font-weight: 600; }
.vi-text small { font-size: 13px; color: var(--muted); }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px;
  font-size: 15px;
}

.setting .seg button { font: 500 13px var(--font); padding: 8px 12px; }

/* Sprachauswahl: native Liste, im Stil der Segmente */
.select { position: relative; display: inline-flex; }
.select select {
  appearance: none;
  -webkit-appearance: none;
  min-width: 150px;
  padding: 10px 36px 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--raise);
  color: var(--text);
  font: 500 14px var(--font);
  cursor: pointer;
}
.select::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -5px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}
.select select:hover { background: var(--raise-2); }
.select select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select option { background: var(--ground); color: var(--text); }

.switch {
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: var(--key-util);
  transition: background-color .2s;
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--raise-2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s;
}

.switch[aria-checked="true"] { background: var(--accent-fill); }
.switch[aria-checked="true"] span { transform: translateX(20px); background: #FFFFFF; }

.setting-hint { margin: 4px 4px 0; font-size: 13px; color: var(--muted); }
.legal-links { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 4px 0; font-size: 13px; color: var(--muted); }
.legal-links .text-btn { padding: 6px 0; font-size: 13px; }

.money-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  border-radius: 16px;
  background: var(--raise);
  text-align: left;
}

.money-row:hover { background: var(--raise-2); }
.money-price { flex-shrink: 0; padding: 6px 12px; border-radius: 999px; background: var(--accent-fill); color: var(--accent-ink); font-weight: 600; }
.money-price:empty { display: none; }
.legal-links a { color: var(--accent); text-decoration: none; }
.legal-links a:hover { text-decoration: underline; }

.picker { height: min(86dvh, 760px); }

.picker-search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--ground);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.picker-search:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.picker-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

.picker-group {
  position: sticky;
  top: 0;
  padding: 10px 6px 6px;
  background: var(--panel);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.picker-item {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 12px;
  text-align: left;
  font-size: 15px;
}

.picker-item:hover, .picker-item:focus-visible { background: var(--raise); }
.picker-item[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.pi-sub { color: var(--muted); font: 400 13px var(--mono); }
.picker-empty { color: var(--muted); text-align: center; margin: 24px 0; }

.share-btn { margin-left: auto; }
.topbar .share-btn:not([hidden]) ~ .topbar-actions { margin-left: -4px; }

.fx-ref { border-bottom: 0 !important; }
.fx-ref a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 4px;
  color: var(--text-2);
  font-size: 14px;
  text-decoration: none;
}
.fx-ref a:hover { color: var(--text); }
.ad-tag {
  flex-shrink: 0;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Einheiten ---------- */

.cat-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px;
  padding: 0 16px 2px;
}

.cat-chips::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--raise);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}

.cat-chip[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-ink); }

.view-conv .fx-pair { touch-action: pan-y; }
.view-calc .display { touch-action: pan-y; }

/* ---------- Graph ---------- */

.view-graph { gap: 10px; }
.graph-side { display: flex; flex-direction: column; gap: 8px; }
.graph-fns { display: grid; gap: 6px; }

.graph-fn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 14px;
  background: var(--raise);
}

.graph-fn:focus-within { box-shadow: inset 0 0 0 1.5px var(--accent); }
.graph-dot { flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; }
.graph-name { flex-shrink: 0; font: 500 14px var(--mono); color: var(--muted); }

.graph-input {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: 400 16px var(--mono);
}

.graph-input:focus { outline: none; }
.graph-input.invalid { color: var(--error); text-decoration: underline wavy var(--error) 1px; text-underline-offset: 4px; }
.graph-input::placeholder { color: var(--muted); opacity: .7; }

.graph-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.graph-bar::-webkit-scrollbar { display: none; }

.graph-bar button {
  flex-shrink: 0;
  min-width: 44px;
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--fn);
  font: 500 15px var(--font);
  color: var(--text-2);
}

.graph-bar button:hover { background: var(--raise-2); color: var(--text); }
.graph-hint { margin: 0 4px; font-size: 12px; color: var(--muted); }

.graph-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
}

#graph-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#graph-canvas:active { cursor: grabbing; }

.graph-tip {
  position: absolute;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--raise-2);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  font: 500 13px var(--mono);
  white-space: nowrap;
  pointer-events: none;
}

.graph-zoom { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.graph-zoom .icon-btn { min-width: 40px; height: 40px; font-size: 20px; background: var(--raise); box-shadow: 0 2px 8px rgba(0, 0, 0, .2); }

/* ---------- Programmierer ---------- */

.view-prog { gap: 10px; }

.prog-display {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  touch-action: pan-y;
}

.prog-controls { display: flex; gap: 6px; margin-bottom: auto; }

.chip-btn {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--raise);
  font: 600 12px var(--mono);
  color: var(--text-2);
}

.chip-btn[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-ink); }

.prog-expr {
  padding: 0 6px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  font-size: var(--fit-size, clamp(30px, 6dvh, 52px));
  font-weight: 300;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.prog-expr.invalid { color: var(--error); }

.prog-bases { display: grid; gap: 2px; }
.prog-bases.stale .pb-val { opacity: .5; }

.prog-base {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 12px;
  text-align: right;
  min-width: 0;
}

.prog-base:hover { background: var(--raise); }
.prog-base[aria-pressed="true"] { background: var(--raise); box-shadow: inset 3px 0 0 var(--accent); }
.pb-label { flex-shrink: 0; width: 34px; text-align: left; font: 600 12px var(--mono); color: var(--muted); }
.prog-base[aria-pressed="true"] .pb-label { color: var(--accent); }
.pb-val { flex: 1; min-width: 0; font: 400 15px var(--mono); color: var(--text-2); overflow-wrap: anywhere; }

.prog-bits { display: grid; gap: 6px; }
.bit-row { display: flex; align-items: center; gap: 2px; }
.bit-label { width: 22px; flex-shrink: 0; font: 500 10px var(--mono); color: var(--muted); }

.bit {
  flex: 1;
  min-width: 0;
  height: 30px;
  border-radius: 6px;
  font: 500 13px var(--mono);
  color: var(--muted);
}

.bit[aria-pressed="true"] { color: var(--accent); background: var(--key-op); }
.bit.nibble-end { margin-right: 6px; }

.pad.prog {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: clamp(42px, 6.6dvh, 64px);
  gap: 8px;
}

.pad.prog .key { font-size: clamp(17px, 2.6dvh, 24px); border-radius: min(18px, 30%); }
.pad.prog .key.fn { font-size: clamp(12px, 1.8dvh, 15px); }
.pad.prog .key.hex { background: var(--fn); }
.pad.prog .key:disabled { opacity: .25; cursor: default; filter: none; transform: none; }
.key.span3 { grid-column: span 3; }
.key.span2 { grid-column: span 2; }

/* Breite je Bereich */
.calculator[data-view="fx"], .calculator[data-view="units"] { --maxw: 520px; }
.calculator[data-view="prog"] { --maxw: 640px; }
.calculator[data-view="graph"] { --maxw: 1200px; }

/* Schmal: Winkelmaß nur über die Anzeige (DEG/RAD antippen), damit die Kopfzeile passt */
@media (max-width: 560px) {
  .topbar .seg { display: none; }
  .tabs button { padding: 10px 16px; }
}

/* Großer Bildschirm: Tastenfeld mit fester Höhe, Reihen teilen sie auf */
@media (min-width: 900px) and (min-height: 600px) {
  .calculator { padding: 24px 32px 32px; gap: 18px; }
  .calculator.sci-on .pads { grid-template-columns: 5fr 4fr; gap: 20px; }
  .pads { height: clamp(380px, 56dvh, 560px); }
  .pad.num { grid-template-rows: repeat(5, minmax(0, 1fr)); grid-auto-rows: auto; gap: 10px; }
  .pad.sci { grid-template-rows: repeat(6, minmax(0, 1fr)); grid-auto-rows: auto; gap: 10px; }
  .view-graph { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
  .graph-wrap { min-height: 0; }
  .graph-bar { flex-wrap: wrap; overflow: visible; }
  .pad.prog { grid-auto-rows: auto; height: clamp(320px, 46dvh, 460px); grid-template-rows: repeat(6, minmax(0, 1fr)); }
}

/* Handy quer: Anzeige links, Tasten rechts über die volle Höhe */
@media (orientation: landscape) and (max-height: 600px) {
  .calculator {
    gap: 8px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
  .calculator, .calculator.sci-on, .calculator[data-view] { --maxw: 1100px; }
  .tabs button { padding: 7px 14px; font-size: 14px; }
  .icon-btn { height: 36px; min-width: 36px; border-radius: 12px; }
  .seg button { padding: 6px 10px; }

  .view-calc {
    display: grid;
    grid-template-columns: minmax(200px, 30%) 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px 14px;
  }
  .display { grid-column: 1; grid-row: 1; min-height: 0; }
  .memory-row { grid-column: 1; grid-row: 2; gap: 6px; }
  .chip { padding: 5px 0; font-size: 12px; }
  .pads { grid-column: 2; grid-row: 1 / span 2; min-height: 0; gap: 12px; }
  .calculator.sci-on .pads { grid-template-columns: 5fr 4fr; }
  .pad { gap: 6px; }
  .pad.num { grid-template-rows: repeat(5, minmax(0, 1fr)); grid-auto-rows: auto; }
  .pad.sci { grid-template-rows: repeat(6, minmax(0, 1fr)); grid-auto-rows: auto; gap: 6px; }
  .key { border-radius: 14px; font-size: 20px; }
  .key.fn { border-radius: 12px; font-size: 14px; }
  .key.op, .key.equals { font-size: 22px; }
  .key.util, .key.small { font-size: 17px; }
  .key.label, .key.equals.label { font-size: 14px; }
  .result { font-size: var(--result-size, clamp(34px, 15dvh, 60px)); }
  .result.error { font-size: 20px; }
  .expression { font-size: 15px; }

  .view-conv { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
  .cat-chips { margin: 0; padding: 0; }
  .cat-chip { padding: 6px 12px; font-size: 13px; }
  .view-graph { display: grid; grid-template-columns: minmax(240px, 34%) minmax(0, 1fr); gap: 12px; }
  .graph-side { min-width: 0; }
  .graph-hint { display: none; }
  .graph-wrap { min-height: 0; }
  .view-prog { display: grid; grid-template-columns: minmax(240px, 40%) 1fr; gap: 14px; }
  .pad.prog { grid-auto-rows: auto; grid-template-rows: repeat(6, minmax(0, 1fr)); gap: 5px; }
  .pad.prog .key { border-radius: 12px; font-size: 17px; }
  .pad.prog .key.fn { font-size: 12px; }
  .pb-val { font-size: 13px; }
  .prog-base { padding: 4px 8px; }
  .prog-expr { font-size: var(--fit-size, 30px); }
  .bit { height: 22px; font-size: 11px; }
  .fx-info { gap: 8px; }
  .fx-row { padding: 8px 12px; border-radius: 16px; }
  .fx-badge { width: 32px; height: 32px; font-size: 13px; }
  .fx-amount { font-size: var(--fit-size, 28px); }
  .pad.fxpad { grid-template-rows: repeat(4, minmax(0, 1fr)); grid-auto-rows: auto; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
