/* ============================================================================
 * style.css — unified light editorial palette for setnex.org
 *
 * One stylesheet for the whole site: home, articles, specification.
 * Derived from the blog.css editorial palette (crème + serif + trit colors)
 * and absorbing the home components (trit display, spec-grid, formats, LMODE,
 * link cards). A dedicated spec.css extends this file with long-form prose
 * and table-of-contents styles for rendered specifications.
 *
 * Class contract: this file supports every class currently used in the site
 * index.html and article files, so no HTML restructuring is required when
 * switching to it.
 * ========================================================================== */

:root {
  /* ── Surface ──────────────────────────────────────────────────────────── */
  --bg:          #f6f3ee;          /* page background — warm cream */
  --bg-deep:     #eae5dc;          /* second surface — deeper cream */
  --card-bg:     #ffffff;          /* card surface — crisp white */
  --code-bg:     #1a1714;          /* code blocks — deep brown-black */
  --code-fg:     #e8e2d8;          /* code foreground on dark bg */

  /* ── Ink ──────────────────────────────────────────────────────────────── */
  --ink:         #1a1714;          /* primary text */
  --ink-soft:    #4a453d;          /* secondary text */
  --ink-muted:   #8a847a;          /* tertiary / metadata */
  --rule:        #ccc5b8;          /* borders and rules */

  /* ── Trit semantics — rouge / vert / bleu ─────────────────────────────── */
  --accent-n:    #b44533;          /* N (−1) — rouge brique */
  --accent-z:    #7a8a6a;          /* Z ( 0) — vert sauge */
  --accent-p:    #2a5a8a;          /* P (+1) — bleu d'encre */
  --accent-impl: #8a5a2a;          /* IMPL / warm accent — ambre */

  /* ── Compatibility aliases for existing class contracts ──────────────── */
  /* The home index.html uses .acc and .acc2 for coloured spans.
   * Map them to the trit semantics so that the visual language is
   * consistent with the rest of the site. */
  --accent:      var(--accent-p);  /* primary accent → blue */
  --accent2:     var(--accent-n);  /* secondary accent → red */
  --warn:        var(--accent-impl);

  /* ── Typography ──────────────────────────────────────────────────────── */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'Libre Franklin', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code:    'Source Code Pro', 'JetBrains Mono', ui-monospace, monospace;
}

/* ── Reset & base ──────────────────────────────────────────────────────── */

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

html {
  font-size: 17px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 300;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

::selection {
  background: var(--accent-p);
  color: #fff;
}

a {
  color: var(--accent-p);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(42, 90, 138, 0.3);
  transition: text-decoration-color 0.2s;
}

a:hover {
  text-decoration-color: var(--accent-p);
}

/* ── Layout wrapper ────────────────────────────────────────────────────── */

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 32px;
}

/* ============================================================================
 * HEADER (home page hero)
 * ========================================================================== */

header {
  padding: 72px 0 48px;
  border-bottom: 1px solid var(--rule);
}

.header-meta {
  font-family: var(--font-code);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 24px;
}

.header-meta span {
  color: var(--accent-p);
  font-weight: 600;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

h1 em {
  font-style: italic;
  color: var(--accent-p);
}

.tagline {
  font-size: 1.08rem;
  font-weight: 300;
  color: var(--ink-soft);
  margin-top: 18px;
  max-width: 620px;
  line-height: 1.65;
}

/* ── Badges ────────────────────────────────────────────────────────────── */

.badge-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 32px;
}

.badge {
  font-family: var(--font-code);
  font-size: 0.7rem;
  padding: 5px 11px;
  border: 1px solid var(--rule);
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 3px;
  background: var(--card-bg);
}

.badge.green {
  border-color: var(--accent-z);
  color: var(--accent-z);
}

.badge.blue {
  border-color: var(--accent-p);
  color: var(--accent-p);
}

.badge.amber {
  border-color: var(--accent-impl);
  color: var(--accent-impl);
}

/* ============================================================================
 * 27-TRIT DISPLAY (home — ADD r3, r1, r2 instruction row)
 * ========================================================================== */

