/* Halving Media — one stylesheet, no build step. */

/* ---------------------------------------------------------------- tokens */

:root {
  --bg: #0b0d10;
  --bg-elev: #12151a;
  --bg-sunk: #090b0e;
  --line: #1e242c;
  --line-soft: #171c22;
  --text: #e7ebf0;
  --text-dim: #96a0ae;
  --text-faint: #6b7684;
  --accent: #f7931a;          /* bitcoin orange, used sparingly */
  --accent-soft: #f7931a26;
  --link: #7fb2ff;
  --radius: 12px;
  --radius-sm: 8px;
  --wrap: 1180px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.28);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --bg-elev: #ffffff;
    --bg-sunk: #f6f7f9;
    --line: #e3e7ec;
    --line-soft: #eef1f4;
    --text: #12161c;
    --text-dim: #59636f;
    --text-faint: #7b8593;
    --link: #1a5fd0;
    --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px rgb(16 24 40 / 0.06);
  }
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --bg-sunk: #f6f7f9;
  --line: #e3e7ec;
  --line-soft: #eef1f4;
  --text: #12161c;
  --text-dim: #59636f;
  --text-faint: #7b8593;
  --link: #1a5fd0;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px rgb(16 24 40 / 0.06);
}

/* ----------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; margin: 0; }

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--text-dim); }
.dot { color: var(--text-faint); margin-inline: 0.45rem; }
.empty { color: var(--text-dim); padding: 2rem 0; }
.kicker {
  display: inline-block;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.5rem;
}

/* --------------------------------------------------------------- header */

.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 62px;
}

.brand { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(145deg, var(--accent), #ffb457);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1rem; letter-spacing: -0.02em; }
.brand-text small { font-size: 0.7rem; color: var(--text-faint); }

.site-nav { display: flex; gap: 1.15rem; margin-right: auto; }
.site-nav a {
  font-size: 0.9rem; color: var(--text-dim);
  padding: 0.25rem 0; border-bottom: 2px solid transparent;
  transition: color 0.15s ease;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current] { color: var(--text); border-bottom-color: var(--accent); }

.header-tools { display: flex; align-items: center; gap: 0.75rem; }

.search-mini input {
  width: 160px; padding: 0.4rem 0.7rem;
  background: var(--bg-sunk); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font: inherit; font-size: 0.85rem;
  transition: width 0.2s ease, border-color 0.15s ease;
}
.search-mini input:focus { width: 210px; border-color: var(--accent); outline: none; }

/* Language switcher: a <details> dropdown, so fifteen languages fit without
   a line of JavaScript. */
.lang-switch { position: relative; }
.lang-switch summary {
  display: flex; align-items: center; gap: 0.4rem; cursor: pointer;
  list-style: none; padding: 0.3rem 0.6rem; border-radius: 999px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  font-size: 0.78rem; color: var(--text-dim); white-space: nowrap;
}
.lang-switch summary::-webkit-details-marker { display: none; }
.lang-switch summary:hover { color: var(--text); border-color: var(--text-faint); }
.lang-switch .lang-code {
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent);
}
.lang-switch .chev { transition: transform 0.15s ease; flex-shrink: 0; }
.lang-switch[open] .chev { transform: rotate(180deg); }

.lang-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  min-width: 230px; max-height: 60vh; overflow-y: auto;
  padding: 0.35rem; border-radius: var(--radius);
  background: var(--bg-elev); border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.lang-menu a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.65rem; border-radius: var(--radius-sm);
  font-size: 0.88rem; color: var(--text-dim);
}
.lang-menu a:hover { background: var(--bg-sunk); color: var(--text); }
.lang-menu a[aria-current] { color: var(--text); font-weight: 650; }
.lang-menu a.unavailable .lang-name { opacity: 0.55; }
.lang-menu .lang-tag {
  margin-left: auto; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-faint);
}
.lang-menu a[aria-current] .lang-tag { margin-left: auto; }
.lang-menu .tick { color: var(--accent); flex-shrink: 0; }

/* Accessibility: a skip link that only appears on keyboard focus. */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  padding: 0.7rem 1.1rem; border-radius: 0 0 var(--radius-sm) 0;
  background: var(--accent); color: #17110a; font-weight: 600;
}
.skip-link:focus { left: 0; }

.theme-toggle {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-sunk); border: 1px solid var(--line);
  cursor: pointer; display: grid; place-items: center; padding: 0;
}
.theme-toggle span {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--text-dim);
  box-shadow: inset -4px -2px 0 0 var(--bg-sunk);
}

