/* FunnyTrains — shared design tokens & base styles */

:root {
  /* Palette */
  --ink: #0E0F10;
  --ink-soft: #2A2B2C;
  --ink-mute: #6E6F70;
  --line: #DCD6C7;
  --line-soft: #E8E3D5;
  --bone: #F4F1E8;
  --bone-deep: #EAE5D5;
  --paper: #FBF9F3;
  --accent: #C8341A;          /* heritage vermilion, modernised */
  --accent-deep: #9F2912;
  --brass: #B89455;
  --signal: #E8B53E;

  /* Type */
  --ff-display: "Bricolage Grotesque", "Helvetica Neue", system-ui, sans-serif;
  --ff-sans: "Bricolage Grotesque", "Helvetica Neue", system-ui, sans-serif;
  --ff-mono: "Geist Mono", "JetBrains Mono", ui-monospace, monospace;

  --fs-eyebrow: 11px;
  --fs-body: 16px;
  --fs-lead: 19px;
  --leading-tight: 1.02;
  --leading-snug: 1.15;
  --leading-body: 1.5;

  /* Layout */
  --maxw: 1440px;
  --gutter: clamp(20px, 4vw, 56px);
  --section: clamp(80px, 10vw, 140px);
  --radius: 4px;
  --radius-lg: 14px;
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; scroll-behavior: smooth; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ff-sans);
  font-size: var(--fs-body);
  line-height: var(--leading-body);
  font-weight: 400;
  overflow-x: hidden;
}

img, video { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

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

/* Type utilities */
.eyebrow {
  font-family: var(--ff-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--ink-mute);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.eyebrow::before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 1px;
  background: currentColor;
  opacity: .6;
}
.eyebrow.no-rule::before { display: none; }

h1, h2, h3, h4, h5 {
  font-family: var(--ff-display);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: var(--leading-tight);
  margin: 0;
  font-feature-settings: "ss01";
}
.display {
  font-family: var(--ff-display);
  font-weight: 400;
  font-size: clamp(56px, 9vw, 156px);
  line-height: 0.94;
  letter-spacing: -0.02em;
}
.h-xl { font-size: clamp(44px, 6.4vw, 96px); line-height: 0.98; letter-spacing: -0.02em; }
.h-lg { font-size: clamp(34px, 4.2vw, 64px); line-height: 1.02; letter-spacing: -0.018em; }
.h-md { font-size: clamp(26px, 2.6vw, 38px); line-height: 1.1; letter-spacing: -0.01em; }
.h-sm { font-size: clamp(20px, 1.6vw, 24px); line-height: 1.2; letter-spacing: -0.005em; }
.italic { font-style: italic; }

.lead { font-size: var(--fs-lead); line-height: 1.45; color: var(--ink-soft); max-width: 56ch; }
.muted { color: var(--ink-mute); }
.serif { font-family: var(--ff-display); font-style: italic; }

/* Layout */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }
section { position: relative; }

/* Header */
.site-header {
  position: fixed; inset: 0 0 auto 0;
  z-index: 100;
  display: flex; align-items: center;
  padding: 18px var(--gutter);
  transition: background .35s var(--ease), color .35s var(--ease), border-color .35s var(--ease);
  border-bottom: 1px solid transparent;
}
.site-header.over-dark { color: var(--paper); }
.site-header.scrolled {
  background: rgba(251, 249, 243, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
}
.site-header.scrolled.dark-page {
  background: rgba(14,15,16,.78);
  border-bottom-color: rgba(255,255,255,.08);
  color: var(--paper);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--ff-display);
  font-size: 22px;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}
.brand .logo-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  position: relative;
  flex: 0 0 auto;
}
.brand .logo-mark img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
/* Black mark by default (light surfaces); swap to white on dark headers */
.brand .logo-mark .mark-dark { display: block; }
.brand .logo-mark .mark-light { display: none; }
.site-header.over-dark:not(.scrolled) .brand .logo-mark .mark-dark,
.site-header.dark-page:not(.scrolled) .brand .logo-mark .mark-dark { display: none; }
.site-header.over-dark:not(.scrolled) .brand .logo-mark .mark-light,
.site-header.dark-page:not(.scrolled) .brand .logo-mark .mark-light { display: block; }
.site-header.scrolled.dark-page .brand .logo-mark .mark-dark { display: none; }
.site-header.scrolled.dark-page .brand .logo-mark .mark-light { display: block; }

