/* Article reading styles layered over the terminal theme. Monospace stays for chrome
   (header, titles, meta); long-form prose gets a proportional CJK-friendly stack. */

:root {
  --accent: #FFA86A;
  --ink: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.55);
  --faint: rgba(255, 255, 255, 0.12);
  --prose: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
           "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

/* ---------- prose ---------- */

.post-content {
  font-family: var(--prose);
  font-size: 1.0625rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
  color: var(--ink);
  font-feature-settings: normal;
  text-align: justify;
  overflow-wrap: break-word;
}

.post-content p {
  margin: 0 0 1.35em;
}

.post-content h2,
.post-content h3 {
  font-family: 'Fira Code', Monaco, Consolas, monospace;
  text-align: left;
}

.post-content a {
  text-decoration-color: rgba(255, 168, 106, 0.5);
  text-underline-offset: 0.2em;
}

/* Key lines: bold with a faint highlighter stroke. */
.post-content strong {
  font-weight: 700;
  color: #fff;
  background: linear-gradient(transparent 64%, rgba(255, 168, 106, 0.22) 0);
}

.post-content blockquote {
  border: none;
  border-left: 2px solid var(--accent);
  margin: 2em 0;
  padding: 0.2em 0 0.2em 1.2em;
  color: var(--muted);
  text-align: left;
}

.post-content blockquote p:first-of-type::before {
  content: none;
}

.lede {
  font-size: 0.95em;
  color: var(--muted);
  text-align: left;
  margin: -0.5em 0 2em !important;
  padding-bottom: 1.5em;
  border-bottom: 1px solid var(--faint);
}

.sep {
  text-align: center;
  color: var(--accent);
  letter-spacing: 0.6em;
  margin: 3em 0;
  opacity: 0.8;
  user-select: none;
}

/* ---------- citations & references ---------- */

sup.cite {
  font-size: 0.68em;
  line-height: 0;
  margin-left: 0.1em;
}

sup.cite a {
  color: var(--accent);
  text-decoration: none;
  font-family: 'Fira Code', monospace;
}

sup.cite a:hover {
  text-decoration: underline;
}

.bib {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
  text-align: left;
  padding-left: 3em;
  text-indent: -3em;
  margin: 0 0 0.7em !important;
  overflow-wrap: anywhere;
  scroll-margin-top: 30vh;
}

.bib__n {
  display: inline-block;
  min-width: 3em;
  text-indent: 0;
  font-family: 'Fira Code', monospace;
  color: var(--ink);
}

.bib:target {
  color: var(--ink);
  animation: bib-flash 2s ease-out;
}

@keyframes bib-flash {
  from { background: rgba(255, 168, 106, 0.18); }
  to   { background: transparent; }
}

/* ---------- figures ---------- */

/* --ar (width / height) comes from the shortcode; tall images are capped to the
   viewport height, --max narrows portrait figures. */
.post-content figure.fig {
  display: block;
  margin: 2.5em auto;
  max-width: min(var(--max, 100%), calc(82vh * var(--ar, 10)));
  max-width: min(var(--max, 100%), calc(82svh * var(--ar, 10)));
}

.post-content figure.fig img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  cursor: zoom-in;
  transition: opacity 0.2s ease;
}

.post-content figure.fig img:hover {
  opacity: 0.92;
}

.post-content figure.fig img:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.fig-caption {
  background: none !important;
  color: var(--muted) !important;
  font-family: var(--prose);
  font-size: 0.85rem !important;
  line-height: 1.7;
  text-align: left;
  padding: 0.7em 0 0 !important;
  margin: 0 !important;
}

.fig-num {
  color: var(--accent);
  font-family: 'Fira Code', monospace;
  margin-right: 0.6em;
  white-space: nowrap;
}

/* Wide landscape figures break out of the text column on large screens, centred. */
@media (min-width: 1000px) {
  .post-content figure.fig:not(.fig--narrow) {
    --bw: min(calc(100% + 96px), calc(82vh * var(--ar, 10)));
    max-width: none;
    width: var(--bw);
    margin-left: calc((100% - var(--bw)) / 2);
    margin-right: 0;
  }
}

/* ---------- charts: shared ---------- */