/* --------------------------------------------------------------- layout */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 3rem;
  align-items: start;
  padding: 2.25rem 0 4rem;
}
.column-main { min-width: 0; }

.section-title {
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-faint);
  padding-bottom: 0.6rem; margin: 2.5rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
}
.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); margin-bottom: 0.4rem; }

/* ----------------------------------------------------------------- hero */

.hero {
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-elev); box-shadow: var(--shadow);
}
.hero-media { aspect-ratio: 21 / 9; overflow: hidden; background: var(--bg-sunk); }
.hero-media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.hero-link:hover .hero-media img { transform: scale(1.03); }
.hero-body { padding: 1.5rem 1.6rem 1.7rem; }
.hero-body h1 {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3.6vw, 2.35rem);
  margin-bottom: 0.6rem;
}
.hero-link:hover h1 { color: var(--accent); }
.hero-body p { color: var(--text-dim); margin: 0 0 0.9rem; }
.hero-meta { font-size: 0.82rem; color: var(--text-faint); margin: 0; }

/* ---------------------------------------------------------------- cards */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}

.card {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-elev); overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.card-link { display: flex; flex-direction: column; flex: 1; }
.card-media { aspect-ratio: 16 / 9; overflow: hidden; background: var(--bg-sunk); }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 1rem 1.1rem 0.5rem; flex: 1; }
.card-title { font-size: 1.05rem; font-weight: 650; margin-bottom: 0.4rem; }
.card:hover .card-title { color: var(--accent); }
.card-summary { color: var(--text-dim); font-size: 0.88rem; margin: 0; }
.card-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.15rem;
  padding: 0.75rem 1.1rem 1rem;
  font-size: 0.76rem; color: var(--text-faint);
}
.card-tags { display: flex; gap: 0.3rem; margin-left: auto; }

/* ---------------------------------------------------------------- pills */

.pills { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 600;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  color: var(--text-dim);
}
.pill:hover { border-color: var(--accent); color: var(--accent); }
.pill-count { color: var(--text-faint); font-variant-numeric: tabular-nums; }

.button {
  display: inline-block; padding: 0.55rem 1.1rem; border-radius: 999px;
  background: var(--accent); color: #17110a; font-weight: 600; font-size: 0.9rem;
}

/* ------------------------------------------------------------ load more */

.load-more {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center; gap: 0.7rem;
  padding: 0.5rem 0;
}
.load-more button {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  padding: 0.6rem 1.6rem; border-radius: 999px; cursor: pointer;
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--line);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.load-more button:hover { border-color: var(--accent); color: var(--accent); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  opacity: 0; transition: opacity 0.15s ease;
}
.htmx-request .spinner, .htmx-request.spinner { opacity: 1; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- post */

.breadcrumb { margin-bottom: 1.1rem; font-size: 0.8rem; color: var(--text-faint); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; }
.breadcrumb li { display: flex; align-items: center; gap: 0.4rem; }
.breadcrumb li + li::before { content: "/"; color: var(--line); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb [aria-current] { color: var(--text-dim); }

.post-header { margin-bottom: 1.75rem; }
.post-header .pills { margin-bottom: 0.9rem; }
.post-header h1 {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 4.5vw, 2.9rem);
  margin-bottom: 0.75rem;
}
.lede { font-size: 1.12rem; color: var(--text-dim); margin: 0 0 1.1rem; }
.byline { font-size: 0.85rem; color: var(--text-faint); margin: 0; }
.byline .author { color: var(--text); font-weight: 600; margin-right: 0.6rem; }

.notice {
  padding: 0.7rem 1rem; margin-bottom: 1.5rem;
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--text-dim); font-size: 0.88rem;
}

.post-cover { margin: 0 0 2rem; }
.post-cover img { border-radius: var(--radius); width: 100%; }
.post-cover figcaption, .post-figure figcaption {
  font-size: 0.78rem; color: var(--text-faint); padding-top: 0.5rem;
}

.prose { font-size: 1.06rem; line-height: 1.75; max-width: 68ch; }
.prose > * + * { margin-top: 1.15rem; }
.prose h2 {
  font-family: var(--serif); font-size: 1.5rem;
  margin-top: 2.4rem; padding-top: 0.2rem;
}
.prose h3 { font-size: 1.18rem; margin-top: 1.9rem; }
.prose a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li + li { margin-top: 0.4rem; }
.prose blockquote {
  margin-inline: 0; padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 3px solid var(--line);
  color: var(--text-dim); font-family: var(--serif); font-size: 1.1rem;
}
.prose code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--bg-sunk); border: 1px solid var(--line-soft);
  padding: 0.1em 0.35em; border-radius: 5px;
}
.prose pre {
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 1rem; overflow-x: auto;
}
.prose pre code { background: none; border: 0; padding: 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.92rem; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); }
.prose th { color: var(--text-faint); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }

