/* CraftBard prototype — full hi-fi
   Ink-first dark theme by default, paper light theme as alt.
*/

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');
@import url('./colors_and_type.css');

@font-face { font-family: 'Allrounder Grotesk Test'; src: url('./fonts/AllrounderGroteskTest-Bold.otf') format('opentype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Allrounder Grotesk Test'; src: url('./fonts/AllrounderGroteskTest-Regular.otf') format('opentype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Allrounder Grotesk Test'; src: url('./fonts/AllrounderGroteskTest-Light.otf') format('opentype'); font-weight: 300; font-display: swap; }

/* ============ THEME TOKENS ============ */
:root, [data-theme="dark"] {
  --bg:        #0d100a;
  --bg-2:      #14170d;
  --surface:   #1a1d12;
  --surface-2: #22251a;
  --ink:       #f3efe6;
  --ink-soft:  #b0b29c;
  --ink-faint: #6e7060;
  --rule:      rgba(243, 239, 230, 0.10);
  --rule-strong: rgba(243, 239, 230, 0.22);

  /* accent — lime by default; tweakable */
  --accent:        #d6f293;
  --accent-deep:   #b4d75c;
  --accent-fg:     #0d100a;          /* foreground on accent surface */
  --accent-soft:   rgba(214, 242, 147, 0.12);
  --chart-accent:  #d6f293;           /* chart line; overridden in light mode */

  --positive:  #b4d75c;
  --negative:  #d24f3a;

  /* density */
  --space-unit: 8px;
  --section-pad-y: 96px;
  --type-scale: 1;
}

[data-theme="light"] {
  --bg:        #f3efe6;
  --bg-2:      #ebe6da;
  --surface:   #ffffff;
  --surface-2: #f3efe6;
  --ink:       #14170d;
  --ink-soft:  #4a4e3b;
  --ink-faint: #8a8e74;
  --rule:      rgba(20, 23, 13, 0.10);
  --rule-strong: rgba(20, 23, 13, 0.22);
  --accent-fg: #14170d;
  --accent-soft: rgba(180, 215, 92, 0.18);
}

[data-density="compact"] { --space-unit: 6px; --section-pad-y: 64px; --type-scale: 0.92; }
[data-density="roomy"]   { --space-unit: 10px; --section-pad-y: 128px; --type-scale: 1.08; }

/* ============ BASE ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); color: var(--ink); }
body {
  font-family: 'Allrounder Grotesk Test', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ============ TYPE SYSTEM ============ */
.eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: calc(11px * var(--type-scale));
  color: var(--accent);
}
.eyebrow.muted { color: var(--ink-faint); }

.display {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 700;
  letter-spacing: -0.028em;
  line-height: 0.95;
  color: var(--ink);
}
.display .light { font-weight: 300; color: var(--ink-soft); }
.display em { font-style: italic; font-weight: 400; }
.display .accent { color: var(--accent); }

.h2 {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 700; letter-spacing: -0.02em;
  line-height: 1.05;
  font-size: calc(40px * var(--type-scale));
}
.h2 .light { font-weight: 300; color: var(--ink-soft); }
.h2 em { font-style: italic; font-weight: 400; }

.h3 {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 700;
  font-size: calc(20px * var(--type-scale));
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.body {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 400;
  font-size: calc(16px * var(--type-scale));
  line-height: 1.55;
  color: var(--ink-soft);
}
.body-lg { font-size: calc(20px * var(--type-scale)); line-height: 1.5; }

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: calc(12px * var(--type-scale));
  letter-spacing: 0;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.mono-lg { font-size: calc(14px * var(--type-scale)); }

.positive { color: var(--positive); }
.negative { color: var(--negative); }
.num-display {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

/* ============ LAYOUT ============ */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 32px;
}
.container-narrow {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 32px;
}
.section { padding: var(--section-pad-y) 0; }
.row { display: flex; }
.col { display: flex; flex-direction: column; }

/* ============ TOP CHROME ============ */
.cb-nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13, 16, 10, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
}
[data-theme="light"] .cb-nav { background: rgba(243, 239, 230, 0.85); }
.cb-nav-inner {
  max-width: 1320px; margin: 0 auto;
  padding: 16px 32px;
  display: flex; align-items: center; gap: 28px;
}
.cb-logo {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none;
}
.cb-logo-img { height: 28px; display: block; }
[data-theme="dark"] .cb-logo-light { display: none; }
[data-theme="light"] .cb-logo-dark { display: none; }

.cb-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s, transform .15s;
  margin-left: 6px;
}
.cb-theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.cb-theme-toggle:active { transform: scale(0.94); }
.cb-theme-toggle .cb-icon-sun,
.cb-theme-toggle .cb-icon-moon { transition: opacity .2s, transform .3s; }
[data-theme="dark"] .cb-theme-toggle .cb-icon-sun { display: block; }
[data-theme="dark"] .cb-theme-toggle .cb-icon-moon { display: none; }
[data-theme="light"] .cb-theme-toggle .cb-icon-sun { display: none; }
[data-theme="light"] .cb-theme-toggle .cb-icon-moon { display: block; }
.cb-nav-links {
  display: flex; gap: 4px;
  list-style: none; margin: 0; padding: 0;
  margin-left: auto;
}
.cb-nav-links a {
  font-family: 'Allrounder Grotesk Test';
  font-weight: 500; font-size: 14px;
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: 999px;
  transition: color .15s, background .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.cb-nav-links a:hover { color: var(--ink); background: var(--rule); }
.cb-nav-links a.active { color: var(--ink); }
.cb-nav-links a.active::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}
.cb-nav-cta {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: var(--accent-fg);
  font-family: 'Allrounder Grotesk Test'; font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  transition: transform .15s, filter .15s;
}
.cb-nav-cta:hover { transform: translateY(-1px); filter: brightness(1.05); }

