/* Codex Grid - Enhanced */

@media (max-width: 520px) {
  .session-chronicle-header, .quest-dashboard-header {
    flex-direction: column;
  }

  .session-chronicle-metrics, .quest-dashboard-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .session-chronicle-path-list,
  .quest-dashboard-focus-list {
    grid-template-columns: 1fr;
  }

  .session-chronicle-actions .btn-secondary,
  .quest-dashboard-actions .btn-secondary {
    width: 100%;
  }
}

/* Quest Journal Cards - Enhanced */

.thread-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all 0.2s;
  border-left: 4px solid var(--border-subtle);
}

.thread-card.is-selected {
  border-color: rgba(216, 167, 58, 0.45);
  border-left-color: var(--accent-reference);
  box-shadow: 0 0 0 1px rgba(216, 167, 58, 0.12);
}

.thread-card:hover {
  border-left-color: var(--accent-reference);
  background: var(--bg-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 1rem;
}

.thread-header h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  margin: 0;
  color: var(--text-primary);
  font-weight: 600;
  flex: 1;
}

.thread-body {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.thread-objectives {
  display: grid;
  gap: 0.55rem;
  margin: 0.85rem 0;
  padding: 0.85rem;
  border: 1px solid rgba(216, 167, 58, 0.22);
  border-radius: var(--radius-md);
  background: rgba(216, 167, 58, 0.055);
}

.thread-objectives.compact {
  padding: 0.65rem;
  gap: 0.45rem;
}

.thread-objectives h4 {
  margin: 0;
  color: var(--accent-reference);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.thread-objectives ul {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.thread-objective {
  display: grid;
  grid-template-columns: minmax(4.25rem, max-content) 1fr;
  gap: 0.55rem;
  align-items: start;
  min-width: 0;
  color: var(--text-primary);
  line-height: 1.35;
}

.thread-objective-state {
  display: inline-flex;
  justify-content: center;
  min-width: 4.25rem;
  padding: 0.18rem 0.42rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.thread-objective-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.thread-objective.next .thread-objective-state,
.thread-objective.active .thread-objective-state {
  border-color: rgba(104, 199, 189, 0.38);
  color: var(--accent-teal);
}

.thread-objective.review .thread-objective-state {
  border-color: rgba(216, 167, 58, 0.45);
  color: var(--accent-reference);
}

.thread-objective.blocked .thread-objective-state {
  border-color: rgba(248, 113, 113, 0.42);
  color: var(--error-color);
}

.thread-objective.done .thread-objective-state {
  border-color: rgba(74, 222, 128, 0.35);
  color: var(--success-color);
}

.thread-source-card {
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent-teal);
  border-radius: var(--radius-md);
  background: rgba(104, 199, 189, 0.06);
  padding: 0.9rem;
  display: grid;
  gap: 0.5rem;
}

.thread-source-card h4,
.thread-source-card p {
  margin: 0;
}

.thread-source-card h4 {
  color: var(--text-primary);
  font-size: 0.95rem;
}

.thread-source-card p {
  color: var(--text-secondary);
  line-height: 1.45;
}

.thread-dossier-summary {
  color: var(--text-primary) !important;
  font-size: 0.95rem;
  line-height: 1.6;
}

.thread-transition-readiness {
  border: 1px solid rgba(104, 199, 189, 0.22);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(104, 199, 189, 0.07), rgba(255, 255, 255, 0.025));
  padding: 0.9rem;
  display: grid;
  gap: 0.75rem;
}

.thread-transition-header,
.thread-transition-top,
.thread-transition-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-transition-header,
.thread-transition-top {
  justify-content: space-between;
}

.thread-transition-header h4 {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.98rem;
}

.thread-transition-header span {
  color: var(--text-muted);
  font-size: 0.76rem;
  text-align: right;
}

.thread-transition-question,
.thread-transition-condition,
.thread-transition-visibility,
.thread-transition-decision {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: var(--radius-md);
  background: rgba(11, 18, 32, 0.32);
  padding: 0.72rem;
  display: grid;
  gap: 0.45rem;
}

.thread-transition-condition.ready,
.thread-transition-question.ready,
.thread-transition-visibility.ready {
  border-color: rgba(104, 199, 189, 0.24);
}

.thread-transition-condition.review,
.thread-transition-decision.priority-high,
.thread-transition-visibility.review {
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.055);
}

.thread-transition-decision.priority-medium,
.thread-transition-condition.open,
.thread-transition-question.open {
  border-color: rgba(216, 167, 58, 0.28);
}

.thread-transition-top strong {
  min-width: 0;
  color: var(--text-primary);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.thread-transition-question p,
.thread-transition-condition p,
.thread-transition-visibility p,
.thread-transition-decision p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.thread-transition-chip {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.16rem 0.42rem;
  color: var(--text-muted);
  font-size: 0.69rem;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
}

.thread-transition-chip.ready {
  color: var(--accent-teal);
  border-color: rgba(104, 199, 189, 0.34);
}

.thread-transition-chip.review {
  color: var(--error-color);
  border-color: rgba(248, 113, 113, 0.34);
}

.thread-transition-chip.open {
  color: var(--accent-reference);
  border-color: rgba(216, 167, 58, 0.36);
}

.thread-transition-checklist,
.thread-transition-decisions {
  display: grid;
  gap: 0.55rem;
}

.thread-timeline-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(11, 18, 32, 0.34);
  padding: 0.9rem;
  display: grid;
  gap: 0.85rem;
}

.thread-timeline-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.thread-timeline-header h4 {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.98rem;
}

.thread-timeline-header span {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: right;
}

.thread-timeline {
  display: grid;
  gap: 0;
}

.thread-timeline-row {
  position: relative;
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  gap: 0.7rem;
  padding-bottom: 0.85rem;
}

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

.thread-timeline-row:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 0.95rem;
  bottom: -0.1rem;
  width: 1px;
  background: var(--border-subtle);
}

