/* Shared writing layout and components. Every page in /pieces uses this file. */

:root {
  --color-accent: #444444;
  --color-accent-bg: #f0f0f0;
  --color-accent-hover: #333333;
  --color-link: #ec5c13;
  --article-width: 760px;
}

[data-theme="dark"] {
  --color-accent: #b0b0b0;
  --color-accent-bg: #1f1f1f;
  --color-accent-hover: #d4d4d4;
  --color-link: #ec5c13;
}

html {
  overflow-y: scroll;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.article-shell {
  width: min(100%, var(--article-width));
  margin: 0 auto;
  padding: 96px 48px 160px;
}

.article-hero {
  margin: 0 0 4rem;
  padding: 2.5rem;
  border: 0.5px solid var(--color-border-light);
  border-radius: 20px;
  background: var(--color-surface);
}

.article-title {
  margin: 0 0 0.75rem;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.3;
}

.article-subtitle {
  margin: 0 0 1.25rem;
  color: var(--color-text-secondary);
  font-size: 1.05rem;
  line-height: 1.6;
}

.article-summary {
  margin: 0 0 1.5rem;
  line-height: 1.7;
}

.article-meta {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  line-height: 1.8;
}

.article-meta a {
  text-decoration: none;
}

.article-shell h2 {
  margin: 3rem 0 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.3;
}

.article-shell h3 {
  margin: 2.25rem 0 0.75rem;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
}

.article-shell h4 {
  margin: 1.75rem 0 0.6rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
}

.article-hero + h2 {
  margin-top: 0;
}

.article-shell > section > h2:first-child {
  margin: 3rem 0 1rem;
}

.article-hero + section > h2:first-child {
  margin-top: 0;
}

.article-shell p {
  margin: 1rem 0;
  line-height: 1.7;
}

.article-shell ul,
.article-shell ol {
  margin: 1rem 0;
  padding-left: 1.4rem;
}

.article-shell li {
  margin: 0.45rem 0;
}

.article-shell strong {
  font-weight: 600;
}

.article-shell a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-color: var(--color-border);
  text-underline-offset: 2px;
}

.article-shell a:hover {
  text-decoration-color: var(--color-text);
}

.article-shell hr {
  margin: 2.5rem 0;
  border: 0;
  border-top: 1px solid var(--color-border-light);
}

.article-shell code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.article-shell pre {
  margin: 1.5rem 0;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  background: var(--color-surface);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

.article-shell pre code {
  padding: 0;
  border-radius: 0;
  background: transparent;
  font-size: inherit;
  white-space: pre;
}

.article-shell blockquote {
  margin: 1.5rem 0;
  padding: 16px 20px;
  border-left: 4px solid var(--color-border);
  border-radius: 0 12px 12px 0;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.95rem;
}

.article-shell blockquote p {
  margin: 0;
}

.design-note {
  color: var(--color-text-secondary) !important;
  font-size: 0.875rem !important;
}

.math-block {
  max-width: 100%;
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  overflow-x: auto;
  border-radius: 12px;
  background: var(--color-surface);
  text-align: center;
}

.katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex {
  max-width: 100%;
}

.caption {
  margin: 1.5rem 0 0.5rem !important;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  line-height: 1.5 !important;
  text-align: center;
  text-transform: uppercase;
}

.xref {
  margin: 0.75rem 0;
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  text-align: center;
}

sup {
  line-height: 0;
  vertical-align: baseline;
}

sup a {
  position: relative;
  top: -0.4em;
  padding: 0 1px;
  color: var(--color-link);
  font-size: 0.55rem;
  text-decoration: none;
  vertical-align: super;
}

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

.footnote {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border-light);
  color: var(--color-text-secondary);
  font-size: 0.85rem;
}

.footnote > sup {
  font-size: 0.75rem;
  vertical-align: baseline;
}

.table-wrap,
.table-scroll {
  width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.article-shell table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-wrap table,
.table-scroll table {
  margin: 0;
}

.article-shell th {
  padding: 12px 16px;
  border-bottom: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  text-align: left;
  text-transform: uppercase;
}

.article-shell td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  text-align: left;
  vertical-align: top;
}

.article-shell tr:hover td {
  background: var(--color-surface);
}

.article-shell caption {
  margin-top: 0.75rem;
  color: var(--color-text-tertiary);
  caption-side: bottom;
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: left;
}

.data-table--numeric th:not(:first-child),
.data-table--numeric td:not(:first-child) {
  text-align: right;
}

.data-table--numeric td {
  font-family: var(--font-mono);
}

.chart-frame {
  position: relative;
  height: 300px;
  margin: 1.5rem 0;
}

.chart-frame--320 { height: 320px; }
.chart-frame--280 { height: 280px; }
.chart-frame--260 { height: 260px; }
.chart-frame--240 { height: 240px; }
.chart-frame--220 { height: 220px; }

.chart-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.interpretation,
.note-card,
.spec-card,
.algo-box {
  margin: 1.5rem 0;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  background: var(--color-surface);
  font-size: 0.95rem;
}

.note-card p,
.spec-card p {
  margin: 0.65rem 0;
}

.spec-card h3:first-child {
  margin-top: 0;
}

.example-box {
  margin: 1.5rem 0;
  overflow: hidden;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
}

.example-box-title {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-surface);
  font-size: 0.9rem;
  font-weight: 600;
}

.example-box-body {
  padding: 1.25rem 1.5rem;
}

