/* ══════════════════════════════════════════════════════
   Calc III Flash Cards — Shared Stylesheet
   ══════════════════════════════════════════════════════ */

/* ── Reset & Tokens ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f5f4f0;
  --surface:    #ffffff;
  --back-bg:    #1a1a1a;
  --back-text:  #f5f4f0;
  --accent:     #2a52be;
  --accent-dim: #d6ddf7;
  --muted:      #8a8880;
  --border:     #e2e0da;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.14);
  --radius:     14px;
  --nav-h:      56px;
  --font-serif: 'DM Serif Display', Georgia, serif;
  --font-sans:  'DM Sans', system-ui, sans-serif;
  --flip-speed: 0.55s;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: #1a1a1a;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Top Nav ─────────────────────────────────────────── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: rgba(245,244,240,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
}

.topnav-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: -.01em;
  text-decoration: none;
  color: #1a1a1a;
}
.topnav-title span { color: var(--accent); font-style: italic; }

/* ── Hamburger ───────────────────────────────────────── */
.hamburger {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  border-radius: 8px;
  transition: background .15s ease;
}
.hamburger:hover { background: var(--accent-dim); }

.hamburger .bar {
  display: block;
  width: 22px;
  height: 2px;
  background: #1a1a1a;
  border-radius: 2px;
  transition: transform .3s ease, opacity .3s ease;
  transform-origin: center;
}
.hamburger.open .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open .bar:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger.open .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Drawer Overlay ──────────────────────────────────── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background .3s ease;
}
.drawer-overlay.open {
  background: rgba(0,0,0,.32);
  pointer-events: all;
}

/* ── Drawer ──────────────────────────────────────────── */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  width: min(280px, 80vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header span {
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.drawer-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.drawer-close:hover { background: var(--bg); color: #1a1a1a; }

.drawer-nav {
  list-style: none;
  padding: .75rem 0;
  flex: 1;
}
.drawer-nav li a {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .85rem 1.5rem;
  text-decoration: none;
  color: #1a1a1a;
  font-size: .95rem;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.drawer-nav li a:hover { background: var(--bg); }
.drawer-nav li a.active { color: var(--accent); font-weight: 500; }
.drawer-nav li a .nav-icon { width: 20px; text-align: center; flex-shrink: 0; }

.nav-soon {
  font-size: .65rem;
  color: var(--muted);
  margin-left: auto;
  font-weight: 400;
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: .5rem 1.5rem;
}

.drawer-footer {
  padding: 1rem 1.5rem;
  font-size: .72rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Shared Divider ──────────────────────────────────── */
.divider {
  max-width: 900px;
  margin: 1rem auto 0;
  height: 1px;
  background: var(--border);
}

/* ── Footer ──────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  font-size: .72rem;
  color: var(--muted);
  letter-spacing: .03em;
}

/* ══════════════════════════════════════════════════════
   INDEX — Cards Page
   ══════════════════════════════════════════════════════ */

.cards-header {
  padding: 1.5rem 1.5rem 0;
  max-width: 900px;
  margin: 0 auto;
}

.cards-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}

h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 400;
  letter-spacing: -.01em;
  line-height: 1.1;
}
h1 span { color: var(--accent); font-style: italic; }

.progress-label {
  font-size: .8rem;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.progress-label strong { color: #1a1a1a; font-weight: 500; }

/* ── Filter Bar ──────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-bottom: .25rem;
}

.filter-btn {
  font-family: var(--font-sans);
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .45rem 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Card Grid ───────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 1rem;
}

/* ── Flip Card ───────────────────────────────────────── */
.card-wrap {
  perspective: 1200px;
  animation: fadeUp .35s ease both;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transform-style: preserve-3d;
  transition: transform var(--flip-speed) cubic-bezier(.4,0,.2,1);
  border-radius: var(--radius);
  /* Force GPU compositing layer for smooth flip */
  will-change: transform;
}

@media (max-width: 400px) { .card { aspect-ratio: 4 / 3; } }

.card.flipped { transform: rotateY(180deg); }

.card.learned .card-front {
  box-shadow: var(--shadow), 0 0 0 2px var(--accent);
}

/* ── Card Faces ──────────────────────────────────────── */
.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 1.2rem 1.1rem 1rem;
  gap: .55rem;
  overflow: hidden;
}

.card-front {
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
}

.card-back {
  background: var(--back-bg);
  color: var(--back-text);
  transform: rotateY(180deg);
  box-shadow: var(--shadow-lg);
}

/* ── Chip ────────────────────────────────────────────── */
.chip {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: .2rem .65rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  flex-shrink: 0;
  line-height: 1.6;
}
.card-back .chip {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.65);
}

/* ── Card Text ───────────────────────────────────────── */
.card-title {
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 3.5vw, 1.25rem);
  font-weight: 400;
  line-height: 1.3;
  color: #1a1a1a;
  max-width: 100%;
  overflow: visible;
}

/* Plain-text titles (no math) get slightly bolder serif weight */
.card-title:not(:has(mjx-container)) {
  font-size: clamp(1.1rem, 3.8vw, 1.3rem);
}

.card-back .card-title {
  color: var(--back-text);
}

.card-sub {
  font-size: clamp(.82rem, 2.4vw, .95rem);
  color: var(--muted);
  line-height: 1.5;
  max-width: 100%;
  font-weight: 300;
}
.card-back .card-sub { color: rgba(255,255,255,.55); }

/*
  MathJax output — keep it from blowing out of the card.
  MathJax renders into mjx-container elements.
*/
mjx-container {
  max-width: 100% !important;
  overflow: visible !important;
}

mjx-container svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Math in the title — render at full card-title size, no shrink */
.card-title mjx-container {
  font-size: 1em !important;
}

/* Math in the subtitle — slightly smaller but still legible */
.card-sub mjx-container {
  font-size: 0.95em !important;
}

/* ── Check Button ────────────────────────────────────── */
.check-btn {
  position: absolute;
  top: .55rem;
  right: .55rem;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all .2s ease;
  z-index: 10;
  color: var(--muted);
  font-size: 12px;
}
.check-btn:hover { border-color: var(--accent); color: var(--accent); }
.card.learned .check-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Empty State ─────────────────────────────────────── */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--muted);
  font-size: .9rem;
}

