.knowledge-forge {
  margin: 18px 0;
  border: 1px solid rgba(167, 139, 250, .34);
  border-radius: 28px;
  padding: clamp(16px, 3vw, 26px);
  background:
    radial-gradient(circle at 9% 0%, rgba(56, 189, 248, .18), transparent 24rem),
    radial-gradient(circle at 94% 100%, rgba(167, 139, 250, .16), transparent 25rem),
    rgba(9, 16, 34, .84);
  box-shadow: var(--shadow);
  scroll-margin-top: 86px;
}

.forge-head,
.forge-head-actions,
.forge-metrics,
.forge-project-actions,
.forge-editor-tools,
.forge-dialog-actions,
.forge-tablist,
.forge-annotation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.forge-head {
  justify-content: space-between;
  gap: 18px;
}

.forge-head-copy { max-width: 780px; }
.forge-head h2 {
  margin: 7px 0 7px;
  font-size: clamp(1.45rem, 3vw, 2.3rem);
  letter-spacing: -.045em;
}
.forge-head p {
  margin: 0;
  color: #cbd5e1;
  line-height: 1.55;
}
.forge-head .eyebrow { color: #c4b5fd; }

.forge-metrics {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.forge-metric {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 6, 23, .42);
}
.forge-metric b { display: block; font-size: 1.35rem; }
.forge-metric span { color: var(--muted); font-size: .8rem; }

.forge-principle {
  margin: 0 0 16px;
  padding: 11px 13px;
  border-left: 4px solid var(--gold);
  border-radius: 0 14px 14px 0;
  background: rgba(251, 191, 36, .08);
  color: #fde68a;
  line-height: 1.5;
}

.forge-projects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.forge-project {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(15, 23, 42, .72);
}
.forge-project img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #020617;
}
.forge-project-body { padding: 13px; display: grid; gap: 9px; }
.forge-project h3 { margin: 0; line-height: 1.2; }
.forge-project p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.forge-project-progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, .18);
}
.forge-project-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--green));
}
.forge-empty {
  grid-column: 1 / -1;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.forge-capabilities {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 16px;
}
.forge-capabilities span {
  padding: 6px 9px;
  border: 1px solid rgba(56, 189, 248, .22);
  border-radius: 999px;
  color: #bae6fd;
  background: rgba(14, 165, 233, .07);
  font-size: .75rem;
}

.forge-dialog {
  width: min(1500px, calc(100% - 12px));
  height: calc(100dvh - 12px);
  max-height: calc(100dvh - 12px);
  margin: 6px auto;
}
.forge-dialog[open] {
  display: flex;
  flex-direction: column;
}
.forge-dialog .modal-body {
  max-height: none;
  min-height: 0;
  flex: 1;
  padding: 0;
}
.forge-dialog-title small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}
.forge-tablist {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(2, 6, 23, .94);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
.forge-tab { flex: 0 0 auto; }
.forge-tab[aria-selected="true"] {
  color: #020617;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.forge-tabpanel { padding: 15px; }
.forge-tabpanel[hidden] { display: none !important; }

.forge-attachments-head,
.forge-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
}
.forge-attachments-head small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}
.forge-attachments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 0 10px;
}
.forge-attachment {
  width: 126px;
  flex: 0 0 126px;
  display: grid;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(15, 23, 42, .66);
  cursor: pointer;
  text-align: left;
}
.forge-attachment[aria-pressed="true"] {
  border-color: var(--accent);
  color: #e0f2fe;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, .17);
}
.forge-attachment img {
  width: 100%;
  height: 72px;
  border-radius: 9px;
  background: #020617;
  object-fit: contain;
}
.forge-attachment b,
.forge-attachment small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.forge-attachment b { font-size: .75rem; }
.forge-attachment small { font-size: .67rem; }