.thread-timeline-marker {
  position: relative;
  z-index: 1;
  width: 0.82rem;
  height: 0.82rem;
  margin-top: 0.22rem;
  border: 2px solid var(--accent-teal);
  border-radius: 50%;
  background: var(--bg-panel);
}

.thread-timeline-row.completed .thread-timeline-marker {
  border-color: #86efac;
}

.thread-timeline-row.warning .thread-timeline-marker {
  border-color: var(--accent-reference);
}

.thread-timeline-row.info .thread-timeline-marker {
  border-color: #7dd3fc;
}

.thread-timeline-body {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.035);
  padding: 0.75rem;
  display: grid;
  gap: 0.55rem;
}

.thread-timeline-kicker,
.thread-timeline-facts,
.thread-timeline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.thread-timeline-kicker {
  justify-content: space-between;
}

.thread-timeline-type,
.thread-timeline-facts span {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.18rem 0.45rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.thread-timeline-type {
  color: var(--accent-teal);
  border-color: rgba(104, 199, 189, 0.34);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.thread-timeline-kicker > span:last-child {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.thread-timeline-body p {
  margin: 0;
  color: var(--text-primary);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.thread-timeline-actions .btn-secondary {
  max-width: 100%;
}

.thread-related-context {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.9rem;
  display: grid;
  gap: 0.75rem;
}

.thread-related-context-header,
.thread-related-top,
.thread-related-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-related-context-header {
  justify-content: space-between;
}

.thread-related-context-header h4 {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.98rem;
}

.thread-related-context-header span,
.thread-related-top span {
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.thread-related-entity-list,
.thread-related-scene-list {
  display: grid;
  gap: 0.55rem;
}

.thread-related-entity,
.thread-related-scene {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.035);
  padding: 0.72rem;
  display: grid;
  gap: 0.45rem;
}

.thread-related-top {
  justify-content: space-between;
}

.thread-related-top strong {
  min-width: 0;
  color: var(--text-primary);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.thread-related-entity p,
.thread-related-scene p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.thread-related-actions .btn-secondary {
  max-width: 100%;
}

.thread-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* World and quest reference views */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-subtle);
}

.mobile-scroll-hint {
  display: none;
}

.filter-btn {
  min-height: 36px;
  padding: 0.42rem 0.72rem;
  border: 1px solid #c9bfad;
  border-radius: 999px;
  background: transparent;
  color: var(--weave-muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: var(--weave-pine);
  color: var(--weave-pine-deep);
}

.filter-btn.active,
.filter-btn[aria-pressed="true"] {
  border-color: var(--weave-pine);
  background: var(--weave-pine);
  color: #fffdf8;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.quest-workbench-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.8rem 1rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--weave-rule);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.66);
}

.quest-search-field {
  flex: 1 1 260px;
}

.thread-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 285px), 1fr));
  gap: 1rem;
}

.thread-card {
  min-height: 190px;
  padding: 1.15rem;
  border: 1px solid var(--weave-rule);
  border-radius: 8px;
  background: var(--weave-paper);
  box-shadow: 0 5px 18px rgba(52, 43, 31, 0.055);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.thread-card h4 {
  color: var(--weave-ink);
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 650;
}

/* Curated field-guide and quest-journal finish */

#codexView,
#questsView {
  max-width: 1240px;
}

