/* ═══════════════════════════════════════════════
   THE LOREBOOK COMPENDIUM — CHAPTER COMPONENTS
   aceenvw

   Loaded by the content chapters only. Home and
   archive do not need these rules.
   Tokens come from style.css; nothing here defines
   its own palette.
   ═══════════════════════════════════════════════ */

/* ─── entry-card — an illustrative lorebook entry ─── */
.entry-card {
  margin: 1.6rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.entry-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.9rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.entry-card-head .label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.entry-card-head .name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text);
}

.entry-field {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.entry-card > .entry-field:last-child { border-bottom: 0; }

.entry-field > dt {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  padding-top: 0.2rem;
}

.entry-field > dd {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-secondary);
}

.entry-field .keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry-field .keys li {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 2px 8px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-pill);
  background: var(--code-bg);
  color: var(--code-text);
}

.entry-field .body-text b {
  display: block;
  margin-top: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--accent-2);
}
.entry-field .body-text b:first-child { margin-top: 0; }

@media (max-width: 620px) {
  .entry-field { grid-template-columns: 1fr; gap: 0.35rem; }
  .entry-field > dt { padding-top: 0; }
}

/* ─── ctx-bar — what shares the context window ─── */
.ctx-bar-wrap {
  margin: 1.6rem 0;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.ctx-bar-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.ctx-bar {
  display: flex;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ctx-bar span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bg);
  white-space: nowrap;
  overflow: hidden;
}

.ctx-bar .seg-sys   { flex: 0 0 10%; background: var(--text-dim); }
.ctx-bar .seg-card  { flex: 0 0 16%; background: var(--accent-2); }
.ctx-bar .seg-lore  { flex: 0 0 22%; background: var(--accent); }
.ctx-bar .seg-chat  { flex: 1 1 auto; background: var(--border-hover); color: var(--text); }
.ctx-bar .seg-reply { flex: 0 0 12%; background: var(--text-secondary); }

.ctx-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem 1rem;
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
}

.ctx-legend li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.ctx-legend i {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  font-style: normal;
}

.ctx-legend .sw-sys   { background: var(--text-dim); }
.ctx-legend .sw-card  { background: var(--accent-2); }
.ctx-legend .sw-lore  { background: var(--accent); }
.ctx-legend .sw-chat  { background: var(--border-hover); }
.ctx-legend .sw-reply { background: var(--text-secondary); }

.ctx-legend b { color: var(--text); font-weight: 600; }

@media (max-width: 560px) {
  .ctx-bar span { font-size: 0; }
  .ctx-bar { height: 22px; }
}

/* ─── tier-ladder — keyword specificity from narrow to ambient ─── */
.tier-ladder {
  display: grid;
  gap: 0.65rem;
  margin: 1.6rem 0;
}

.tier {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.tier-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--bg);
  background: var(--accent-2);
}

.tier:nth-child(2) .tier-num {
  background: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 72%, var(--accent));
}
.tier:nth-child(3) .tier-num {
  background: var(--accent);
  background: color-mix(in srgb, var(--accent) 72%, var(--accent-2));
}
.tier:nth-child(4) .tier-num { background: var(--accent); }

.tier-body { padding: 0.85rem 1rem; }

.tier-body h3 {
  margin: 0 0 0.3rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
}

.tier-body p {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.6;
}

.tier-examples {
  display: block;
  margin-top: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

@media (max-width: 520px) {
  .tier { grid-template-columns: 2.75rem 1fr; }
}

/* ─── message audit — a small corpus of ordinary chat lines ─── */
.audit-messages {
  counter-reset: sample;
  display: grid;
  gap: 0.5rem;
  margin: 1.4rem 0;
  padding: 0;
  list-style: none;
}

.audit-messages li {
  counter-increment: sample;
  position: relative;
  margin: 0;
  padding: 0.75rem 1rem 0.75rem 3.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.audit-messages li::before {
  content: "M" counter(sample, decimal-leading-zero);
  position: absolute;
  left: 0.9rem;
  top: 0.82rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.word-tally {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 1rem 0 1.5rem;
}

.word-tally span {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.word-tally b { color: var(--accent); font-weight: 500; }

/* ─── regex-card — copyable pattern with positive and negative cases ─── */
.regex-card {
  margin: 1.4rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.regex-card-head {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-elevated);
}

.regex-card .codeblock {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.regex-tests {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}

.regex-test-col { padding: 0.75rem 1rem; }
.regex-test-col + .regex-test-col { border-left: 1px solid var(--border); }

.regex-test-label {
  display: block;
  margin-bottom: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.regex-test-col--yes .regex-test-label { color: var(--ok); }
.regex-test-col--no .regex-test-label { color: var(--bad); }

.regex-test-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.regex-test-list li {
  margin: 0;
  padding: 0.18rem 0.5rem;
  border: 1px solid var(--code-border);
  border-radius: var(--radius-pill);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--code-text);
}

@media (max-width: 600px) {
  .regex-tests { grid-template-columns: 1fr; }
  .regex-test-col + .regex-test-col {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

/* ─── test-sentence — paired activation checks ─── */
.test-sentence {
  margin: 1rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow-wrap: anywhere;
}

.test-sentence--safe {
  border-left-color: var(--ok);
  background: var(--ok-faint);
}

.test-sentence--fires {
  border-left-color: var(--bad);
  background: var(--bad-faint);
}

.test-sentence-head {
  margin-bottom: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.test-sentence--safe .test-sentence-head { color: var(--ok); }
.test-sentence--fires .test-sentence-head { color: var(--bad); }

.test-sentence blockquote {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.5vw, 1.18rem);
  line-height: 1.55;
  color: var(--text);
}

.test-sentence p {
  margin: 0.65rem 0 0;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

@media (max-width: 420px) {
  .test-sentence { padding: 0.85rem 0.9rem; }
}
