:root {
  --bg-deep: #07090f;
  --ink-primary: #f7f3eb;
  --ink-secondary: #ded8cc;
  --ink-muted: #b0aa9e;
  --accent-gold: #f5c978;
  --accent-gold-soft: rgba(245, 201, 120, 0.22);
  --accent-steel: #9ac6e6;
  --border-subtle: rgba(247, 243, 235, 0.18);
  --panel-glass: rgba(9, 12, 19, 0.86);
  --text-scrim: rgba(7, 9, 15, 0.78);
  --focus-ring: #f5c978;
  --radius-card: 16px;
  --font-serif: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

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

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-deep);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.sanctuary-mount {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.sanctuary-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.material-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.app-shell {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.75rem;
  background: linear-gradient(180deg, rgba(7, 9, 15, 0.88) 0%, rgba(7, 9, 15, 0.45) 100%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(242, 237, 228, 0.08);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.brand-kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: var(--accent-gold);
  font-weight: 600;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.stage-rail {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.rail-step {
  transition: color 220ms ease;
}

.rail-step.is-active {
  color: var(--accent-gold);
  font-weight: 600;
}

.rail-step.is-done {
  color: var(--ink-secondary);
}

.rail-sep {
  opacity: 0.35;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

/* Buttons */
.ghost-btn,
.primary-btn,
.secondary-btn {
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.ghost-btn {
  padding: 0.42rem 0.9rem;
  background: rgba(242, 237, 228, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--ink-secondary);
}

.ghost-btn:hover {
  background: rgba(242, 237, 228, 0.1);
  color: var(--ink-primary);
  border-color: rgba(242, 237, 228, 0.28);
}

.primary-btn {
  padding: 0.78rem 1.75rem;
  background: linear-gradient(135deg, #e0b065 0%, #bf893b 100%);
  border: 1px solid rgba(255, 229, 178, 0.55);
  color: #120e08;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 28px rgba(217, 165, 87, 0.22);
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(217, 165, 87, 0.32);
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  padding: 0.72rem 1.35rem;
  background: rgba(15, 19, 30, 0.72);
  border: 1px solid var(--border-subtle);
  color: var(--ink-primary);
}

.secondary-btn:hover {
  background: rgba(26, 33, 52, 0.85);
  border-color: rgba(217, 165, 87, 0.45);
}

/* Main Stage Container */
.stage-root {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stage-view {
  animation: stageEnter 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes stageEnter {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kicker {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: 0.55rem;
}

.stage-header {
  max-width: 740px;
  margin-bottom: 1.85rem;
  padding: 1.15rem 1.35rem;
  border-radius: 14px;
  background: rgba(7, 9, 15, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(247, 243, 235, 0.08);
}

.stage-header h1,
.stage-header h2 {
  margin: 0 0 0.7rem;
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.16;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
  text-shadow: 0 2px 10px rgba(4, 6, 10, 0.85);
}

.stage-header h1 {
  font-size: clamp(2.1rem, 4.4vw, 3.35rem);
}

.stage-header h2 {
  font-size: clamp(1.7rem, 3.2vw, 2.45rem);
}

.stage-lead {
  margin: 0;
  font-size: 1.04rem;
  line-height: 1.65;
  color: var(--ink-secondary);
}

/* Procedural GPU Material Cards */
.gpu-card {
  position: relative;
  border-radius: var(--radius-card);
  padding: 1.35rem 1.45rem;
  background: linear-gradient(
    180deg,
    rgba(7, 9, 15, 0.32) 0%,
    rgba(7, 9, 15, 0.56) 45%,
    rgba(7, 9, 15, 0.74) 100%
  );
  border: 1px solid rgba(247, 243, 235, 0.14);
  color: var(--ink-primary);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), border-color 220ms ease;
}

body.css-fallback .gpu-card {
  background: linear-gradient(155deg, rgba(22, 27, 40, 0.95), rgba(10, 13, 20, 0.97));
  border-color: rgba(247, 243, 235, 0.2);
}

.gpu-card.is-clickable {
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
}

.gpu-card.is-clickable:hover {
  transform: translateY(-3px);
}

.gpu-card.is-selected {
  transform: translateY(-2px);
  border-color: rgba(245, 201, 120, 0.65);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-gold);
  background: var(--text-scrim);
  padding: 0.24rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(245, 201, 120, 0.24);
}

.card-chip {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: rgba(7, 9, 15, 0.84);
  border: 1px solid rgba(247, 243, 235, 0.22);
  color: var(--ink-primary);
}

.gpu-card h3 {
  display: inline-block;
  margin: 0 0 0.65rem;
  padding: 0.2rem 0.65rem;
  border-radius: 8px;
  background: var(--text-scrim);
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.32rem;
  color: var(--ink-primary);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

.gpu-card p {
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--text-scrim);
  font-size: 0.95rem;
  line-height: 1.58;
  color: var(--ink-primary);
}

.gpu-card .verdict-lead,
.gpu-card .verdict-title {
  background: var(--text-scrim);
  border-radius: 10px;
}

.gpu-card .verdict-title {
  display: inline-block;
  padding: 0.3rem 0.85rem;
}

/* Threshold */
.threshold-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.8rem 0 2rem;
}

.resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  border-radius: 14px;
  background: rgba(217, 165, 87, 0.1);
  border: 1px solid rgba(217, 165, 87, 0.35);
}

.resume-banner p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink-primary);
}

/* Stage I: Calibration Pillars */
.pillars-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.pillars-grid .pillar-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.pillar-prompt {
  font-size: 0.91rem !important;
  color: var(--ink-secondary) !important;
  margin-bottom: 0.85rem !important;
}

.slider-group {
  display: grid;
  gap: 0.85rem;
  padding: 0.8rem 0.9rem;
  border-radius: 10px;
  background: rgba(7, 9, 15, 0.82);
  border: 1px solid rgba(247, 243, 235, 0.1);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.36rem;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  color: var(--ink-primary);
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--accent-gold);
  font-weight: 600;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(247, 243, 235, 0.24);
  outline: none;
  cursor: pointer;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 2px solid #0b0e16;
  box-shadow: 0 0 12px rgba(217, 165, 87, 0.55);
  transition: transform 140ms ease;
}

input[type='range']::-webkit-slider-thumb:hover {
  transform: scale(1.16);
}

input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-gold);
  border: 2px solid #0b0e16;
  box-shadow: 0 0 12px rgba(217, 165, 87, 0.55);
}

/* Stage II: Choice Grid & Prompts */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.1rem;
}

.fracture-callout {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: rgba(11, 14, 22, 0.72);
  border: 1px solid rgba(217, 165, 87, 0.35);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--accent-gold);
  margin-bottom: 1.15rem;
}