.post-figure { margin: 1.75rem 0; }
.post-figure img { border-radius: var(--radius-sm); }

.callout {
  border: 1px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius-sm); padding: 0.9rem 1.1rem;
  background: var(--bg-sunk); font-size: 0.95rem;
}
.callout-title { font-weight: 700; margin: 0 0 0.35rem; }
.callout-body { color: var(--text-dim); }
.callout-body > :first-child { margin-top: 0; }
.callout-note { border-left-color: var(--link); }
.callout-warn { border-left-color: var(--accent); }
.callout-risk { border-left-color: #e5484d; }

.key-facts {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; background: var(--bg-sunk);
}
.key-facts h2 { font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 0.75rem; font-family: var(--sans); }
.key-facts dl { margin: 0; display: grid; gap: 0.5rem; }
.key-facts dl > div { display: flex; justify-content: space-between; gap: 1rem;
  border-bottom: 1px dashed var(--line); padding-bottom: 0.5rem; }
.key-facts dl > div:last-child { border-bottom: 0; padding-bottom: 0; }
.key-facts dt { color: var(--text-dim); font-size: 0.9rem; }
.key-facts dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }

.related { margin-top: 3rem; }

/* -------------------------------------------------------------- sidebar */

.sidebar { position: sticky; top: 82px; display: grid; gap: 1.75rem; }
.side-block {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; background: var(--bg-elev);
}
.side-title {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 0.85rem;
}
.side-list { list-style: none; margin: 0; padding: 0; counter-reset: n; }
.side-list li { padding: 0.6rem 0; border-top: 1px solid var(--line-soft); }
.side-list li:first-child { border-top: 0; padding-top: 0; }
.side-list a { font-size: 0.9rem; font-weight: 550; display: block; }
.side-list a:hover { color: var(--accent); }
.side-list time { font-size: 0.74rem; color: var(--text-faint); }
.side-note p { font-size: 0.82rem; color: var(--text-dim); margin: 0; }

/* --------------------------------------------------------------- search */

.search-full { position: relative; display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.search-full input {
  flex: 1; padding: 0.75rem 1.1rem; font: inherit; font-size: 1rem;
  background: var(--bg-sunk); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
}
.search-full input:focus { border-color: var(--accent); outline: none; }

/* --------------------------------------------------------------- footer */

.site-footer { border-top: 1px solid var(--line); background: var(--bg-sunk); margin-top: auto; }
.footer-inner { padding: 2.25rem 0; display: grid; gap: 1rem; }
.footer-inner p { color: var(--text-dim); font-size: 0.88rem; margin: 0.3rem 0 0; max-width: 46ch; }
.footer-inner nav { display: flex; flex-wrap: wrap; gap: 1.1rem; font-size: 0.88rem; color: var(--text-dim); }
.footer-inner nav a:hover { color: var(--accent); }
.copyright { font-size: 0.78rem !important; color: var(--text-faint) !important; }

/* ------------------------------------------------------- progress + fx  */

.progress {
  position: fixed; inset: 0 auto auto 0; height: 2px; width: 100%;
  transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent), #ffcf8b);
  z-index: 100; opacity: 0; pointer-events: none;
}
.progress.active {
  opacity: 1;
  /* Creeps toward 90% and waits; the swap removes it before it lands. */
  animation: creep 8s cubic-bezier(0.1, 0.85, 0.2, 1) forwards;
}
@keyframes creep {
  0%   { transform: scaleX(0); }
  40%  { transform: scaleX(0.6); }
  100% { transform: scaleX(0.92); }
}

/* View transitions, courtesy of hx-swap="... transition:true". */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: fade-out 0.12s ease both; }
::view-transition-new(root) { animation: fade-in 0.18s ease both; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ----------------------------------------------------------- responsive */

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 2.5rem; }
  .sidebar { position: static; }
  .site-nav { display: none; }
}

@media (max-width: 620px) {
  .header-inner { gap: 0.75rem; }
  .brand-text small { display: none; }
  .lang-switch .lang-current { display: none; }
  .search-mini input { width: 110px; }
  .search-mini input:focus { width: 140px; }
  .grid { grid-template-columns: 1fr; }
  .hero-body { padding: 1.2rem; }
}
