:root {
  --bg: #eef3f8;
  --card: #ffffff;
  --ink: #16212e;
  --muted: #5f6f80;
  --blue: #1F6FB2;
  --blue-2: #3A85C4;
  --blue-3: #5A9BD3;
  --disc: #A9BDD4;
  --track: #dde6ef;
  --red: #c0392b;
  --red-bg: rgba(192, 57, 43, .08);
  --shadow: 0 6px 24px rgba(22, 33, 46, .07);
  --input-bg: #f7f9fc;
}
html[data-theme="dark"] {
  --bg: #0d141c;
  --card: #152030;
  --ink: #e8eef5;
  --muted: #9fb0c2;
  --blue: #5fa8e8;
  --blue-2: #7ab8ec;
  --blue-3: #9ccaf1;
  --disc: #3f5a78;
  --track: #24344a;
  --red: #ff7a6b;
  --red-bg: rgba(255, 122, 107, .12);
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --input-bg: #0f1823;
}
html { scroll-behavior: smooth; }
html, body { background: var(--bg); color: var(--ink); margin: 0; transition: background-color .25s, color .25s; }
body { font-family: Manrope, Inter, "Segoe UI", Arial, sans-serif; }
a { color: var(--blue); }
code { font-size: 12.5px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.sm-page { max-width: 1180px; margin: 0 auto; padding: 0 20px 48px; overflow-x: hidden; }
/* grid and flex children may shrink below their content width (plots, tables, code) */
.sm-grid > *, .sm-gauges > *, .sm-charts > *, .sm-gauge-text, .sm-row > *, .sm-field { min-width: 0; }
.sm-input { min-width: 0; }

/* Hero: logo, title, one line, dark-mode toggle */
.sm-hero { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 26px 0 14px; }
.sm-logo { width: 260px; height: auto; display: block; user-select: none; -webkit-user-drag: none; }
.sm-hero h1 { font-size: 34px; font-weight: 800; margin: 0; letter-spacing: -.3px; }
.sm-hero p { color: var(--muted); margin: 6px 0 0; font-size: 15px; max-width: 680px; line-height: 1.5; }

/* Cards */
.sm-card { background: var(--card); border-radius: 16px; padding: 20px 22px; box-shadow: var(--shadow); min-width: 0; overflow: hidden; }
.sm-card .js-plotly-plot, .sm-card .dash-graph { width: 100%; max-width: 100%; }
.sm-card h2 { margin: 0 0 12px; font-size: 18px; font-weight: 800; }
.sm-card h3 { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--blue); font-weight: 700; }

/* Gauges row (always on top) */
.sm-gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 10px; }
.sm-gauge { display: flex; align-items: center; gap: 22px; padding: 18px 24px; }
.sm-ring { width: 124px; height: 124px; flex-shrink: 0; border-radius: 50%; position: relative;
           background: conic-gradient(var(--blue) 0%, var(--track) 0); }
.sm-ring::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--card); }
.sm-gauge-text { min-width: 0; }
.sm-gauge-label { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 700; }
.sm-gauge-value { font-size: 46px; font-weight: 800; color: var(--blue); line-height: 1.1; margin: 4px 0;
                  font-variant-numeric: tabular-nums; }
.sm-gauge-sub { font-size: 13px; color: var(--muted); line-height: 1.4; }