#codexView .view-header {
  align-items: flex-end;
}

@media (max-width: 1023px) {
  #codexView .view-header {
    align-items: flex-start;
  }
}

.filter-bar {
  gap: 0.2rem;
  padding: 0.25rem;
  border-color: rgba(135, 101, 47, 0.18);
  border-radius: var(--radius-md);
  background: var(--weave-paper-soft);
  box-shadow: inset 0 1px 2px rgba(52, 43, 31, 0.035);
}

.filter-btn {
  min-height: 38px;
  padding: 0.45rem 0.78rem;
  border: 0;
  border-radius: 6px;
  color: var(--weave-muted);
  font-size: 0.77rem;
  font-weight: 650;
}

.filter-btn:hover {
  border: 0;
  background: rgba(255, 254, 250, 0.64);
}

.filter-btn.active,
.filter-btn[aria-pressed="true"] {
  border: 0;
  background: var(--weave-pine);
  color: var(--weave-inverse);
  box-shadow: 0 3px 9px rgba(23, 41, 37, 0.14);
}

.quest-workbench-toolbar {
  gap: 0.9rem 1.25rem;
  margin-bottom: 1.5rem;
  padding: 1.1rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.thread-grid {
  gap: 1.1rem;
}

.thread-card h3, .thread-card h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.012em;
}

.thread-card:hover {
  border-color: rgba(135, 101, 47, 0.46);
  box-shadow: 0 18px 42px rgba(52, 43, 31, 0.11);
  transform: translateY(-2px);
}

.thread-card {
  min-height: 0;
  border-color: rgba(135, 101, 47, 0.2);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--weave-paper-raised);
  box-shadow: var(--weave-shadow-soft);
}

.thread-card.is-completed {
  border-left-color: var(--weave-pine);
  box-shadow: none;
  opacity: 0.82;
}

.thread-header h3 {
  margin: 0;
  font-size: 1.42rem;
}

.thread-grid > .empty-state.compact {
  position: relative;
  grid-column: 1 / -1;
  display: grid;
  width: 100%;
  max-width: none;
  min-height: 280px;
  place-content: center;
  justify-items: center;
  overflow: hidden;
  margin: 0;
  padding: 5.5rem 2rem 2rem;
  border: 1px solid rgba(135, 101, 47, 0.18);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 16%, rgba(193, 154, 85, 0.11), transparent 9rem),
    rgba(255, 253, 248, 0.56);
  text-align: center;
}

.thread-grid > .empty-state.compact::before {
  content: "";
  position: absolute;
  top: 2rem;
  left: 50%;
  width: 48px;
  height: 48px;
  background: var(--weave-bronze);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.55'%3E%3Cpath d='M4 5.5c2.8-.9 5.4-.2 8 1.8v12c-2.6-2-5.2-2.7-8-1.8v-12ZM20 5.5c-2.8-.9-5.4-.2-8 1.8v12c2.6-2 5.2-2.7 8-1.8v-12Z'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
  transform: translateX(-50%);
}

.archive-insights {
  border-color: rgba(135, 101, 47, 0.2);
  background: rgba(255, 253, 248, 0.52);
}

#questJournalList.thread-grid {
  display: block;
}

.quest-mobile-lead {
  display: none;
}

.thread-card.is-compact {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "header actions"
    "meta actions"
    "body actions";
  gap: 0.35rem 1rem;
  align-items: center;
  padding: 0.9rem 1rem;
  box-shadow: none;
}

.thread-card.is-compact .thread-header {
  grid-area: header;
  margin: 0;
}

.thread-card.is-compact .thread-body {
  grid-area: body;
  margin: 0;
}

#questsView > .quest-workbench-toolbar {
  padding-block: 0.75rem;
}

#questsView > .quest-workbench-toolbar .filter-bar,
#codexView > .view-header .filter-bar {
  background: transparent;
  box-shadow: none;
}

