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

/* ===== BASE ===== */
html, body {
  height: 100%;
  background: #0c0d0f;
  color: #ededed;
  font-family: "Aptos", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== PAGE ENTRY (MATCH HOME) ===== */
body {
  opacity: 0;
  transition: opacity 0.8s ease;
}

body.loaded {
  opacity: 1;
}

/* ===== TOP BAR ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 78px;
  background: rgba(12,13,15,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 100;
}

.topbar-inner {
  max-width: 1600px;
  height: 100%;
  margin: 0 auto;
  padding: 0 5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  color: rgba(255,255,255,0.95);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  margin: 5px 0;
  background: rgba(255,255,255,0.9);
}

/* ===== NAV ===== */
.nav {
  display: flex;
  gap: 2.2rem;
}

.nav a {
  position: relative;
  text-decoration: none;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.6);
  padding-bottom: 6px;
  transition: color 0.25s ease;
}

.nav a:hover,
.nav a.active {
  color: #ffffff;
}

.nav a::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0%;
  height: 1px;
  background: rgba(255,255,255,0.6);
  transition: width 0.28s ease, left 0.28s ease;
}

.nav a:hover::after,
.nav a.active::after {
  width: 100%;
  left: 0;
}

/* ===== PAGE ===== */
.page {
  padding-top: 120px;
}

.page-header {
  text-align: center;
  margin-bottom: 80px;
}

.page-header h1 {
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: rgba(255,255,255,0.9);
}

/* ===== CONTENT SURFACE ===== */
.content-surface {
  background: #181818;
}

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 96px 6vw 140px;
}

/* ===== INTRO ===== */
.intro {
  max-width: 720px;
  margin: 0 auto 80px;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.7;
  color: rgba(255,255,255,0.75);
}

/* ==================================================
   RESEARCH: STACKED HORIZONTAL CARDS
   ================================================== */

.research-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.research-card {
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  transition: border-color 0.25s ease, background 0.25s ease;
}

.research-card a {
  display: block;
  padding: 36px 40px;
  text-decoration: none;
  color: inherit;
}

.research-card:hover {
  border-color: rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.04);
}

.research-card h2 {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 14px;
  letter-spacing: 0.04em;
  color: rgba(255,255,255,0.95);
}

.research-card p {
  font-size: 0.9rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.75);
  margin-bottom: 18px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  max-width: 420px;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.62);
  text-transform: uppercase;
}

/* ===== FOOTER ===== */
.footer {
  height: 64px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.6);
}

/* ===== GRAIN ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.008'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {

  .topbar {
    height: 64px;
  }

  .brand {
    font-size: 0.9rem;
    letter-spacing: 0.18em;
  }

  .menu-toggle {
    display: block;
  }

  .nav {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: #0c0d0f;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 28px 0 36px;
    border-bottom: 1px solid rgba(255,255,255,0.06);

    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
  }

  .nav.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .nav a {
    font-size: 0.78rem;
  }

  .page-header h1 {
    font-size: 1.8rem;
  }

  .content {
    padding: 72px 6vw 120px;
  }

  .intro {
    font-size: 0.95rem;
    margin-bottom: 64px;
  }

  .research-card a {
    padding: 28px;
  }

  .research-card h2 {
    font-size: 1rem;
  }

  .research-card p {
    font-size: 0.85rem;
  }
}


/* ==================================================
   CALCULATOR
   ================================================== */
.content p.lede {
  font-size: 1.05rem; line-height: 1.75; margin: 0 auto 48px;
  text-align: center; color: rgba(255,255,255,0.78); max-width: 640px;
}

