:root {
  --bg: #06060c; --bg2: #0c0c16; --bg3: #111120;
  --card: #0e0e1a; --border: #1e1e32; --glow-border: #2a2a48;
  --text: #e4e2df; --text2: #7d7a8c; --text3: #4a475a;
  --a1: #ff6b6b; --a2: #4ecdc4; --a3: #ffd166; --a4: #a78bfa;
  --a5: #f472b6; --a6: #38bdf8; --a7: #fb923c; --a8: #34d399;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --mono: 'Fira Code', 'Consolas', monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: #1e1e32 #06060c; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.65; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
a { color: var(--a2); text-decoration: none; transition: color .25s var(--ease); }
a:hover { color: var(--a3); }

/* ===== TOP NAV ===== */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(6,6,12,.82); backdrop-filter: blur(20px) saturate(1.6);
  border-bottom: 1px solid rgba(30,30,50,.5);
  padding: .55rem 1.8rem; display: flex; align-items: center; justify-content: space-between;
}
.topnav .logo {
  font-family: var(--serif); font-weight: 900; font-size: 1rem; letter-spacing: -.02em;
  background: linear-gradient(135deg, #fff 20%, var(--a2) 80%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.topnav .nav-links { display: flex; gap: .25rem; }
.topnav .nav-links a {
  font-family: var(--mono); font-size: .6rem; padding: .2rem .55rem;
  border: 1px solid transparent; border-radius: 20px;
  color: var(--text2); transition: all .25s var(--ease);
}
.topnav .nav-links a:hover, .topnav .nav-links a.active {
  border-color: var(--a2); color: var(--a2); background: rgba(78,205,196,.06);
}

/* ===== EW LOGO ===== */
.ew-logo {
  display: inline-flex; align-items: center; gap: .6rem;
  margin-bottom: 1.5rem; animation: fadeDown .8s var(--ease) both;
}
.ew-logo svg { width: 42px; height: 42px; flex-shrink: 0; }
.ew-logo .ew-text {
  font-family: var(--sans); font-weight: 600; font-size: .68rem;
  letter-spacing: .16em; text-transform: uppercase; color: #8a8a9a;
}

/* ===== AUTHOR ===== */
.author-line { margin-top: .6rem; animation: fadeUp .8s .38s var(--ease) both; }
.author-line a {
  font-family: var(--mono); font-size: .68rem; color: var(--text3);
  border-bottom: 1px dashed var(--text3); padding-bottom: 1px; transition: all .25s;
}
.author-line a:hover { color: var(--a2); border-color: var(--a2); }

/* ===== HERO ===== */
.hero {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  position: relative; overflow: hidden; padding: 2rem;
}
.hero-bg {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 55% 45% at 50% 40%, rgba(78,205,196,.06), transparent 70%),
    radial-gradient(ellipse 35% 25% at 25% 65%, rgba(255,107,107,.04), transparent),
    radial-gradient(ellipse 35% 25% at 75% 55%, rgba(167,139,250,.04), transparent);
}
.hero-content { position: relative; z-index: 2; }
.hero .badge {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .35rem 1rem; border: 1px solid var(--border); border-radius: 50px;
  font-family: var(--mono); font-size: .68rem; color: var(--a2);
  letter-spacing: .04em; margin-bottom: 1.2rem;
  animation: fadeDown .8s var(--ease) both;
}
.hero .badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--a2); animation: blink 2s infinite; }
.hero h1 {
  font-family: var(--serif); font-size: clamp(3rem, 8vw, 6.5rem);
  font-weight: 900; letter-spacing: -.03em; line-height: 1.05;
  background: linear-gradient(135deg, #fff 0%, var(--a2) 45%, var(--a5) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  animation: fadeUp .8s .15s var(--ease) both;
}
.hero .sub {
  font-size: clamp(.95rem, 2.2vw, 1.2rem); color: var(--text2);
  max-width: 520px; margin: 1rem auto .5rem; font-weight: 300; line-height: 1.7;
  animation: fadeUp .8s .3s var(--ease) both;
}
.hero .scroll-cue {
  animation: fadeUp .8s .5s var(--ease) both, float 3s ease-in-out infinite 1s;
  color: var(--text3); font-size: .75rem; font-family: var(--mono);
}

/* ===== TOC GRID ===== */
.toc { max-width: 960px; margin: 0 auto; padding: 0 1.5rem 5rem; }
.toc h2 { font-family: var(--serif); font-size: 1.6rem; margin-bottom: 2rem; text-align: center; color: var(--a3); font-weight: 700; }
.toc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1.2rem; }
.toc-card {
  background: linear-gradient(135deg, var(--bg2), rgba(14,14,26,.8));
  border: 1px solid var(--border); border-radius: 16px;
  padding: 1.5rem 1.7rem; transition: all .4s var(--ease);
  position: relative; overflow: hidden; cursor: pointer;
}
.toc-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; transition: opacity .4s, height .4s; opacity: .5; }
.toc-card::after { content: ''; position: absolute; inset: 0; border-radius: 16px; background: radial-gradient(ellipse at 50% 0%, var(--card-glow, rgba(78,205,196,.04)), transparent 70%); opacity: 0; transition: opacity .4s; }
.toc-card:hover { border-color: var(--card-accent, var(--a2)); transform: translateY(-4px); box-shadow: 0 20px 60px rgba(0,0,0,.4), 0 0 40px var(--card-glow, rgba(78,205,196,.06)); }
.toc-card:hover::before { opacity: 1; height: 3px; }
.toc-card:hover::after { opacity: 1; }
.toc-card .era-num { font-family: var(--mono); font-size: .62rem; letter-spacing: .12em; text-transform: uppercase; margin-bottom: .15rem; }
.toc-card h3 { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; margin-bottom: .2rem; position: relative; z-index: 1; }
.toc-card h3 a { color: var(--text); }
.toc-card .era-desc { font-size: .8rem; color: var(--text2); margin-bottom: .7rem; position: relative; z-index: 1; }
.toc-card .model-tags { display: flex; flex-wrap: wrap; gap: .2rem; position: relative; z-index: 1; }
.toc-card .model-tags span { font-size: .58rem; font-family: var(--mono); color: var(--text3); padding: .1rem .4rem; border: 1px solid rgba(30,30,50,.6); border-radius: 20px; transition: all .2s; }
.toc-card:hover .model-tags span { color: var(--text2); border-color: var(--border); }
.toc-card .enter-arrow { position: absolute; right: 1.5rem; bottom: 1.4rem; font-family: var(--mono); font-size: .72rem; opacity: 0; transform: translateX(-8px); transition: all .3s var(--ease); z-index: 1; }
.toc-card:hover .enter-arrow { opacity: 1; transform: translateX(0); }