/* Mark colours validated (dataviz validate_palette, dark mode) against the page surface #222129.
   Text never wears these; a swatch or the mark itself carries identity. */
.dchart,
.egy {
  --c-household: rgba(255, 255, 255, 0.28);
  --c-entry: #1f9d7f;
  --c-507: #d9732c;
  --c-ferrari: #5a8fe0;
  --c-ev: #5a8fe0;
  --grid: rgba(255, 255, 255, 0.07);
  --tile: #27262f;
  display: block;
  position: relative;
  margin: 2.5em 0;
  font-family: var(--prose);
  text-align: left;
}

.chart-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.chart-sub {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--muted);
  margin-top: 0.3em;
}

.chart-src {
  margin: 0.4em 0 0 !important;
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--muted);
}

/* ---------- displacement chart ---------- */

.dchart__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1em;
}

.dchart__tabs {
  flex: none;
  display: inline-flex;
  border: 1px solid var(--faint);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.dchart__tabs[hidden] {
  display: none;
}

.dchart__tab {
  font: inherit;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 0.3em 0.95em;
  margin: 0;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}

.dchart__tab:hover {
  background: transparent;
  color: var(--ink);
}

@media (hover: hover) {
  .dchart__tab:not([aria-selected="true"]):hover {
    background: rgba(255, 255, 255, 0.08);
  }
}

.dchart__tab[aria-selected="true"],
.dchart__tab[aria-selected="true"]:hover {
  background: var(--accent);
  color: #1d1e28;
}

.dchart__tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dchart__panels {
  display: grid;
}

.dchart__panel + .dchart__panel {
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px solid var(--faint);
}

/* With JS the first panel is the live view; the rest are its data. */
.dchart.is-tabbed .dchart__panel + .dchart__panel {
  display: none;
}

.dchart__year {
  font-family: 'Fira Code', monospace;
  font-size: 1.1rem;
  color: var(--ink);
  margin-top: 0.6em;
}

.dchart.is-tabbed .dchart__year {
  display: none;
}

.dchart__hero {
  display: flex;
  align-items: center;
  gap: 0.4em 1.2em;
  flex-wrap: wrap;
  margin: 1.3em 0 0.4em;
}

.dchart__x {
  font-size: clamp(3.2rem, 10vw, 4.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
}

.dchart__x span {
  font-size: 0.55em;
  font-weight: 400;
  color: var(--muted);
  margin-right: 0.08em;
}

.dchart__lead {
  flex: 1 1 14em;
  margin: 0 !important;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted);
  text-align: left;
}

.dchart__engines {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1em;
  padding: 1.1em 0 1.2em;
  border-bottom: 1px solid var(--faint);
}

.dchart__engine {
  --cell: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6em;
}

.dchart__engine--entry { --c: var(--c-entry); }
.dchart__engine--507 { --c: var(--c-507); }
.dchart__engine--ferrari { --c: var(--c-ferrari); }

/* Circle area is proportional to single-cylinder displacement; rows are cylinder banks. */
.dchart__pistons {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: 4px;
}

.dchart__pistons i {
  display: block;
  place-self: center;
  width: calc(var(--cell) * var(--d));
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.2);
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.dchart__elabel {
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
}

.dchart__elabel > span {
  display: block;
  white-space: nowrap;
}

.dchart__elabel b {
  display: block;
  font-size: 0.85rem;
  color: var(--ink);
}

.dchart__plot {
  position: relative;
  padding-top: 1.9em;
  margin-top: 0.4em;
}

/* Solid hairline gridlines at every litre (scale: 6.5 L across). */
.dchart__plot::before {
  content: "";
  position: absolute;
  top: 1.5em;
  bottom: 0;
  left: 0;
  right: 0;
  background: repeating-linear-gradient(to right, var(--grid) 0 1px, transparent 1px 15.3846%);
  pointer-events: none;
}

.dchart__axis {
  position: absolute;
  top: 0.3em;
  left: 0;
  right: 0;
  height: 1.2em;
  font-family: 'Fira Code', monospace;
  font-size: 0.66rem;
  color: var(--muted);
}

.dchart__axis span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.dchart__axis span:first-child {
  transform: none;
}

/* The 6 L tick would collide with the 507 label. */
.dchart__axis span:last-child {
  display: none;
}

.dchart__ref507 {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--marker);
  border-left: 1px solid rgba(217, 115, 44, 0.8);
  pointer-events: none;
  z-index: 2;
}