.algo-box ol {
  margin: 0.5rem 0 0;
  padding-left: 1.5rem;
}

.cite-link {
  color: var(--color-link);
  cursor: pointer;
  text-decoration: none;
}

.cite-link:hover {
  text-decoration: underline;
}

.split-grid,
.surface-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 1.5rem 0;
}

.surface-list {
  gap: 12px;
}

.surface-item {
  padding: 14px 16px;
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  background: var(--color-bg);
}

.surface-item strong {
  display: block;
  margin-bottom: 4px;
}

.surface-item span {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 1.75rem 0;
}

.flow-step {
  position: relative;
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  background: var(--color-surface);
}

.flow-step:not(:last-child)::after {
  content: ">";
  position: absolute;
  z-index: 2;
  top: 50%;
  right: -8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  border: 1px solid var(--color-border-light);
  border-radius: 50%;
  background: var(--color-bg);
  color: var(--color-text-tertiary);
  font-size: 0.8rem;
}

.flow-kicker {
  margin-bottom: 8px;
  color: var(--color-text-tertiary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.flow-step strong {
  display: block;
  margin-bottom: 8px;
  line-height: 1.35;
}

.flow-step p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 0.88rem;
  line-height: 1.55;
}

.timeline {
  margin: 1.5rem 0;
  overflow: hidden;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  min-height: 64px;
  border-bottom: 1px solid var(--color-border-light);
}

.timeline-row:last-child {
  border-bottom: 0;
}

.timeline-label {
  padding: 14px 16px;
  border-right: 1px solid var(--color-border-light);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
}

.timeline-copy {
  padding: 14px 16px;
  color: var(--color-text-secondary);
}

.window-track {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 1.5rem 0;
  overflow: hidden;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
}

.window-track > div {
  min-height: 118px;
  padding: 16px;
  border-right: 1px solid var(--color-border-light);
  background: var(--color-surface);
}

.window-track > div:nth-child(2) {
  background: var(--color-bg);
}

.window-track > div:last-child {
  border-right: 0;
}

.window-track strong {
  display: block;
  margin-bottom: 6px;
}

.window-track span {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  line-height: 1.55;
}

.layers {
  margin: 1.5rem 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

.layer {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border-light);
  background: var(--color-surface);
}

.layer:nth-child(even) {
  background: var(--color-bg);
}

.layer:last-child {
  border-bottom: 0;
}

.layer-title {
  margin-bottom: 2px;
  color: var(--color-text);
  font-weight: 600;
}

.layer-copy {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

.regulatory-timeline {
  position: relative;
  margin: 1.5rem 0;
  padding-left: 28px;
}

.regulatory-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 13px;
  width: 2px;
  background: var(--color-border);
}

.regulatory-event {
  position: relative;
  padding: 10px 0 10px 24px;
}

.regulatory-marker {
  position: absolute;
  top: 16px;
  left: -19px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-bg);
  border-radius: 50%;
  background: #ec5c13;
}

.regulatory-marker--complete {
  background: #10b981;
}

.regulatory-date {
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
}

.regulatory-copy {
  font-size: 0.875rem;
}

.pseudocode-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 1rem;
}

.pseudocode-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--color-border-light);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-link);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pseudocode-link:hover {
  border-color: var(--color-link);
  background: var(--color-accent-bg);
  text-decoration: none;
}

.pseudocode-link svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-backdrop.open {
  display: flex;
  animation: modal-fade-in 0.15s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  width: 100%;
  max-width: 720px;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: var(--color-bg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-border-light);
}

.modal-header h3,
.modal-header h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.modal-close:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.modal-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.modal-body {
  padding: 16px 24px 24px;
}

.modal-body pre {
  margin: 0;
  border: 0;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.55;
}

.article-references {
  margin-top: 4rem !important;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border-light);
}

.article-references > h2:first-child {
  display: block !important;
  margin: 0 0 1.5rem !important;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

.article-references > ol {
  margin: 0;
  padding-left: 1.4rem;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  list-style: decimal;
}

.article-references > ol > li {
  margin: 0.6rem 0;
  line-height: 1.6;
}

.thanks {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

.article-footer {
  margin-top: 80px;
  padding-top: 40px;
  border-top: 1px solid var(--color-border-light);
  font-size: 0.75rem;
}

.article-footer p {
  margin: 1rem 0;
}

@media (max-width: 760px) {
  .article-shell {
    width: 100%;
    padding: 64px 20px 140px;
  }

  .article-hero {
    padding: 1.5rem;
    border-radius: 14px;
  }

  .article-title {
    font-size: 1.85rem;
  }

  .split-grid,
  .surface-list,
  .flow-grid,
  .window-track {
    grid-template-columns: 1fr;
  }

  .flow-step:not(:last-child)::after {
    content: "v";
    top: auto;
    right: 50%;
    bottom: -10px;
    transform: translateX(50%);
  }

  .timeline-row {
    grid-template-columns: 1fr;
  }

  .timeline-label {
    border-right: 0;
    border-bottom: 1px solid var(--color-border-light);
  }

  .table-wrap table,
  .table-scroll table {
    min-width: 560px;
  }

  .chart-frame,
  .chart-frame--320,
  .chart-frame--280,
  .chart-frame--260,
  .chart-frame--240,
  .chart-frame--220 {
    height: 280px;
  }
}

@media print {
  .article-shell {
    max-width: 100%;
    padding: 0;
  }

  .dock,
  .modal-backdrop {
    display: none !important;
  }
}