/* ===== SECTION PAGE ===== */
.section-hero { padding: 7.5rem 1.5rem 3.5rem; text-align: center; position: relative; overflow: hidden; }
.section-hero .era-label { font-family: var(--mono); font-size: .72rem; letter-spacing: .15em; text-transform: uppercase; margin-bottom: .5rem; animation: fadeDown .6s var(--ease) both; }
.section-hero h1 { font-family: var(--serif); font-size: clamp(2rem, 5.5vw, 3.2rem); font-weight: 900; letter-spacing: -.02em; margin-bottom: .4rem; animation: fadeUp .6s .1s var(--ease) both; }
.section-hero p { color: var(--text2); max-width: 500px; margin: 0 auto; font-size: .92rem; animation: fadeUp .6s .2s var(--ease) both; }
.section-hero .nav-arrows { margin-top: 1.5rem; display: flex; justify-content: center; gap: 1rem; animation: fadeUp .6s .3s var(--ease) both; }
.section-hero .nav-arrows a { font-family: var(--mono); font-size: .72rem; padding: .4rem 1rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text2); transition: all .25s var(--ease); }
.section-hero .nav-arrows a:hover { border-color: var(--a2); color: var(--a2); }

/* ===== MODEL CARDS ===== */
.models-container { max-width: 960px; margin: 0 auto; padding: 1rem 1.5rem 4rem; }
.model-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden; margin-bottom: 2.8rem;
  transition: all .4s var(--ease); animation: fadeUp .6s var(--ease) both;
}
.model-card:hover { border-color: rgba(78,205,196,.2); box-shadow: 0 16px 60px rgba(0,0,0,.35), 0 0 30px rgba(78,205,196,.03); }
.mc-head { padding: 1.6rem 1.6rem 1rem; display: flex; align-items: flex-start; gap: 1rem; }
.mc-year {
  font-family: var(--mono); font-size: .62rem; font-weight: 500;
  background: rgba(255,209,102,.06); border: 1px solid rgba(255,209,102,.15);
  padding: .18rem .6rem; border-radius: 20px; white-space: nowrap; flex-shrink: 0; margin-top: .3rem;
}
.mc-info h3 {
  font-family: var(--serif); font-size: 1.3rem; font-weight: 700;
  margin-bottom: .3rem; letter-spacing: -.01em;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
.mc-info p { font-size: .86rem; color: var(--text2); line-height: 1.55; }
/* Model lineage / relationship link */
.mc-info .model-lineage {
  font-size: .74rem; color: var(--text3); margin-top: .25rem;
  font-style: italic; line-height: 1.5;
}
.mc-info .model-lineage a {
  color: var(--a2); font-style: normal; font-weight: 500;
  border-bottom: 1px dashed rgba(78,205,196,.35); padding-bottom: 0;
}
.mc-info .model-lineage a:hover { color: var(--a3); border-color: var(--a3); }
.mc-formula {
  margin: 0 1.6rem; padding: .65rem 1rem; background: var(--bg);
  border-radius: 8px; border: 1px solid rgba(30,30,50,.4);
  font-family: var(--mono); font-size: .72rem; overflow-x: auto; white-space: nowrap;
}

/* ===== PAPER LINK — Distinct button ===== */
.paper-link {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .52rem; font-family: var(--mono); font-weight: 500;
  color: var(--text3); letter-spacing: .06em; text-transform: uppercase;
  background: var(--bg2); border: 1px solid var(--border);
  padding: .18rem .5rem .18rem .35rem; border-radius: 5px;
  transition: all .25s var(--ease); text-decoration: none; flex-shrink: 0;
  vertical-align: middle;
}
.paper-link::before { content: '📄'; font-size: .55rem; line-height: 1; }
.paper-link:hover { color: var(--a2); border-color: var(--a2); background: rgba(78,205,196,.06); box-shadow: 0 0 12px rgba(78,205,196,.1); }

/* ===== DEMO AREA ===== */
.mc-demo {
  margin: 1rem 1.6rem 1.6rem; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden; position: relative;
}
.mc-demo canvas { display: block; width: 100%; height: auto; cursor: crosshair; background: transparent; }
.demo-controls {
  padding: .65rem 1rem; display: flex; gap: .5rem; flex-wrap: wrap;
  align-items: center; border-top: 1px solid var(--border); background: var(--bg3);
}
.demo-hint { font-size: .65rem; color: var(--text3); padding: .4rem 1rem; font-family: var(--mono); letter-spacing: .02em; }
.demo-area { padding: 1rem; min-height: 100px; }

/* Form elements */
input[type=range] { -webkit-appearance: none; background: var(--border); height: 3px; border-radius: 2px; outline: none; flex: 1; max-width: 140px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: var(--a2); border-radius: 50%; cursor: pointer; box-shadow: 0 0 8px rgba(78,205,196,.3); }
.btn {
  font-family: var(--mono); font-size: .65rem; font-weight: 500;
  padding: .35rem .75rem; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); border-radius: 6px;
  cursor: pointer; transition: all .2s var(--ease); letter-spacing: .02em; white-space: nowrap;
}
.btn:hover { border-color: var(--a2); color: var(--a2); background: rgba(78,205,196,.04); }
.btn.active { background: var(--a2); color: var(--bg); border-color: var(--a2); }
label { font-family: var(--mono); font-size: .62rem; color: var(--text3); }

