/* ── Shared Styles — Mesoamerica ML Interactive Site ──────────── */
/* Palette: Codex Deep — matches the slide deck                    */

:root {
  /* ── Codex Deep palette ── */
  --bg:      #F2ECE0;
  --head:    #302618;
  --body:    #504838;
  --teal:    #327070;
  --ochre:   #847040;
  --terra:   #8A4C34;
  --muted:   #A09880;
  --rule:    rgba(48,38,24,0.12);
  --rule-lt: rgba(48,38,24,0.06);
  --card-bg: rgba(48,38,24,0.03);
  --green:   #4a9e6b;
  --serif:   Baskerville, 'Palatino Linotype', Georgia, serif;
  --sans:    Aptos, 'Avenir Next', 'Helvetica Neue', Arial, sans-serif;
  --mono:    'SF Mono', 'Fira Code', 'Consolas', monospace;
  --radius:  6px;

  /* ── Backward-compatible aliases (old dark-theme names) ── */
  --bg-card:       rgba(48,38,24,0.03);
  --border:        rgba(48,38,24,0.12);
  --border-subtle: rgba(48,38,24,0.07);
  --text:          #302618;
  --text-dim:      #504838;
  --text-muted:    #A09880;
  --gold:          #327070;
  --gold-text:     #847040;
  --gold-dim:      rgba(50,112,112,0.08);
  --green-dim:     rgba(74,158,107,0.15);
  --orange:        #8A4C34;
}

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

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

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--body);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 2rem;
}

.page-header {
  padding: 2.5rem 0 1.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2rem;
}

