/* Shared styles for wordcloud-wasm example articles.
   Paper, ink, and colored type — a word cloud, not a dashboard. */
@import url("https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,560;0,9..144,700;1,9..144,560&family=IBM+Plex+Mono:ital,wght@0,400;0,500;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;1,8..60,400&display=swap");

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

:root {
  color-scheme: light;
  --bg:     #f3ecdf;
  --bg2:    #fffdf8;
  --bg3:    #efe4d2;
  --border: #d4c4ae;
  --text:   #241c16;
  --muted:  #5e5348;
  --blue:   #1d4e89;
  --blue2:  #1d4e89;
  --green:  #1e7a45;
  --purple: #7a3e62;
  --orange: #b45309;
  --red:    #c0392b;
  --cyan:   #0f6e68;
  --ink:    #241c16;
  --display: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --serif:   "Source Serif 4", "Iowan Old Style", Palatino, Georgia, serif;
  --mono:    "IBM Plex Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

::selection { background: #f4c7b8; color: var(--ink); }

html {
  scroll-padding-top: 72px;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='760' height='520'><g font-family='Georgia, serif' font-weight='700'><text x='18' y='78' font-size='62' fill='%23c0392b' fill-opacity='.07' transform='rotate(-8 18 78)'>cloud</text><text x='290' y='92' font-size='36' fill='%230f6e68' fill-opacity='.07'>wasm</text><text x='470' y='64' font-size='24' fill='%231d4e89' fill-opacity='.07' font-style='italic'>layout</text><text x='78' y='200' font-size='20' fill='%23b45309' fill-opacity='.07' transform='rotate(90 78 200)'>weight</text><text x='156' y='248' font-size='46' fill='%237a3e62' fill-opacity='.065'>spiral</text><text x='430' y='228' font-size='30' fill='%231e7a45' fill-opacity='.07'>canvas</text><text x='500' y='340' font-size='52' fill='%23c0392b' fill-opacity='.055' transform='rotate(6 500 340)'>rust</text><text x='28' y='378' font-size='26' fill='%231d4e89' fill-opacity='.06'>pretty</text><text x='200' y='408' font-size='34' fill='%230f6e68' fill-opacity='.06' font-style='italic'>fast</text><text x='340' y='436' font-size='20' fill='%23b45309' fill-opacity='.06'>treemap</text><text x='600' y='190' font-size='18' fill='%237a3e62' fill-opacity='.06' transform='rotate(-90 600 190)'>words</text></g></svg>");
  background-size: 760px 520px;
}

body {
  margin: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.65;
}

a { color: var(--blue2); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--red); }

/* ── Nav (same header as the homepage) ───────────────────── */
nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 16px;
  padding: 16px 24px 12px;
  background:
    linear-gradient(90deg, #c0392b 0 16%, #0f6e68 16% 33%, #1d4e89 33% 50%, #b45309 50% 66%, #7a3e62 66% 83%, #1e7a45 83% 100%) top / 100% 5px no-repeat,
    rgba(243, 236, 223, 0.94);
  border-bottom: 2px solid var(--ink);
}
nav .brand-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
nav .brand {
  font-family: var(--display);
  font-weight: 700; font-size: 22px; color: var(--ink);
  letter-spacing: -0.03em;
  text-decoration: none;
  white-space: nowrap;
}
nav .brand span { color: var(--red); font-style: italic; font-weight: 560; }
nav .brand:hover { color: var(--ink); text-decoration: none; }
nav .nav-version {
  font-family: var(--mono);
  font-size: 11px; font-weight: 500;
  padding: 2px 7px;
  border: 1px dashed var(--ink);
  background: var(--bg2); color: var(--ink);
  transform: rotate(-2deg);
}
nav .nav-version:empty { display: none; }
.nav-toggle {
  display: none;
  margin-left: auto;
  padding: 6px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  line-height: 0;
}
.nav-toggle:hover { border-color: var(--red); color: var(--red); }
.nav-toggle svg { display: block; }
.nav-links {
  display: flex; align-items: center; gap: 16px;
  flex: 1 1 auto; justify-content: flex-end;
  flex-wrap: nowrap;
}
nav a { font-size: 15px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.nav-links > a,
.gh-link { flex-shrink: 0; }
nav a:hover { color: var(--red); text-decoration: none; }
nav a.active { color: var(--ink); font-weight: 600; }
.gh-link {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--ink);
  background: var(--bg2); color: var(--ink) !important;
  font-size: 14px;
}
.gh-link:hover { background: var(--ink); color: #f6f0e6 !important; border-color: var(--ink); }

@media (max-width: 768px) {
  html { scroll-padding-top: 64px; }
  nav { padding: 14px 16px 10px; gap: 0; }
  .nav-toggle { display: flex; align-items: center; justify-content: center; }
  .nav-links {
    display: none;
    flex: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  nav.open .nav-links { display: flex; }
  .nav-links a { padding: 10px 4px; font-size: 16px; }
  .nav-links .gh-link {
    margin-top: 6px;
    justify-content: center;
    padding: 10px 12px;
  }
}

/* ── Page wrapper ─────────────────────────────────────────── */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 36px 24px 72px;
}

/* ── Article sections ─────────────────────────────────────── */
.guide-lead {
  font-size: 18px;
  color: var(--text);
  margin: 0 0 28px;
  line-height: 1.65;
}
.guide-lead strong { color: var(--red); font-weight: 600; }

.prose {
  font-size: 16px;
  color: var(--text);
  line-height: 1.75;
  margin: 0 0 16px;
}
.prose p { margin: 0 0 12px; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol {
  margin: 0 0 12px;
  padding-left: 1.35em;
  color: var(--muted);
}
.prose li { margin-bottom: 6px; }
.prose li strong { color: var(--text); }
.prose code,
.ref-table td code,
code {
  font-family: var(--mono);
  font-size: 0.84em;
  padding: 1px 5px;
  border-radius: 2px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--purple);
}

.callout {
  font-size: 15px;
  line-height: 1.65;
  padding: 14px 16px;
  margin: 0 0 20px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
}
.callout strong { color: var(--text); }
.callout.tip { border-left: 4px solid var(--green); }
.callout.warn { border-left: 4px solid var(--orange); }

.walkthrough { margin-bottom: 36px; }
.walkthrough h3 {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 560;
  margin: 0 0 8px;
  color: var(--text);
  letter-spacing: -0.02em;
}
.walkthrough .step-label {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 6px;
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  margin: 0 0 8px;
  background: var(--bg2);
}
.ref-table th, .ref-table td {
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
.ref-table th {
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--ink);
}
.ref-table td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }

.section-playground h2 { margin-top: 0; }

.code-block + .code-block { margin-top: 12px; }
.code-block .code-caption {
  padding: 6px 14px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 8px 0 0;
}

/* ── Sections ─────────────────────────────────────────────── */
.section { margin-bottom: 52px; }
.section h2 {
  font-family: var(--display);
  font-size: 32px; font-weight: 560;
  letter-spacing: -0.03em;
  margin: 0 0 8px;
  padding-bottom: 0;
  border-bottom: none;
  line-height: 1.15;
}
.section h2::after {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  margin-top: 10px;
  background: var(--red);
}
.section:nth-of-type(3n+2) h2::after { background: var(--cyan); }
.section:nth-of-type(3n) h2::after { background: var(--blue); }
.section-sub {
  font-size: 16px; color: var(--muted);
  margin: 0 0 20px;
}

/* ── Panel (demo container) ───────────────────────────────── */
.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(36, 28, 22, 0.05);
}
.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px; color: var(--muted);
  letter-spacing: 0.04em;
}
.panel-body { padding: 16px; }