/* Footer */
footer { text-align: center; padding: 3rem 1.5rem; color: var(--text3); font-size: .78rem; border-top: 1px solid var(--border); margin-top: 2rem; }
footer a { color: var(--text2); }

/* Utility */
.progress-bar { position: fixed; top: 0; left: 0; height: 2px; z-index: 200; transition: width .12s; }
.back-top {
  position: fixed; bottom: 2rem; right: 2rem; width: 38px; height: 38px;
  background: var(--a2); color: var(--bg); border: none; border-radius: 50%;
  font-size: 1rem; cursor: pointer; opacity: 0; transition: all .3s var(--ease);
  z-index: 99; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(78,205,196,.25);
}
.back-top.show { opacity: 1; }
.back-top:hover { transform: scale(1.1) translateY(-2px); }

/* Animations */
@keyframes fadeUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ===== MOBILE — Tablet ===== */
@media (max-width: 768px) {
  .toc-grid { grid-template-columns: 1fr; }
  .mc-head { flex-direction: column; gap: .5rem; padding: 1.2rem 1rem .8rem; }
  .mc-formula { margin: 0 1rem; font-size: .62rem; }
  .mc-demo { margin: .8rem 1rem 1rem; }
  .models-container { padding: 1rem .8rem 3rem; }
  .topnav { padding: .5rem .8rem; }
  .topnav .nav-links { gap: .12rem; }
  .topnav .nav-links a { font-size: .52rem; padding: .15rem .38rem; }
  .section-hero { padding: 5.5rem 1rem 2.5rem; }
  .section-hero .nav-arrows a { font-size: .62rem; padding: .3rem .7rem; }
  .demo-controls { padding: .5rem .6rem; gap: .35rem; }
  .btn { font-size: .58rem; padding: .28rem .55rem; }
  label { font-size: .55rem; }
  input[type=range] { max-width: 100px; }
  .hero .stat-row { gap: 1.5rem; }
  .hero .stat .num { font-size: 1.5rem; }
  .toc { padding: 0 .8rem 3rem; }
  .toc-card { padding: 1.2rem; }
}