@media (max-width: 720px) {
  .quest-mobile-lead {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .quest-mobile-lead[hidden] {
    display: none;
  }

  .thread-card.is-compact {
    display: block;
  }

  .thread-card.is-compact .thread-header,
  .thread-card.is-compact .thread-card-meta,
  .thread-card.is-compact .thread-body {
    margin-bottom: 0.65rem;
  }

}

/* Published Threads use the reader projection; the DM journal owns draft review. */
#questsView.is-thread-page > .view-header,
#questsView.is-thread-page > .quest-workbench-toolbar,
#questsView.is-thread-page > .quest-journal-meta { display: none; }
.reader-thread-list { margin: var(--weave-space-5) 0; padding: 0; list-style: none; }
.reader-thread-row { display: grid; grid-template-columns: 6rem minmax(0, 1fr) auto; align-items: center; gap: var(--weave-space-4); padding: var(--weave-space-5) 0; border-bottom: 1px solid var(--weave-color-rule); }
.reader-thread-kind { color: var(--weave-color-action); font: var(--weave-weight-semibold) var(--weave-text-sm) / var(--weave-leading-ui) var(--weave-font-ui); }
.reader-thread-title { color: var(--weave-color-ink); font: var(--weave-weight-medium) var(--weave-text-xl) / var(--weave-leading-snug) var(--weave-font-display); }
.reader-thread-title:hover { color: var(--weave-color-action); }
.reader-thread-review { color: var(--weave-color-action); }
.reader-thread-page a { color: var(--weave-color-action); text-decoration: underline; text-underline-offset: .12em; }
.reader-thread-page a:hover { color: var(--weave-color-action-hover); }
#questsView .control-label { text-transform: none; letter-spacing: normal; color: var(--weave-color-action); }
#questsView .filter-btn.active { background: var(--weave-color-selected); color: var(--weave-color-action); }
.reader-thread-situation { grid-column: 2; color: var(--weave-color-secondary); }
.reader-thread-situation p { margin: 0 0 var(--weave-space-2); }
.reader-thread-section pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-thread-section .meta { overflow-wrap: anywhere; }
.reader-thread-row .weave-track { max-width: 100%; grid-column: 3; grid-row: 2; }
.reader-thread-page { max-width: var(--weave-measure-prose); padding-bottom: var(--weave-space-6); overflow-wrap: anywhere; }
.reader-thread-header { margin: var(--weave-space-6) 0; }
.reader-thread-header h1 { font: var(--weave-weight-semibold) var(--weave-text-3xl) / var(--weave-leading-tight) var(--weave-font-display); margin: var(--weave-space-3) 0; }
.reader-thread-status { color: var(--weave-color-secondary); font-size: var(--weave-text-sm); }
.reader-thread-status.is-completed { color: var(--weave-color-success); }
.reader-thread-status.is-failed { color: var(--weave-color-danger); }
.reader-thread-section { margin: var(--weave-space-6) 0; }
.reader-thread-section h2 { color: var(--weave-color-action); font: var(--weave-weight-semibold) var(--weave-text-xl) / var(--weave-leading-snug) var(--weave-font-display); margin: 0 0 var(--weave-space-3); }
.reader-thread-section p, .reader-thread-section li { font: var(--weave-text-lg) / var(--weave-leading-reading) var(--weave-font-reading); }
.reader-thread-section p { margin: 0 0 var(--weave-space-3); }
.reader-thread-refs { display: flex; flex-wrap: wrap; gap: var(--weave-space-2) var(--weave-space-5); list-style: none; padding: 0; }
.reader-thread-trail { padding: 0; list-style: none; }
.reader-thread-trail li { position: relative; padding: 0 0 var(--weave-space-5) var(--weave-space-6); }
.reader-thread-trail li::before { content: ""; position: absolute; left: 0; top: var(--weave-space-2); width: var(--weave-space-2); height: var(--weave-space-2); border: 1px solid var(--weave-color-secondary); border-radius: var(--weave-radius-full); }
.reader-thread-trail li::after { content: ""; position: absolute; left: var(--weave-space-1); top: var(--weave-space-5); bottom: 0; border-left: 1px solid var(--weave-color-rule); }
.reader-thread-trail li:last-child::after { display: none; }
.reader-thread-trail .is-completed::before { background: var(--weave-color-secondary); }
.reader-thread-trail .is-fresh::before { background: var(--weave-color-spark); border-color: var(--weave-color-spark); }
.reader-thread-trail h3 { margin: 0 0 var(--weave-space-2); font: var(--weave-weight-medium) var(--weave-text-lg) / var(--weave-leading-snug) var(--weave-font-display); }
.reader-thread-trail .reader-thread-step-meta { display: flex; flex-wrap: wrap; gap: var(--weave-space-3); color: var(--weave-color-secondary); font: var(--weave-text-sm) / var(--weave-leading-ui) var(--weave-font-ui); }
@media (max-width: 640px) {
  .reader-thread-row { grid-template-columns: minmax(0, 1fr) auto; gap: var(--weave-space-2); }
  .reader-thread-row > .reader-thread-kind { grid-column: 1 / -1; }
  .reader-thread-situation { grid-column: 1; }
  .reader-thread-row .weave-track { grid-column: 2; grid-row: 3; }
  .reader-thread-title { font-size: var(--weave-text-lg); }
}
