/* ============================================================
   $CATE — "The Gilded Exchange"
   Stock-certificate engraving × trading terminal.
   Ink black, hairline gold, serif display, mono ledger.
   ============================================================ */

:root {
  /* color */
  --ink: #0c0a07;
  --ink-2: #121008;
  --paper: #f2ead8;
  --gold: #d4a017;
  --gold-bright: #f5b301;
  --gold-dim: #8a6a12;
  --hairline: rgba(212, 160, 23, .32);
  --hairline-faint: rgba(212, 160, 23, .14);
  --text: #e9e2d0;
  --muted: #9a8f74;
  --up: #35d07f;
  --danger: #e5484d;
  --focus: var(--gold-bright);

  /* type */
  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-body: "Space Grotesk", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", monospace;

  /* rhythm */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 14px; --sp-4: 20px; --sp-6: 32px; --sp-8: 56px;

  /* motion */
  --fast: 140ms; --base: 240ms;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

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

html { scrollbar-color: var(--gold-dim) var(--ink); }

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
}

/* film grain — texture with a pulse, never noise for its own sake */
.grain {
  position: fixed; inset: 0; z-index: 999; pointer-events: none; opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--gold); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

a { color: var(--gold-bright); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- type utilities ---------- */
.kicker {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500;
  letter-spacing: .22em;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.clause {
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 600;
  letter-spacing: .2em;
  color: var(--gold);
  display: block;
  margin-bottom: var(--sp-3);
}
.view-title {
  font-family: var(--font-display);
  font-size: clamp(38px, 5vw, 56px);
  font-weight: 400;
  line-height: 1.02;
  margin-bottom: var(--sp-6);
}

/* ---------- nav ---------- */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  position: sticky; top: 0; z-index: 50;
  background: rgba(12, 10, 7, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline-faint);
}
.nav-brand { cursor: pointer; display: flex; align-items: center; }
.nav-coin { width: 34px; height: 34px; display: block; transition: transform var(--base) var(--ease); }
.nav-brand:hover .nav-coin { transform: rotate(12deg); }
.nav-links { display: flex; gap: 2px; }
.nav-link {
  background: none; border: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
  padding: 10px 13px;
  border-bottom: 1px solid transparent;
  transition: color var(--fast) var(--ease);
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--gold-bright); border-bottom-color: var(--gold-bright); }

/* ---------- signature: the tape ---------- */
.tape {
  position: sticky; top: 55px; z-index: 45;
  overflow: hidden; cursor: pointer;
  background: var(--ink-2);
  border-bottom: 1px solid var(--hairline);
  user-select: none;
}
.tape-track {
  display: flex; width: max-content;
  animation: tape-scroll 36s linear infinite;
}
.tape:hover .tape-track { animation-play-state: paused; }
.tape-run { display: flex; }
.tape .cell {
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 500;
  letter-spacing: .12em; white-space: nowrap;
  color: var(--gold);
  padding: 8px 0 8px 28px;
  font-variant-numeric: tabular-nums;
}
.tape .cell::after { content: "◆"; color: var(--gold-dim); font-size: 7px; margin-left: 28px; vertical-align: 2px; }
.tape .cell b { color: var(--text); font-weight: 600; }
.tape .up { color: var(--up); }
.tape .down { color: var(--danger); }
@keyframes tape-scroll { from { transform: translateX(0) } to { transform: translateX(-50%) } }

/* milestone bar rides beneath the tape */
.milestone-bar {
  position: sticky; top: 87px; z-index: 44;
  text-align: center; padding: 10px 14px; cursor: pointer;
  background: var(--gold-bright); color: var(--ink);
  font-family: var(--font-mono); font-size: 13px; letter-spacing: .06em;
  border-bottom: 1px solid var(--ink);
}
.milestone-bar:hover { background: var(--gold); }

/* ---------- views ---------- */
.view { display: none; padding: 44px 28px 72px; max-width: 1240px; margin: 0 auto; }
.view.active { display: block; }

