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

:root {
  --navy: #ffffff;
  --card-bg: #f7f7f8;
  --cyan: #d42222;
  --red: #d42222;
  --text: #111111;
  --muted: #4b5563;
  --border: rgba(17,17,17,0.12);
  --radius: 12px;
}

html, body {
  height: 100%;
  background: var(--navy);
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── HEADER ── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#btn-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: rgba(212,34,34,0.08);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--cyan);
  cursor: pointer;
  flex-shrink: 0;
}
#btn-back.visible { display: flex; }
#btn-back svg { pointer-events: none; }

.logo-circle {
  width: 34px; height: 34px;
  background: var(--cyan);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 13px;
  color: var(--navy);
  flex-shrink: 0;
  letter-spacing: -0.5px;
}

#header-title {
  flex: 1;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.03em;
  color: var(--text);
  text-align: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px; height: 34px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: color .2s, background .2s;
}
.icon-btn:hover, .icon-btn.active {
  color: var(--cyan);
  background: rgba(212,34,34,0.08);
}

/* Search bar */
#search-bar {
  display: none;
  padding: 8px 14px;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid var(--border);
}
#search-bar.visible { display: block; }

#search-input {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}
#search-input:focus { border-color: var(--cyan); }
#search-input::placeholder { color: var(--muted); }

/* ── MAIN CONTENT ── */
#content {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
}

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── HOME: CATEGORY GRID ── */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.cat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  transition: border-color .2s, transform .15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-card:hover {
  transform: translateY(-2px);
}

.cat-icon-box {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.cat-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 17px;
  color: var(--text);
  line-height: 1.1;
}
.cat-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}
.cat-count {
  font-size: 11px;
  font-weight: 600;
  margin-top: 2px;
}

/* ── FORMULA LIST ── */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.section-icon-box {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.section-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 22px;
}

.formula-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.formula-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .2s, transform .15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.formula-card:hover { transform: translateY(-2px); }

.formula-badge {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 13px;
  flex-shrink: 0;
  text-align: center;
  line-height: 1.2;
}

.formula-info { flex: 1; min-width: 0; }
.formula-name {
  font-family: 'Barlow', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.formula-short {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.formula-unit {
  font-size: 11px;
  font-weight: 600;
  margin-top: 3px;
}

.formula-arrow {
  color: var(--muted);
  flex-shrink: 0;
}

/* ── CALCULATOR SCREEN ── */
.calc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}
.calc-title-block { flex: 1; }
.calc-name {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 22px;
  line-height: 1.1;
}
.calc-category {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

#btn-fav {
  width: 38px; height: 38px;
  background: rgba(212,34,34,0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color .2s, background .2s, border-color .2s;
  flex-shrink: 0;
}
#btn-fav.active {
  color: #b45309;
  border-color: rgba(245,166,35,0.4);
  background: rgba(245,166,35,0.08);
}

/* Formula display box */
.formula-display {
  background: rgba(212,34,34,0.06);
  border: 1px solid rgba(212,34,34,0.18);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--cyan);
  gap: 8px;
  flex-wrap: wrap;
}

/* Fraction CSS */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  gap: 0;
  margin: 0 4px;
}
.frac-num {
  font-size: 15px;
  padding-bottom: 3px;
  border-bottom: 2px solid var(--cyan);
  color: var(--text);
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
  white-space: nowrap;
}
.frac-den {
  font-size: 13px;
  padding-top: 3px;
  color: rgba(212,34,34,0.65);
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
  white-space: nowrap;
}
.fml-sym {
  font-size: 18px;
  color: var(--muted);
}
.fml-result {
  color: var(--text);
  font-size: 18px;
}

