/* Dark theme of the web app for the python_sc101 post. The tokens follow
   the write-app template and the colors of the post figures. */
:root {
  --bg: #0f1729;
  --panel: #1f2b5e;
  --panel-2: #182447;
  --code-bg: #0b1222;
  --steel: #6a9bcc;
  --orange: #d97757;
  --teal: #00d4c8;
  --gold: #e8b04b;
  --grey: #54618a;
  --lavender: #a58fd8;
  --sage: #8fbf7f;
  --light: #c8d0e0;
  --text: #e8ecf2;
  --muted: #8b9dc3;
  --line: rgba(232, 236, 242, 0.12);
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--steel); text-decoration: none; }
a:hover { color: var(--teal); text-decoration: underline; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: var(--light);
}

header.app-header {
  background: linear-gradient(135deg, #0f1729 0%, #1f2b5e 100%);
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
}
header.app-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: 0.01em;
}
header.app-header .subtitle {
  color: var(--muted);
  font-size: 13px;
}
header.app-header .post-link {
  font-size: 12px;
  color: var(--steel);
  margin-left: 8px;
  white-space: nowrap;
}

nav.tab-strip {
  display: flex;
  gap: 4px;
  background: var(--panel-2);
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
nav.tab-strip button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
nav.tab-strip button:hover { color: var(--text); }
nav.tab-strip button.active {
  color: var(--text);
  border-bottom-color: var(--orange);
}

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }
.tab-pane:focus { outline: none; }
.tab-pane:focus-visible { outline: 2px solid var(--teal); outline-offset: 4px; }

h2 {
  font-size: 20px;
  margin: 0 0 14px;
  color: var(--text);
}
h3 {
  font-size: 16px;
  margin: 18px 0 8px;
  color: var(--steel);
}
h4 {
  font-size: 14px;
  margin: 0 0 8px;
  color: var(--text);
}
p { margin: 0 0 12px; }

.lede {
  font-size: 16px;
  color: var(--muted);
  max-width: 820px;
}
.lede strong, .note strong { color: var(--text); }

.section-head {
  margin: 30px 0 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 18px;
  color: var(--text);
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h3 { margin-top: 0; }

.grid {
  display: grid;
  gap: 18px;
}
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Charts */
.chart-area {
  position: relative; /* anchors the absolutely positioned tooltip */
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 8px;
  margin-bottom: 12px;
  min-width: 0;
}
.card .chart-area {
  background: rgba(15, 23, 41, 0.45);
}
.chart-area svg.chart { width: 100%; height: auto; display: block; }
.chart-area svg.chart text { font-family: inherit; }
.chart-area .chart-placeholder {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 4px;
}
/* A dark outline keeps chart labels legible where they cross a line. */
.chart-area svg text.halo {
  paint-order: stroke;
  stroke: #141e3a;
  stroke-width: 3px;
  stroke-linejoin: round;
}
.chart-area path.path-placebo.hl {
  stroke: var(--light);
  stroke-opacity: 1;
  stroke-width: 2.2px;
}
.caption {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 14px;
}
.load-error {
  padding: 16px 20px;
  color: var(--orange);
  font-size: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 8px 2px 2px;
  font-size: 12px;
  color: var(--light);
}
.legend .item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.legend svg { width: 26px; height: 12px; flex: none; }

/* Controls */
fieldset.seg {
  border: none;
  margin: 0 0 12px;
  padding: 0;
  min-width: 0;
}
fieldset.seg legend, .control-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0;
  margin-bottom: 6px;
}
.toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.toggle label {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  transition: border-color 0.15s, background 0.15s;
}
.toggle input { accent-color: var(--orange); margin: 0; }
.toggle label:has(input:checked) {
  border-color: var(--teal);
  background: rgba(0, 212, 200, 0.10);
  color: var(--text);
}
.toggle label:focus-within {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
.toggle .swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 28px;
  align-items: flex-start;
}

/* Stat tiles and readouts */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}
.card .stat { background: rgba(15, 23, 41, 0.45); }
.stat .stat-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.stat .stat-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stat .stat-value.teal { color: var(--teal); }
.stat .stat-value.orange { color: var(--orange); }
.stat .stat-value.gold { color: var(--gold); }
.stat .stat-value.steel { color: var(--steel); }
.stat .stat-value.lavender { color: var(--lavender); }
.stat .stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.tiles .stat .stat-value { font-size: 26px; }

.readout-line {
  font-size: 13px;
  color: var(--light);
  margin: 0 0 12px;
}
.readout-line .k { color: var(--muted); }

.v {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.nowrap { white-space: nowrap; }

.pedagogy {
  background: rgba(106, 155, 204, 0.08);
  border-left: 3px solid var(--steel);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
}
.pedagogy h4 {
  margin: 0 0 8px;
  color: var(--steel);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pedagogy ul { margin: 0; padding-left: 20px; }
.pedagogy li { margin-bottom: 6px; color: var(--text); font-size: 14px; }
.pedagogy li strong { color: var(--teal); }

/* Glossary */
details.gloss {
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
}
details.gloss[open] { background: rgba(0, 212, 200, 0.05); }
details.gloss summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}
details.gloss summary::-webkit-details-marker { display: none; }
details.gloss summary::after {
  content: "\25BE";
  color: var(--muted);
  transition: transform 0.2s;
}
details.gloss[open] summary::after { transform: rotate(180deg); }
details.gloss summary:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 4px;
}
details.gloss .gloss-body {
  margin-top: 8px;
  font-size: 13.5px;
  color: var(--muted);
}
details.gloss .gloss-body p { margin: 0; }
details.gloss .gloss-body strong { color: var(--text); }

