/* Solid, modern, SEO-friendly static site (no external deps) */
:root{
  --bg: #0b1220;
  --surface: #0f1a2e;
  --card: rgba(255,255,255,0.06);
  --card-2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.12);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.72);
  --muted2: rgba(255,255,255,0.58);
  --accent: #7dd3fc;
  --accent2: #a78bfa;
  --good: #86efac;
  --warn: #fbbf24;
  --bad: #fb7185;
  --shadow: 0 18px 50px rgba(0,0,0,0.35);
  --radius: 18px;
  --radius-sm: 12px;
  --max: 1100px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}
@media (prefers-color-scheme: light){
  :root{
    --bg:#f7fafc;
    --surface:#ffffff;
    --card:#ffffff;
    --card-2:#ffffff;
    --border: rgba(2,6,23,0.12);
    --text: rgba(2,6,23,0.92);
    --muted: rgba(2,6,23,0.70);
    --muted2: rgba(2,6,23,0.55);
    --shadow: 0 18px 50px rgba(2,6,23,0.10);
  }
}
*{ box-sizing:border-box; }
html, body{ min-height:100%; }
html{ background: var(--bg); }
body{ height:auto; }
body{
  margin:0;
  font-family:var(--sans);
  background: transparent;
color:var(--text);
  line-height:1.5;
}
a{ color:inherit; text-decoration:none; }
a:hover{ text-decoration:underline; }
.container{ max-width:var(--max); margin:0 auto; padding: 0 1px; }
.skip-link{ position:absolute; left:-999px; top:auto; width:1px; height:1px; overflow:hidden; }
.skip-link:focus{
  left: 16px; top: 16px; width:auto; height:auto; padding:10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; z-index: 9999;
}
.site-header{
  position:sticky; top:0; z-index:50;
  backdrop-filter: blur(10px);
  background: linear-gradient(to bottom, rgba(15,26,46,0.78), rgba(15,26,46,0.35));
  border-bottom: 1px solid var(--border);
}
@media (prefers-color-scheme: light){
  .site-header{ background: rgba(255,255,255,0.8); }
}
.header-inner{ display:flex; align-items:center; justify-content:space-between; padding: 14px 0; gap: 12px; }
.brand{ display:flex; align-items:center; gap:10px; font-weight: 800; letter-spacing: 0.2px; }
.logo{
  width:34px; height:34px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 24px rgba(125,211,252,0.18);
}
.nav{ display:flex; gap: 10px; align-items:center; flex-wrap:wrap; }
.nav a{
  padding: 8px 10px; border: 1px solid transparent; border-radius: 12px; color: var(--muted);
}
.nav a:hover{ border-color: var(--border); color: var(--text); text-decoration:none; }
.nav .pill{
  display:flex; align-items:center; gap:8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 999px; color: var(--muted);
}
.nav select{ background: transparent; border:none; color: inherit; font: inherit; outline:none; padding: 2px 0; }
.nav select option{ color: #0b1220; }
.hero{ padding: 34px 0 10px; }
.hero-grid{ display:grid; grid-template-columns: 1.3fr 0.7fr; gap: 18px; align-items:stretch; }
@media (max-width: 900px){ .hero-grid{ grid-template-columns: 1fr; } }
.hero-card{
  padding: 22px; border: 1px solid var(--border); border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  box-shadow: var(--shadow);
}
@media (prefers-color-scheme: light){ .hero-card{ background: var(--surface); } }
.hero h1{ margin:0 0 10px; font-size: clamp(24px, 3.2vw, 40px); line-height:1.1; }
.hero p{ margin:0; color: var(--muted); max-width: 70ch; }
.kpis{ display:grid; gap:12px; }
.kpi{
  padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
}
@media (prefers-color-scheme: light){ .kpi{ background: var(--surface); } }
.kpi .label{ color: var(--muted2); font-size: 13px; }
.kpi .value{ font-weight: 800; font-size: 16px; margin-top: 3px; }
.section{ padding: 5px 0 5px; }
.section h2{ margin: 18px 0 10px; font-size: 20px; }
.tools-toolbar{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin: 8px 0 14px; }
.search{
  flex: 1 1 240px; display:flex; gap:10px; padding: 10px 12px;
  border:1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,0.04);
}
@media (prefers-color-scheme: light){ .search{ background: var(--surface); } }
.search input{
  flex:1; border:none; background: transparent; color: var(--text);
  outline:none; font-size: 14px;
}
.badge{ font-family: var(--mono); font-size: 12px; color: var(--muted2); }
.grid{ display:grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.card{
  grid-column: span 6; padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: rgba(255,255,255,0.04);
  box-shadow: 0 10px 24px rgba(0,0,0,0.15);
  display:flex; flex-direction:column; gap: 10px; min-height: 180px;
}
@media (prefers-color-scheme: light){ .card{ background: var(--surface); } }
@media (max-width: 900px){ .card{ grid-column: span 12; } }
.card h3{ margin:0; font-size: 18px; }
.card p{ margin:0; color: var(--muted); }
.card .meta{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; color: var(--muted2); font-size: 13px; }
.dot{ width:7px; height:7px; border-radius: 999px; background: var(--accent); display:inline-block; }
.dot.violet{ background: var(--accent2); }
.card .actions{ margin-top:auto; display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap: 8px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.06); color: var(--text); font-weight: 700;
  cursor:pointer; text-decoration:none !important;
}
.btn:hover{ filter: brightness(1.06); }
.btn.primary{
  border-color: rgba(125,211,252,0.45);
  background: linear-gradient(135deg, rgba(125,211,252,0.22), rgba(167,139,250,0.16));
}
.btn.ghost{ background: transparent; color: var(--muted); }
.small{ font-size: 13px; padding: 8px 10px; border-radius: 10px; }
.page{ padding: 15px 0 15px; }
.breadcrumbs{ color: var(--muted2); font-size: 13px; margin: 6px 0 14px; }
.breadcrumbs a{ color: var(--muted2); }
.layout{ display:grid; grid-template-columns: 1fr 0.8fr; gap: 16px; align-items:start; }
@media (max-width: 980px){ .layout{ grid-template-columns: 1fr; } }
.panel{
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: rgba(255,255,255,0.04); box-shadow: var(--shadow);
}
@media (prefers-color-scheme: light){ .panel{ background: var(--surface); } }
.panel h1{ margin: 0 0 8px; font-size: clamp(22px, 2.5vw, 32px); line-height:1.15; }
.panel p.lead{ margin: 0 0 14px; color: var(--muted); max-width: 80ch; }
.form{ display:grid; grid-template-columns: repeat(12, 1fr); gap: 10px; margin-top: 12px; }
.field{ grid-column: span 6; display:flex; flex-direction:column; gap: 6px; }
.field.full{ grid-column: span 12; }
@media (max-width: 680px){ .field{ grid-column: span 12; } }
label{ font-size: 13px; color: var(--muted2); }
input, select{
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: rgba(255,255,255,0.05); color: var(--text); outline:none;
}
@media (prefers-color-scheme: light){ input, select{ background: #ffffff; } }
input::placeholder{ color: var(--muted2); }
.help{ font-size: 12px; color: var(--muted2); }
.row{ display:flex; gap: 10px; align-items:center; flex-wrap:wrap; }
.segment{
  display:flex; border:1px solid var(--border); border-radius: 999px; overflow:hidden;
  background: rgba(255,255,255,0.04);
}
.segment button{
  border:none; background: transparent; color: var(--muted); padding: 8px 10px;
  cursor:pointer; font-weight:700;
}
.segment button.active{ color: var(--text); background: rgba(125,211,252,0.12); }
.result{ display:grid; gap: 10px; }
.result .big{ font-size: 34px; font-weight: 900; letter-spacing: -0.5px; }
.pill{
  display:inline-flex; align-items:center; gap: 8px;
  padding: 8px 10px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); font-size: 13px;
}
.pill.good{ border-color: rgba(134,239,172,0.35); color: rgba(134,239,172,0.95); }
.pill.warn{ border-color: rgba(251,191,36,0.35); color: rgba(251,191,36,0.95); }
.pill.bad{ border-color: rgba(251,113,133,0.35); color: rgba(251,113,133,0.95); }
.notice{
  padding: 12px 12px; border-radius: var(--radius-sm); border:1px solid var(--border);
  color: var(--muted); background: rgba(255,255,255,0.03); font-size: 13px;
}
hr.sep{ border:none; border-top: 1px solid var(--border); margin: 16px 0; }
.faq h2{ margin: 0 0 10px; font-size: 18px; }
.faq h3{ margin: 14px 0 6px; font-size: 15px; }
.faq p{ margin: 0; color: var(--muted); }
.footer{ padding: 22px 0; color: var(--muted2); font-size: 13px; }

/* Footer layout fixes */
.footer .notice{ width:100%; margin-top:1px; }
.footer .footer-tip{ text-align:right; width:100%; }
.footer .copyright{ width:100%; }

.footer .row{ justify-content:flex-start; }
.footer .footer-top{ justify-content:flex-end; }
.footer .footer-bottom{ justify-content:flex-start; }
kbd{
  font-family: var(--mono); border:1px solid var(--border);
  border-bottom-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  padding: 2px 6px; border-radius: 8px; font-size: 12px; color: var(--muted);
}


/* History list (stored locally in the browser) */
.history-list{ display:grid; gap:8px; margin-top:10px; }
.history-item{
  display:flex; gap:10px; align-items:flex-start; justify-content:space-between;
  padding:10px 10px; border:1px solid var(--border); border-radius: 14px;
  background: rgba(255,255,255,0.03);
}
@media (prefers-color-scheme: light){ .history-item{ background: #ffffff; } }
.history-item .left{ display:grid; gap:2px; }
.history-item .ts{ font-size:12px; color: var(--muted2); }
.history-item .txt{ font-size:13px; color: var(--muted); }
.history-item .right{ display:flex; gap:8px; }
.btn.icon{ padding: 8px 10px; border-radius: 10px; font-weight: 800; }


/* History header actions */
.history-header{ display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.history-actions{ display:flex; gap:8px; align-items:center; }

/* Smaller action buttons (used in History header) */
.btn.tiny{
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
}

/* Home (mobile): collapsible "Quick info" section containing KPI cards */
.kpi-collapsible{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
  overflow: clip;
}
@media (prefers-color-scheme: light){
  .kpi-collapsible{ background: var(--surface); }
}
.kpi-collapsible > summary{
  cursor: pointer;
  user-select: none;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  color: var(--text);
  background: linear-gradient(135deg, rgba(125,211,252,0.14), rgba(167,139,250,0.10));
  border-bottom: 1px solid var(--border);
}
.kpi-collapsible > summary::-webkit-details-marker{ display:none; }
.kpi-collapsible > summary::marker{ content:""; }
.kpi-collapsible > summary::after{
  content:"";
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .18s ease;
  margin-left: auto;
}
.kpi-collapsible[open] > summary::after{
  transform: rotate(-135deg);
}
.kpi-collapsible .kpis{
  padding: 12px;
}
.kpi-collapsible .kpi{
  background: rgba(255,255,255,0.02);
}

/* Desktop: behave like normal column (no collapsible header shown) */
@media (min-width: 901px){
  .kpi-collapsible{
    border: none;
    background: transparent;
    overflow: visible;
  }
  .kpi-collapsible > summary{ display:none; }
  .kpi-collapsible .kpis{ padding: 0; }
}

/* Desktop resilience: even if <details> is closed, show KPI content when layout is 2-column */
@media (min-width: 901px){
  .kpi-collapsible:not([open]) > .kpis{ display: grid !important; }
}

/* Robustness: on wide layout, show KPI content even if <details> was closed on mobile */
@media (min-width: 901px){
  details.kpi-collapsible:not([open]) > :not(summary){
    display: block !important;
  }
}

/* KPI third line */
.kpi .label.sub{
  margin-top: 6px;
  line-height: 1.35;
}

/* Result gauge (shared visual component) */
.gauge{
  position: relative;
  margin-top: 12px;
}
.gauge-track{
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
}
.gauge-seg{ height: 100%; }
.gauge-marker{
  position: absolute;
  top: -2px;
  transform: translateX(-50%);
  pointer-events: none;
}
.gauge-marker .pin{
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid var(--text);
  margin: 0 auto;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
}
.gauge-marker .line{
  width: 2px;
  height: 14px;
  background: var(--text);
  margin: 0 auto;
  opacity: 0.9;
}
.gauge-labels{
  position: relative;
  height: 18px;
  margin-top: 6px;
  color: var(--muted2);
  font-size: 12px;
}
.gauge-labels span{
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Home: grouped calculator sections */
.calc-group{ margin-top: 18px; }
.calc-group > h2{ margin: 10px 4px 12px; font-size: 1.15rem; }
.calc-group .grid{ margin-top: 0; }
.calc-card .meta{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

/* Small toast for copy/bookmark hints */
.toast{
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(10px);
  opacity: 0;
  background: rgba(17,24,39,.92);
  color: #fff;
  padding: 10px 12px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 99;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.show{ opacity: 1; transform: translateX(-50%) translateY(0); }


/* ------------------------------------------------------------
   Explicit theme override (user-selected)
   - If data-theme is set, it wins over prefers-color-scheme.
   ------------------------------------------------------------ */

html[data-theme="light"]{
  color-scheme: light;
  --bg:#f7fafc;
  --surface:#ffffff;
  --card:#ffffff;
  --card-2:#ffffff;
  --border: rgba(2,6,23,0.12);
  --text: rgba(2,6,23,0.92);
  --muted: rgba(2,6,23,0.70);
  --muted2: rgba(2,6,23,0.55);
  --shadow: 0 18px 50px rgba(2,6,23,0.10);
}

html[data-theme="dark"]{
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #0f1a2e;
  --card: rgba(255,255,255,0.06);
  --card-2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.12);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.72);
  --muted2: rgba(255,255,255,0.58);
  --shadow: 0 18px 50px rgba(0,0,0,0.35);
}

/* Property overrides for blocks that were previously hard-coded in prefers-color-scheme */
html[data-theme="light"] .site-header{ background: rgba(255,255,255,0.8); }
html[data-theme="dark"] .site-header{
  background: linear-gradient(to bottom, rgba(15,26,46,0.78), rgba(15,26,46,0.35));
}

html[data-theme="light"] .hero-card,
html[data-theme="light"] .kpi,
html[data-theme="light"] .search,
html[data-theme="light"] .card,
html[data-theme="light"] .panel,
html[data-theme="light"] .kpi-collapsible{
  background: var(--surface);
}

html[data-theme="dark"] .hero-card{
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
}
html[data-theme="dark"] .kpi,
html[data-theme="dark"] .search,
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .kpi-collapsible{
  background: rgba(255,255,255,0.04);
}

html[data-theme="light"] input,
html[data-theme="light"] select{ background: #ffffff; }

html[data-theme="dark"] input,
html[data-theme="dark"] select{ background: rgba(255,255,255,0.05); }

html[data-theme="light"] .history-item{ background: #ffffff; }
html[data-theme="dark"] .history-item{ background: rgba(255,255,255,0.03); }

#themeToggle{ min-width: 42px; text-align:center; }

/* BMI Sex segmented control: i18n-friendly sizing */
.segment[aria-label="Sex"]{
  width:100%;
}
/* Let each option take the space it needs, but still fill the whole pill */
.segment[aria-label="Sex"] button{
  flex: 1 1 auto;          /* base size = content, then share remaining space */
  min-width: 0;            /* allow shrinking if the container is very narrow */
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;

  white-space: nowrap;     /* keep labels on one line */
  overflow: visible;       /* do NOT cut text in normal cases */
}

/* If the screen is extremely narrow, allow graceful fallback (smaller text, then ellipsis) */
@media (max-width: 360px){
  .segment[aria-label="Sex"] button{
    font-size: 12px;
    overflow:hidden;
    text-overflow: ellipsis;
  }
}

/* Subtle dividers (draw on the right edge of each option except last) */
.segment[aria-label="Sex"] button{
  position: relative;
}
.segment[aria-label="Sex"] button:not(:last-child)::after{
  content:"";
  position:absolute;
  right:0;
  top:22%;
  bottom:22%;
  width:1px;
  background: var(--border);
  opacity:0.85;
}
/* END BMI Sex segmented control */

/* Fixed gradient background (no seams on long pages) */
html{ background: var(--bg); }
body{ background: transparent; }
body::before{
  content:"";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(1200px 900px at 25% 10%, rgba(125,211,252,0.16), transparent 55%),
              radial-gradient(900px 700px at 80% 15%, rgba(167,139,250,0.12), transparent 60%),
              var(--bg);
}
/* END Fixed gradient background */