/* Window dots are leftover chrome — hide them, keep the filename. */
.dot { display: none; }

/* ── Canvas ───────────────────────────────────────────────── */
canvas {
  display: block;
  width: 100%;
  border-radius: 2px;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--border);
}
canvas.dark { background: #241c16; }

.canvas-wrap {
  overflow-y: auto;
  border-radius: 2px;
  max-height: 580px;
}

/* ── Controls ─────────────────────────────────────────────── */
.controls {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.controls-below {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 12px;
}
.btn {
  font-family: var(--serif);
  cursor: pointer;
  padding: 5px 14px; border-radius: 2px;
  border: 1px solid var(--ink);
  background: var(--bg2); color: var(--text);
  font-size: 14px; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover { background: #f8e4df; border-color: var(--red); }
.btn.active { background: var(--ink); border-color: var(--ink); color: #f6f0e6; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.flashing { animation: btn-flash 0.45s ease; }
select.btn { max-width: 180px; }
input[type="checkbox"] { accent-color: var(--red); }
.meta { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: 2px; }
.demo-note {
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0 0;
  line-height: 1.55;
}
.demo-viewport:fullscreen {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background: var(--bg);
  padding: 20px;
  overflow: hidden;
}
.demo-viewport:fullscreen .canvas-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border-radius: 2px;
}
.demo-viewport:fullscreen .canvas-wrap canvas {
  width: 100%;
  height: auto;
  border-radius: 2px;
}
.demo-viewport:fullscreen .svg-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border-radius: 2px;
}
.demo-viewport:fullscreen .svg-wrap .word-cloud-svg {
  width: 100%;
  height: auto;
}
.demo-viewport:fullscreen .controls,
.demo-viewport:fullscreen .controls-below {
  flex-shrink: 0;
  margin-top: 12px;
  margin-bottom: 0;
}
.demo-viewport:fullscreen .fullscreen-hint {
  display: block;
  flex-shrink: 0;
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}
.fullscreen-hint { display: none; }
#worker-viewport .worker-fs-spin { display: none; }
#worker-viewport:fullscreen .worker-fs-spin {
  display: inline-block;
  flex-shrink: 0;
}
.demo-note kbd, .fullscreen-hint kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 2px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  background: var(--bg2);
  color: var(--ink);
}

@keyframes btn-flash {
  0%   { background: var(--red); border-color: var(--red); color: #fffdf8; }
  100% { background: var(--bg2); border-color: var(--ink); color: var(--text); }
}

/* ── Code block ───────────────────────────────────────────── */
.code-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(36, 28, 22, 0.05);
}
.code-block-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px; color: var(--muted);
  letter-spacing: 0.03em;
}
.code-block-header::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--red);
  flex-shrink: 0;
}
pre {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  font-family: var(--mono);
}
pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Syntax colours — ink on paper */
.kw  { color: #c0392b; }
.fn  { color: #7a3e62; }
.str { color: #1e7a45; }
.cm  { color: #8a7b6b; font-style: italic; }
.nu  { color: #1d4e89; }
.id  { color: #b45309; }
.op  { color: #241c16; }

/* ── Spinner ──────────────────────────────────────────────── */
.spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Benchmark table ──────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background: var(--bg2);
}
th, td {
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: right;
}
th:first-child, td:first-child { text-align: left; }
thead th {
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--ink);
}
.pass { color: var(--green); font-weight: 600; }
.fail { color: var(--red);   font-weight: 600; }

/* ── SVG word cloud ───────────────────────────────────────── */
.svg-wrap {
  overflow-y: auto;
  border-radius: 2px;
  background: #fff;
  max-height: 580px;
  box-shadow: inset 0 0 0 1px var(--border);
}
.word-cloud-svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}
.word-cloud-svg.interactive text {
  cursor: pointer;
  transition: opacity 0.15s;
}
.word-cloud-svg.interactive text.dimmed { opacity: 0.25; }
.word-cloud-svg.interactive text.highlighted { opacity: 1; filter: drop-shadow(0 0 6px rgba(192, 57, 43, 0.35)); }

/* ── Interactive detail panel ─────────────────────────────── */
.interactive-cloud-host {
  position: relative;
}
.word-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, calc(-100% - 10px));
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 11px;
  border-radius: 2px;
  border: 1px solid var(--ink);
  background: var(--bg2);
  box-shadow: 3px 3px 0 rgba(36, 28, 22, 0.12);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}
.word-tooltip[hidden] { display: none; }
.word-tooltip-term {
  font-family: var(--display);
  font-weight: 560;
  color: var(--text);
}
.word-tooltip-weight {
  font-family: var(--mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* ── Text input stack (cloud above, editor below) ─────────── */
.text-input-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cloud-col canvas {
  width: 100%;
  border-radius: 2px;
}
.field-label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.text-input-area {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  border-radius: 2px;
  border: 1px solid var(--ink);
  background: var(--bg2);
  color: var(--text);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  resize: vertical;
}
.text-input-area:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
}
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.input-col .controls { margin-top: 10px; margin-bottom: 0; }

/* ── Responsive resize demo ───────────────────────────────── */
.resize-panel .panel-header {
  justify-content: flex-start;
}
.resize-panel-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.resize-dim-badge {
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 2px 9px;
  border-radius: 2px;
  border: 1px dashed var(--ink);
  background: var(--bg2);
  color: var(--cyan);
}
.resize-status {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.resize-status[data-state="ready"] { color: var(--green); }
.resize-status[data-state="resizing"] { color: var(--orange); }
.resize-status[data-state="reflowing"] { color: var(--cyan); }
.code-block-tag {
  margin-left: 4px;
  opacity: 0.75;
}
.resize-demo {
  position: relative;
  width: min(100%, 720px);
  min-width: 280px;
  border-radius: 2px;
  border: 1px solid var(--ink);
  background: var(--bg3);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.resize-demo.is-resizing {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
}
.resize-cloud-host {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 12px;
}
.resize-cloud-host canvas {
  width: 100%;
  height: 100%;
  border-radius: 2px;
}
.resize-drag-hint {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: rgba(255, 253, 248, 0.92);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  opacity: 0.95;
  transition: opacity 0.2s;
}
.resize-drag-hint svg { opacity: 0.7; flex-shrink: 0; }
.resize-drag-hint--desktop {
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
}
.resize-drag-hint--mobile { display: none; }
.resize-demo.is-resizing .resize-drag-hint { opacity: 0; }
.resize-handle {
  width: 10px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--ink);
  border-radius: 0 2px 2px 0;
  transition: background 0.15s;
  touch-action: none;
}
.resize-handle:hover,
.resize-handle.active {
  background: var(--red);
}
.controls-presets {
  margin-top: 10px;
  margin-bottom: 0;
}
.preset-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 2px;
}
.section-sub--mobile,
.demo-note--mobile,
.resize-drag-hint--mobile,
.controls-presets--desktop { display: none; }
@media (max-width: 768px) {
  .resize-demo {
    width: 100%;
    min-width: 0;
    flex-direction: column;
  }
  .resize-cloud-host {
    min-height: 0;
    flex: 1;
  }
  .resize-handle {
    width: auto;
    height: 10px;
    cursor: row-resize;
    border-radius: 0 0 2px 2px;
  }
  .resize-drag-hint--desktop,
  .section-sub--desktop,
  .demo-note--desktop,
  .controls-presets--desktop { display: none; }
  .resize-drag-hint--mobile,
  .section-sub--mobile,
  .demo-note--mobile { display: block; }
  .resize-drag-hint--mobile {
    display: inline-flex;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
  }
}