/* in-page launch */
.launch { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.launch-board {
  position: relative; width: 220px; height: 132px;
  border: 1px solid rgba(120,190,255,0.28);
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 22px),
    radial-gradient(120% 120% at 50% 40%, rgba(120,190,255,0.10), transparent 60%),
    #0a0b0d;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.launch-board span { font-size: 1.6rem; letter-spacing: 0.4em; text-indent: 0.4em; color: #eaf2ff; font-weight: 600; }
.launch-btn {
  -webkit-appearance: none; appearance: none; background: #ffffff; color: #0c0d0f; border: none;
  font-family: inherit; font-size: 0.82rem; letter-spacing: 0.2em; text-transform: uppercase;
  padding: 16px 44px; cursor: pointer; transition: transform 0.15s ease;
}
.launch-btn:hover { transform: translateY(-2px); }
.launch-note { font-size: 0.72rem; letter-spacing: 0.08em; color: rgba(255,255,255,0.42); }

.how { margin: 72px auto 0; max-width: 460px; }
.how h2 { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,0.6); margin-bottom: 18px; text-align: center; }
.how dl { display: grid; grid-template-columns: auto 1fr; gap: 11px 20px; font-size: 0.84rem; }
.how dt { color: #fff; letter-spacing: 0.04em; }
.how dd { color: rgba(255,255,255,0.6); }
.back-link { margin-top: 64px; text-align: center; }
.back-link a { font-size: 0.75rem; letter-spacing: 0.08em; color: rgba(255,255,255,0.62); text-decoration: none; }
.back-link a:hover { color: #fff; }

/* full-screen stage */
.stage {
  position: fixed; inset: 0; height: 100dvh; z-index: 2000;
  background: radial-gradient(120% 80% at 50% 0%, rgba(120,190,255,0.06), transparent 60%), #06070a;
  display: flex; flex-direction: column;
  touch-action: none; overscroll-behavior: contain;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.stage[hidden] { display: none; }

.stage-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 14px;
  padding: 12px max(16px, env(safe-area-inset-left));
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.tabs { display: flex; gap: 8px; }
.tab {
  -webkit-appearance: none; appearance: none; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.14); color: rgba(255,255,255,0.7);
  font-family: inherit; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase;
  padding: 8px 16px; border-radius: 9px; cursor: pointer;
}
.tab.active { background: #eaf2ff; color: #06070a; border-color: #eaf2ff; }
.flags { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: center; }
.cx-flag {
  font-size: 0.58rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(255,255,255,0.28); border: 1px solid transparent; padding: 4px 8px; border-radius: 6px;
}
.cx-flag.on { color: #8fd8ff; border-color: rgba(120,190,255,0.5); background: rgba(120,190,255,0.08); }
.btnflag { -webkit-appearance: none; appearance: none; background: none; font-family: inherit; cursor: pointer; color: #8fd8ff; border: 1px solid rgba(120,190,255,0.45); }
.icon-btn {
  -webkit-appearance: none; appearance: none; background: none; border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.85); font-family: inherit; font-size: 0.64rem; letter-spacing: 0.14em;
  text-transform: uppercase; padding: 9px 14px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.4); color: #fff; }

.stage-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 12px; gap: 12px; max-width: 720px; width: 100%; margin: 0 auto; }

/* display */
.cx-top[hidden], .cx-graph[hidden] { display: none; }
.cx-top { flex: 0 0 auto; display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-end; gap: 6px; padding: 18px 12px; min-height: 96px; }
.cx-expr { font-size: 1.1rem; color: rgba(255,255,255,0.55); letter-spacing: 0.02em; word-break: break-all; text-align: right; min-height: 1.3em; }
.cx-result { font-size: 2.6rem; font-weight: 500; color: #fff; font-variant-numeric: tabular-nums; word-break: break-all; text-align: right; line-height: 1.1; }
.cx-result.err { color: #ff7a7a; font-size: 1.4rem; }

/* graph */
.cx-graph { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.gx-eq { display: flex; align-items: baseline; gap: 8px; padding: 8px 12px; border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; background: rgba(255,255,255,0.03); }
.gx-y { color: #8fd8ff; font-size: 1rem; }
.gx-expr { color: #fff; font-size: 1.1rem; word-break: break-all; min-height: 1.3em; }
.gx-canvas-wrap { flex: 1 1 auto; min-height: 0; border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden; background: #08090c; }
#graph { display: block; width: 100%; height: 100%; touch-action: none; }
.gx-ctrls { display: flex; align-items: center; gap: 10px; }
.gx-win { font-size: 0.62rem; color: rgba(255,255,255,0.45); font-variant-numeric: tabular-nums; letter-spacing: 0.04em; margin-left: auto; }

/* keypad */
.cx-keys { flex: 0 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.key {
  -webkit-appearance: none; appearance: none; position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 54px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05); color: #f2f5fa; font-family: inherit;
  font-size: 1.15rem; cursor: pointer; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform 0.05s ease, background 0.1s ease, border-color 0.1s ease;
}
.key:active { transform: scale(0.95); background: rgba(255,255,255,0.14); }
.key .lbl2 {
  position: absolute; top: 4px; right: 7px; font-size: 0.56rem;
  color: rgba(143,216,255,0.75); letter-spacing: 0.02em; display: none;
}
.key.fn { background: rgba(255,255,255,0.03); font-size: 0.95rem; color: #cfe6ff; }
.key.mem { background: rgba(255,255,255,0.03); font-size: 0.82rem; color: rgba(255,255,255,0.75); }
.key.op { background: rgba(120,190,255,0.10); color: #dbeeff; }
.key.op.clear { background: rgba(255,120,120,0.14); color: #ffd6d6; }
.key.eq { grid-column: span 2; background: #8fd8ff; color: #06121a; font-weight: 600; }
.key.mod.on { background: #ffd54a; color: #2a1c05; border-color: #ffd54a; }

/* when 2nd is active, show the secondary labels prominently */
.stage.second .key .lbl2 { display: block; }
.stage.second .key[data-ins2] .lbl { opacity: 0.35; }

/* ===== phone ===== */
@media (max-width: 640px) {
  .launch-board { width: 180px; height: 108px; }
  .stage-body { padding: 10px; gap: 10px; }
  .cx-keys { gap: 7px; }
  .key { min-height: 52px; font-size: 1.1rem; }
  .cx-result { font-size: 2.1rem; }
  .cx-top { min-height: 76px; padding: 12px 8px; }
  .flags .cx-flag { padding: 4px 6px; }
}
@media (max-height: 720px) and (max-width: 640px) {
  .key { min-height: 46px; }
  .cx-top { min-height: 60px; }
  .cx-result { font-size: 1.8rem; }
}


/* more-functions drawer */
.stage-body { position: relative; }
.icon-btn.on { background: #8fd8ff; color: #06121a; border-color: #8fd8ff; }
.more-panel { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; padding: 12px; background: rgba(6,7,10,0.98); }
.more-panel[hidden] { display: none; }
.more-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.6); }
.more-grid { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-content: start; }
.chip {
  -webkit-appearance: none; appearance: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 4px;
  border-radius: 12px; border: 1px solid rgba(120,190,255,0.25); background: rgba(255,255,255,0.04);
  color: #dbeeff; font-family: inherit; font-size: 1rem; cursor: pointer; text-align: center;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.chip em { font-style: normal; font-size: 0.5rem; letter-spacing: 0.03em; color: rgba(255,255,255,0.42); }
.chip:active { transform: scale(0.96); background: rgba(120,190,255,0.16); }

@media (max-width: 640px) {
  .more-grid { grid-template-columns: repeat(3, 1fr); }
  .stage-bar { flex-wrap: wrap; gap: 8px; }
}


/* readable math (stacked fractions, raised exponents) */
.mrow { display: inline-flex; align-items: center; }
.mop { padding: 0 2px; opacity: 0.85; }
.mfn { padding-right: 1px; }
.mfrac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 4px; }
.mfnum { padding: 0 6px 2px; border-bottom: 1.5px solid currentColor; line-height: 1.15; }
.mfden { padding: 2px 6px 0; line-height: 1.15; }
.msup { font-size: 0.68em; align-self: flex-start; margin-left: 1px; position: relative; top: -0.5em; }
.cx-result .mfnum, .cx-result .mfden { padding: 0 8px; }