.forge-image-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(260px, .65fr);
  gap: 14px;
  align-items: start;
}
.forge-canvas-shell {
  position: relative;
  min-height: 280px;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px;
  background:
    linear-gradient(45deg, rgba(148, 163, 184, .08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, .08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, .08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, .08) 75%),
    #020617;
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
#forgeCanvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 68vh;
  margin: 0;
  border: 0;
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
}
.forge-editor-panel {
  display: grid;
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(15, 23, 42, .66);
}
.forge-editor-panel h3 { margin: 0; }
.forge-editor-panel p { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.forge-tool.active {
  border-color: var(--gold);
  color: #fde68a;
  background: rgba(251, 191, 36, .11);
}
.forge-color {
  width: 46px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
}
.forge-editor-status {
  min-height: 1.4em;
  color: #bae6fd;
  font-size: .83rem;
}

.forge-ocr-grid {
  display: grid;
  grid-template-columns: minmax(250px, .6fr) minmax(0, 1.4fr);
  gap: 14px;
}
.forge-ocr-card,
.forge-mission-intro {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(15, 23, 42, .62);
}
.forge-ocr-card h3,
.forge-mission-intro h3 { margin: 0 0 7px; }
.forge-ocr-card p,
.forge-mission-intro p { color: var(--muted); line-height: 1.5; }
.forge-ocr-progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(148, 163, 184, .12);
}
.forge-ocr-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width .2s ease;
}
#forgeOcrText { min-height: 330px; }
.forge-ocr-status { min-height: 1.5em; color: #bae6fd; }

.forge-missions { display: grid; gap: 12px; margin-top: 12px; }
.forge-mission {
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(15, 23, 42, .68);
}
.forge-mission summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  cursor: pointer;
}
.forge-mission summary::-webkit-details-marker { display: none; }
.forge-mission-number {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(56, 189, 248, .22), rgba(167, 139, 250, .24));
  color: #e0f2fe;
  font-weight: 900;
}
.forge-mission-title { flex: 1; }
.forge-mission-title b { display: block; }
.forge-mission-title small { color: var(--muted); }
.forge-maturity {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #c4b5fd;
  font-size: .74rem;
}
.forge-mission-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 14px 14px;
}
.forge-mission-body label { display: grid; gap: 5px; color: #dbeafe; font-size: .82rem; }
.forge-mission-body label:first-child { grid-column: 1 / -1; }
.forge-mission-body textarea { min-height: 110px; }
.forge-prompt {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border-left: 4px solid var(--accent2);
  border-radius: 0 12px 12px 0;
  background: rgba(167, 139, 250, .09);
  color: #ddd6fe;
  line-height: 1.5;
}

.forge-dialog-actions {
  justify-content: space-between;
  width: 100%;
}
.forge-save-status { color: #bbf7d0; font-size: .83rem; }

.forge-panel-head h3,
.forge-source-columns h4 { margin: 0 0 5px; }
.forge-panel-head p {
  max-width: 850px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.forge-cards-grid,
.forge-temi-grid,
.forge-reviews {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.forge-knowledge-card,
.forge-temi-card,
.forge-review-card,
.forge-source-item,
.forge-causal-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px;
  background: rgba(15, 23, 42, .68);
}
.forge-knowledge-card {
  display: grid;
  gap: 9px;
}
.forge-knowledge-card label {
  display: grid;
  gap: 4px;
  color: #dbeafe;
  font-size: .78rem;
}
.forge-knowledge-card textarea { min-height: 88px; }
.forge-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .72rem;
}
.forge-temi-grid { margin-top: 20px; }
.forge-temi-card h4,
.forge-review-card h4,
.forge-source-item h4,
.forge-causal-card h3 { margin: 0 0 7px; }
.forge-temi-card p,
.forge-review-card p,
.forge-source-item p {
  margin: 5px 0;
  color: var(--muted);
  line-height: 1.48;
}
.forge-temi-options {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}
.forge-temi-options button {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: rgba(2, 6, 23, .46);
  cursor: pointer;
  text-align: left;
}
.forge-temi-options button[data-result="correct"] {
  border-color: var(--green);
  background: rgba(34, 197, 94, .15);
}
.forge-temi-options button[data-result="incorrect"] {
  border-color: var(--red);
  background: rgba(244, 63, 94, .13);
}
.forge-temi-feedback { min-height: 1.4em; color: #bfdbfe; font-size: .8rem; }

.forge-source-search { display: grid; gap: 5px; }
.forge-source-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.forge-source-results {
  display: grid;
  gap: 8px;
  max-height: 52vh;
  overflow: auto;
}
.forge-source-item {
  display: grid;
  gap: 7px;
}
.forge-source-meta {
  color: #c4b5fd;
  font: .68rem/1.45 ui-monospace, monospace;
  overflow-wrap: anywhere;
}
.forge-source-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.forge-peer-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(15, 23, 42, .58);
}
.forge-peer-form label { display: grid; gap: 5px; color: #dbeafe; font-size: .78rem; }
.forge-peer-wide { grid-column: span 2; }
.forge-peer-wide textarea { min-height: 100px; }
.forge-peer-save { align-self: end; min-height: 44px; }
.forge-review-scores {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.forge-review-scores span {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #bae6fd;
  font-size: .7rem;
}

.forge-export-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 15px;
}
.forge-export-card {
  min-height: 120px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, .09), rgba(167, 139, 250, .09)),
    rgba(15, 23, 42, .66);
  cursor: pointer;
  text-align: left;
}
.forge-export-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.forge-export-card b { font-size: 1rem; }
.forge-export-card span { color: var(--muted); line-height: 1.45; }

.forge-gallery-dialog {
  width: min(1320px, calc(100% - 18px));
  max-height: calc(100dvh - 18px);
}
.forge-gallery-dialog .modal-body { max-height: calc(100dvh - 120px); }
.forge-causal-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  margin-top: 13px;
}
.forge-causal-chain {
  display: flex;
  align-items: stretch;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0;
}
.forge-causal-node {
  min-width: 150px;
  max-width: 240px;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px solid rgba(56, 189, 248, .3);
  border-radius: 13px;
  background: rgba(14, 165, 233, .08);
  line-height: 1.4;
  text-align: center;
}
.forge-causal-arrow {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 1.1rem;
}