/* ── Loading overlay ─────────────────────────────────── */
.math-loading {
  opacity: 0;
  transition: opacity .3s ease;
}
.math-ready {
  opacity: 1;
}

/* ══════════════════════════════════════════════════════
   ABOUT PAGE
   ══════════════════════════════════════════════════════ */

.about-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
}

.about-eyebrow {
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .75rem;
}

.about-page h2 {
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -.02em;
  margin-bottom: 1.75rem;
}
.about-page h2 em { color: var(--accent); font-style: italic; }

.about-body {
  font-size: .97rem;
  line-height: 1.8;
  color: #3d3d3d;
}
.about-body p + p { margin-top: 1.15rem; }

.about-divider {
  height: 1px;
  background: var(--border);
  margin: 2.25rem 0;
}

.about-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1rem;
  text-align: center;
}

.stat-num {
  font-family: var(--font-serif);
  font-size: 2.1rem;
  color: var(--accent);
  font-style: italic;
  line-height: 1;
}

.stat-label {
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: .4rem;
}

.about-back-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin-top: 2.25rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  text-decoration: none;
  transition: opacity .15s;
}
.about-back-btn:hover { opacity: .65; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */

@media (orientation: landscape) and (max-height: 600px) {
  .cards-header { padding-top: .75rem; }
  h1 { font-size: 1.3rem; }
  .filter-bar { margin-top: .6rem; }
  main { padding-top: .75rem; }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: .75rem;
  }
  .card { aspect-ratio: 5 / 3; }
}

@media (max-width: 480px) {
  .cards-header { padding: 1.1rem 1rem 0; }
  .about-page { padding: 1.5rem 1rem 2rem; }
}

/* ══════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-fadein { animation: pageFadeIn .22s ease both; }