/* ============ TICKER ============ */
.cb-ticker {
  background: var(--bg-2);
  border-bottom: 1px solid var(--rule);
  overflow: hidden;
  position: relative;
}
.cb-ticker-track {
  display: inline-flex; gap: 40px;
  padding: 10px 0;
  white-space: nowrap;
  animation: ticker-scroll 60s linear infinite;
}
.cb-ticker-stop { animation-play-state: paused; }
.cb-ticker-item {
  display: inline-flex; gap: 8px; align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.cb-ticker-item .sym { color: var(--accent); font-weight: 500; }
.cb-ticker-item .px { color: var(--ink-soft); }
.cb-ticker-live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--negative); display: inline-block; margin-right: 8px;
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@keyframes blink {
  0%,100% { opacity: 1; }
  50% { opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
  .cb-ticker-track { animation: none; }
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-fg);
  font-family: 'Allrounder Grotesk Test'; font-weight: 600;
  font-size: 15px;
  padding: 14px 22px;
  border-radius: 999px;
  border: none;
  transition: transform .15s, filter .15s, box-shadow .15s;
  cursor: pointer;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 8px 24px -8px var(--accent-soft); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}
.btn.ghost:hover { background: var(--rule); transform: translateY(-1px); filter: none; box-shadow: none; }
.btn.sm { font-size: 13px; padding: 8px 14px; }
.btn.lg { font-size: 17px; padding: 16px 28px; }

/* ============ CHIPS ============ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  color: var(--ink-soft);
  background: transparent;
}
.chip.accent { color: var(--accent); border-color: var(--accent); }
.chip.live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--negative);
  animation: blink 1.4s ease-in-out infinite;
}
.chip.solid { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* ============ SURFACE / CARD ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 24px;
  transition: border-color .2s, transform .2s;
}
.card.tight { padding: 16px; }
.card.spaced { padding: 32px; }
.card.glow {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%);
  position: relative;
}
.card.glow::before {
  content: ''; position: absolute; inset: 0; border-radius: 14px;
  pointer-events: none;
  background: radial-gradient(60% 60% at 50% 0%, var(--accent-soft) 0%, transparent 70%);
  opacity: 0.6;
}

/* ============ FOOTER ============ */
.cb-footer {
  border-top: 1px solid var(--rule);
  background: var(--bg-2);
  padding: 64px 0 32px;
  margin-top: 64px;
}
.cb-footer-grid {
  max-width: 1320px; margin: 0 auto; padding: 0 32px;
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 48px;
}
.cb-footer-col h4 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 16px;
}
.cb-footer-col ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.cb-footer-col a {
  font-family: 'Allrounder Grotesk Test'; font-size: 14px;
  color: var(--ink-soft);
  transition: color .15s;
}
.cb-footer-col a:hover { color: var(--ink); }
.cb-footer-meta {
  max-width: 1320px; margin: 48px auto 0; padding: 24px 32px 0;
  border-top: 1px solid var(--rule);
  display: flex; justify-content: space-between; align-items: center;
}
.cb-footer-meta .mono { color: var(--ink-faint); font-size: 11px; }
.cb-disclaimer {
  max-width: 1320px; margin: 24px auto 0; padding: 0 32px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; line-height: 1.6;
  color: var(--ink-faint);
}

/* ============ TABLE ============ */
.cb-table {
  width: 100%;
  border-collapse: collapse;
}
.cb-table th, .cb-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
.cb-table th {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500; font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--bg-2);
}
.cb-table td {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
}
.cb-table td.label {
  font-family: 'Allrounder Grotesk Test', sans-serif;
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
}
.cb-table tr:last-child td { border-bottom: none; }
.cb-table tr:hover td { background: var(--bg-2); }

/* ============ METRIC TILE ============ */
.metric {
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
}
.metric .lbl {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-faint);
}
.metric .val {
  font-family: 'Allrounder Grotesk Test';
  font-weight: 700;
  font-size: calc(28px * var(--type-scale));
  letter-spacing: -0.025em;
  line-height: 1;
  margin-top: 10px;
  color: var(--ink);
}
.metric .sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  margin-top: 8px;
  color: var(--ink-faint);
}
.metric.accent {
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 80%);
  border-color: var(--accent);
}
.metric.accent .val { color: var(--accent); }