.trit-row {
  display: flex;
  gap: 3px;
  margin: 48px 0 8px;
  flex-wrap: wrap;
}

.trit {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-code);
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card-bg);
  color: var(--ink-muted);
  user-select: none;
}

.trit.N {
  background: #f3ddd8;
  border-color: #e8c4bb;
  color: var(--accent-n);
}

.trit.Z {
  background: #e4ead8;
  border-color: #d0d8bb;
  color: var(--accent-z);
}

.trit.P {
  background: #d0dfe8;
  border-color: #b5cbdb;
  color: var(--accent-p);
}

.trit-label {
  font-family: var(--font-code);
  font-size: 0.74rem;
  color: var(--ink-soft);
  margin-top: 10px;
  margin-bottom: 0;
  letter-spacing: 0.02em;
}

/* ============================================================================
 * SECTIONS
 * ========================================================================== */

section {
  padding: 56px 0;
  border-top: 1px solid var(--rule);
}

.section-label {
  font-family: var(--font-code);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 24px;
}

.section-label::before {
  content: '§ ';
  color: var(--accent-p);
}

h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 20px;
}

h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  margin: 2rem 0 0.8rem;
  line-height: 1.3;
}

section p {
  color: var(--ink-soft);
  max-width: 660px;
  margin-bottom: 16px;
  font-size: 1rem;
}

/* ============================================================================
 * SPEC-GRID (key/value architecture table on home)
 * ========================================================================== */

.spec-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  margin: 28px 0;
}

.spec-key,
.spec-val {
  padding: 12px 18px;
  font-size: 0.88rem;
  background: var(--card-bg);
}

.spec-key {
  color: var(--ink-muted);
  font-family: var(--font-code);
  letter-spacing: 0.03em;
}

.spec-val {
  color: var(--ink);
  font-weight: 500;
}

.spec-val .acc  { color: var(--accent-p); font-weight: 600; }
.spec-val .acc2 { color: var(--accent-n); font-weight: 600; }

/* ============================================================================
 * INSTRUCTION FORMATS (R / I / J / U / B field diagrams)
 * ========================================================================== */

.format-block {
  margin: 28px 0;
}

.format-name {
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: var(--accent-p);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 10px;
}

.format-fields {
  display: flex;
  gap: 2px;
  height: 42px;
}

.field {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-code);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid;
  border-radius: 2px;
  flex-shrink: 0;
  padding: 0 4px;
}

.field.opcode {
  background: #d0dfe8;
  border-color: #b5cbdb;
  color: var(--accent-p);
}

.field.reg {
  background: #e4ead8;
  border-color: #d0d8bb;
  color: var(--accent-z);
}

.field.imm {
  background: #f0e4cf;
  border-color: #d8c8a8;
  color: var(--accent-impl);
}

.field.funct {
  background: var(--bg-deep);
  border-color: var(--rule);
  color: var(--ink-muted);
}

.field.offset {
  background: #f3ddd8;
  border-color: #e8c4bb;
  color: var(--accent-n);
}

.field-sub {
  font-size: 0.62rem;
  font-weight: 300;
  opacity: 0.75;
  margin-left: 4px;
  letter-spacing: 0;
  text-transform: none;
}

/* ============================================================================
 * LMODE CARDS (5 configurable ternary logics)
 * ========================================================================== */

.lmode-row {
  display: flex;
  gap: 12px;
  margin: 28px 0;
  flex-wrap: wrap;
}

.lmode-card {
  flex: 1;
  min-width: 150px;
  padding: 18px 20px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card-bg);
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.lmode-card:hover {
  border-color: var(--accent-p);
  box-shadow: 0 2px 12px rgba(42, 90, 138, 0.08);
}

.lmode-card.active {
  border-color: var(--accent-p);
  background: linear-gradient(135deg, rgba(42, 90, 138, 0.04), transparent);
}

