/* ============================================================
   ChemLearn — Design System
   ============================================================ */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1a2033;
  --text-muted: #5b6478;
  --border: #e3e7f0;
  --border-strong: #b3bdd6;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --accent: #06b6d4;
  --gradient: linear-gradient(120deg, #4f46e5 0%, #7c3aed 55%, #06b6d4 100%);

  --success: #16a34a;
  --success-soft: #e7f8ee;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #d97706;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 24px rgba(23, 32, 64, 0.07);
  --shadow-lg: 0 16px 44px rgba(23, 32, 64, 0.13);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #171e2e;
  --surface-2: #1f2740;
  --text: #e8ecf6;
  --text-muted: #9aa4bd;
  --border: #2a3450;
  --border-strong: #4d5b85;

  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-soft: #232b4d;
  --accent: #22d3ee;

  --success: #4ade80;
  --success-soft: #11321f;
  --danger: #f87171;
  --danger-soft: #3a1719;
  --warning: #fbbf24;

  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.5);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ============ Header / Nav ============ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 62px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text);
  text-decoration: none !important;
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--gradient);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: #fff;
}

.main-nav { display: flex; align-items: center; gap: 4px; }

.main-nav a {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 999px;
  transition: all 0.15s ease;
}

.main-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.main-nav a.active { color: var(--primary); background: var(--primary-soft); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease;
}
.theme-toggle:hover { background: var(--surface-2); transform: rotate(15deg); }
.theme-toggle:active { transform: rotate(15deg) scale(0.9); }

.nav-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
}
.nav-toggle:hover { background: var(--surface-2); }
.nav-toggle:active { transform: scale(0.9); }

/* Keyboard focus rings for the header icon buttons */
.theme-toggle:focus-visible, .nav-toggle:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.28);
}

/* ============ Buttons ============ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.18s ease, filter 0.15s ease,
    background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none !important;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.3); }

.btn-primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(79, 70, 229, 0.45); filter: brightness(1.07); }

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost .arrow { display: inline-block; transition: transform 0.18s ease; }
.btn-ghost:hover .arrow { transform: translateX(4px); }

/* Press feedback — declared after variants so it wins while hovering */
.btn:active { transform: translateY(0) scale(0.97); filter: brightness(0.97); }

.btn-sm { padding: 8px 16px; font-size: 0.9rem; border-radius: 10px; }

/* ============ Hero ============ */

.hero {
  position: relative;
  overflow: hidden;
  background: var(--gradient);
  color: #fff;
  padding: 84px 0 92px;
}

.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.09);
}
.hero::before { width: 480px; height: 480px; top: -200px; right: -120px; }
.hero::after { width: 320px; height: 320px; bottom: -160px; left: -100px; }

.hero-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 48px;
}

.hero-copy { max-width: 600px; }

.hero-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 18px;
  letter-spacing: 0.4px;
}

.hero h1 {
  font-size: clamp(2.1rem, 4.5vw, 3.3rem);
  line-height: 1.15;
  font-weight: 800;
  margin-bottom: 18px;
}

.hero p {
  font-size: 1.13rem;
  opacity: 0.92;
  margin-bottom: 30px;
  max-width: 520px;
}

.hero-cta { display: flex; gap: 14px; flex-wrap: wrap; }

.hero .btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.55); }
.hero .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* Animated hand-drawn atom (injected by js/demos.js) */
.hero-atom {
  width: 250px;
  height: 250px;
  flex-shrink: 0;
  color: #fff;
  animation: float 5s ease-in-out infinite;
}
.hero-atom svg { width: 100%; height: 100%; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }

/* ============ Hand-drawn SVG icons ============ */

.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.22em;
  fill: none;
}
.logo-mark .icon { width: 19px; height: 19px; color: #fff; }
.theme-toggle .icon { width: 19px; height: 19px; }
.nav-toggle .icon { width: 20px; height: 20px; }
.hero-badge .icon { width: 1em; height: 1em; }
.feature-icon .icon { width: 30px; height: 30px; color: var(--primary); }
.lesson-icon .icon { width: 34px; height: 34px; color: var(--primary); }
.badge .icon { width: 0.95em; height: 0.95em; }
.tool-card h2 .icon { width: 26px; height: 26px; color: var(--primary); }
.footer-bottom .icon { width: 14px; height: 14px; color: var(--primary); }
.result-msg .icon { width: 1.25em; height: 1.25em; }
.back-link .icon { width: 1.1em; height: 1.1em; }

/* ============ Animated demo cards ============ */

.demo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.demo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.demo-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.demo-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.demo-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 10px; }
.demo-card a { font-weight: 700; font-size: 0.9rem; }