.prompts-stack {
  display: grid;
  gap: 1rem;
}

.prompt-field {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.prompt-field label {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  background: var(--text-scrim);
  font-family: var(--font-serif);
  font-size: 1.12rem;
  color: var(--ink-primary);
}

.prompt-field textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(7, 9, 15, 0.86);
  border: 1px solid rgba(247, 243, 235, 0.24);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.5;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.prompt-field textarea::placeholder {
  color: var(--ink-muted);
}

.prompt-field textarea:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(217, 165, 87, 0.16);
}

/* Stage Footer Nav */
.stage-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(242, 237, 228, 0.1);
}

/* Stage III: Synthesis Dossier */
.synthesis-layout {
  display: grid;
  gap: 1.25rem;
}

.verdict-card {
  padding: 1.85rem 2rem;
}

.verdict-title {
  margin: 0.25rem 0 0.8rem;
  font-family: var(--font-serif);
  font-size: clamp(1.85rem, 3.5vw, 2.7rem);
  font-weight: 400;
  line-height: 1.15;
}

.verdict-lead {
  font-size: 1.12rem !important;
  color: #f8dfb1 !important;
  margin-bottom: 0.85rem !important;
}

.synthesis-columns {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 1.25rem;
}

.glass-panel {
  padding: 1.5rem 1.6rem;
  border-radius: var(--radius-card);
  background: var(--panel-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
}

.glass-panel h3 {
  margin: 0 0 0.85rem;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.35rem;
}

.mirror-copy p {
  margin: 0 0 0.95rem;
  font-size: 0.96rem;
  line-height: 1.68;
  color: var(--ink-secondary);
}

.mirror-copy p:last-child {
  margin-bottom: 0;
}

.tradeoff-box {
  display: grid;
  gap: 0.85rem;
}

.tradeoff-item {
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: rgba(7, 9, 15, 0.55);
  border: 1px solid rgba(242, 237, 228, 0.1);
}

.tradeoff-item strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: 0.3rem;
}