.brand-name {
  font-family: var(--ff-sans);
  font-size: 15px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  line-height: 1;
  display: inline-flex; gap: 0.35em;
  align-self: center;
  position: relative;
  top: 3px;
}
.brand-name b { font-weight: 500; }
.brand-name em { font-style: normal; font-weight: 400; opacity: .82; }

.nav {
  margin-left: auto;
  display: flex; align-items: center; gap: 4px;
  font-family: var(--ff-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav a {
  padding: 10px 14px;
  border-radius: 99px;
  transition: background .2s var(--ease), color .2s var(--ease);
  position: relative;
}
.nav a:hover { background: rgba(0,0,0,.06); }
.over-dark .nav a:hover { background: rgba(255,255,255,.1); }
.scrolled .nav a:hover { background: rgba(0,0,0,.06); }
.nav a.active { color: var(--accent); }

.header-aside {
  display: flex; align-items: center; gap: 14px;
  margin-left: 18px;
}
.lang-toggle {
  display: inline-flex;
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 99px;
  padding: 2px;
  opacity: .85;
}
.lang-toggle button {
  padding: 5px 10px;
  border-radius: 99px;
  color: inherit;
  opacity: .55;
  transition: all .2s var(--ease);
}
.lang-toggle button[aria-pressed="true"] {
  background: currentColor;
  opacity: 1;
}
.lang-toggle button[aria-pressed="true"] span { mix-blend-mode: difference; color: white; }

.cta-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent);
  color: var(--paper) !important;
  padding: 11px 18px 11px 20px;
  border-radius: 99px;
  font-family: var(--ff-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform .25s var(--ease), background .25s var(--ease);
}
.cta-pill:hover { background: var(--accent-deep); transform: translateY(-1px); }
.cta-pill .arrow { width: 14px; height: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 22px;
  border-radius: 99px;
  font-family: var(--ff-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all .25s var(--ease);
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--accent); }
.btn-accent { background: var(--accent); color: var(--paper); }
.btn-accent:hover { background: var(--accent-deep); }
.btn-ghost { border-color: currentColor; color: inherit; }
.btn-ghost:hover { background: currentColor; }
.btn-ghost:hover span { mix-blend-mode: difference; color: white; }
.btn .arrow { width: 14px; height: 14px; transition: transform .25s var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }

/* Mobile nav */
.menu-btn { display: none; }
@media (max-width: 900px) {
  .nav, .header-aside .cta-pill { display: none; }
  .menu-btn {
    display: inline-flex; align-items: center; gap: 8px;
    margin-left: auto;
    font-family: var(--ff-mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 10px 14px;
    border: 1px solid currentColor;
    border-radius: 99px;
  }
  .menu-btn .bar {
    width: 16px; height: 8px;
    display: inline-block;
    position: relative;
  }
  .menu-btn .bar::before, .menu-btn .bar::after {
    content: ""; position: absolute; left: 0; right: 0; height: 1px; background: currentColor;
  }
  .menu-btn .bar::before { top: 1px; }
  .menu-btn .bar::after { bottom: 1px; }
}

/* Mobile drawer */
.mobile-nav {
  position: fixed; inset: 0;
  background: var(--ink); color: var(--paper);
  z-index: 200;
  display: none;
  padding: 80px var(--gutter) 40px;
  flex-direction: column;
}
.mobile-nav.open { display: flex; }
.mobile-nav a {
  font-family: var(--ff-display);
  font-size: 40px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.mobile-nav .close {
  position: absolute; top: 22px; right: var(--gutter);
  font-family: var(--ff-mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
}

/* Footer */
.site-footer {
  background: var(--ink);
  color: var(--paper);
  padding: var(--section) var(--gutter) 36px;
  position: relative;
  overflow: hidden;
}
.site-footer .wrap-inner { max-width: var(--maxw); margin: 0 auto; }
.footer-display {
  font-family: var(--ff-display);
  font-size: clamp(56px, 11vw, 200px);
  line-height: 0.9;
  letter-spacing: -0.02em;
  margin: 0 0 80px;
  display: flex;
  align-items: center;
  gap: clamp(20px, 3vw, 48px);
  flex-wrap: wrap;
}
.footer-display em { color: var(--accent); font-style: italic; }
.footer-logo {
  width: clamp(180px, 22vw, 360px);
  height: auto;
  display: block;
  flex: 0 0 auto;
}
.footer-display .sup-tag {
  font-family: var(--ff-mono);
  font-size: clamp(11px, 0.9vw, 14px);
  letter-spacing: 0.14em;
  color: rgba(255,255,255,.45);
  text-transform: uppercase;
  align-self: flex-end;
  margin-bottom: clamp(14px, 2vw, 28px);
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 40px;
  align-items: start;
  padding-top: 40px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.footer-grid h5 {
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
  margin: 0 0 16px;
  font-weight: 500;
}
.footer-grid a, .footer-grid p { display: block; padding: 4px 0; color: rgba(255,255,255,.85); font-size: 15px; }
.footer-grid a:hover { color: var(--paper); }
.footer-bottom {
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--ff-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
}
@media (max-width: 720px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-bottom { flex-direction: column; gap: 12px; align-items: flex-start; }
}

/* Generic section */
.section-head {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 40px;
  align-items: end;
  margin-bottom: 64px;
}
.section-head h2 { max-width: 18ch; }
@media (max-width: 760px) { .section-head { grid-template-columns: 1fr; gap: 16px; } }

/* Cards */
.card {
  background: var(--bone);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
  overflow: hidden;
}
.card .num {
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
  margin-bottom: 28px;
  display: flex; justify-content: space-between;
}
.card h3 { font-size: 26px; margin-bottom: 12px; line-height: 1.1; }
.card p { color: var(--ink-soft); font-size: 15px; line-height: 1.5; margin: 0; }

/* Marquee */
.marquee {
  overflow: hidden;
  display: flex;
  border-block: 1px solid var(--line-soft);
  padding: 22px 0;
}
.marquee-track {
  display: flex; gap: 60px;
  animation: marquee 50s linear infinite;
  font-family: var(--ff-display);
  font-size: clamp(28px, 4vw, 48px);
  white-space: nowrap;
  padding-left: 60px;
}
.marquee-track span { display: inline-flex; align-items: center; gap: 60px; }
.marquee-track .dot { color: var(--accent); }
@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* Image placeholder defaults */
.img-placeholder {
  border-radius: var(--radius-lg);
  background: var(--bone-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.img-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.img-placeholder .ph-icon {
  opacity: .18;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Pill row */
.pill-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 7px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--paper);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* Reveal animation */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .9s var(--ease), transform .9s var(--ease); }
.reveal.in { opacity: 1; transform: none; }
.reveal.d2 { transition-delay: .1s; }
.reveal.d3 { transition-delay: .2s; }
.reveal.d4 { transition-delay: .3s; }

/* Language switching */
[data-lang]:not(.lang-show) { display: none; }

/* Arrow icon */
.icon-arrow { width: 14px; height: 14px; flex-shrink: 0; }

/* Hide chrome when on small screen */
@media (max-width: 600px) {
  .section-head { margin-bottom: 32px; }
  .card { padding: 22px; }
  .footer-display { margin-bottom: 40px; }
}

/* Dark theme blocks */
.theme-dark {
  background: var(--ink);
  color: var(--paper);
}
.theme-dark .lead, .theme-dark p { color: rgba(255,255,255,.7); }
.theme-dark .muted { color: rgba(255,255,255,.55); }
.theme-dark .eyebrow { color: rgba(255,255,255,.6); }
.theme-dark .card { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.08); }
.theme-dark .card p { color: rgba(255,255,255,.7); }
.theme-dark .pill { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.14); color: rgba(255,255,255,.8); }

/* Accent text */
.accent { color: var(--accent); }
.accent-bg { background: var(--accent); color: var(--paper); }

/* ============================================================
   MOBILE OPTIMIZATION  (≤900 tablet, ≤640 phone, ≤420 small)
   Comprehensive overrides — keep at bottom so they win specificity.
   ============================================================ */

/* ------- TABLET / ≤900px ------- */
@media (max-width: 900px) {
  :root {
    --section: clamp(56px, 9vw, 96px);
    --gutter: clamp(18px, 4.5vw, 32px);
  }
  .site-header { padding: 14px var(--gutter); }
  .brand { font-size: 20px; gap: 10px; }
  .brand .logo-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 13px; letter-spacing: 0.16em; }
}

/* ------- PHONE / ≤640px ------- */
@media (max-width: 640px) {
  :root {
    --section: clamp(48px, 12vw, 76px);
    --gutter: 18px;
    --maxw: 100%;
  }

  /* Header */
  .site-header { padding: 12px 18px; }
  .brand { font-size: 17px; gap: 9px; }
  .brand .logo-mark { width: 30px; height: 30px; }
  .brand-name { font-size: 12px; letter-spacing: 0.14em; }
  .header-aside { gap: 10px; margin-left: 10px; }
  .lang-toggle { font-size: 10px; }
  .lang-toggle button { padding: 4px 8px; }
  .menu-btn { padding: 8px 12px; font-size: 11px; min-height: 38px; }

  /* Mobile drawer — better touch targets */
  .mobile-nav { padding: 70px 22px 30px; gap: 4px; }
  .mobile-nav a { font-size: 30px; padding: 12px 0; }

  /* Type scale on phone */
  .display { font-size: clamp(40px, 12vw, 72px); line-height: .95; }
  .h-xl { font-size: clamp(32px, 9vw, 52px); }
  .h-lg { font-size: clamp(28px, 8vw, 44px); }
  .h-md { font-size: clamp(22px, 5.4vw, 30px); }
  .h-sm { font-size: clamp(17px, 4.4vw, 21px); }
  .lead { font-size: 16px; line-height: 1.5; }

  /* Buttons → full width on phone for primary CTAs */
  .btn { padding: 14px 20px; font-size: 11px; min-height: 48px; box-sizing: border-box; }
  .cta-pill { padding: 10px 14px 10px 16px; font-size: 11px; min-height: 38px; }

  /* Section head: stack tighter */
  .section-head { grid-template-columns: 1fr; gap: 14px; margin-bottom: 36px; }
  .section-head h2 { max-width: none; }

  /* Footer — single col, smaller display */
  .footer-display {
    font-size: clamp(40px, 14vw, 64px);
    margin-bottom: 40px;
    gap: 16px;
  }
  .footer-logo { width: clamp(140px, 50vw, 220px); }
  .footer-display .sup-tag { display: none; }
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 28px; padding-top: 32px; }
  .footer-grid h5 { font-size: 10px; }
  .footer-grid a, .footer-grid p { font-size: 14px; padding: 3px 0; }
  .footer-bottom { margin-top: 40px; padding-top: 18px; flex-direction: column; gap: 10px; align-items: flex-start; font-size: 10px; }

  /* Marquee — quieter on phone */
  .marquee { padding: 16px 0; }
  .marquee-track { font-size: clamp(22px, 7vw, 32px); gap: 40px; padding-left: 40px; }
  .marquee-track span { gap: 40px; }

  /* Cards */
  .card { padding: 20px; border-radius: 12px; }
  .card h3 { font-size: 22px; }
  .card p { font-size: 14px; }

  /* Pills — touch-friendly */
  .pill { padding: 8px 12px; min-height: 32px; }
}

/* ------- SMALL PHONE / ≤420px ------- */
@media (max-width: 420px) {
  .brand-name { display: none; } /* keep only logo mark on tiny screens */
  .header-aside .lang-toggle { display: none; }
  .footer-grid { grid-template-columns: 1fr; }
}

/* Touch hover-suppression — phones don't sustain hover state */
@media (hover: none) {
  .nav a:hover, .btn:hover, .cta-pill:hover,
  .app-tile:hover, .g-tile:hover, .config-card:hover, .p-card:hover,
  .adv:hover {
    background: revert; transform: none; border-color: revert; box-shadow: revert;
  }
}

/* Smooth scroll snap on mobile horizontal scrollers (if any) */
@media (max-width: 640px) {
  .scroll-snap-x {
    display: flex; gap: 14px; overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 0 var(--gutter);
    scrollbar-width: none;
  }
  .scroll-snap-x::-webkit-scrollbar { display: none; }
  .scroll-snap-x > * { scroll-snap-align: start; flex: 0 0 86%; }
}
