/* BuildWise — design tokens, light + dark themes, mobile-first layout */

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --surface-3: #e8edf5;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --brand: #c2410c;
  --brand-hover: #9a3412;
  --brand-soft: #fff1e8;
  --on-brand: #ffffff;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --c1: #c2410c;
  --c2: #059669;
  --c3: #a16207;
  --c4: #0369a1;
  --ring: 0 0 0 3px rgba(194, 65, 12, .35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -8px rgba(15, 23, 42, .12);
  --radius: 14px;
  --radius-sm: 10px;
  --max: 1180px;
  --header-h: 64px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

/* Dark theme: when chosen explicitly, or when the system prefers it and no choice was saved */
:root[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182032;
  --surface-3: #1f2940;
  --text: #e8edf6;
  --text-2: #c3cddd;
  --muted: #8b98ad;
  --border: #243049;
  --border-strong: #33415e;
  --brand: #fb923c;
  --brand-hover: #fdba74;
  --brand-soft: #3a1d0c;
  --on-brand: #0b0f17;
  --warn: #fbbf24;
  --warn-soft: #2a2110;
  --c1: #fb923c;
  --c2: #34d399;
  --c3: #facc15;
  --c4: #38bdf8;
  --ring: 0 0 0 3px rgba(251, 146, 60, .45);
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .02), 0 12px 32px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #182032;
    --surface-3: #1f2940;
    --text: #e8edf6;
    --text-2: #c3cddd;
    --muted: #8b98ad;
    --border: #243049;
    --border-strong: #33415e;
    --brand: #fb923c;
    --brand-hover: #fdba74;
    --brand-soft: #3a1d0c;
    --on-brand: #0b0f17;
    --warn: #fbbf24;
    --warn-soft: #2a2110;
    --c1: #fb923c;
    --c2: #34d399;
    --c3: #facc15;
    --c4: #38bdf8;
    --ring: 0 0 0 3px rgba(251, 146, 60, .45);
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .02), 0 12px 32px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* Script-specific fonts */
:lang(km) { --font: "Noto Sans Khmer", "Khmer OS", "Khmer UI", "Leelawadee UI", ui-sans-serif, system-ui, sans-serif; }
:lang(zh-Hans) { --font: ui-sans-serif, system-ui, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
:lang(km) body, :lang(zh-Hans) body { line-height: 1.8; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}
img, svg { max-width: 100%; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
main:focus { outline: none; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.015em; color: var(--text); }
:lang(km) h1, :lang(km) h2, :lang(km) h3, :lang(zh-Hans) h1, :lang(zh-Hans) h2, :lang(zh-Hans) h3 { letter-spacing: 0; line-height: 1.5; }
.container { width: 100%; max-width: var(--max); margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
@media (min-width: 768px) { .container { padding-left: 24px; padding-right: 24px; } }
.i { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: 12px; top: 12px; transform: translateY(-200%); z-index: 100; background: var(--brand); color: var(--on-brand); padding: 10px 14px; border-radius: 8px; text-decoration: none; font-weight: 600; transition: transform .15s; }
.skip-link:focus { transform: none; color: var(--on-brand); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: var(--header-h); }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; letter-spacing: -.02em; }
.logo:hover { color: var(--text); }
.logo b { color: var(--brand); font-weight: 800; }
.logo-mark { width: 30px; height: 30px; color: var(--on-brand); background: var(--brand); border-radius: 9px; padding: 4px; stroke-width: 2.2; }
.logo-mark rect { display: none; }

.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { color: var(--text-2); text-decoration: none; font-size: .94rem; font-weight: 500; padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }

.header-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn, .lang-menu summary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 42px; height: 42px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text-2); cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600;
}
.icon-btn:hover, .lang-menu summary:hover { background: var(--surface-2); color: var(--text); }

/* Theme toggle: show the icon for the theme you'd switch to */
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* Language menu */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-list {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 60;
}
.lang-list a { font-family: var(--font); display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem; }
.lang-list a:hover { background: var(--surface-2); }
.lang-list .i-check { width: 16px; height: 16px; visibility: hidden; color: var(--brand); }
.lang-list a[aria-current="true"] { font-weight: 600; }
.lang-list a[aria-current="true"] .i-check { visibility: visible; }