/* ---------- hero ---------- */
.hero {
  display: grid; grid-template-columns: 1.15fr .85fr; gap: var(--sp-8);
  align-items: center;
  padding: var(--sp-8) 0 var(--sp-6);
  border-bottom: 1px solid var(--hairline-faint);
  margin-bottom: var(--sp-6);
}
.hero-title {
  font-family: var(--font-display);
  font-size: clamp(56px, 8.5vw, 118px);
  font-weight: 400;
  line-height: .95;
  letter-spacing: -.01em;
  margin: var(--sp-3) 0 var(--sp-4);
}
.hero-title em { font-style: italic; color: var(--gold-bright); }
.hero-sub { color: var(--muted); font-size: 17px; max-width: 46ch; margin-bottom: var(--sp-6); }
.hero-ctas { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.hero-art { display: flex; justify-content: center; }
.hero-coin {
  width: min(320px, 80%);
  filter: drop-shadow(0 24px 60px rgba(212, 160, 23, .25));
  animation: coin-drift 7s ease-in-out infinite;
}
@keyframes coin-drift { 0%,100% { transform: translateY(0) rotate(-2deg) } 50% { transform: translateY(-12px) rotate(2deg) } }

.feature-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); }
.feature-card {
  position: relative;
  border: 1px solid var(--hairline);
  padding: var(--sp-4);
  cursor: pointer;
  background: var(--ink-2);
  transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.feature-card::after {
  content: ""; position: absolute; inset: 5px;
  border: 1px solid var(--hairline-faint); pointer-events: none;
}
.feature-card:hover { border-color: var(--gold-bright); transform: translateY(-2px); }
.feature-card h3 { font-family: var(--font-display); font-size: 26px; font-weight: 400; margin-bottom: var(--sp-2); }
.feature-card p { color: var(--muted); font-size: 14.5px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--gold-bright);
  background: transparent;
  border: 1px solid var(--hairline);
  padding: 13px 20px;
  cursor: pointer; text-align: center;
  transition: all var(--fast) var(--ease);
}
.btn:hover { border-color: var(--gold-bright); background: rgba(212, 160, 23, .08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-gold { background: var(--gold-bright); color: var(--ink); border-color: var(--gold-bright); }
.btn-gold:hover { background: var(--gold); border-color: var(--gold); }
.btn-small { padding: 9px 13px; font-size: 11px; }
.btn-block { width: 100%; margin-bottom: var(--sp-3); }

/* ---------- studio layout ---------- */
.studio-layout { display: grid; grid-template-columns: 260px 1fr 290px; gap: var(--sp-3); align-items: start; }

.panel {
  background: var(--ink-2);
  border: 1px solid var(--hairline);
  padding: var(--sp-4);
}
.panel h3 {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .2em;
  color: var(--gold);
  margin: var(--sp-4) 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--hairline-faint);
}
.panel h3:first-child { margin-top: 0; }

.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 470px; overflow-y: auto; }
.template-tile {
  overflow: hidden; cursor: pointer;
  border: 1px solid var(--hairline-faint);
  aspect-ratio: 1; background: var(--ink); position: relative;
  transition: border-color var(--fast) var(--ease);
}
.template-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.template-tile:hover { border-color: var(--gold); }
.template-tile.selected { border-color: var(--gold-bright); box-shadow: inset 0 0 0 1px var(--gold-bright); }
.template-tile .tname {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-family: var(--font-mono); font-size: 8.5px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  background: rgba(12, 10, 7, .82); color: var(--text);
  padding: 4px 6px; text-align: center;
}

.upload-tile {
  display: flex; align-items: center; justify-content: center; margin-top: var(--sp-2);
  border: 1px dashed var(--hairline);
  padding: 13px; min-height: 46px;
  color: var(--gold); cursor: pointer;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  transition: all var(--fast) var(--ease);
}
.upload-tile:hover { border-color: var(--gold-bright); color: var(--gold-bright); }
.upload-tile.big { padding: 26px; }