/* ============ DOTTED PATH (brand motif) ============ */
.dotted-path {
  background-image: linear-gradient(to right, var(--accent-deep) 50%, transparent 50%);
  background-size: 12px 2px;
  background-repeat: repeat-x;
  height: 2px;
}
.dotted-path-v {
  background-image: linear-gradient(to bottom, var(--accent-deep) 50%, transparent 50%);
  background-size: 2px 12px;
  background-repeat: repeat-y;
  width: 2px;
}

/* ============ TAG ============ */
.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-fg);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.tag.muted { background: var(--surface-2); color: var(--ink-faint); }
.tag.dev { background: transparent; color: var(--ink-faint); border: 1px dashed var(--rule-strong); }

/* ============ INPUT / TEXTAREA ============ */
.cb-input, .cb-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 18px;
  font-family: 'Allrounder Grotesk Test';
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, background .15s;
}
.cb-input::placeholder, .cb-textarea::placeholder { color: var(--ink-faint); }
.cb-input:focus, .cb-textarea:focus {
  border-color: var(--accent);
  background: var(--bg-2);
}
.cb-textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

/* ============ ANIMATIONS / UTILITIES ============ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp .5s ease both; }

.scrollbar-hide::-webkit-scrollbar { display: none; }
.scrollbar-hide { scrollbar-width: none; }

/* ============ SVG CHART STYLING ============ */
.cb-chart {
  width: 100%;
  height: 100%;
  display: block;
}
.cb-chart .grid { stroke: var(--rule); stroke-width: 1; }
.cb-chart .axis-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  fill: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ============ LIGHT THEME REFINEMENTS ============ */
/*
  Problem: --accent (#d6f293 lime) used as text colour has ~1.2:1 contrast
  on the cream/white light backgrounds — invisible. Fix: introduce a dark
  olive-lime (#426912) for all text uses of accent in light mode.
  Calculated: #426912 on #f3efe6 = 5.5:1, on #ffffff = 6.5:1 — passes WCAG AA.
*/
[data-theme="light"] {
  --positive:    #3d6b10;   /* dark lime-green — 5.8:1 on --bg */
  --negative:    #b83228;   /* deeper red — 5.2:1 on --bg */
  --accent-text: #426912;   /* accent safe for text in light mode */
  --chart-accent: #5c8a1a;  /* chart line on cream/white — 4.2:1 on --surface */
}

/* Eyebrows */
[data-theme="light"] .eyebrow               { color: var(--accent-text); }
[data-theme="light"] .eyebrow.muted         { color: var(--ink-faint); }

/* Display / heading accent spans */
[data-theme="light"] .display .accent       { color: var(--accent-text); }

/* Chips */
[data-theme="light"] .chip.accent           { color: var(--accent-text); border-color: #8cba2a; }

/* Ticker symbols */
[data-theme="light"] .cb-ticker-item .sym   { color: var(--accent-text); }

/* Nav active indicator dot */
[data-theme="light"] .cb-nav-links a.active::before { background: var(--accent-text); }

/* Metric accent tile */
[data-theme="light"] .metric.accent         { border-color: #8cba2a; }
[data-theme="light"] .metric.accent .val    { color: var(--accent-text); }

/* Dotted-path brand motif — swap to visible dark olive */
[data-theme="light"] .dotted-path {
  background-image: linear-gradient(to right, #8cba2a 50%, transparent 50%);
}
[data-theme="light"] .dotted-path-v {
  background-image: linear-gradient(to bottom, #8cba2a 50%, transparent 50%);
}

/* Cards — stronger definition on light backgrounds */
[data-theme="light"] .card {
  border-color: rgba(20, 23, 13, 0.14);
  box-shadow: 0 1px 6px rgba(20, 23, 13, 0.06);
}
[data-theme="light"] .card.glow::before {
  background: radial-gradient(60% 60% at 50% 0%, rgba(140, 186, 42, 0.16) 0%, transparent 70%);
}

/* Table */
[data-theme="light"] .cb-table th          { background: var(--bg); }
[data-theme="light"] .cb-table tr:hover td { background: var(--bg); }

/* Ghost button readable on cream */
[data-theme="light"] .btn.ghost {
  border-color: rgba(20, 23, 13, 0.28);
}
[data-theme="light"] .btn.ghost:hover      { background: rgba(20, 23, 13, 0.06); }

/* Nav backdrop slightly more opaque in light */
[data-theme="light"] .cb-nav              { background: rgba(243, 239, 230, 0.92); }

/* Charts — stronger grid lines + boosted fill in light mode */
[data-theme="light"] .cb-chart .grid     { stroke: rgba(20, 23, 13, 0.16); }
[data-theme="light"] .cb-chart .axis-label { fill: var(--ink-faint); }

/* ============ MOBILE ============ */
@media (max-width: 880px) {
  .container, .container-narrow { padding: 0 20px; }
  .cb-nav-inner { padding: 14px 20px; }
  .cb-nav-links { display: none; }
  .cb-footer-grid { grid-template-columns: 1fr; gap: 32px; }
}
