/* ── Theme: Light (default) ────────────────────────────── */

:root {
  color-scheme: light;
  --bg: #eef1ef;
  --surface: #fbfbf8;
  --soft: #f3f6ff;
  --warm: #fff6e8;
  --ink: #17212b;
  --muted: #65717d;
  --line: #d8dfdc;
  --blue: #246bfe;
  --blue-dark: #174bb5;
  --orange: #f28522;
  --green: #2c8f61;
  --shadow: 0 20px 56px rgba(23, 33, 43, 0.12);
  --bg-stripe: repeating-linear-gradient(45deg, #dce2df 0 2px, transparent 2px 18px);
  --warm-border: #ffd4a2;
  --warm-text: #9d4b00;
  --topbar-bg: rgba(238, 241, 239, 0.9);
  --topbar-border: rgba(216, 223, 220, 0.8);
  --mobile-bg: rgba(255, 246, 232, 0.96);
  --mobile-border: #ffd4a2;
  --disclaimer-bg: #f5f6f3;
  --tab-bg: white;
  --input-bg: #ffffff;
}

/* ── Theme: Dark ───────────────────────────────────────── */

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141920;
  --surface: #1e252e;
  --soft: #1a2540;
  --warm: #2a2014;
  --ink: #e2e8ee;
  --muted: #8694a1;
  --line: #2c333d;
  --blue: #4a8aff;
  --blue-dark: #7aa7ff;
  --orange: #ff9b42;
  --green: #4ade80;
  --shadow: 0 20px 56px rgba(0, 0, 0, 0.35);
  --bg-stripe: repeating-linear-gradient(45deg, #1c2128 0 2px, transparent 2px 18px);
  --warm-border: #553a18;
  --warm-text: #e8a554;
  --topbar-bg: rgba(20, 25, 32, 0.9);
  --topbar-border: rgba(44, 51, 61, 0.8);
  --mobile-bg: rgba(42, 32, 20, 0.96);
  --mobile-border: #553a18;
  --disclaimer-bg: #181e26;
  --tab-bg: var(--surface);
  --input-bg: #1a2028;
}

/* ── Reset ─────────────────────────────────────────────── */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 96%, transparent)),
    var(--bg-stripe);
  color: var(--ink);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ── Layout ────────────────────────────────────────────── */

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 88px;
}

/* ── Topbar ────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px 0;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 9px;
  background: var(--blue);
  color: white;
  font-weight: 900;
}

.brand strong,
.brand small { display: block; line-height: 1.08; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 13px; font-weight: 700; }

.topbar nav { display: flex; gap: 8px; }
.topbar nav a {
  min-height: 38px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}
.topbar nav a:hover { background: var(--surface); color: var(--ink); }

.topbar-actions { display: flex; gap: 8px; }

.icon-button,
.primary-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 900;
}

.icon-button {
  display: grid;
  width: 42px;
  place-items: center;
}
.icon-button:hover { background: var(--soft); }

.primary-button,
.ghost-button { padding: 0 16px; }
.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

/* ── Workspace grid ────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 18px;
  align-items: start;
  padding-top: 26px;
}

.intro {
  grid-column: 1 / -1;
  display: block;
  max-width: 760px;
  padding: 12px 0 6px;
}

.eyebrow {
  margin: 0;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

.intro h1 {
  margin-bottom: 0;
  max-width: 720px;
  font-size: 48px;
  line-height: 1.02;
}

.intro p:last-child {
  max-width: 720px;
  margin: 18px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.55;
}

/* ── Panels ────────────────────────────────────────────── */

.calculator-panel,
.result-panel,
.report-section,
.formula-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-panel, .result-panel { padding: 18px; }

/* ── Tabs ──────────────────────────────────────────────── */

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tabs button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
  color: var(--ink);
  font-weight: 900;
}

.tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

/* ── Project note ──────────────────────────────────────── */