.lmode-val {
  font-family: var(--font-code);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.lmode-card:nth-child(1) .lmode-val { color: var(--accent-n); }   /* Heyting — N·N */
.lmode-card:nth-child(2) .lmode-val { color: var(--accent-impl); } /* Łukasiewicz */
.lmode-card:nth-child(3) .lmode-val { color: #8a2a7a; }             /* RM3 */
.lmode-card:nth-child(4) .lmode-val { color: var(--accent-p); }   /* Kleene */
.lmode-card:nth-child(5) .lmode-val { color: var(--accent-z); }   /* B3 */

.lmode-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.lmode-note {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.45;
}

.lmode-card.active .lmode-note::before {
  content: '★ ';
  color: var(--accent-p);
}

/* ============================================================================
 * LINK CARDS (Resources, Articles, Related work)
 * ========================================================================== */

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.link-card {
  display: block;
  padding: 22px 26px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card-bg);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  position: relative;
  overflow: hidden;
}

.link-card::after {
  content: '→';
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  transition: right 0.15s, color 0.15s;
}

.link-card:hover {
  border-color: var(--accent-p);
  box-shadow: 0 2px 14px rgba(42, 90, 138, 0.08);
}

.link-card:hover::after {
  right: 16px;
  color: var(--accent-p);
}

.link-card:hover .lc-title {
  color: var(--accent-p);
}

.lc-label {
  font-family: var(--font-code);
  font-size: 0.68rem;
  color: var(--ink-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.lc-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
  transition: color 0.15s;
  line-height: 1.3;
  padding-right: 28px;
}

.lc-desc {
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

/* ============================================================================
 * FOOTER
 * ========================================================================== */

footer {
  border-top: 1px solid var(--rule);
  padding: 36px 0 56px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.footer-left strong {
  color: var(--ink-soft);
  font-weight: 600;
}

.footer-right a {
  color: var(--accent-p);
  text-decoration: none;
}

.footer-right a:hover {
  text-decoration: underline;
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 13px;
  background: var(--accent-p);
  margin-left: 4px;
  vertical-align: middle;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ============================================================================
 * ARTICLE BODY (blog posts — merged from blog.css)
 * ========================================================================== */

.hero {
  max-width: 860px;
  margin: 0 auto;
  padding: 5rem 2rem 3rem;
}

.hero-kicker {
  font-family: var(--font-code);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.hero-sub {
  font-size: 1.15rem;
  font-weight: 300;
  color: var(--ink-soft);
  max-width: 600px;
  line-height: 1.65;
}

.hero-meta {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: var(--ink-muted);
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

article {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 2rem 6rem;
}

article p {
  margin-bottom: 1.4rem;
}

article h2 {
  font-size: 1.9rem;
  margin: 3.5rem 0 1rem;
}

article h3 {
  font-size: 1.3rem;
  margin: 2.5rem 0 0.8rem;
}

article strong {
  font-weight: 600;
  color: var(--ink);
}

article a {
  color: var(--accent-p);
}

/* Drop cap (opening paragraph of an article) */
.drop-cap::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 3.8rem;
  line-height: 0.8;
  padding-right: 0.12em;
  margin-top: 0.08em;
  color: var(--accent-p);
  font-weight: 700;
}

/* Pull quote */
.pullquote {
  margin: 2.5rem -2rem;
  padding: 2rem 2.5rem;
  border-left: 4px solid var(--accent-p);
  background: linear-gradient(135deg, rgba(42, 90, 138, 0.04), transparent);
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-style: italic;
  line-height: 1.55;
  color: var(--ink-soft);
}

/* ── Truth tables ──────────────────────────────────────────────────────── */

.truth-table-wrap {
  margin: 2rem 0;
  overflow-x: auto;
}

.truth-table {
  border-collapse: collapse;
  font-family: var(--font-code);
  font-size: 0.82rem;
  width: 100%;
}

.truth-table caption {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.85rem;
  text-align: left;
  margin-bottom: 0.5rem;
  color: var(--ink-soft);
}

.truth-table th {
  background: var(--ink);
  color: var(--code-fg);
  padding: 0.5rem 1rem;
  text-align: center;
  font-weight: 600;
}

.truth-table td {
  padding: 0.45rem 1rem;
  text-align: center;
  border-bottom: 1px solid var(--rule);
}

.truth-table tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.02);
}

.trit-n { color: var(--accent-n); font-weight: 600; }
.trit-z { color: var(--accent-z); font-weight: 600; }
.trit-p { color: var(--accent-p); font-weight: 600; }

/* ── Inline code and code blocks ───────────────────────────────────────── */

code {
  font-family: var(--font-code);
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  color: var(--ink);
}

pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1.5rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-family: var(--font-code);
  font-size: 0.82rem;
  line-height: 1.65;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

.code-comment { color: #7a8a6a; }
.code-keyword { color: #d4a06a; }
.code-value   { color: #8ab4d4; }

/* ── Diagram cards ─────────────────────────────────────────────────────── */

.diagram-card {
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 2rem;
  margin: 2rem 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.diagram-card h4 {
  font-family: var(--font-code);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1rem;
}

/* ── Trit visualization (article inline) ──────────────────────────────── */

.trit-viz {
  display: flex;
  gap: 3px;
  margin: 0.5rem 0;
  font-family: var(--font-code);
  font-size: 0.85rem;
}

.trit-viz .t {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 600;
}

.trit-viz .t-n { background: #f3ddd8; color: var(--accent-n); }
.trit-viz .t-z { background: #e4ead8; color: var(--accent-z); }
.trit-viz .t-p { background: #d0dfe8; color: var(--accent-p); }

.trit-op {
  font-family: var(--font-code);
  font-size: 0.78rem;
  color: var(--ink-muted);
  width: 100%;
  text-align: right;
  font-style: italic;
}

/* ── Application blocks ────────────────────────────────────────────────── */

.app-block {
  margin: 2.5rem 0;
  padding: 1.8rem 2rem;
  border-radius: 8px;
  border-left: 4px solid;
}

.app-block.app-tmr  { border-color: var(--accent-p);    background: rgba(42, 90, 138, 0.04); }
.app-block.app-diff { border-color: var(--accent-n);    background: rgba(180, 69, 51, 0.04); }
.app-block.app-acl  { border-color: var(--accent-impl); background: rgba(138, 90, 42, 0.04); }
.app-block.app-sql  { border-color: var(--accent-z);    background: rgba(122, 138, 106, 0.04); }

.app-block h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0 0 0.6rem;
}

.app-block p {
  margin-bottom: 0.8rem;
}

/* ── Comparison table ──────────────────────────────────────────────────── */

.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 1.5rem 0;
}

.cmp-table th {
  text-align: left;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-bottom: 2px solid var(--ink);
  font-size: 0.82rem;
}

.cmp-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.cmp-table .num {
  font-family: var(--font-code);
  font-weight: 600;
  color: var(--accent-p);
  text-align: center;
}

/* ── Section separator ─────────────────────────────────────────────────── */

.sep {
  text-align: center;
  margin: 3rem 0;
  color: var(--rule);
  font-size: 1.2rem;
  letter-spacing: 0.5em;
}

/* ── Article footer ────────────────────────────────────────────────────── */

.article-footer {
  max-width: 680px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-code);
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.7;
}

.article-footer a {
  color: var(--accent-p);
}

/* ============================================================================
 * RESPONSIVE
 * ========================================================================== */

@media (max-width: 720px) {
  html { font-size: 16px; }
  .wrap { padding: 0 20px; }
  .spec-grid { grid-template-columns: 1fr; }
  .format-fields { height: auto; flex-wrap: wrap; gap: 3px; }
  .field { height: 34px; padding: 0 8px; }
  footer { flex-direction: column; align-items: flex-start; }
  .pullquote { margin: 2rem 0; padding: 1.5rem; }
  .diagram-card { padding: 1.2rem; }
}

@media (max-width: 640px) {
  .hero h1 { font-size: 2.2rem; }
  article h2 { font-size: 1.5rem; }
}