/* Inputs */
.inputs-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.input-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding-left: 2px;
}
/* Sichtbarer Tastatur-Fokus */
.cat-card:focus-visible,
.formula-card:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.calc-input {
  flex: 1;
  background: var(--navy);
  border: 1px solid rgba(212,34,34,0.3);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 16px; /* >=16px verhindert iOS-Auto-Zoom beim Fokus */
  font-weight: 500;
  outline: none;
  transition: border-color .2s;
}
.calc-input:focus { border-color: var(--cyan); }
.calc-input.invalid { border-color: var(--red, #d42222); }
.calc-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
/* Einheiten-Umschalter neben dem Eingabefeld (µF/nF, mH/H, kW/W …) */
.input-unit-sel {
  flex-shrink: 0;
  min-width: 62px;
  min-height: 44px;
  background: var(--navy);
  border: 1px solid rgba(212,34,34,0.3);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--cyan);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  outline: none;
  transition: border-color .2s;
}
.input-unit-sel:focus { border-color: var(--cyan); }
/* Ergebnis kopieren */
.btn-copy {
  margin-top: 12px;
  background: rgba(212,34,34,0.12);
  border: 1px solid rgba(212,34,34,0.35);
  color: var(--cyan);
  border-radius: 8px;
  padding: 9px 16px;
  min-height: 40px;
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .2s, transform .12s;
}
.btn-copy:hover { background: rgba(212,34,34,0.2); }
.btn-copy:active { transform: scale(0.97); }
.calc-input::placeholder { color: var(--muted); opacity: 0.6; }
.input-unit {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  min-width: 36px;
  text-align: left;
}

/* Note */
.calc-note {
  font-size: 11px;
  color: var(--muted);
  background: rgba(212,34,34,0.04);
  border: 1px solid rgba(212,34,34,0.1);
  border-radius: 7px;
  padding: 7px 10px;
  margin-bottom: 12px;
}

/* Buttons */
.btn-calc {
  width: 100%;
  background: var(--cyan);
  color: var(--navy);
  border: none;
  border-radius: 9px;
  padding: 13px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  min-height: 48px;
}
.btn-calc:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-calc:active { transform: translateY(0); opacity: 1; }

.btn-reset {
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(75,85,99,0.2);
  border-radius: 9px;
  padding: 10px;
  font-family: 'Barlow', sans-serif;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  transition: color .2s, border-color .2s;
}
.btn-reset:hover { color: var(--text); border-color: var(--muted); }

/* Result box */
.result-box {
  background: rgba(212,34,34,0.08);
  border: 1px solid rgba(212,34,34,0.3);
  border-radius: 10px;
  padding: 16px;
  margin-top: 14px;
  text-align: center;
  display: none;
}
.result-box.visible { display: block; }
.result-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.result-value {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 36px;
  color: var(--cyan);
  line-height: 1;
}
.result-unit {
  font-size: 16px;
  color: var(--muted);
  margin-left: 4px;
}
.result-formula {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
/* Zusatzzeile: Prozentbewertung, Normquerschnitt, Umrechnung */
.result-alt {
  font-size: 13px;
  color: var(--text);
  margin-top: 8px;
  line-height: 1.5;
}
.result-alt .ok   { color: #15803d; font-weight: 600; }
.result-alt .warn { color: #b45309; font-weight: 600; }
.result-alt .bad  { color: #dc2626; font-weight: 600; }

/* Error */
.result-error {
  background: rgba(212,34,34,0.08);
  border: 1px solid rgba(212,34,34,0.25);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 14px;
  color: #dc2626;
  font-size: 13px;
  text-align: center;
  display: none;
}
.result-error.visible { display: block; }

/* ── SEARCH RESULTS ── */
#screen-search .search-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── FAVORITES ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state svg { opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── SETTINGS ── */
.settings-section {
  margin-bottom: 20px;
}
.settings-section-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  gap: 12px;
}
.setting-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}
.setting-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}
.setting-input {
  background: var(--navy);
  border: 1px solid rgba(212,34,34,0.3);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 16px; /* >=16px verhindert iOS-Auto-Zoom */
  font-weight: 500;
  outline: none;
  width: 90px;
  text-align: right;
  transition: border-color .2s;
}
.setting-input:focus { border-color: var(--cyan); }
.setting-select {
  background: var(--navy);
  border: 1px solid rgba(212,34,34,0.3);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  outline: none;
  cursor: pointer;
  transition: border-color .2s;
}
.setting-select:focus { border-color: var(--cyan); }

.btn-settings-save {
  width: 100%;
  background: var(--cyan);
  color: var(--navy);
  border: none;
  border-radius: 9px;
  padding: 13px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity .15s;
}
.btn-settings-save:hover { opacity: 0.9; }

/* ── FOOTER ── */
#footer {
  padding: 16px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
#footer a { color: var(--cyan); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #eef0f3;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text);
  z-index: 999;
  transition: transform .3s ease;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── DISCLAIMER BAR ── */
#disclaimer-bar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(245,166,35,0.06);
  border-top: 1px solid rgba(245,166,35,0.18);
  font-size: 11px;
  color: #4b5563;
  line-height: 1.45;
}

/* ── COOKIE BANNER ── */
#cookie-banner {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #f7f7f8;
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#cookie-text {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  min-width: 180px;
}
#cookie-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#cookie-accept {
  background: var(--cyan);
  color: var(--navy);
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#cookie-reject {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(75,85,99,0.25);
  border-radius: 7px;
  padding: 8px 12px;
  font-family: 'Barlow', sans-serif;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#cookie-reject:hover { color: var(--text); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(212,34,34,0.2); border-radius: 4px; }