.page-header h1 {
  font-family: var(--serif);
  color: var(--head);
  font-size: 2rem;
  margin: 0 0 0.3rem;
  font-weight: 300;
  letter-spacing: -0.02em;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
  font-family: var(--sans);
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ── Navigation ──────────────────────────────────────────────── */

nav {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  border-top: 3px solid var(--teal);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav .container {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
  overflow-x: auto;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-family: var(--sans);
  font-weight: 400;
  padding: 0.3rem 0.65rem;
  border-radius: 3px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

nav a:hover, nav a.active {
  color: var(--teal);
  background: rgba(50,112,112,0.07);
}

nav .site-title {
  font-family: var(--serif);
  color: var(--head);
  font-size: 0.95rem;
  font-weight: 300;
  margin-right: auto;
  padding-right: 1.5rem;
  letter-spacing: -0.01em;
}

/* ── Typography ──────────────────────────────────────────────── */

h1, h2, h3 {
  font-family: var(--serif);
  color: var(--head);
  font-weight: 400;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.3rem;
  border-bottom: 2px solid var(--teal);
  padding-bottom: 0.25em;
  margin: 2rem 0 1rem;
  font-weight: 300;
}

h3 {
  font-size: 1.05rem;
  color: var(--head);
  margin: 1.2rem 0 0.5rem;
  font-weight: 400;
}

p { margin: 0 0 1em; color: var(--body); }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

em { color: var(--head); font-style: italic; }

strong { color: var(--head); font-weight: 500; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(48,38,24,0.06);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  color: var(--head);
}

/* ── Cards ───────────────────────────────────────────────────── */

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

.card {
  background: var(--card-bg);
  border: 1px solid var(--rule-lt);
  border-top: 2px solid var(--teal);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1.25rem 1.4rem;
  transition: border-top-color 0.2s, box-shadow 0.15s;
  text-decoration: none;
  color: inherit;
  display: block;
}

.card:hover {
  border-top-color: var(--ochre);
  box-shadow: 0 2px 8px rgba(48,38,24,0.08);
  text-decoration: none;
}

.card-badge {
  display: inline-block;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  font-family: var(--sans);
  font-weight: 500;
  border: 1px solid rgba(50,112,112,0.3);
  background: rgba(50,112,112,0.06);
  padding: 0.12em 0.5em;
  border-radius: 2px;
  margin-bottom: 0.6rem;
}

.card h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  color: var(--head);
}

.card p {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
  line-height: 1.55;
}

/* ── Interactive Controls ────────────────────────────────────── */

.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.2rem;
  background: var(--card-bg);
  border: 1px solid var(--rule-lt);
  border-radius: var(--radius);
  margin: 1rem 0;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.control-group label {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  outline: none;
  min-width: 200px;
  accent-color: var(--teal);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(48,38,24,0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg);
}

/* ── Stats Panel ─────────────────────────────────────────────── */

.stats-panel {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.stat-box {
  text-align: center;
  min-width: 90px;
  padding: 0.6rem 0.8rem;
  background: var(--card-bg);
  border: 1px solid var(--rule-lt);
  border-radius: var(--radius);
}

.stat-value {
  font-family: var(--serif);
  font-size: 1.9rem;
  font-weight: 300;
  line-height: 1.1;
  display: block;
  color: var(--head);
}

.stat-value.good, .metric-val.good  { color: var(--teal); }
.stat-value.warn, .metric-val.warn  { color: var(--ochre); }
.stat-value.bad,  .metric-val.bad   { color: var(--terra); }

.stat-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--sans);
  display: block;
  margin-top: 0.25em;
}

/* ── Canvas Container ────────────────────────────────────────── */

.canvas-wrap {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: #2a2218;
  margin: 1rem 0;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Legend ───────────────────────────────────────────────────── */

.legend {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0;
  font-family: var(--sans);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  font-size: 0.8rem;
  font-family: var(--sans);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid rgba(50,112,112,0.4);
  border-radius: 3px;
  background: rgba(50,112,112,0.06);
  color: var(--teal);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}

.btn:hover {
  background: rgba(50,112,112,0.12);
  border-color: var(--teal);
  text-decoration: none;
}

.btn-primary {
  background: var(--teal);
  color: var(--bg);
  border-color: var(--teal);
  font-weight: 500;
}

.btn-primary:hover {
  background: #2a5f5f;
  border-color: #2a5f5f;
}

/* ── Info Box ────────────────────────────────────────────────── */

.info-box {
  border-left: 3px solid var(--teal);
  background: rgba(50,112,112,0.04);
  padding: 0.8rem 1.1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1rem 0;
  font-size: 0.88rem;
  color: var(--body);
}

.info-box p { margin: 0; }
.info-box strong { color: var(--head); }

/* ── Reference List ──────────────────────────────────────────── */

.ref-list {
  list-style: none;
  padding: 0;
}

.ref-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule-lt);
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.ref-list li:last-child { border-bottom: none; }
.ref-venue { color: var(--teal); }

/* ── Key line (matches slide deck) ──────────────────────────── */

.key-line {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  color: var(--head);
  border-left: 2px solid var(--teal);
  padding-left: 0.75rem;
  margin: 1rem 0;
  line-height: 1.55;
}

/* ── Footer ──────────────────────────────────────────────────── */

footer {
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--sans);
}

/* ── Mode indicator (threshold lab) — fixed width prevents layout shift ── */
.mode-indicator {
  min-width: 12em;
  white-space: nowrap;
  text-align: center;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: var(--sans);
  font-weight: 500;
  transition: background 0.3s, color 0.3s;
}

/* ── Loading overlay — light on dark ───────────────────────── */
.loading-overlay {
  background: rgba(48,38,24,0.75) !important;
  color: #F2ECE0 !important;
}

/* ── Histogram wrap — warm instead of dark ─────────────────── */
.histogram-wrap {
  background: rgba(48,38,24,0.04);
  border: 1px solid var(--rule-lt);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem 0.4rem;
  margin: 0.5rem 0 1rem;
}

/* ── Panel labels on image canvases — always white ─────────── */
.panel-label {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.65);
  color: rgba(242,236,224,0.9) !important;
  font-size: 0.72rem;
  font-family: var(--sans);
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 700px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
  .stats-panel {
    justify-content: center;
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  input[type="range"] {
    min-width: 100%;
  }
  .page-header h1 {
    font-size: 1.5rem;
  }
  .container {
    padding: 0 1rem;
  }
}
