.river-piece {
  --page: #fffff8;
  --panel: #fff;
  --ink: #171717;
  --muted: #656560;
  --accent: #313669;
  --accent-ink: #fff;
  --border: #d8d8d2;
  --outline-stroke: 1px;
  --controls-width: min(320px, 85vw);
  --site-header-height: 100px;
  position: relative;
  color: var(--ink);
  background: var(--page);
  font: 16px/1.5 Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: calc(100dvh - var(--site-header-height));
}
html.dark .river-piece {
  --page: #151515;
  --panel: #212121;
  --ink: #ddd;
  --muted: #aaa;
  --accent: #aab0e8;
  --accent-ink: #151515;
  --border: #555;
}
.river-piece *, .river-piece *::before, .river-piece *::after {
  box-sizing: border-box;
}
.river-piece p {
  font: inherit;
}
.river-piece h2 {
  font-family: inherit;
  font-style: normal;
}
.river-piece .collection-link {
  display: inline-block;
  margin-left: 52px;
  color: var(--muted);
  font-size: 14px;
}
.river-piece .visualization {
  --visualization-padding: 24px;
  min-height: calc(100dvh - var(--site-header-height));
  min-width: 0;
  max-width: none;
  width: 100%;
  padding: 18px var(--visualization-padding) 12px;
}
.river-piece .controls {
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  height: calc(100dvh - var(--site-header-height));
  left: 0;
  overflow-y: auto;
  padding: 20px 24px;
  position: fixed;
  top: var(--site-header-height);
  transition: transform 220ms ease;
  transform: translateX(-105%);
  width: var(--controls-width);
  z-index: 20;
}
.river-piece .controls.is-open {
  transform: translateX(0);
}
.river-piece .controls-header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 22px;
  padding-bottom: 12px;
}
.river-piece .controls-header h2 {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}
.river-piece .menu-button, .river-piece .close-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  padding: 0;
  transition: background-color 150ms ease;
  width: 44px;
}
.river-piece .menu-button:hover, .river-piece .close-button:hover {
  background: rgba(128, 128, 128, 0.12);
}
.river-piece .menu-button {
  left: 14px;
  position: absolute;
  top: 14px;
}
.river-piece .menu-button svg, .river-piece .close-button svg {
  fill: none;
  height: 22px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
  width: 22px;
}
.river-piece .visualization h1 {
  font-size: clamp(64px, 8vw, 112px);
  font-weight: 700;
  letter-spacing: -0.07em;
  line-height: 0.85;
  margin: 0;
  text-transform: uppercase;
}
.river-piece .masthead {
  align-items: start;
  border-bottom: 1px solid var(--ink);
  display: grid;
  gap: 40px;
  grid-template-columns: minmax(max-content, 1fr) 2fr;
  margin: 24px 0 16px;
  padding-bottom: 24px;
}
.river-piece .masthead h1 span { display: block; }
.river-piece .masthead h1 .title-region {
  align-items: end;
  display: flex;
  gap: 0.1em;
}
.river-piece .title-region svg {
  flex: none;
  height: 0.85em;
  margin: 0;
  width: 0.85em;
}
.river-piece .title-region path {
  fill: none;
  stroke: var(--ink);
  stroke-width: var(--outline-stroke);
  vector-effect: non-scaling-stroke;
}
.river-piece .description { min-width: 0; }
.river-piece .eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  margin: 0 0 12px;
  text-transform: uppercase;
}
.river-piece .description p { text-align: justify; }
.river-piece .export-button, .river-piece .export-actions button {
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  color: var(--page);
  cursor: pointer;
  font: inherit;
  padding: 8px 16px;
}
.river-piece button:disabled { cursor: wait; opacity: 0.5; }
.river-piece dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
  max-height: 94dvh;
  padding: 24px;
  width: min(1100px, 94vw);
}
.river-piece dialog::backdrop { background: rgb(0 0 0 / 55%); }
.river-piece .export-toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}
.river-piece .export-toolbar h2 { flex: 1; margin: 0; }
.river-piece .export-toolbar label { font-size: 14px; }
.river-piece .export-toolbar select { width: auto; }
.river-piece .export-actions { display: flex; gap: 12px; }
.river-piece #export-preview { background: #e7e7e2; max-height: 58dvh; overflow: auto; padding: 16px; }
.river-piece #export-preview svg { box-shadow: 0 2px 12px rgb(0 0 0 / 12%); height: auto; width: 100%; }
.river-piece #export-details, .river-piece #export-error { font-size: 14px; }
.river-piece #export-error { color: #a32121; }
.river-piece .control-groups {
  display: grid;
  gap: 28px;
}
.river-piece .control-group {
  border: 0;
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 0;
}
.river-piece .control-group legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
  padding: 0;
  width: 100%;
  text-transform: uppercase;
}
.river-piece label {
  display: grid;
  gap: 8px;
  font-size: 18px;
}
.river-piece select, .river-piece input, .river-piece output {
  font: inherit;
}
.river-piece select, .river-piece input[type="range"] {
  box-sizing: border-box;
  max-width: 100%;
  width: 100%;
}
.river-piece select {
  appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23656560' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 36px 10px 12px;
}
.river-piece select:hover {
  border-color: var(--muted);
}
.river-piece select:focus-visible, .river-piece input:focus-visible, .river-piece button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.river-piece .sort-label {
  font-size: 18px;
}
.river-piece .sort-help {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}
.river-piece .sort-list {
  display: grid;
  gap: 6px;
}
.river-piece .sort-chip {
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  transition: transform 180ms cubic-bezier(.2, 1.4, .4, 1), box-shadow 180ms;
}
.river-piece .sort-chip:has([aria-pressed="true"]) {
  background: var(--accent);
  border-color: var(--accent);
}
.river-piece .sort-chip.dragging {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: scale(1.02);
}
.river-piece .sort-chip button {
  background: transparent;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  min-height: 40px;
}
.river-piece .sort-toggle {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  text-align: left;
}
.river-piece .sort-handle {
  color: var(--muted) !important;
  cursor: grab !important;
  padding: 0 12px;
  touch-action: none;
}
.river-piece .sort-handle:active {
  cursor: grabbing !important;
}
.river-piece .sort-chip:has([aria-pressed="true"]) button {
  color: var(--accent-ink);
}
.river-piece .sort-chip:has([aria-pressed="true"]) .sort-handle {
  color: var(--accent-ink) !important;
}
@media (prefers-reduced-motion: reduce) {
  .river-piece .controls, .river-piece .sort-chip {
    transition: none;
  }
}
.river-piece input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
  min-height: 24px;
}
.river-piece output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.river-piece #status, .river-piece #note {
  color: var(--muted);
  font-size: 18px;
  margin: 8px 0 0;
  text-align: justify;
}
.river-piece #status[role="alert"] {
  color: #a32121;
}
.river-piece #note {
  display: grid;
}
.river-piece #note span, .river-piece #note::after {
  grid-area: 1 / 1;
}
.river-piece #note::after {
  content: attr(data-reserve);
  visibility: hidden;
}
.river-piece #chart {
  margin: 0 auto;
  max-width: 100%;
  width: 100%;
}
.river-piece.controls-open #chart {
  margin-left: max(0px, calc(var(--controls-width) - var(--visualization-padding) + 8px));
  width: calc(100% - max(0px, var(--controls-width) - var(--visualization-padding) + 8px));
}
.river-piece .attribution {
  color: var(--muted);
  font-size: 16px;
  margin: 8px auto 0;
  max-width: 66rem;
  text-align: center;
}
.river-piece .attribution a {
  color: var(--accent);
}
.river-piece svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}
.river-piece .axis path, .river-piece .axis line {
  stroke: var(--muted);
  stroke-width: 0.6px;
}
.river-piece .axis text {
  fill: var(--muted);
  font: 12pt Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.river-piece .axis-label {
  fill: var(--ink);
  font-size: 14pt;
}
.river-piece .profile {
  stroke: var(--ink);
  stroke-width: 0.7px;
  vector-effect: non-scaling-stroke;
}
.river-piece .profile:hover {
  stroke: #bd4b2d;
  stroke-width: 1.6px;
}
@media (max-width: 600px) {
  .river-piece .visualization {
    --visualization-padding: 8px;
    padding: 14px var(--visualization-padding) 8px;
  }
  .river-piece .controls {
    padding: 20px 12px;
  }
  .river-piece .masthead { gap: 20px; grid-template-columns: 1fr; margin-top: 32px; }
  .river-piece.controls-open #chart { margin-left: 0; width: 100%; }
  .river-piece .visualization h1 { font-size: clamp(42px, 10vw, 64px); }
  .river-piece #status, .river-piece #note { font-size: 14px; }
  .river-piece .menu-button {
    left: 4px;
    top: 4px;
  }
}
@media print {
  .river-piece .controls, .river-piece .menu-button, .river-piece .export-button, .river-piece dialog { display: none; }
  .river-piece.controls-open #chart { margin-left: 0; width: 100%; }
  .river-piece, html.dark .river-piece { --page: #fffff8; --ink: #171717; --muted: #656560; --accent: #313669; }
  .river-piece #chart path[fill]:not([fill="none"]) { fill: var(--page); }
  .river-piece { print-color-adjust: exact; }
  body.rivers-page > header, body.rivers-page > footer { display: none; }
}