html.a11y-light .knowledge-forge,
html.a11y-light .forge-project,
html.a11y-light .forge-editor-panel,
html.a11y-light .forge-ocr-card,
html.a11y-light .forge-mission-intro,
html.a11y-light .forge-mission,
html.a11y-light .forge-attachment,
html.a11y-light .forge-knowledge-card,
html.a11y-light .forge-temi-card,
html.a11y-light .forge-review-card,
html.a11y-light .forge-source-item,
html.a11y-light .forge-causal-card,
html.a11y-light .forge-peer-form,
html.a11y-light .forge-export-card {
  color: var(--text);
  background: #fff;
}
html.a11y-light .forge-head p,
html.a11y-light .forge-project p,
html.a11y-light .forge-editor-panel p,
html.a11y-light .forge-ocr-card p,
html.a11y-light .forge-mission-intro p { color: #334e68; }
html.a11y-light .forge-tablist { background: #eef4f8; }
html.a11y-light .forge-canvas-shell { background-color: #eef4f8; }
html.a11y-light .forge-principle { color: #684100; background: #fff8e7; }
html.a11y-light .forge-prompt { color: #3f2f77; background: #f5f3ff; }
html.a11y-light .forge-mission-body label { color: var(--text); }
html.a11y-light .forge-maturity { color: #5946c7; }
html.a11y-light .forge-capabilities span { color: #075985; background: #f0f9ff; }
html.a11y-light .forge-knowledge-card label,
html.a11y-light .forge-peer-form label { color: var(--text); }
html.a11y-light .forge-temi-options button { color: var(--text); background: #f8fafc; }

@media (max-width: 920px) {
  .forge-projects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .forge-image-layout,
  .forge-ocr-grid,
  .forge-source-columns,
  .forge-causal-gallery { grid-template-columns: 1fr; }
  .forge-editor-panel { order: -1; }
  .forge-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .forge-peer-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .forge-projects,
  .forge-metrics,
  .forge-mission-body,
  .forge-cards-grid,
  .forge-temi-grid,
  .forge-export-grid,
  .forge-peer-form { grid-template-columns: 1fr; }
  .forge-mission-body label,
  .forge-mission-body label:first-child,
  .forge-prompt { grid-column: 1; }
  .forge-peer-wide { grid-column: 1; }
  .forge-head-actions .btn { flex: 1 1 100%; }
  .forge-mission summary { align-items: flex-start; }
  .forge-maturity { display: none; }
  .forge-dialog {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  .forge-tabpanel { padding: 11px; }
  .forge-attachments-head,
  .forge-panel-head { align-items: flex-start; flex-direction: column; }
}

@media print {
  .knowledge-forge,
  .forge-dialog { display: none !important; }
}