.nav-toggle { display: none; }
.nav-toggle .i-close { display: none; }
.nav-toggle[aria-expanded="true"] .i-menu { display: none; }
.nav-toggle[aria-expanded="true"] .i-close { display: block; }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .header-actions { margin-left: auto; }
  .nav {
    display: none; position: fixed; inset: var(--header-h) 0 auto 0; margin: 0;
    flex-direction: column; gap: 2px; padding: 8px 16px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
    max-height: calc(100dvh - var(--header-h)); overflow-y: auto;
  }
  .nav.open { display: flex; }
  .nav a { padding: 14px 12px; font-size: 1rem; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: var(--on-brand); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--brand-hover); color: var(--on-brand); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-link { background: none; border: 0; padding: 6px 0; min-height: 44px; display: inline-flex; align-items: center; color: var(--muted); font: inherit; font-size: .875rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { color: var(--text); }

/* ---------- Home ---------- */
.hero {
  padding: clamp(40px, 8vw, 88px) 0 clamp(28px, 5vw, 48px);
  background:
    radial-gradient(60% 80% at 15% 0%, color-mix(in srgb, var(--brand) 14%, transparent), transparent 70%),
    radial-gradient(50% 70% at 95% 10%, color-mix(in srgb, var(--c4) 10%, transparent), transparent 70%);
  border-bottom: 1px solid var(--border);
}
.eyebrow { margin: 0 0 12px; color: var(--brand); font-weight: 700; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.hero h1 { font-size: clamp(2rem, 5.5vw, 3.4rem); margin: 0 0 16px; max-width: 18ch; letter-spacing: -.03em; }
:lang(km) .hero h1, :lang(zh-Hans) .hero h1 { max-width: 24ch; letter-spacing: 0; }
.hero-lede { font-size: clamp(1.05rem, 2vw, 1.2rem); color: var(--text-2); max-width: 62ch; margin: 0; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }

.grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin: 32px 0; scroll-margin-top: calc(var(--header-h) + 16px); }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.card {
  display: flex; flex-direction: column; gap: 8px; padding: 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card:hover { color: var(--text); border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); box-shadow: var(--shadow); transform: translateY(-2px); }
.card h2 { font-size: 1.1rem; margin: 6px 0 0; }
.card p { margin: 0; color: var(--muted); font-size: .94rem; flex: 1; }
.card-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 12px; background: var(--brand-soft); color: var(--brand); }
.card-icon .i { width: 22px; height: 22px; }
.card-cta { color: var(--brand); font-weight: 600; font-size: .9rem; margin-top: 6px; }

.features { display: grid; grid-template-columns: 1fr; gap: 16px; margin: 8px 0 32px; }
@media (min-width: 760px) { .features { grid-template-columns: repeat(3, 1fr); } }
.feature { padding: 20px; border-radius: var(--radius); background: var(--surface-2); }
.feature .i { color: var(--brand); width: 24px; height: 24px; }
.feature h3 { margin: 10px 0 4px; font-size: 1rem; }
.feature p { margin: 0; color: var(--muted); font-size: .94rem; }