/* Main grid: form left, charts right. Columns stretch so there is never a gap. */
.sm-grid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 20px; align-items: stretch; margin-top: 20px; }
.sm-form { height: 100%; box-sizing: border-box; }
.sm-charts { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.sm-left { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.sm-grow { flex: 1; display: flex; flex-direction: column; }
.sm-fill { flex: 1; min-height: 360px; }
.sm-fill .js-plotly-plot, .sm-fill .plot-container { height: 100%; }

/* Form */
.sm-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sm-field { margin-bottom: 12px; }
.sm-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; }
.sm-help { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.sm-input { width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1.5px solid transparent; border-radius: 10px;
            font: inherit; font-size: 15px; background: var(--input-bg); color: var(--ink); }
.sm-input:focus { outline: none; border-color: var(--blue); }
.sm-input.sm-bad { border-color: var(--red); background: var(--red-bg); }
.sm-radio label { margin-right: 14px; font-size: 14px; cursor: pointer; }
.sm-radio input { margin-right: 5px; accent-color: var(--blue); }
.sm-dd { font-size: 14px; }
html[data-theme="dark"] .sm-dd .Select-control,
html[data-theme="dark"] .sm-dd .Select-menu-outer { background: var(--input-bg); color: var(--ink); border-color: var(--track); }
html[data-theme="dark"] .sm-dd .Select-value-label { color: var(--ink) !important; }

/* Small tables in the form column */
.sm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sm-table th { text-align: left; font-weight: 700; color: var(--muted); font-size: 11.5px; text-transform: uppercase;
               letter-spacing: .5px; padding: 4px 6px 6px; border-bottom: 1px solid var(--track); }
.sm-table td { padding: 6px; border-bottom: 1px solid var(--track); }
.sm-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sm-table td:first-child { white-space: nowrap; }
.sm-table tr.sm-bad-row td { color: var(--red); font-weight: 700; background: var(--red-bg); }

.sm-sweep-head { display: grid; grid-template-columns: auto minmax(0, 300px); align-items: center; gap: 10px; margin-bottom: 4px; }
.sm-sweep-head .sm-label { margin: 0; }
.sm-sweep-head .sm-dd, .sm-sweep-head .Select { width: 100%; }

/* Buttons */
.sm-btn { background: transparent; color: var(--blue); border: 1.5px solid var(--blue); border-radius: 999px; padding: 8px 16px;
          font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; }
.sm-btn:hover { background: var(--blue); color: #fff; }
.sm-nav { display: flex; gap: 10px; margin: 6px 0 4px; position: sticky; top: 0; z-index: 20;
          padding: 10px 0; background: var(--bg); }
.sm-nav .sm-btn { flex: 1; text-align: center; white-space: nowrap; }
.sm-btn-nav { text-decoration: none; border-color: var(--track); color: var(--muted); background: var(--card); }
.sm-btn-nav:hover { border-color: var(--blue); }
[id^="sec-"] { scroll-margin-top: 72px; }

/* Cohort note, references, footer */
.sm-cohort { margin-top: 20px; }
.sm-cohort h3 { margin: 0 0 6px; font-size: 16px; color: var(--ink); text-transform: none; letter-spacing: 0; }
.sm-cohort p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; }
.sm-cohort pre { margin: 0; padding: 12px 14px; background: var(--bg); border-radius: 10px; overflow-x: auto; }
.sm-cohort pre code { background: none; padding: 0; font-size: 13px; }
.sm-disclaimer { margin: 30px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.sm-refs { margin-top: 20px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.sm-refs-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.sm-refs ol { margin: 0; padding-left: 20px; }
.sm-refs li { margin-bottom: 4px; }
.sm-foot-row { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.sm-dsd { height: 34px; width: auto; display: block; user-select: none; -webkit-user-drag: none; }
html[data-theme="dark"] .sm-dsd { filter: brightness(1.6); }
.sm-foot { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--track); font-size: 13px; color: var(--muted); line-height: 1.6; }

@media (max-width: 860px) {
  /* Inputs come before results on a phone: you fill the form, then the numbers
     update just below it. .sm-grid becomes transparent so its two children can
     be ordered against the page's other sections. */
  .sm-page { display: flex; flex-direction: column; padding: 0 12px 32px; }
  .sm-grid, .sm-left { display: contents; }
  .sm-hero { order: 1; }
  .sm-nav { order: 2; }
  .sm-form { order: 3; }
  .sm-gauges { order: 4; }
  .sm-ref-card { order: 5; }
  .sm-charts { order: 6; }
  .sm-cohort { order: 7; }
  .sm-disclaimer { order: 8; }
  .sm-refs { order: 9; }
  .sm-foot { order: 10; }

  .sm-hero { flex-direction: column-reverse; align-items: flex-start; gap: 8px; padding: 16px 0 8px; }
  .sm-hero h1 { font-size: 26px; }
  .sm-hero p { font-size: 14px; }
  .sm-logo { width: 180px; }

  /* one scrollable row of buttons instead of a tall wrapped block, with a
     fade on the right so it is obvious there is more to swipe to */
  .sm-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 8px;
            margin: 0 -12px; padding: 8px 12px; scrollbar-width: none;
            -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
            mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%); }
  .sm-nav::-webkit-scrollbar { display: none; }
  .sm-nav .sm-btn { flex: 0 0 auto; padding: 7px 12px; font-size: 12.5px; }

  /* compact gauges: a short row each, so both results fit in one glance */
  .sm-gauges { grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
  .sm-gauge { padding: 12px 14px; gap: 14px; align-items: center; }
  .sm-ring { width: 76px; height: 76px; flex: 0 0 76px; }
  .sm-ring::after { inset: 9px; }
  .sm-gauge-value { font-size: 30px; line-height: 1.1; }
  .sm-gauge-label { font-size: 11px; }
  .sm-gauge-sub { font-size: 11.5px; }

  .sm-charts { gap: 14px; }
  .sm-card { padding: 16px; border-radius: 14px; }
  .sm-form { height: auto; }
  .sm-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .sm-input { font-size: 16px; }   /* iOS zooms into inputs under 16px */
  #g-contrib { height: 260px !important; }
  .sm-fill { min-height: 300px !important; }
  .sm-sweep-head { grid-template-columns: auto minmax(0, 1fr); }
  .sm-table { font-size: 12.5px; width: 100%; }
  .sm-cohort pre { font-size: 12px; }
  .sm-foot-row { flex-wrap: wrap; }
  [id^="sec-"] { scroll-margin-top: 60px; }
}

@media (max-width: 420px) {
  .sm-hero h1 { font-size: 23px; }
  .sm-gauge { gap: 12px; padding: 12px; }
  .sm-ring { width: 66px; height: 66px; flex: 0 0 66px; }
  .sm-ring::after { inset: 8px; }
  .sm-gauge-value { font-size: 26px; }
}