.demo-frame {
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 16px;
  color: var(--text);
}
.demo-frame svg { display: block; width: 100%; height: auto; }
.demo-frame[data-demo="atom"] svg { max-width: 380px; margin: 0 auto; }

.demo-caption {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  margin: 8px 0 16px;
}
.article .demo-frame { margin: 24px 0 8px; }

/* ============ Stats bar ============ */

.stats-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 26px 0;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  text-align: center;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-label { color: var(--text-muted); font-size: 0.92rem; font-weight: 600; }

/* ============ Sections ============ */

.section { padding: 64px 0; }
.section-alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.section-head { text-align: center; max-width: 640px; margin: 0 auto 44px; }
.section-head .kicker {
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 0.8rem;
}
.section-head h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); font-weight: 800; margin: 8px 0 12px; }
.section-head p { color: var(--text-muted); }

/* ============ Feature cards ============ */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  color: var(--text);
  text-decoration: none !important;
  display: flex;
  flex-direction: column;
}
.feature-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }

.feature-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 26px;
  background: var(--primary-soft);
  margin-bottom: 16px;
}

.feature-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.feature-card p { color: var(--text-muted); font-size: 0.93rem; flex: 1; }
.feature-card .card-link { margin-top: 14px; font-weight: 700; font-size: 0.9rem; color: var(--primary); }

/* ============ Topic list (home) ============ */

.topics-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.topic-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none !important;
  transition: border-color 0.15s ease;
}
.topic-item:hover { border-color: var(--primary); }
.topic-item .num {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ============ CTA banner ============ */

.cta-banner {
  background: var(--gradient);
  border-radius: 20px;
  padding: 48px 40px;
  text-align: center;
  color: #fff;
}
.cta-banner h2 { font-size: 1.8rem; font-weight: 800; margin-bottom: 10px; }
.cta-banner p { opacity: 0.9; margin-bottom: 24px; }

/* ============ Ad slots ============ */

.ad-slot {
  margin: 0 auto;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  overflow: hidden;
}
.ad-slot .ad-label {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 0.66rem;
  font-weight: 700;
  opacity: 0.7;
}
.ad-leaderboard { max-width: 970px; min-height: 100px; padding: 14px; margin: 18px auto; }
.ad-inline { max-width: 970px; min-height: 100px; padding: 14px; margin: 26px auto; }
.ad-rectangle { width: 300px; min-height: 250px; padding: 14px; }

/* ============ Page hero (subpages) ============ */

.page-hero {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 44px 0 36px;
}
.page-hero h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); font-weight: 800; margin-bottom: 8px; }
.page-hero p { color: var(--text-muted); max-width: 640px; }

/* ============ Periodic Table ============ */

.pt-layout { display: flex; gap: 22px; align-items: flex-start; }

.pt-table-wrap { flex: 1; min-width: 0; overflow-x: auto; padding-bottom: 10px; }

.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(54px, 1fr));
  grid-auto-rows: minmax(58px, auto);
  gap: 5px;
  min-width: 1080px;
}

.pt-cell {
  border-radius: 7px;
  padding: 4px 5px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.15s ease;
  user-select: none;
}
.pt-cell:hover { transform: scale(1.08); z-index: 5; box-shadow: var(--shadow-lg); }
.pt-cell.selected { outline: 2.5px solid var(--text); outline-offset: 1px; }
.pt-cell.dim { opacity: 0.18; pointer-events: none; }

.pt-cell .num { font-size: 0.6rem; font-weight: 700; opacity: 0.75; }
.pt-cell .sym { font-size: 1.06rem; font-weight: 800; line-height: 1.15; }
.pt-cell .mass { font-size: 0.55rem; opacity: 0.75; }

.pt-spacer { grid-column: 1 / -1; height: 14px; }

.pt-placeholder {
  display: grid;
  place-items: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  border-radius: 7px;
  text-align: center;
  line-height: 1.3;
  padding: 4px;
}