/* ── RESPONSIVE: TABLET (768px+) ── */
@media (min-width: 768px) {
  #app { max-width: 700px; }
  #cookie-banner { max-width: 700px; }
  #content { padding: 18px 20px; }
  #header { padding: 0 20px; height: 60px; }
  .logo-circle { width: 38px; height: 38px; font-size: 14px; }
  #header-title { font-size: 20px; }
}

/* ── RESPONSIVE: DESKTOP (1024px+) ── */
@media (min-width: 1024px) {
  #app { max-width: 900px; }
  #cookie-banner { max-width: 900px; }
  #content { padding: 24px 32px; }

  /* Header */
  #header { padding: 0 32px; height: 66px; }
  .logo-circle { width: 40px; height: 40px; font-size: 15px; }
  #header-title { font-size: 22px; }

  /* Category grid: 3 columns */
  .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .cat-card { padding: 20px 16px; }
  .cat-icon-box { width: 52px; height: 52px; font-size: 24px; }
  .cat-label { font-size: 20px; }
  .cat-sub { font-size: 12px; }
  .cat-count { font-size: 12px; }

  /* Formula list: 2-column grid */
  .formula-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .formula-card { padding: 14px 16px; }
  .formula-badge { width: 52px; height: 52px; font-size: 14px; }
  .formula-name { font-size: 15px; }

  /* Calculator: centered, max 600px */
  #screen-calc { max-width: 620px; margin: 0 auto; }
  .formula-display { font-size: 22px; min-height: 80px; padding: 18px 24px; }
  .frac-num { font-size: 18px; }
  .frac-den { font-size: 16px; }
  .fml-sym, .fml-result { font-size: 22px; }
  .calc-name { font-size: 28px; }
  .result-value { font-size: 44px; }

}

/* ── RESPONSIVE: LARGE DESKTOP (1400px+) ── */
@media (min-width: 1400px) {
  #app { max-width: 1100px; }
  #cookie-banner { max-width: 1100px; }
  #content { padding: 28px 40px; }
  #header { padding: 0 40px; }

  /* Category grid: 4 columns */
  .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .cat-card { padding: 22px 18px; }
}

/* Mobile Fixes */
@media(max-width:480px){
  section { padding: 40px 20px; }
  body { overflow-x: hidden; }
  img { max-width: 100%; height: auto; }
  h1 { font-size: clamp(24px, 8vw, 48px); }
  h2 { font-size: clamp(20px, 6vw, 36px); }
}