/* ---------- Calculator page layout ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 20px 0 0; font-size: .875rem; color: var(--muted); }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); text-decoration: underline; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; padding: 12px 0 56px; }
@media (min-width: 1024px) { .layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; } }
.page-head h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin: 8px 0 8px; }
.lede { color: var(--text-2); margin: 0 0 24px; font-size: 1.05rem; max-width: 65ch; }
.sidebar .sticky { position: sticky; top: calc(var(--header-h) + 20px); }
.sidebar h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }
.related { display: grid; gap: 8px; }
@media (min-width: 560px) and (max-width: 1023px) { .related { grid-template-columns: repeat(3, 1fr); } }
.related a { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600; font-size: .94rem; }
.related a:hover { border-color: var(--brand); color: var(--text); }
.related .i { color: var(--brand); }

/* ---------- Calculator widget ---------- */
.calc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.calc-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.calc-title { margin: 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.toolbar-picks { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: flex-end; }
.result-sub { margin: -4px 0 12px; color: var(--muted); font-size: .9rem; }
.currency-pick { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.currency-pick select { height: 36px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; }

.calc-body { display: grid; grid-template-columns: 1fr; }
@media (min-width: 720px) { .calc-body { grid-template-columns: 1.1fr 1fr; } }
.calc-inputs { padding: 20px; }
.calc-results { padding: 20px; background: var(--surface-2); border-top: 1px solid var(--border); }
@media (min-width: 720px) { .calc-inputs, .calc-results { padding: 24px; } .calc-results { border-top: 0; border-left: 1px solid var(--border); } }

.field { margin-bottom: 16px; min-width: 0; }
.field label { display: block; font-size: .875rem; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.hint { margin: 6px 0 0; font-size: .8rem; color: var(--muted); }
.input-wrap { display: flex; align-items: stretch; height: 46px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.input-wrap:hover { border-color: var(--muted); }
.input-wrap:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.input-wrap .affix { display: flex; align-items: center; padding: 0 12px; background: var(--surface-2); color: var(--muted); font-size: .9rem; font-weight: 600; white-space: nowrap; }
.input-wrap input, .input-wrap select {
  flex: 1; min-width: 0; width: 100%; border: 0; padding: 0 12px; background: transparent; color: var(--text);
  font: inherit; font-size: 1rem; /* 16px stops iOS zooming on focus */ font-variant-numeric: tabular-nums; outline: none; box-shadow: none;
}
.input-wrap select { cursor: pointer; }
.input-wrap input::-webkit-inner-spin-button { opacity: .4; }
.input-wrap input:invalid { color: var(--warn); }
.row-2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 420px) { .row-2 { grid-template-columns: 1fr 1fr; } }

.result-label { margin: 0; font-size: .875rem; color: var(--muted); font-weight: 600; }
.result-value { display: block; font-size: clamp(2rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin: 4px 0 12px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-3); margin-bottom: 12px; }
.bar span { display: block; height: 100%; transition: width .25s ease; }
.bar .b1, .sw-1 { background: var(--c1); }
.bar .b2, .sw-2 { background: var(--c2); }
.bar .b3, .sw-3 { background: var(--c3); }
.bar .b4, .sw-4 { background: var(--c4); }
.stats { list-style: none; margin: 0; padding: 0; }
.stats li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .94rem; }
.stats li:last-child { border-bottom: 0; }
.stats .k { color: var(--text-2); display: inline-flex; align-items: center; gap: 8px; }
.stats .v { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.notice { margin: 12px 0 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: .9rem; border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }

details.schedule { border-top: 1px solid var(--border); }
details.schedule > summary { cursor: pointer; padding: 16px 20px; font-weight: 600; list-style-position: inside; }
details.schedule > summary:hover { background: var(--surface-2); }
.table-wrap { overflow: auto; max-height: 480px; margin: 0 20px 20px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- Articles ---------- */
.article { margin-top: 40px; color: var(--text-2); font-size: 1.02rem; }
.article h2 { font-size: clamp(1.3rem, 3vw, 1.6rem); margin: 40px 0 12px; }
.article h3 { font-size: 1.12rem; margin: 28px 0 8px; }
.article p, .article ul { margin: 0 0 16px; }
.article li { margin-bottom: 6px; }
.article strong { color: var(--text); }
.article .formula { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 18px; font-family: var(--mono); font-size: .95rem; overflow-x: auto; color: var(--text); }
.article .table-wrap { margin: 16px 0 20px; max-height: none; }
.article table { background: var(--surface); }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; }
.faq summary { cursor: pointer; padding: 16px 18px; font-weight: 600; color: var(--text); }
.faq details[open] summary { border-bottom: 1px solid var(--border); }
.faq details p { margin: 0; padding: 14px 18px 16px; }
.fine-print { margin-top: 28px; font-size: .85rem; color: var(--muted); }

.prose { max-width: 760px; padding: 8px 0 64px; }
.prose > h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); margin: 32px 0 8px; }
.prose.center { text-align: center; margin: 0 auto; }
.prose.center .hero-cta { justify-content: center; }

/* ---------- Contact form ---------- */
.form { display: grid; gap: 4px; max-width: 560px; margin: 24px 0; }
.form input, .form textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 1rem;
}
.form input:focus, .form textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.form .btn { justify-self: start; margin-top: 8px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Ads ---------- */
.ad { margin: 28px 0; text-align: center; min-height: 120px; }
.ad-sidebar { min-height: 260px; margin-top: 0; }
.ad-label { display: block; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.ad-placeholder { display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.ad .adsbygoogle { display: block; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 48px 0 calc(32px + env(safe-area-inset-bottom)); font-size: .92rem; color: var(--muted); }
.footer-grid { display: grid; grid-template-columns: 1fr; gap: 32px; }
@media (min-width: 640px) { .footer-grid { grid-template-columns: 2fr 1fr 1fr; } }
.footer-brand p { margin: 12px 0 0; max-width: 36ch; }
.site-footer h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text); margin: 0 0 12px; }
.site-footer nav a { display: block; padding: 5px 0; color: var(--muted); text-decoration: none; }
.site-footer nav a:hover { color: var(--text); }
.disclaimer { margin: 36px 0 0; padding-top: 20px; border-top: 1px solid var(--border); font-size: .82rem; }

/* ---------- Motion + print ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .site-header, .site-footer, .sidebar, .ad, .toolbar-picks, .btn-link, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .calc { box-shadow: none; }
  details.schedule > .table-wrap { display: block; max-height: none; }
  .layout { display: block; }
}