.project-note {
  min-height: 44px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

/* ── Stair mode toggle ─────────────────────────────────── */

.stair-mode-group {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.stair-mode-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  margin-bottom: 10px;
}

.stair-mode-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.stair-mode-btn {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  padding: 8px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.stair-mode-btn.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.stair-diagram {
  border-radius: 8px;
  background: var(--tab-bg);
  border: 1px solid var(--line);
  overflow: hidden;
}

.stair-diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Dynamic fields ────────────────────────────────────── */

.dynamic-fields,
.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.control-grid { margin-top: 12px; }

label {
  display: grid;
  gap: 8px;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(36, 107, 254, 0.12);
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus {
  box-shadow: 0 0 0 4px rgba(74, 138, 255, 0.2);
}

.input-with-unit {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.input-with-unit b { color: var(--ink); }

.unit-select {
  min-height: 36px !important;
  padding: 0 6px !important;
  font-size: 13px !important;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
}

/* ── Result panel ──────────────────────────────────────── */

.result-panel {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 16px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  background: var(--warm);
  color: var(--warm-text);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 900;
}

.primary-result {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--warm-border);
  border-radius: 10px;
  background: var(--warm);
}
.primary-result span { color: var(--warm-text); font-size: 13px; font-weight: 900; text-transform: uppercase; }
.primary-result strong { color: var(--blue-dark); font-size: 54px; line-height: 1; overflow-wrap: anywhere; }
.primary-result p { margin: 0; color: var(--muted); font-weight: 800; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.result-grid div {
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
}
.result-grid span, .report-disclaimer { color: var(--muted); font-size: 12px; font-weight: 800; }
.result-grid strong { display: block; margin-top: 8px; overflow-wrap: anywhere; font-size: 20px; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

/* ── Report section ────────────────────────────────────── */

.report-section, .formula-section { margin-top: 22px; padding: 20px; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.section-heading h2 { margin: 4px 0 0; font-size: 28px; }

.report-card { display: grid; gap: 14px; }
.report-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.summary-card {
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
}
.summary-card span { color: var(--muted); font-size: 12px; font-weight: 900; }
.summary-card strong { display: block; margin-top: 8px; font-size: 22px; }

.report-disclaimer { padding: 12px; border-radius: 8px; background: var(--disclaimer-bg); line-height: 1.5; }

/* ── Formula section ───────────────────────────────────── */

.formula-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.formula-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tab-bg);
}
.formula-list b {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: var(--soft);
  color: var(--blue);
}
.formula-list span { color: var(--muted); font-size: 12px; font-weight: 900; }
.formula-list strong { font-size: 13px; overflow-wrap: anywhere; }

/* ── Search-friendly guidance and tool cluster ─────────── */

.seo-content {
  max-width: 1120px;
  margin: 24px auto 0;
  padding: 32px;
  border-top: 1px solid var(--line);
}

.seo-content h2 { margin-bottom: 12px; font-size: 28px; }
.seo-content h3 { margin-top: 28px; }
.seo-content p, .seo-content li { color: var(--muted); line-height: 1.75; }
.seo-content details { border-bottom: 1px solid var(--line); padding: 16px 0; }
.seo-content summary { cursor: pointer; font-weight: 700; }

.guide-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 28px;
  padding-left: 22px;
}

.content-note {
  padding: 16px;
  border-left: 3px solid var(--blue);
  background: var(--surface);
}

.tool-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tool-link-grid a {
  display: grid;
  gap: 5px;
  padding: 16px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.tool-link-grid a:hover { border-color: var(--blue); }
.tool-link-grid span { color: var(--muted); font-size: 14px; }

.site-footer {
  max-width: 1120px;
  margin: 36px auto 80px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.8fr 1fr;
  gap: 40px;
}

.site-footer p { margin: 12px 0 0; }
.site-footer a { color: var(--ink); font-weight: 700; }

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.footer-brand > span:last-child,
.footer-brand strong,
.footer-brand small {
  display: block;
}

.footer-brand strong { font-size: 16px; }
.footer-brand small { margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }

.footer-nav {
  display: grid;
  align-content: start;
  gap: 7px;
}

.footer-nav > strong,
.footer-method > strong {
  margin-bottom: 5px;
  color: var(--ink);
  font-size: 13px;
  text-transform: uppercase;
}

.footer-nav a { width: fit-content; color: var(--muted); font-weight: 600; }
.footer-nav a:hover { color: var(--blue); }
.footer-method b { color: var(--ink); }

.footer-bottom {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 28px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.footer-bottom span:last-child { text-align: right; }

/* ── Mobile floating result ────────────────────────────── */

.mobile-result { display: none; }

/* ── Toast ─────────────────────────────────────────────── */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: calc(100vw - 36px);
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Print ─────────────────────────────────────────────── */

@media print {
  .topbar, .calculator-panel, .actions, .mobile-result,
  .formula-section, .toast, .stair-mode-group { display: none; }

  body { background: white; }
  .app-shell { width: 100%; }
  .workspace, .intro, .report-section { display: block; box-shadow: none; }
}

/* ── Responsive: Tablet ────────────────────────────────── */

@media (max-width: 960px) {
  .app-shell { width: min(100% - 22px, 760px); }
  .topbar nav { display: none; }
  .brand { min-width: 0; }

  .workspace, .intro { grid-template-columns: 1fr; }
  .intro h1 { font-size: 34px; }
  .result-panel { position: static; }

  .dynamic-fields, .control-grid, .result-grid, .report-summary {
    grid-template-columns: 1fr;
  }

  .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .mobile-result {
    position: fixed;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 70px;
    padding: 10px 12px;
    border: 1px solid var(--mobile-border);
    border-radius: 10px;
    background: var(--mobile-bg);
    box-shadow: 0 14px 44px rgba(23, 33, 43, 0.18);
    backdrop-filter: blur(14px);
  }
  .mobile-result small, .mobile-result strong { display: block; }
  .mobile-result small { color: var(--warm-text); font-size: 12px; font-weight: 900; }
  .mobile-result strong { max-width: 56vw; overflow-wrap: anywhere; color: var(--blue-dark); font-size: 24px; }
  .seo-content { padding: 24px 20px; }
  .guide-steps, .tool-link-grid { grid-template-columns: 1fr; }
  .site-footer { padding: 24px 20px; }
  .footer-grid { grid-template-columns: 1fr; gap: 28px; }
  .footer-bottom { grid-template-columns: 1fr; gap: 8px; }
  .footer-bottom span:last-child { text-align: left; }
}

/* ── Responsive: Mobile ────────────────────────────────── */

@media (max-width: 520px) {
  .primary-result strong { font-size: 40px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .stair-mode-buttons { flex-direction: column; }
}
