@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@700;900&family=Barlow:wght@400;500;600&display=swap');

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

:root {
  --navy: #0d1b2e;
  --card-bg: #0f2035;
  --cyan: #00c6ff;
  --red: #e63030;
  --text: #f0f4ff;
  --muted: #7a95b0;
  --border: rgba(0,198,255,0.15);
  --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(13,27,46,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(0,198,255,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(0,198,255,0.08);
}

/* Search bar */
#search-bar {
  display: none;
  padding: 8px 14px;
  background: rgba(13,27,46,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: 14px;
  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(0,198,255,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: #f5a623;
  border-color: rgba(245,166,35,0.4);
  background: rgba(245,166,35,0.08);
}

/* Formula display box */
.formula-display {
  background: rgba(0,198,255,0.06);
  border: 1px solid rgba(0,198,255,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(0,198,255,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 {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding-left: 2px;
}
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.calc-input {
  flex: 1;
  background: var(--navy);
  border: 1px solid rgba(0,198,255,0.3);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  font-weight: 500;
  outline: none;
  transition: border-color .2s;
}
.calc-input:focus { border-color: var(--cyan); }
.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(0,198,255,0.04);
  border: 1px solid rgba(0,198,255,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(122,149,176,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(0,198,255,0.08);
  border: 1px solid rgba(0,198,255,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;
}

/* Error */
.result-error {
  background: rgba(230,48,48,0.08);
  border: 1px solid rgba(230,48,48,0.25);
  border-radius: 10px;
  padding: 12px 16px;
  margin-top: 14px;
  color: #f87171;
  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(0,198,255,0.3);
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 14px;
  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(0,198,255,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: #1a2f4a;
  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: rgba(240,244,255,0.55);
  line-height: 1.45;
}

/* ── COOKIE BANNER ── */
#cookie-banner {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #0f2035;
  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(122,149,176,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); }

/* ── PRO LOCK ── */
.pro-badge {
  font-size: 9px;
  font-weight: 700;
  font-family: 'Barlow Condensed', sans-serif;
  background: linear-gradient(135deg, #f5a623, #e63030);
  color: #fff;
  padding: 2px 6px;
  border-radius: 5px;
  letter-spacing: 0.06em;
  vertical-align: middle;
  margin-left: 5px;
  text-transform: uppercase;
}

.cat-card.locked {
  opacity: 0.65;
}
.cat-card.locked .cat-icon-box {
  position: relative;
}

.formula-card.locked {
  opacity: 0.6;
  cursor: default;
}
.formula-card.locked:hover {
  transform: none;
}

/* Paywall modal */
#paywall-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
#paywall-overlay.open {
  display: flex;
}
#paywall-modal {
  width: 100%;
  max-width: 480px;
  background: #0f2035;
  border-top: 2px solid rgba(245,166,35,0.5);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 36px;
  text-align: center;
}
.paywall-crown {
  font-size: 40px;
  margin-bottom: 10px;
  line-height: 1;
}
.paywall-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 26px;
  color: var(--text);
  margin-bottom: 6px;
}
.paywall-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.5;
}
.paywall-features {
  text-align: left;
  background: rgba(245,166,35,0.06);
  border: 1px solid rgba(245,166,35,0.2);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 20px;
}
.paywall-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  padding: 4px 0;
}
.paywall-feature-icon {
  color: #f5a623;
  flex-shrink: 0;
}
.paywall-price {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 14px;
}
.paywall-price strong {
  color: var(--text);
  font-size: 26px;
}
.btn-pro {
  width: 100%;
  background: linear-gradient(135deg, #f5a623, #e63030);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 900;
  font-size: 18px;
  cursor: pointer;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  transition: opacity .15s;
}
.btn-pro:hover { opacity: 0.9; }
.btn-paywall-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px;
  font-family: 'Barlow', sans-serif;
}
.btn-paywall-close:hover { color: var(--text); }

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