.panel-canvas { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
#meme-canvas, #pfp-canvas {
  width: 100%; max-width: 560px; height: auto;
  background: var(--ink); border: 1px solid var(--hairline-faint);
  touch-action: none;
}
.canvas-hint { color: var(--muted); font-size: 13px; text-align: center; }

.panel-controls input[type="text"] {
  width: 100%; padding: 12px; margin-bottom: var(--sp-2);
  border: 1px solid var(--hairline); background: var(--ink); color: var(--text);
  font-family: var(--font-mono); font-size: 13px; letter-spacing: .04em;
}
.panel-controls input[type="text"]:focus { outline: none; border-color: var(--gold-bright); }
.panel-controls input[type="text"]::placeholder { color: var(--muted); }
.panel-controls label { display: block; color: var(--muted); font-size: 13px; margin: var(--sp-2) 0; }
.panel-controls input[type="range"] { width: 100%; accent-color: var(--gold-bright); }
.panel-controls select {
  width: 100%; padding: 9px; background: var(--ink); color: var(--text);
  border: 1px solid var(--hairline); font-family: var(--font-mono); font-size: 12px;
}
.control-group { margin: var(--sp-2) 0; }
.sticker-row { display: flex; gap: 6px; flex-wrap: wrap; }
.export-row { display: flex; flex-direction: column; gap: var(--sp-2); }
.check { display: flex; align-items: center; gap: 9px; color: var(--text) !important; font-size: 14px !important; cursor: pointer; }
.check input { accent-color: var(--gold-bright); width: 15px; height: 15px; }

/* ---------- trending ---------- */
.drop-card {
  display: grid; grid-template-columns: 360px 1fr;
  background: var(--ink-2);
  border: 1px solid var(--gold);
  position: relative;
}
.drop-card::after { content: ""; position: absolute; inset: 6px; border: 1px solid var(--hairline-faint); pointer-events: none; }
.drop-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.drop-body { padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-3); align-items: flex-start; position: relative; z-index: 1; }
.drop-tag {
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  letter-spacing: .22em; color: var(--ink);
  background: var(--gold-bright); padding: 5px 10px;
}
.drop-body h3 { font-family: var(--font-display); font-size: 38px; font-weight: 400; line-height: 1; }
.drop-caption { font-family: var(--font-mono); color: var(--gold-bright); font-size: 15px; letter-spacing: .02em; }
.drop-why { color: var(--muted); font-size: 14px; max-width: 52ch; }
.trend-subtitle { font-family: var(--font-display); font-size: 30px; font-weight: 400; margin: var(--sp-8) 0 var(--sp-4); }
.trend-subtitle .clause { margin-bottom: 4px; }
.trend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--sp-3); }
.trend-card {
  background: var(--ink-2); border: 1px solid var(--hairline);
  transition: border-color var(--fast) var(--ease);
}
.trend-card:hover { border-color: var(--gold-bright); }
.trend-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; border-bottom: 1px solid var(--hairline-faint); }
.trend-body { padding: var(--sp-3); }
.trend-body h4 { font-family: var(--font-display); font-size: 22px; font-weight: 400; margin-bottom: 6px; }
.trend-body p { color: var(--muted); font-size: 13px; margin-bottom: var(--sp-3); }