.dchart__ref507 span {
  position: absolute;
  top: 0.15em;
  right: 0;
  transform: translateX(50%);
  padding: 0 0.4em;
  border-radius: 3px;
  background: var(--c-507);
  color: #1d1e28;
  font-family: 'Fira Code', monospace;
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.5;
}

.dchart__rows {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.dchart__rows--ref {
  margin-top: 0.7em;
  padding-top: 0.7em;
  border-top: 1px solid var(--faint);
}

.dchart__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: 0.7em;
  padding: 0.3em 0 0.5em;
  margin: 0;
  border-radius: 4px;
  cursor: default;
  outline: none;
}

.dchart__row::before {
  content: none !important;
}

.dchart__rows--ref .dchart__row {
  grid-template-columns: 1fr auto;
}

.dchart__row:hover .dchart__label {
  color: #fff;
}

.dchart__row:focus-visible {
  box-shadow: 0 0 0 1px var(--accent);
}

.dchart__rank {
  font-family: 'Fira Code', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 1.2em;
}

.dchart__label {
  font-size: 0.92rem;
  color: var(--ink);
  min-width: 0;
}

.dchart__label small {
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: 0.6em;
  white-space: nowrap;
}

.dchart__sw {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 0.5em;
  vertical-align: 0.05em;
  background: var(--c);
}

/* Values sit above the 507 guide line, masked by the page surface. */
.dchart__value {
  position: relative;
  z-index: 3;
  padding-left: 0.45em;
  background: #222129;
  font-family: 'Fira Code', monospace;
  font-size: 0.88rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dchart__row { --c: var(--c-household); }
.dchart__row--entry { --c: var(--c-entry); }
.dchart__row--507 { --c: var(--c-507); }
.dchart__row--ferrari { --c: var(--c-ferrari); }

.dchart__row--507 .dchart__label,
.dchart__row--507 .dchart__value {
  font-weight: 700;
}

.dchart__bar {
  grid-column: 1 / -1;
  display: block;
  height: 10px;
  margin-top: 0.35em;
  border-radius: 0 4px 4px 0;
  background: var(--c);
  width: var(--w);
  transform-origin: left center;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition-delay: 0s, calc(var(--i, 0) * 45ms);
}

.dchart.is-tabbed:not(.is-seen) .dchart__bar {
  transform: scaleX(0);
}

.dchart__note {
  margin: 1.2em 0 0.3em !important;
  font-size: 0.95rem;
  color: var(--ink);
}

.dchart__tip {
  position: absolute;
  z-index: 5;
  max-width: min(320px, 90%);
  padding: 0.45em 0.75em;
  border-radius: 6px;
  background: #34333d;
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* ---------- energy comparison ---------- */

.egy {
  padding: 1.4em 1.4em 1.2em;
  border: 1px solid var(--faint);
  border-radius: 14px;
  background:
    radial-gradient(120% 70% at 0% 0%, rgba(217, 115, 44, 0.12), transparent 60%),
    rgba(255, 255, 255, 0.015);
  overflow: hidden;
}

.egy__kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 1.2em 0 1.4em;
  border-radius: 10px;
  overflow: hidden;
  background: var(--faint);
}

.egy__kpis div {
  padding: 0.65em 0.8em;
  background: var(--tile);
}

.egy__kpis dt {
  font-size: 0.7rem;
  color: var(--muted);
}

.egy__kpis dd {
  margin: 0.15em 0 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.egy__kpis dd small {
  font-size: 0.62em;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.2em;
}

.egy__hero {
  display: flex;
  align-items: flex-end;
  gap: 0.6em 1.6em;
  flex-wrap: wrap;
}

.egy__big {
  white-space: nowrap;
}

.egy__big b {
  font-size: clamp(3.6rem, 12vw, 5.4rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-shadow: 0 0 36px rgba(217, 115, 44, 0.45);
}

.egy__big span {
  font-size: 0.95rem;
  color: var(--muted);
  margin-left: 0.35em;
}

.egy__vs {
  padding-bottom: 0.4em;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink);
}

.egy__vs b {
  font-size: 1.7rem;
  font-weight: 800;
}

.egy__vs small {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.egy__waffles {
  margin: 1.4em 0 0.4em;
}

.egy__wf + .egy__wf {
  margin-top: 1em;
}

.egy__wl {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 0.5em;
  font-size: 0.85rem;
  color: var(--ink);
}

.egy__wl b {
  margin-left: auto;
  font-family: 'Fira Code', monospace;
  font-weight: 600;
}

.egy__wf--c63 { --c: var(--c-507); --glow: rgba(217, 115, 44, 0.5); }
.egy__wf--ev { --c: var(--c-ev); --glow: rgba(90, 143, 224, 0.5); }

.egy__sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--c);
}

/* Each cell is 1 kWh; cells light up in sequence when the figure scrolls into view. */
.egy__grid {
  display: grid;
  grid-template-columns: repeat(25, 1fr);
  gap: 2px;
}

.egy__grid i {
  display: block;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 8px var(--glow);
  transition: background 0.2s ease, box-shadow 0.4s ease;
  transition-delay: calc(var(--n) * 5ms);
}

.egy.is-armed:not(.is-seen) .egy__grid i {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

.egy__unit {
  margin-top: 0.5em;
  text-align: right;
  font-size: 0.7rem;
  color: var(--muted);
}

.egy__trip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1em;
  margin: 1.2em 0 0;
  padding-top: 1.1em;
  border-top: 1px solid var(--faint);
}

.egy__trip dt {
  font-size: 0.72rem;
  color: var(--muted);
}

.egy__trip dd {
  margin: 0.2em 0 0;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

.egy__trip dd small {
  font-size: 0.55em;
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.2em;
}

.egy__trip p {
  margin: 0.2em 0 0 !important;
  font-size: 0.72rem;
  color: var(--muted);
}

.egy__cost {
  margin-top: 1.3em;
  padding-top: 1.1em;
  border-top: 1px solid var(--faint);
}

.egy__cost[hidden] {
  display: none;
}

.egy__sliders {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8em 1.6em;
}

.egy__sliders label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.egy__sliders output {
  float: right;
  font-family: 'Fira Code', monospace;
  color: var(--ink);
}

.egy__sliders input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 26px;
  margin: 0.3em 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.egy__sliders input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p, 50%), rgba(255, 255, 255, 0.14) var(--p, 50%));
}