/* ===== MOBILE — Phone ===== */
@media (max-width: 420px) {
  .topnav .logo { font-size: .78rem; }
  .topnav .nav-links a { font-size: .42rem; padding: .1rem .22rem; }
  .mc-info h3 { font-size: 1.05rem; gap: .4rem; }
  .mc-demo { margin: .5rem .5rem .7rem; border-radius: 10px; }
  .mc-formula { margin: 0 .5rem; padding: .4rem .5rem; font-size: .52rem; }
  .mc-head { padding: .9rem .7rem .5rem; }
  .mc-info p { font-size: .78rem; }
  .demo-hint { font-size: .52rem; padding: .25rem .5rem; }
  .hero h1 { font-size: clamp(2.2rem, 10vw, 3.5rem); }
  .hero .sub { font-size: .88rem; }
  .paper-link { font-size: .48rem; padding: .15rem .4rem; }
  .ew-logo svg { width: 32px; height: 32px; }
  .ew-logo .ew-text { font-size: .58rem; }
  .section-hero h1 { font-size: clamp(1.5rem, 6vw, 2.2rem); }
  .back-top { bottom: 1rem; right: 1rem; width: 32px; height: 32px; font-size: .85rem; }
}

/* Responsive: avoid horizontal clipping on small screens */
@media (max-width: 520px){
  .toc-grid{grid-template-columns: 1fr !important;}
}

@media (prefers-reduced-motion: reduce){
  html{scroll-behavior: auto;}
  .hero-bg{display:none;}
  *{animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important;}
}

/* Better mobile interactions for demos */
canvas{touch-action: none;}
