/* CaloriesTools – styles. One file, no dependencies, system fonts only. */

:root {
  --ink: #15303B;
  --muted: #4F6670;
  --bg: #F2F7F6;
  --surface: #FFFFFF;
  --line: #D6E3E0;
  --field-line: #B3C7C3;

  --teal: #1D7F78;
  --teal-dark: #166A64;
  --teal-soft: #DCEFEC;
  --peach: #FFEBDD;
  --peach-line: #F4CDB4;
  --coral: #E0643A;
  --danger: #B42318;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --maxw: 1120px;
  --narrow: 860px;
}

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

[hidden] { display: none !important; }

/* Arabic: right-to-left. Hidden for a moment while js/i18n.js swaps the text in. */
html.i18n-pending body { visibility: hidden; }
[dir="rtl"] body { --font: system-ui, "Segoe UI", Tahoma, "Geeza Pro", "Noto Sans Arabic", Arial, sans-serif; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] .logo, [dir="rtl"] .glyph,
[dir="rtl"] .quick-value, [dir="rtl"] .result-number { letter-spacing: 0; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { line-height: 1.35; }
[dir="rtl"] body { line-height: 1.75; }

html { scroll-behavior: smooth; scroll-padding-top: 88px; }

body {
  margin: 0;
  font: 400 1rem/1.6 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 0.5em; }
h1 { font-size: clamp(2.2rem, 5.5vw, 3.5rem); font-weight: 800; }
h2 { font-size: clamp(1.45rem, 3vw, 1.95rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--teal-dark); }
a:hover { color: var(--ink); }

:focus-visible { outline: 3px solid var(--coral); outline-offset: 2px; }

.container { width: min(100% - 2.5rem, var(--maxw)); margin-inline: auto; }
.narrow { width: min(100% - 2.5rem, var(--narrow)); margin-inline: auto; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; inset-inline-start: 1rem; top: -4rem; z-index: 50;
  background: var(--ink); color: #fff; padding: 0.6rem 1rem; border-radius: var(--r-sm);
}
.skip-link:focus { top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; height: 68px; }
.header-inner .logo { margin-inline-end: auto; }
.logo {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.nav ul { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; }
.nav a {
  display: block; padding: 0.5rem 0.95rem; border-radius: 999px;
  color: var(--muted); font-weight: 600; text-decoration: none;
}
.nav a:hover { background: var(--teal-soft); color: var(--ink); }
.nav a[aria-current] { background: var(--teal-soft); color: var(--teal-dark); }

.nav { order: 1; }
.lang-toggle {
  order: 2; margin-inline-start: 0.5rem; font: inherit; font-weight: 600; color: var(--teal-dark);
  background: #fff; border: 1.5px solid var(--field-line); border-radius: 999px;
  padding: 0.4rem 0.9rem; cursor: pointer;
}
.lang-toggle:hover { border-color: var(--teal); }
.nav-toggle {
  order: 3; margin-inline-start: 0.5rem;
  display: none; font: inherit; font-weight: 600; color: var(--ink);
  background: #fff; border: 1.5px solid var(--field-line); border-radius: 999px;
  padding: 0.45rem 1rem; cursor: pointer;
}

@media (max-width: 760px) {
  .nav-toggle { display: inline-flex; }
  .nav {
    display: none; position: absolute; top: 68px; left: 0; right: 0;
    background: #fff; border-bottom: 1px solid var(--line); padding: 0.5rem 1.25rem 1rem;
  }
  .nav.is-open { display: block; }
  .nav ul { flex-direction: column; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.8rem 1.5rem; border-radius: 999px; border: 2px solid transparent;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--field-line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--teal); color: var(--teal-dark); }

/* ---------- Hero (home) ---------- */
.hero { position: relative; overflow: hidden; padding: clamp(2.5rem, 6vw, 5rem) 0; }
.hero::before {
  content: ""; position: absolute; z-index: 0;
  width: 560px; height: 560px; border-radius: 50%;
  background: var(--peach); inset-inline-end: -140px; top: -90px;
}
.hero-grid {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 3rem; align-items: center;
}
.hero-copy .lead { font-size: 1.2rem; color: var(--muted); max-width: 33rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; gap: 2rem; }
  .hero::before { width: 380px; height: 380px; inset-inline-end: -150px; top: auto; bottom: -80px; }
}

/* Quick calculator card in the hero */
.quick {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: clamp(1.1rem, 3vw, 1.75rem);
  box-shadow: 0 22px 44px -26px rgba(21, 48, 59, 0.4);
}
.quick h2 { font-size: 1.25rem; margin-bottom: 1rem; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.quick-grid .field-wide { grid-column: 1 / -1; }
.quick-result {
  margin-top: 1.25rem; padding: 1rem 1.25rem;
  background: var(--peach); border: 1px solid var(--peach-line); border-radius: var(--r-md);
}
.quick-value { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; margin: 0 0 0.35rem; font-variant-numeric: tabular-nums; }
.quick-label { margin: 0; font-weight: 600; }
.quick-hint { margin: 0.35rem 0 0; font-size: 0.9rem; color: var(--muted); }
.quick-more { display: inline-block; margin-top: 1rem; font-weight: 600; }

/* ---------- Sections ---------- */
.section { padding: clamp(2.25rem, 5vw, 3.75rem) 0; }
.section-head {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem;
}
.section-head h2 { margin: 0; }
.section-head > div { flex: 0 1 320px; min-width: min(100%, 220px); }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; }
.tool-tile {
  display: flex; gap: 1rem; padding: 1.25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  color: inherit; text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.tool-tile:hover { border-color: var(--teal); transform: translateY(-2px); color: inherit; }
.tool-tile h3 { margin: 0 0 0.25rem; }
.tool-tile p { margin: 0; color: var(--muted); font-size: 0.95rem; }

.empty-state { padding: 1.25rem; border: 1px dashed var(--field-line); border-radius: var(--r-md); color: var(--muted); }

/* Glyph tiles: show what each calculator gives you back */
.glyph {
  flex: none; display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 14px;
  font-weight: 800; font-size: 0.82rem; letter-spacing: -0.01em; color: var(--ink);
  background: var(--teal-soft);
}
[data-tint="1"] { background: #FFEBDD; }
[data-tint="2"] { background: #E1EFFA; }
[data-tint="3"] { background: #FFF3CF; }
[data-tint="4"] { background: #E7F3DD; }
[data-tint="5"] { background: #F1E8F8; }
[data-tint="6"] { background: #FDE3E7; }

.points { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 2rem; }
.point { border-top: 3px solid var(--teal); padding-top: 1rem; }
.point p { color: var(--muted); margin: 0; }

.paths { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.path { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 1.25rem; }
.path h3 { margin-bottom: 0.5rem; }
.path p { color: var(--muted); font-size: 0.95rem; }
.path ul { margin: 0; padding-inline-start: 1.1rem; }
.path li { margin-bottom: 0.3rem; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; border: 0; padding: 0; margin: 0; }
.field label, .field legend { font-weight: 650; padding: 0; }
.field-hint { color: var(--muted); font-size: 0.88rem; margin: 0; }

input[type="number"], input[type="text"], input[type="email"], input[type="search"], select, textarea {
  width: 100%; min-height: 46px; padding: 0.7rem 0.85rem;
  font: inherit; color: var(--ink); background: #fff;
  border: 1.5px solid var(--field-line); border-radius: var(--r-sm);
}
textarea { min-height: 150px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(29, 127, 120, 0.35); border-color: var(--teal);
}
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-inline-end: 3.4rem; }
.input-wrap .suffix { position: absolute; inset-inline-end: 0.9rem; color: var(--muted); pointer-events: none; font-size: 0.95rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.error { color: var(--danger); font-size: 0.9rem; font-weight: 600; margin: 0; }

.segmented { display: inline-flex; align-self: flex-start; padding: 3px; background: #fff; border: 1.5px solid var(--field-line); border-radius: 999px; }
.segmented label { position: relative; display: block; cursor: pointer; font-weight: 600; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 0.45rem 1.15rem; border-radius: 999px; color: var(--muted); }
.segmented input:checked + span { background: var(--teal); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--coral); outline-offset: 2px; }

body[data-units="metric"] [data-unit="imperial"],
body[data-units="imperial"] [data-unit="metric"] { display: none; }

/* ---------- Page headers ---------- */
.crumbs { padding: 1rem 0 0; font-size: 0.9rem; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; list-style: none; margin: 0; padding: 0; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-inline-end: 0.5rem; color: var(--field-line); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }

.page-head { padding: clamp(1.25rem, 4vw, 2.25rem) 0 0.5rem; }
.page-head h1 { font-size: clamp(2rem, 5vw, 2.9rem); }
.page-head .lead { color: var(--muted); font-size: 1.15rem; max-width: 40rem; }
.meta-line { color: var(--muted); font-size: 0.9rem; margin-top: 0.5rem; }

/* ---------- Calculator ---------- */
.calc-wrap { padding: 1.25rem 0 0.5rem; }
.units-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.units-bar .label { font-weight: 650; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: clamp(1.25rem, 3vw, 2rem); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem 1.25rem; margin: 0 0 1.5rem; }
.form-grid .field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

@media (max-width: 640px) {
  .form-grid, .quick-grid { grid-template-columns: 1fr; }
}

/* ---------- Results ---------- */
.result {
  margin-top: 1.75rem; padding: clamp(1.1rem, 3vw, 1.75rem);
  background: var(--peach); border: 1px solid var(--peach-line); border-radius: var(--r-lg);
}
.result-title { margin: 0 0 0.25rem; font-weight: 700; }
.result-value { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; }
.result-number { font-size: clamp(2.7rem, 7vw, 3.75rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.result-unit { font-weight: 600; color: var(--muted); }
.result-rows { margin: 1.25rem 0 0; display: grid; gap: 0; border-top: 1px solid var(--peach-line); }
.result-rows div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--peach-line); }
.result-rows dt { color: var(--muted); }
.result-rows dd { margin: 0; font-weight: 700; text-align: end; }
.result-text { margin: 1.1rem 0 0; }
.result-note { margin: 0.9rem 0 0; padding: 0.7rem 0.9rem; background: #fff; border-inline-start: 4px solid var(--coral); border-start-end-radius: var(--r-sm); border-end-end-radius: var(--r-sm); font-size: 0.95rem; }
.result-table-title { margin: 1.4rem 0 0.5rem; font-size: 1rem; }
.working { margin-top: 1.1rem; }
.working summary { cursor: pointer; font-weight: 650; }
.working p { margin: 0.5rem 0 0; padding: 0.7rem 0.9rem; background: #fff; border-radius: var(--r-sm); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-link { margin: 1rem 0 0; font-size: 0.95rem; }

.scale { position: relative; margin-top: 1.75rem; direction: ltr; }
.scale-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; }
.scale-bar span:nth-child(1) { width: 14%; background: #8DC0E6; }
.scale-bar span:nth-child(2) { width: 26%; background: #67BDAE; }
.scale-bar span:nth-child(3) { width: 20%; background: #F1C455; }
.scale-bar span:nth-child(4) { width: 40%; background: #E8825E; }
.scale-marker { position: absolute; top: -7px; width: 4px; height: 26px; background: var(--ink); border-radius: 2px; transform: translateX(-50%); border: 2px solid var(--peach); box-sizing: content-box; }
.scale-labels { display: flex; margin-top: 0.45rem; font-size: 0.8rem; color: var(--muted); }
.scale-labels span:nth-child(1) { width: 14%; }
.scale-labels span:nth-child(2) { width: 26%; }
.scale-labels span:nth-child(3) { width: 20%; }
.scale-labels span:nth-child(4) { width: 40%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1rem 0 1.5rem; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; background: var(--surface); }
caption { text-align: start; padding: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; caption-side: top; }
th, td { padding: 0.6rem 0.85rem; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--teal-soft); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.is-selected td { background: #FFF6EE; font-weight: 700; }
.result .table-wrap { margin: 0 0 0.5rem; }
.result table { background: #fff; }
.result thead th { background: #fff; border-bottom: 2px solid var(--peach-line); }

/* ---------- Article content on calculator and text pages ---------- */
.content { padding: 2rem 0 1rem; }
.content h2 { margin-top: 2.5rem; }
.content h2:first-child { margin-top: 0; }
.content h3 { margin-top: 1.75rem; }
.content p, .content li { max-width: 46rem; }
.content ul, .content ol { padding-inline-start: 1.3rem; }
.content li { margin-bottom: 0.45rem; }

.formula {
  margin: 1.25rem 0; padding: 1rem 1.25rem; max-width: 46rem;
  background: var(--teal-soft); border-inline-start: 5px solid var(--teal); border-start-end-radius: var(--r-md); border-end-end-radius: var(--r-md);
  font-weight: 650; font-size: 1.05rem; line-height: 1.7; overflow-wrap: anywhere;
}
.formula small { display: block; font-weight: 400; color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }

.example {
  margin: 1.25rem 0; padding: 1.25rem; max-width: 46rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.example h3 { margin-top: 0; }
.example p:last-child, .example ol:last-child { margin-bottom: 0; }

.faq h3 { margin-top: 1.5rem; margin-bottom: 0.35rem; font-size: 1.1rem; }
.faq p { margin-bottom: 0; }

.callout { padding: 1rem 1.25rem; background: var(--peach); border: 1px solid var(--peach-line); border-radius: var(--r-md); max-width: 46rem; }

.related { padding: 1rem 0 0.5rem; }
.related h2 { margin-top: 1.5rem; }

.sources { font-size: 0.92rem; color: var(--muted); max-width: 46rem; }
.sources h2 { font-size: 1.15rem; color: var(--ink); }
.sources li { margin-bottom: 0.35rem; }

/* ---------- Ad slots: reserved, hidden until ads are switched on ---------- */
.ad-slot { display: none; margin: 2.5rem auto; max-width: 970px; clear: both; }
.ads-enabled .ad-slot, .ad-preview .ad-slot { display: block; }
.ad-label { display: block; margin-bottom: 0.35rem; text-align: center; font-size: 0.75rem; color: var(--muted); }
.ad-box { display: grid; place-items: center; width: 100%; min-height: 280px; overflow: hidden; }
.ad-preview .ad-box {
  border: 2px dashed var(--field-line); border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.6); color: var(--muted); font-size: 0.9rem; text-align: center; padding: 1rem;
}
.ad-preview .ad-box::before { content: "Ad placeholder: " attr(data-slot) " (responsive, reserves 280px)"; }
@media (min-width: 900px) { .ad-box { min-height: 250px; } }

/* ---------- Text pages ---------- */
.prose { padding-bottom: 3rem; }
.contact-form { display: grid; gap: 1.1rem; max-width: 36rem; margin: 1.5rem 0; }

/* ---------- Footer ---------- */
.site-footer { margin-top: 3rem; background: #fff; border-top: 1px solid var(--line); padding: 2.5rem 0 2rem; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 2rem 3rem; }
.footer-grid p { margin: 0.6rem 0 0; color: var(--muted); font-size: 0.95rem; max-width: 26rem; }
.footer-grid h2 { font-size: 1rem; margin-bottom: 0.6rem; letter-spacing: 0; }
.footer-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.footer-links a { color: var(--ink); font-weight: 500; text-decoration: none; }
.install-app { padding: 0; border: 0; background: none; font: inherit; font-weight: 600; color: var(--teal-dark); cursor: pointer; }
.install-app:hover { color: var(--ink); }
.footer-links a:hover { text-decoration: underline; }
.footer-fine { margin: 2rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--line); font-size: 0.85rem; color: var(--muted); }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* Arabic: research titles stay in English, so let each one keep its own direction */
[dir="rtl"] .sources li { unicode-bidi: plaintext; }