.egy__sliders input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
}

.egy__sliders input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.egy__sliders input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 168, 106, 0.18), 0 0 14px rgba(255, 168, 106, 0.5);
}

.egy__sliders input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 168, 106, 0.18), 0 0 14px rgba(255, 168, 106, 0.5);
}

.egy__sliders input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.egy__costout {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.3em 0.8em;
  margin-top: 0.9em;
  font-size: 0.9rem;
  color: var(--muted);
}

.egy__costout b {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
}

.egy__costout em {
  font-style: normal;
  font-size: 0.8rem;
}

.egy__tick {
  margin-top: 1.3em;
  padding: 0.85em 1em;
  border-radius: 10px;
  border: 1px solid rgba(217, 115, 44, 0.3);
  background: rgba(217, 115, 44, 0.08);
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--ink);
}

.egy__tick[hidden] {
  display: none;
}

.egy__tick b {
  font-family: 'Fira Code', monospace;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.egy .chart-src {
  margin-top: 1em !important;
}

@media (max-width: 684px) {
  .post-content {
    font-size: 1rem;
    line-height: 1.85;
  }
  .dchart__head {
    flex-direction: column;
  }
  .dchart__engine {
    --cell: 17px;
  }
  .egy {
    padding: 1.1em 1em 1em;
  }
  .egy__kpis {
    grid-template-columns: repeat(2, 1fr);
  }
  .egy__grid {
    grid-template-columns: repeat(20, 1fr);
  }
  .egy__trip {
    grid-template-columns: repeat(2, 1fr);
  }
  .egy__sliders {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dchart__bar,
  .dchart__pistons i,
  .egy__grid i,
  .post-content figure.fig img {
    transition: none !important;
  }
}
