/* ==========================================================================
   Design Tokens — Light theme (default)
   ========================================================================== */

:root {
  /* Backgrounds */
  --bg: #fff;
  --surface: #fafafa;
  --surface-alt: #f8f8f8;
  --surface-strong: #f0f0f0;

  /* Text */
  --text-heading: #333;
  --text-body: #333;
  --text-secondary: #555;
  --text-soft: #444;
  --text-muted: #999;

  /* Border scale */
  --neutral-500: #888;
  --neutral-400: #aaa;
  --neutral-300: #ccc;
  --neutral-200: #e0e0e0;
  --border-light: #eee;

  /* Accent (success / green) */
  --accent-bg: #eef7ee;
  --accent-border: #8cb88c;
  --accent-text: #a8cca8;

  /* Components */
  --btn-bg: #fff;

  /* Scrollbar */
  --scrollbar-thumb: rgba(0, 0, 0, 0);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.12);
  --scrollbar-thumb-active: rgba(0, 0, 0, 0.2);

  /* Focus */
  --focus-overlay: rgba(0, 0, 0, 0.1);

  /* Fonts */
  --font-serif: 'Source Serif 4', serif;
  --font-sans: 'Inter', sans-serif;

  /* Pico framework — wired to tokens */
  --pico-font-family: var(--font-serif);
  --pico-font-size: 17px;
  --pico-line-height: 1.7;
  --pico-background-color: var(--bg);
  --pico-color: var(--text-body);
  --pico-code-background-color: var(--surface-alt);
  --pico-code-color: var(--text-body);
}

/* ==========================================================================
   Design Tokens — Dark theme (Charcoal)
   ========================================================================== */

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1a1a1a;
  --surface: #222;
  --surface-alt: #222;
  --surface-strong: #252525;

  --text-heading: #e8e8e8;
  --text-body: #c8c8c8;
  --text-secondary: #999;
  --text-soft: #999;
  --text-muted: #666;

  --neutral-500: #666;
  --neutral-400: #555;
  --neutral-300: #444;
  --neutral-200: #333;
  --border-light: #2a2a2a;

  --accent-bg: #2a332a;
  --accent-border: #3a4a3a;
  --accent-text: #a8cca8;

  --btn-bg: #222;

  --scrollbar-thumb: rgba(255, 255, 255, 0);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.12);
  --scrollbar-thumb-active: rgba(255, 255, 255, 0.2);

  --focus-overlay: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Pico neutralization — wired to tokens, auto-switches
   ========================================================================== */

*, *::before, *::after {
  --pico-primary: var(--text-secondary);
  --pico-primary-hover: var(--text-heading);
  --pico-primary-focus: var(--focus-overlay);
  --pico-border-color: var(--neutral-200);
  --pico-table-border-color: var(--neutral-200);
  --pico-muted-border-color: var(--neutral-200);
}

/* ==========================================================================
   Layout
   ========================================================================== */

body {
  max-width: 820px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  background: var(--bg);
  color: var(--text-body);
}

article {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  border-radius: 0;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--text-heading);
}

h2 {
  font-size: 1.45rem;
  font-weight: 600;
  margin-top: 3rem;
  color: var(--text-heading);
}

pre {
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-x: auto;
  border-radius: 8px;
}

blockquote {
  border-left: 3px solid var(--neutral-300);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  font-style: italic;
  color: var(--text-soft);
}

hr {
  border-color: var(--neutral-200);
  margin: 2.5rem 0;
}

/* ==========================================================================
   Shared: horizontal scroll with auto-reveal scrollbar
   ========================================================================== */

.scrollable-x {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.scrollable-x::-webkit-scrollbar { height: 5px; }
.scrollable-x::-webkit-scrollbar-track { background: transparent; }
.scrollable-x::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
  transition: background 0.2s;
}
.scrollable-x:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb-hover); }
.scrollable-x::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-active); }

/* ==========================================================================
   Diagrams (Mermaid)
   ========================================================================== */

.diagram-container {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 2rem 1.5rem;
  margin: 1rem 0 1.5rem;
  position: relative;
}

pre.mermaid {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

.diagram-container .mermaid svg,
.diagram-container .mermaid-host svg {
  width: 100% !important;
  height: auto !important;
  max-width: none;
}

.diagram-container.diagram-container--vertical .mermaid svg,
.diagram-container.diagram-container--vertical .mermaid-host svg {
  width: auto !important;
  max-width: 100% !important;
  max-height: min(72vh, 760px);
  display: block;
  margin: 0 auto;
}

.mermaid .nodeLabel,
.mermaid-host .nodeLabel {
  font-family: var(--font-sans) !important;
  font-size: 13px !important;
  line-height: 1.5 !important;
}

.mermaid .edgeLabel,
.mermaid-host .edgeLabel {
  font-family: var(--font-sans) !important;
  font-size: 11px !important;
}

.diagram-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  letter-spacing: 0.03em;
}

.diagram-label-center {
  text-align: center;
}

/* ==========================================================================
   Compare grid (side-by-side diagrams)
   ========================================================================== */

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

.compare-grid > section {
  text-align: center;
}