/* Navigation cards on the first tab */
.cta-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.cta-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}
.cta-card:hover {
  border-color: var(--teal);
  transform: translateY(-2px);
}
.cta-card .cta-tag {
  font-size: 11px;
  color: var(--orange);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.cta-card h4 {
  margin: 6px 0 6px;
  font-size: 15px;
  color: var(--text);
}
.cta-card .cta-text {
  font-size: 13px;
  color: var(--muted);
}

/* Tooltip */
.tooltip {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--steel);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1000;
  box-shadow: var(--shadow);
  max-width: 260px;
  left: 0;
  top: 0;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-title { font-weight: 700; margin-bottom: 3px; }
.tooltip .tooltip-key { color: var(--muted); }
.tooltip .tooltip-val { color: var(--teal); font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  color: var(--text);
  font-weight: 600;
  text-align: left;
  background: rgba(15, 23, 41, 0.45);
}
table.data th.num, table.data td.num {
  text-align: right;
  white-space: nowrap;
}
table.data .pct { color: var(--muted); font-size: 11.5px; }
table.data .pct.big { color: var(--orange); font-weight: 600; }
table.data tr:hover td { background: rgba(106, 155, 204, 0.06); }
table.data tfoot td {
  color: var(--light);
  font-weight: 600;
  border-bottom: none;
}
table.data tr.ref td { color: var(--muted); font-style: italic; }
table.data td code { color: var(--light); font-size: 12px; }
table.balance th:first-child, table.balance tbody td:first-child { white-space: nowrap; }
table.tour td code { white-space: normal; overflow-wrap: anywhere; }
table.tour td:nth-child(1) { min-width: 140px; }
table.tour td:nth-child(2) { min-width: 200px; max-width: 280px; }
table.tour td:nth-child(3), table.tour td:nth-child(4) { min-width: 150px; }
table.tour td:nth-child(5) { min-width: 100px; }
.scroll-hint { display: none; margin: 8px 0 0; }

/* Predictor weights: chart and note side by side on wide screens */
.v-grid { align-items: center; }
.v-grid .chart-area { margin-bottom: 0; }
.v-grid .note { font-size: 14px; color: var(--light); margin: 0; }

/* Configuration dictionaries */
.code-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.code-grid > * { min-width: 0; }
@media (max-width: 900px) {
  .code-grid { grid-template-columns: 1fr; }
}
.code-card h4 {
  font-size: 13px;
  color: var(--steel);
  margin: 0 0 6px;
}
pre.code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0;
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  tab-size: 4;
}
pre.code code { color: inherit; font-size: inherit; }
@media (min-width: 901px) {
  /* The long baseline block fills the right column next to the short ones. */
  .code-grid { grid-auto-flow: row dense; }
  .code-grid .code-adh { grid-column: 2; grid-row: 1 / span 4; }
}

.note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

footer.app-footer {
  border-top: 1px solid var(--line);
  padding: 18px 28px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
}

/* Keyboard focus, phone gutters, and reduced motion */
nav.tab-strip button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}
.cta-card:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  header.app-header { padding: 16px; }
  header.app-header h1 { font-size: 19px; }
  nav.tab-strip {
    padding: 0 8px;
    flex-wrap: wrap;
    overflow-x: visible;
  }
  nav.tab-strip button {
    flex: 1 1 45%;
    white-space: normal;
    text-align: left;
    padding: 10px 8px;
    font-size: 13px;
  }
  main { padding: 16px; }
  .card { padding: 14px 12px; }
  .chart-area { padding: 10px 8px 6px; }
  .pedagogy { padding: 12px 14px; }
  .lede { font-size: 15px; }
  footer.app-footer { padding: 16px; }
  table.data th, table.data td { padding: 6px 7px; }
  table.balance .pct { display: block; }
  .scroll-hint { display: block; }
  .tiles .stat .stat-value { font-size: 22px; }
  .tiles .stat:first-child, .stat.wide { grid-column: 1 / -1; }
  pre.code { font-size: 11.5px; padding: 10px 11px; }
}

/* The comparison table becomes one card per estimator on narrow screens. */
@media (max-width: 700px) {
  table.tour, table.tour tbody, table.tour tr, table.tour td {
    display: block;
    width: 100%;
  }
  table.tour thead { display: none; }
  table.tour tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 6px 2px;
  }
  table.tour td,
  table.tour td:nth-child(n) {
    border: none;
    padding: 4px 10px;
    min-width: 0;
    max-width: none;
    text-align: left;
  }
  table.tour td::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    font-style: normal;
    color: var(--muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }
  table.tour td:first-child { font-weight: 700; font-size: 14px; }
  table.tour td:first-child::before { display: none; }
}

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