.tradeoff-item p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink-secondary);
}

.experiments-list {
  display: grid;
  gap: 0.85rem;
}

.experiment-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  align-items: start;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  background: rgba(7, 9, 15, 0.52);
  border: 1px solid rgba(242, 237, 228, 0.12);
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.experiment-item:hover {
  border-color: rgba(217, 165, 87, 0.42);
}

.experiment-item input[type='checkbox'] {
  margin-top: 0.25rem;
  width: 18px;
  height: 18px;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

.experiment-item.is-checked {
  border-color: rgba(89, 201, 180, 0.45);
  background: rgba(89, 201, 180, 0.08);
}

.experiment-item h4 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-primary);
}

.experiment-item p {
  margin: 0;
  font-size: 0.89rem;
  line-height: 1.55;
  color: var(--ink-secondary);
}

/* Pillar Balance Bars */
.balance-list {
  display: grid;
  gap: 0.75rem;
}

.balance-row {
  display: grid;
  gap: 0.28rem;
}

.balance-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
}

.balance-nums {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.balance-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(242, 237, 228, 0.1);
  overflow: hidden;
}

.balance-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #bf893b, #e6be7a);
}

.balance-marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  background: #f2ede4;
  border-radius: 2px;
}

.export-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

/* History Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 6, 10, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: 100%;
  max-width: 640px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 1.6rem;
  border-radius: 18px;
  background: #0e121c;
  border: 1px solid rgba(242, 237, 228, 0.16);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.6rem;
}

.modal-note {
  margin: 0.5rem 0 1.2rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.history-list {
  display: grid;
  gap: 0.75rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.05rem;
  border-radius: 12px;
  background: rgba(242, 237, 228, 0.04);
  border: 1px solid rgba(242, 237, 228, 0.1);
}

.history-item h4 {
  margin: 0 0 0.2rem;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.1rem;
}

.history-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.history-btns {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  background: #171d2c;
  border: 1px solid rgba(217, 165, 87, 0.5);
  color: var(--ink-primary);
  font-size: 0.86rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

/* Responsive */
@media (max-width: 820px) {
  .topbar {
    flex-wrap: wrap;
    padding: 0.8rem 1rem;
  }

  .stage-rail {
    order: 3;
    width: 100%;
    justify-content: center;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(242, 237, 228, 0.06);
  }

  .threshold-grid,
  .pillars-grid,
  .choice-grid,
  .synthesis-columns {
    grid-template-columns: 1fr;
  }

  .stage-root {
    padding: 1.5rem 1rem 3rem;
  }
}

/* Clean Print / PDF Output */
@media print {
  .sanctuary-mount,
  .material-canvas,
  .topbar,
  .export-bar,
  .stage-nav,
  .modal-backdrop,
  .toast {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #111111 !important;
  }

  .stage-root {
    max-width: 100%;
    padding: 0;
  }

  .gpu-card,
  .glass-panel,
  .tradeoff-item,
  .experiment-item {
    background: #ffffff !important;
    color: #111111 !important;
    border: 1px solid #cccccc !important;
    box-shadow: none !important;
  }

  .kicker,
  .card-tag,
  .verdict-lead,
  .tradeoff-item strong {
    color: #5c3d0c !important;
  }

  .stage-lead,
  .mirror-copy p,
  .gpu-card p,
  .experiment-item p,
  .tradeoff-item p {
    color: #222222 !important;
  }
}