/* Category colors */
.cat-alkali      { background: #ffe4e0; border-color: #fca5a5; }
.cat-alkaline    { background: #ffedd8; border-color: #fdba74; }
.cat-transition  { background: #dfe9ff; border-color: #93b4fd; }
.cat-post        { background: #e5eaf4; border-color: #a9b8d4; }
.cat-metalloid   { background: #fdf6d3; border-color: #f3d250; }
.cat-nonmetal    { background: #ddf7e5; border-color: #7ed99b; }
.cat-halogen     { background: #d6f7fb; border-color: #67e0ee; }
.cat-noble       { background: #f1e6ff; border-color: #cba8f9; }
.cat-lanthanide  { background: #fde5f1; border-color: #f5a0ce; }
.cat-actinide    { background: #ffe3ea; border-color: #fb8faf; }

[data-theme="dark"] .cat-alkali     { background: #4a2320; border-color: #b45c52; }
[data-theme="dark"] .cat-alkaline   { background: #4a3418; border-color: #b97b3d; }
[data-theme="dark"] .cat-transition { background: #1e2d55; border-color: #4a6db8; }
[data-theme="dark"] .cat-post       { background: #2b3348; border-color: #5d6d8f; }
[data-theme="dark"] .cat-metalloid  { background: #4a421a; border-color: #ab9a3a; }
[data-theme="dark"] .cat-nonmetal   { background: #16382691; border-color: #3f9464; background: #173426; }
[data-theme="dark"] .cat-halogen    { background: #123b44; border-color: #3d92a1; }
[data-theme="dark"] .cat-noble      { background: #332052; border-color: #7a57b3; }
[data-theme="dark"] .cat-lanthanide { background: #472036; border-color: #a35580; }
[data-theme="dark"] .cat-actinide   { background: #461b26; border-color: #a34a60; }

/* Legend */
.pt-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s ease;
}
.legend-chip .dot { width: 11px; height: 11px; border-radius: 4px; }
.legend-chip.active { border-color: var(--text); box-shadow: 0 0 0 1.5px var(--text); }

.pt-search {
  width: 100%;
  max-width: 340px;
  margin-bottom: 16px;
  padding: 11px 16px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}
.pt-search:focus { outline: none; border-color: var(--primary); }

/* Detail panel */
.pt-panel {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.pt-panel .big-sym {
  width: 74px; height: 74px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 14px;
}
.pt-panel h3 { font-size: 1.3rem; margin-bottom: 4px; }
.pt-panel .panel-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 16px; }
.pt-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 0.92rem; }
.pt-panel dt { color: var(--text-muted); font-weight: 600; }
.pt-panel dd { font-weight: 700; text-align: right; }
.pt-panel .panel-hint { color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 30px 8px; }

/* ============ Lessons ============ */

.lesson-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  text-align: left;
  border-left: none;
  position: relative;
}
.lesson-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); border-color: var(--primary); }

.lesson-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.lesson-icon { font-size: 32px; }
.badge {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge-done { background: var(--success-soft); color: var(--success); }

.lesson-card h3 { font-size: 1.12rem; margin-bottom: 8px; }
.lesson-card p { color: var(--text-muted); font-size: 0.9rem; flex: 1; }
.lesson-meta { display: flex; gap: 14px; margin-top: 16px; color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }

/* Lesson article */
.lesson-view { display: none; }
.lesson-view.visible { display: block; }
.lesson-list-view.hidden { display: none; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  margin-bottom: 20px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.95rem;
}

.article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(24px, 4vw, 48px);
  max-width: 860px;
}

.article-header { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.article-header h1 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 800; margin: 6px 0 10px; }
.article-header .article-sub { color: var(--text-muted); font-size: 0.95rem; display: flex; gap: 16px; flex-wrap: wrap; }

.article h3 {
  font-size: 1.25rem;
  margin: 32px 0 12px;
  padding-left: 12px;
  border-left: 4px solid var(--primary);
}
.article h4 { font-size: 1.05rem; margin: 20px 0 8px; }
.article p { margin-bottom: 14px; color: var(--text); }
.article ul, .article ol { margin: 0 0 16px 22px; }
.article li { margin-bottom: 7px; }

.formula-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin: 18px 0;
  font-family: var(--mono);
  font-size: 1.05rem;
  overflow-x: auto;
}
.formula-box .formula-note {
  font-family: var(--font);
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.example-box {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  margin: 18px 0;
}
.example-box .example-title { font-weight: 800; color: var(--primary); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }

.keypoints {
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  margin: 26px 0 10px;
}
.keypoints .kp-title { font-weight: 800; color: var(--success); margin-bottom: 8px; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; }
.keypoints ul { margin-bottom: 0; }

.article-actions { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }

table.data-table { width: 100%; border-collapse: collapse; margin: 14px 0 20px; font-size: 0.93rem; }
.data-table th { text-align: left; padding: 10px 12px; background: var(--surface-2); border-bottom: 2px solid var(--border); }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }

/* ============ Quiz ============ */

.quiz-layout { max-width: 780px; margin: 0 auto; }

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.quiz-progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 24px;
}
.quiz-progress .bar {
  height: 100%;
  width: 0%;
  background: var(--gradient);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.quiz-meta { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 0.85rem; font-weight: 700; margin-bottom: 12px; }

.quiz-question { font-size: 1.2rem; font-weight: 700; margin-bottom: 22px; line-height: 1.45; }

.quiz-options { display: grid; gap: 11px; }
.quiz-options button {
  text-align: left;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.quiz-options button:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.quiz-options button:disabled { cursor: default; opacity: 0.75; }
.quiz-options button.correct { border-color: var(--success); background: var(--success-soft); opacity: 1; }
.quiz-options button.wrong { border-color: var(--danger); background: var(--danger-soft); opacity: 1; }

.quiz-explain {
  display: none;
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  font-size: 0.95rem;
}
.quiz-explain.visible { display: block; }

.quiz-actions { display: flex; justify-content: flex-end; margin-top: 22px; }

/* Setup & results */
.quiz-setup label { display: block; font-weight: 700; margin: 18px 0 8px; }
.quiz-setup select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
}

.result-score { text-align: center; padding: 10px 0 4px; }
.result-score .score-num {
  font-size: 3.4rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.result-score .score-sub { color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.result-msg { display: flex; align-items: center; justify-content: center; gap: 9px; text-align: center; font-size: 1.05rem; font-weight: 700; margin: 10px 0 26px; }

.review-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 12px;
  text-align: left;
}
.review-item .rq { font-weight: 700; margin-bottom: 6px; }
.review-item .ra { font-size: 0.92rem; }
.review-item .ra.ok { color: var(--success); font-weight: 700; }
.review-item .ra.no { color: var(--danger); font-weight: 700; }
.review-item .rc { color: var(--text-muted); font-size: 0.9rem; }

/* ============ Tools ============ */

.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: stretch; }

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
}
.tool-card h2 { font-size: 1.3rem; margin-bottom: 6px; display: flex; align-items: center; gap: 10px; }
.tool-card .tool-sub { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 22px; }

/* Link-style tool cards (tools hub) */
a.tool-link { text-decoration: none !important; color: inherit; transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease; }
a.tool-link:hover { transform: translateY(-3px); border-color: var(--primary); box-shadow: var(--shadow-lg); }
a.tool-link .tool-go { display: inline-block; color: var(--primary); font-weight: 700; font-size: 0.95rem; }
a.tool-link:hover .tool-go { text-decoration: underline; }

.tool-field { margin-bottom: 16px; }
.tool-field label { display: block; font-weight: 700; font-size: 0.92rem; margin-bottom: 7px; }
.tool-field input,
.tool-field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tool-field input::placeholder { color: var(--text-muted); opacity: 1; }
.tool-field input:focus, .tool-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
}
.tool-field .hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 5px; }

/* Example quick-fill chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    background-color 0.15s ease, box-shadow 0.15s ease;
}
.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.18);
}
.chip:active { transform: translateY(0) scale(0.94); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 3px 12px rgba(79, 70, 229, 0.32);
}
.chip:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.28); }

/* Uniform full-width action button inside tool cards */
.tool-card .btn { width: 100%; margin-top: 4px; }

.tool-result { display: none; margin-top: 20px; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.tool-result.visible { display: block; animation: fadeUp 0.3s ease; }

.result-hero {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  text-align: center;
  padding: 20px;
  margin-bottom: 16px;
}
.result-hero .rr-label { font-size: 0.8rem; font-weight: 800; color: var(--primary); text-transform: uppercase; letter-spacing: 1.2px; }
.result-hero .rr-value { font-size: 2rem; font-weight: 800; font-family: var(--mono); }
.result-hero .rr-sub { color: var(--text-muted); font-size: 0.85rem; }

.tool-error {
  display: none;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  font-size: 0.92rem;
}
.tool-error.visible { display: block; animation: shake 0.3s ease; }

/* "Learn the concept" line under results */
.result-learn { margin-top: 14px; font-size: 0.92rem; color: var(--text-muted); line-height: 1.6; }
.result-learn a { color: var(--primary); font-weight: 600; text-decoration: none; }
.result-learn a:hover { text-decoration: underline; }

/* Email capture card */
.email-capture {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 26px 30px;
  margin-top: 30px;
}
.email-capture h3 { font-size: 1.15rem; margin-bottom: 6px; }
.email-capture .ec-text p { color: var(--text-muted); font-size: 0.92rem; line-height: 1.6; margin-bottom: 14px; max-width: 70ch; }
.email-capture .ec-form { display: flex; gap: 10px; flex-wrap: wrap; }
.email-capture .ec-form input {
  flex: 1;
  min-width: 220px;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.98rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.email-capture .ec-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18); }
.email-capture .ec-form .btn { width: auto; }
.ec-msg { display: none; margin-top: 12px; font-size: 0.92rem; font-weight: 600; }
.ec-msg.visible { display: block; }
.ec-msg.ok { color: var(--success); }
.ec-msg.err { color: var(--danger); }

/* Explanation block under the tools */
.tool-explainer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px;
  margin-top: 34px;
}
.tool-explainer h2 { font-size: 1.35rem; margin-bottom: 12px; }
.tool-explainer p { color: var(--text-muted); line-height: 1.75; margin-bottom: 12px; max-width: 70ch; }
.tool-explainer p a { color: var(--primary); font-weight: 600; text-decoration: none; }
.tool-explainer p a:hover { text-decoration: underline; }
.tool-explainer .btn { margin-top: 8px; width: auto; }

/* Inline input + unit-select rows (gas law calculator) */
.tool-inline { display: flex; gap: 10px; }
.tool-inline input { flex: 1; min-width: 0; }
.tool-inline select { width: 112px; flex: none; }
.tool-inline input:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============ Footer ============ */

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 70px;
  padding: 44px 0 28px;
}

.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 36px; margin-bottom: 32px; }
.footer-grid h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-muted); margin-bottom: 14px; }
.footer-grid ul { list-style: none; }
.footer-grid li { margin-bottom: 9px; }
.footer-grid a { color: var(--text-muted); font-weight: 600; font-size: 0.92rem; }
.footer-grid a:hover { color: var(--primary); }
.footer-about p { color: var(--text-muted); font-size: 0.92rem; margin-top: 12px; max-width: 340px; }

.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ============ Privacy page ============ */

.legal-content { max-width: 780px; margin: 0 auto; }
.legal-content h2 { font-size: 1.3rem; margin: 30px 0 10px; }
.legal-content p, .legal-content li { color: var(--text-muted); margin-bottom: 10px; }
.legal-content ul { margin-left: 22px; }
.legal-updated { color: var(--text-muted); font-size: 0.9rem; font-style: italic; }

/* ============ Responsive ============ */

@media (max-width: 1024px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .lesson-grid { grid-template-columns: repeat(2, 1fr); }
  .tools-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .hero-inner { flex-direction: column; text-align: center; }
  .hero-copy { max-width: 100%; }
  .hero p { margin-left: auto; margin-right: auto; }
  .hero-cta { justify-content: center; }
  .hero-atom { display: none; }

  .demo-grid { grid-template-columns: 1fr; }

  .pt-layout { flex-direction: column; }
  .pt-panel { width: 100%; position: static; }

  .nav-toggle { display: grid; place-items: center; }
  .main-nav {
    display: none;
    position: absolute;
    top: 62px; left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 12px 20px 16px;
    gap: 4px;
    box-shadow: var(--shadow-lg);
  }
  .main-nav.open { display: flex; }
  .main-nav a { padding: 12px 14px; }
}

@media (max-width: 640px) {
  .cards-grid { grid-template-columns: 1fr; }
  .lesson-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 22px; }
  .topics-list { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; gap: 24px; }
  .quiz-card, .tool-card { padding: 22px; }
  .section { padding: 46px 0; }
  .cta-banner { padding: 34px 22px; }
  .pt-grid { grid-template-columns: repeat(18, minmax(46px, 1fr)); grid-auto-rows: minmax(52px, auto); gap: 3px; }
  .pt-cell .mass { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}