/* ---------- post builder ---------- */
.posts-layout { grid-template-columns: 300px 1fr; }
.vibe-row { display: flex; flex-wrap: wrap; gap: 6px; }
.vibe-btn.active { background: var(--gold-bright); color: var(--ink); border-color: var(--gold-bright); }
.stats-strip {
  border: 1px solid var(--hairline);
  padding: 10px 13px; margin-bottom: var(--sp-3);
  color: var(--gold); font-family: var(--font-mono); font-size: 12px;
  letter-spacing: .04em; line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
#post-text {
  width: 100%; resize: vertical; padding: var(--sp-3);
  font-size: 16px; line-height: 1.6;
  background: var(--ink); color: var(--text);
  border: 1px solid var(--hairline);
  font-family: var(--font-body);
}
#post-text:focus { outline: none; border-color: var(--gold-bright); }
.post-meta {
  text-align: right; color: var(--muted);
  font-family: var(--font-mono); font-size: 11px;
  margin: 6px 0 var(--sp-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- chart ---------- */
.chart-wrap { border: 1px solid var(--hairline); overflow: hidden; }
.chart-wrap iframe { width: 100%; height: 620px; border: 0; display: block; }
.gtrends-wrap { background: #ffffff; }
.gtrends-wrap iframe { height: 460px; }
.chart-setup { padding: 56px 24px; text-align: center; background: var(--ink-2); }
.chart-setup h3 { font-family: var(--font-display); font-size: 28px; font-weight: 400; color: var(--gold-bright); margin-bottom: var(--sp-2); }
.chart-setup p { color: var(--muted); max-width: 560px; margin: 0 auto; }
.chart-setup code { font-family: var(--font-mono); color: var(--gold); font-size: 13px; }

/* ---------- vault ---------- */
.vault-note {
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--gold);
  padding: var(--sp-3) var(--sp-4);
  color: var(--muted); font-size: 14px; margin-bottom: var(--sp-4);
}
.vault-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--sp-3); }
.vault-card { background: var(--ink-2); border: 1px solid var(--hairline); overflow: hidden; }
.vault-card img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; border-bottom: 1px solid var(--hairline-faint); }
.vault-actions { display: flex; }
.vault-actions button {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--gold); font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 11px 4px;
  border-right: 1px solid var(--hairline-faint);
  transition: all var(--fast) var(--ease);
}
.vault-actions button:last-child { border-right: none; }
.vault-actions button:hover { background: var(--gold-bright); color: var(--ink); }
.vault-empty { color: var(--muted); text-align: center; padding: 72px 0; font-family: var(--font-display); font-size: 22px; }

/* ---------- footer ---------- */
.footer {
  text-align: center; padding: var(--sp-8) 20px;
  border-top: 1px solid var(--hairline-faint);
}
.footer-coin { width: 36px; margin-bottom: var(--sp-3); opacity: .9; }
.footer-line { font-family: var(--font-mono); font-size: 11px; letter-spacing: .18em; color: var(--muted); }
.disclaimer { font-size: 12px; max-width: 620px; margin: var(--sp-3) auto 0; line-height: 1.6; color: var(--muted); opacity: .75; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .tape-track { animation: none; }
  .hero-coin { animation: none; }
  .milestone-bar { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .studio-layout, .posts-layout { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; gap: var(--sp-4); }
  .hero-art { order: -1; }
  .hero-coin { width: 180px; }
  .feature-row { grid-template-columns: 1fr; }
  .drop-card { grid-template-columns: 1fr; }
  .drop-card img { max-height: 320px; }
}

@media (max-width: 700px) {
  .nav { padding: 8px 12px; gap: 8px; }
  .nav-coin { width: 28px; height: 28px; }
  .nav-links { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex: 1; justify-content: flex-start; margin-left: 4px; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link { white-space: nowrap; padding: 9px 9px; font-size: 11px; }
  .tape { top: 46px; }
  .milestone-bar { top: 76px; }

  .view { padding: 26px 14px 56px; }
  .hero { padding: var(--sp-4) 0; }
  .btn { padding: 13px 16px; }

  .panel-canvas { order: -2; padding: var(--sp-2); }
  .panel-templates { order: -1; }
  .template-grid { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: none; gap: 6px; padding-bottom: 6px; scrollbar-width: none; }
  .template-grid::-webkit-scrollbar { display: none; }
  .template-tile { flex: 0 0 92px; }
  .chart-wrap iframe { height: 480px; }
}