@media (max-width: 600px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Table
   ========================================================================== */

.table-wrap {
  margin: 1.5rem 0;
  border: 1px solid var(--neutral-200);
  border-radius: 8px;
  padding-bottom: 6px;
}

table {
  font-size: 0.92rem;
  margin: 0;
  border: none;
  width: max-content;
  min-width: 100%;
}

thead th {
  background: var(--surface-strong);
  border-bottom: 1px solid var(--neutral-200);
}

table, td, th, tr {
  border-color: var(--neutral-200) !important;
}

tbody tr:last-child td {
  border-bottom: none !important;
}

/* ==========================================================================
   Checkpoint card
   ========================================================================== */

.checkpoint {
  background: var(--surface-alt);
  border: 1px solid var(--neutral-200);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

.checkpoint strong {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
}

/* ==========================================================================
   Prompt/code blocks (checkpoint look + monospace)
   ========================================================================== */

article pre:not(.mermaid),
.practice-block {
  background: var(--surface-alt);
  border: 1px solid var(--neutral-200);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
  overflow-x: auto;
}

.prompt-card {
  position: relative;
  margin: 1rem 0 1.5rem;
}

.prompt-card > pre:not(.mermaid) {
  margin: 0 !important;
  padding-top: 1.15rem;
  padding-right: 6rem;
  overflow-x: hidden;
}

.prompt-card > pre:not(.mermaid) code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

article pre:not(.mermaid),
article pre:not(.mermaid) code,
.practice-block,
.practice-block code {
  background: transparent;
}

article pre:not(.mermaid) code,
.practice-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-body);
  white-space: pre;
}

.prompt-copy-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  min-width: 4.1rem;
}

.prompt-copy-btn.copied {
  border-color: var(--text-heading);
  color: var(--text-heading);
}

/* ==========================================================================
   Copy button
   ========================================================================== */

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--btn-bg);
  border: 1px solid var(--neutral-200);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-family: var(--font-serif);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--neutral-500);
}

.copy-btn:focus,
.copy-btn:active {
  outline: none;
  box-shadow: none;
}

.copy-btn:hover {
  border-color: var(--neutral-400);
  color: var(--text-heading);
  background: var(--surface);
}

.copy-btn.copied {
  border-color: var(--text-heading);
  color: var(--text-heading);
}

.copy-btn svg {
  width: 14px;
  height: 14px;
}

.copy-btn--full {
  display: flex;
  justify-content: center;
  width: 100%;
}

/* ==========================================================================
   Header row
   ========================================================================== */

.header-row {
  margin-bottom: 1rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-row .copy-btn {
  margin-top: 0.75rem;
  padding: 0.5rem;
}

/* ==========================================================================
   Theme toggle
   ========================================================================== */

.theme-toggle {
  background: none;
  border: 1px solid var(--neutral-200);
  border-radius: 6px;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:focus {
  outline: none;
  box-shadow: none;
}

.theme-toggle:hover {
  color: var(--text-heading);
  border-color: var(--neutral-400);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Show moon in light, sun in dark */
.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ==========================================================================
   Diagram expand viewer (full width + pan/zoom)
   ========================================================================== */

.diagram-expand-btn,
.prompt-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  border: 1px solid var(--neutral-200);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.35rem 0.5rem;
  margin: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}

.diagram-expand-btn {
  top: 0.7rem;
  right: 0.7rem;
  z-index: 2;
}

.diagram-expand-btn:hover,
.prompt-copy-btn:hover {
  border-color: var(--neutral-400);
  color: var(--text-heading);
  background: var(--surface);
}

.diagram-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.75rem;
  display: flex;
  align-items: stretch;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.diagram-modal.is-open {
  opacity: 1;
}

.diagram-modal.is-closing {
  pointer-events: none;
}

.diagram-modal__panel {
  width: min(100%, 1500px);
  height: 100%;
  max-height: 100%;
  background: var(--bg);
  border: 1px solid var(--neutral-200);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px);
  filter: blur(6px);
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
}

.diagram-modal.is-open .diagram-modal__panel {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.diagram-modal__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  min-height: 4rem;
  border-bottom: 1px solid var(--neutral-200);
  background: var(--surface-alt);
}

.diagram-modal__title {
  display: flex;
  align-items: center;
  line-height: 1;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.diagram-modal__controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.diagram-modal__controls button {
  border: 1px solid var(--neutral-200);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  margin: 0 !important;
  cursor: pointer;
  transition: all 0.15s ease;
}

.diagram-modal__controls button:hover {
  border-color: var(--neutral-400);
  color: var(--text-heading);
}

.diagram-modal__viewport {
  flex: 1;
  overflow: auto;
  background: var(--surface);
  cursor: grab;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.diagram-modal__viewport:hover {
  scrollbar-color: var(--scrollbar-thumb-hover) transparent;
}

.diagram-modal__viewport::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.diagram-modal__viewport::-webkit-scrollbar-track {
  background: transparent;
}

.diagram-modal__viewport::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
  transition: background 0.2s;
}

.diagram-modal__viewport:hover::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb-hover);
}

.diagram-modal__viewport::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-active);
}

.diagram-modal__viewport.is-dragging {
  cursor: grabbing;
}

.diagram-modal__stage {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  padding: 1rem;
  display: grid;
  place-items: center;
}

.diagram-modal__canvas {
  width: max-content;
}

.diagram-modal__canvas svg {
  width: 100% !important;
  max-width: none !important;
  height: auto !important;
  display: block;
  margin: 0;
}

body.has-diagram-modal {
  overflow: hidden;
}

@media (max-width: 700px) {
  .diagram-modal {
    padding: 0;
  }

  .diagram-modal__panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    width: 100%;
  }
}

/* ==========================================================================
   Follow-up questions
   ========================================================================== */

.follow-up-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--neutral-200);
}

.follow-up-item:last-child {
  border-bottom: none;
}

.follow-up-item p {
  margin: 0;
}

.follow-up-item .copy-btn {
  padding: 0.45rem;
}

.follow-up-number {
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 0.25rem;
}

/* ==========================================================================
   Staggered reveal animation
   ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(16px);
  filter: blur(6px);
  transition: opacity 0.5s ease, transform 0.5s ease, filter 0.5s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}
