:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1c2530;
  --text-dim: #5b6675;
  --border: #dde3ea;
  --primary: #2563eb;
  --primary-dim: #eef3ff;
  --accent: #0e9f6e;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 1px rgba(16, 24, 40, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card-bg: #1b212a;
    --text: #e7ebf0;
    --text-dim: #9aa5b1;
    --border: #2b333f;
    --primary: #5b8def;
    --primary-dim: #1c2740;
    --accent: #37c98f;
    --danger: #ef6a6a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* Explicit theme override (set via the toggle button) — wins over OS preference */
:root[data-theme="dark"] {
  --bg: #12161c;
  --card-bg: #1b212a;
  --text: #e7ebf0;
  --text-dim: #9aa5b1;
  --border: #2b333f;
  --primary: #5b8def;
  --primary-dim: #1c2740;
  --accent: #37c98f;
  --danger: #ef6a6a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
:root[data-theme="light"] {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1c2530;
  --text-dim: #5b6675;
  --border: #dde3ea;
  --primary: #2563eb;
  --primary-dim: #eef3ff;
  --accent: #0e9f6e;
  --danger: #d64545;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 1px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 20px 24px 16px;
}
.topbar-inner { max-width: 1080px; margin: 0 auto; }
.topbar h1 { margin: 0 0 4px; font-size: 1.5rem; }
.subtitle { margin: 0; color: var(--text-dim); font-size: 0.92rem; }

.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.guide-links {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}
.theme-toggle-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.theme-toggle-btn:hover { border-color: var(--primary); transform: scale(1.06); }
.theme-toggle-fixed {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
}
.guides-link, .back-link {
  flex-shrink: 0;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.guides-link:hover, .back-link:hover { text-decoration: underline; }

.tabs {
  max-width: 1080px;
  margin: 16px auto 0;
  padding: 0 24px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tab-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-dim);
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab-btn:hover { border-color: var(--primary); color: var(--text); }
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

#app { max-width: 1080px; margin: 20px auto 40px; padding: 0 24px; }

.panel { display: none; flex-direction: column; gap: 16px; }
.panel.active { display: flex; }

.panel-head { margin-bottom: -4px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0 0 2px; font-size: 1.15rem; }
.panel-head p { margin: 0; color: var(--text-dim); font-size: 0.88rem; }
.print-btn { flex-shrink: 0; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; }
.field .hint { font-size: 0.76rem; color: var(--text-dim); font-weight: 400; }

input[type="number"], input[type="text"], select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 0.92rem;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }
.radio-opt {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.88rem; cursor: pointer;
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 7px;
}
.radio-opt input { accent-color: var(--primary); }
.radio-opt.checked { border-color: var(--primary); background: var(--primary-dim); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; margin-bottom: 10px; }
.checkbox-row input { accent-color: var(--primary); width: 16px; height: 16px; }

.subsection { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.subsection:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.subsection-title { font-size: 0.84rem; font-weight: 700; margin-bottom: 8px; color: var(--text); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--primary-dim);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat .label { font-size: 0.74rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.stat .value { font-size: 1.25rem; font-weight: 700; color: var(--primary); margin-top: 2px; }
.stat .sub { font-size: 0.76rem; color: var(--text-dim); margin-top: 1px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.recipe { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 0.88rem; }
table.recipe.recipe-data { table-layout: auto; min-width: 480px; }
table.recipe th, table.recipe td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); overflow-wrap: break-word; }
table.recipe th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
table.recipe tr:last-child td { border-bottom: none; }
table.recipe td.num { font-variant-numeric: tabular-nums; }
table.recipe.recipe-data td:not(:first-child), table.recipe.recipe-data th:not(:first-child) { white-space: nowrap; }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 12px;
  background: rgba(214, 69, 69, 0.1);
  border-radius: 7px;
}

.actions { display: flex; justify-content: flex-end; margin-top: 10px; }
button.copy-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.82rem;
  cursor: pointer;
  font-weight: 600;
}
button.copy-btn:hover { border-color: var(--primary); color: var(--primary); }

details.assumptions { font-size: 0.85rem; color: var(--text-dim); }
details.assumptions summary { cursor: pointer; font-weight: 600; color: var(--text); }
details.assumptions .body { margin-top: 8px; }
details.assumptions ul { margin: 6px 0; padding-left: 20px; }

.footer {
  max-width: 1080px;
  margin: 0 auto 30px;
  padding: 0 24px;
  color: var(--text-dim);
  font-size: 0.78rem;
}

@media (max-width: 560px) {
  .topbar h1 { font-size: 1.25rem; }
}

#guide {
  max-width: 1080px;
  margin: 20px auto 40px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.guide-list, .guide-sublist { margin: 0; padding-left: 20px; }
.guide-list li, .guide-sublist li { margin-bottom: 8px; font-size: 0.92rem; }
.guide-list li:last-child, .guide-sublist li:last-child { margin-bottom: 0; }
.guide-steps { margin: 0; padding-left: 22px; }
.guide-steps > li { margin-bottom: 16px; font-size: 0.92rem; }
.guide-steps > li:last-child { margin-bottom: 0; }
.guide-sublist { margin: 8px 0; }
.guide-note {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}
.guide-formula {
  margin: 10px 0;
  padding: 12px 16px;
  background: var(--primary-dim);
  border-radius: 8px;
  font-size: 0.95rem;
  text-align: center;
  color: var(--text);
  overflow-x: auto;
}
h4.guide-subhead { margin: 14px 0 8px; font-size: 0.9rem; }

.glossary-dl { margin: 0; }
.glossary-dl dt {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text);
  margin-top: 16px;
}
.glossary-dl dt:first-child { margin-top: 0; }
.glossary-dl dd {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---------------------------------------------------------------------
   Home page hero + generative polymer art
--------------------------------------------------------------------- */

.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0b1120 0%, #17233f 45%, #0d332f 100%);
  padding: 72px 24px 48px;
  text-align: center;
}
.polymer-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hero-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 65% 85% at center, rgba(4,8,16,0.6) 0%, rgba(4,8,16,0.42) 45%, rgba(4,8,16,0.12) 75%, rgba(4,8,16,0) 92%);
}
.hero-content {
  position: relative;
  z-index: 2;
  max-width: 680px;
  margin: 0 auto;
}
.hero-content h1 {
  color: #fff;
  font-size: 2.1rem;
  margin: 0 0 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 2px 12px rgba(0,0,0,0.6);
}
.hero-content p {
  color: #fff;
  font-size: 1.02rem;
  margin: 0 0 20px;
  line-height: 1.5;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 2px 10px rgba(0,0,0,0.6);
}

.tech-pills {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.tech-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(10, 14, 24, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 5px 12px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
.home-links-header {
  margin: 28px 0 0;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}
.home-links-header h2 { margin: 0 0 3px; font-size: 1.25rem; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 2px 10px rgba(0,0,0,0.6); }
.home-links-header p { margin: 0; font-size: 0.85rem; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 2px 10px rgba(0,0,0,0.6); }

.home-links {
  max-width: 1080px;
  margin: 40px auto 40px;
  padding: 0 24px;
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}
.home-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: 3px solid var(--card-accent, var(--primary));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 24px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.home-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 26px rgba(16, 24, 40, 0.14);
}
.home-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--card-accent, var(--primary)) 16%, transparent);
}
.home-card-eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--card-accent, var(--primary));
  font-weight: 700;
  margin-bottom: 8px;
}
.home-card h2 { margin: 0 0 8px; font-size: 1.15rem; }
.home-card p { margin: 0; color: var(--text-dim); font-size: 0.9rem; line-height: 1.5; }
.home-card-arrow { display: block; margin-top: 16px; font-size: 0.85rem; font-weight: 600; color: var(--card-accent, var(--primary)); }

.home-footnote {
  max-width: 1080px;
  margin: 0 auto 40px;
  padding: 0 24px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-align: center;
}

@media (max-width: 560px) {
  .hero { padding: 56px 20px 36px; }
  .hero-content h1 { font-size: 1.6rem; }
}

/* ---------------------------------------------------------------------
   Mechanism reaction schemes
--------------------------------------------------------------------- */

.mech-scheme {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 14px 0;
  overflow-x: auto;
  padding-bottom: 4px;
}
.mech-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: max-content;
}
.mech-eq {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.98rem;
  white-space: nowrap;
}
.mech-step-name {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  white-space: nowrap;
  padding-left: 10px;
  margin-left: auto;
}
.pn { color: var(--primary); font-weight: 700; }
.radical { color: var(--danger); font-weight: 700; }
.metal { color: var(--accent); font-weight: 700; }

.mech-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  min-width: 46px;
}
.mech-arrow .mech-k {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-style: italic;
}
.mech-arrow .mech-arrow-line {
  font-size: 1.35rem;
  color: var(--text);
  margin: 1px 0;
}

.mech-ring-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 14px 0 6px;
  padding: 18px 16px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.mech-ring {
  display: block;
  max-width: 100%;
  height: auto;
}
.mech-ring .bond { stroke-linecap: round; }
.mech-ring .bond-keep { stroke: var(--text-dim); stroke-width: 3; }
.mech-ring .bond-break {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 2, 7;
}
.mech-ring .ring-atom circle {
  stroke-width: 2;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}
.mech-ring .ring-atom-metal circle { fill: var(--accent); stroke: var(--accent); }
.mech-ring .ring-atom-carbon circle { fill: var(--card-bg); stroke: var(--border); }
.mech-ring .ring-atom text {
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  text-anchor: middle;
  dominant-baseline: central;
}
.mech-ring .ring-atom-metal text { fill: #fff; }
.mech-ring .ring-atom-carbon text { fill: var(--text); }
.mech-ring .ring-substituent {
  font-size: 11px;
  fill: var(--text-dim);
  font-style: italic;
}
.mech-ring-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.76rem;
  color: var(--text-dim);
}
.mech-ring-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 18px; height: 0; border-top-width: 3px; border-top-style: solid; }
.legend-break { border-top-color: var(--accent); border-top-style: dashed; }
.legend-keep { border-top-color: var(--text-dim); }
.mech-ring-caption {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 2px;
}

/* ---------------------------------------------------------------------
   Generic illustrative diagrams (GPC page, etc.)
--------------------------------------------------------------------- */

.diagram-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 14px 0 6px;
  padding: 16px 14px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.diagram-svg { display: block; max-width: 100%; height: auto; }
.diagram-svg text { font-family: inherit; fill: var(--text); }
.diagram-svg .dim { fill: var(--text-dim); }
.diagram-svg .small { font-size: 10px; }
.diagram-caption {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 2px;
}
.diagram-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.76rem;
  color: var(--text-dim);
}
.diagram-legend span { display: inline-flex; align-items: center; gap: 6px; }
.diagram-legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

/* ---------------------------------------------------------------------
   Founder page
--------------------------------------------------------------------- */

.founder-hero {
  display: flex;
  gap: 28px;
  align-items: center;
  flex-wrap: wrap;
}
.founder-photo {
  width: 200px;
  height: 240px;
  object-fit: cover;
  object-position: top center;
  border-radius: 14px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.founder-intro { flex: 1; min-width: 240px; }
.founder-intro h2 { margin: 0 0 4px; font-size: 1.4rem; }
.founder-tagline { color: var(--text-dim); font-size: 0.95rem; margin: 0 0 14px; }
.founder-facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
}
.founder-facts .fact-label {
  color: var(--text-dim);
  font-weight: 600;
  margin-right: 6px;
}
.founder-facts a { color: var(--primary); text-decoration: none; }
.founder-facts a:hover { text-decoration: underline; }

.pub-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pub-list li {
  font-size: 0.9rem;
  line-height: 1.55;
  padding-left: 18px;
  position: relative;
}
.pub-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}
.pub-list a { color: var(--primary); text-decoration: none; }
.pub-list a:hover { text-decoration: underline; }

@media (max-width: 560px) {
  .founder-hero { flex-direction: column; text-align: center; }
  .founder-facts { align-items: center; }
}

.donate-card { text-align: center; }
.donate-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 24px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  border-radius: 999px;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: filter 0.15s, transform 0.15s;
}
.donate-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ---------------------------------------------------------------------
   Brand lockup (logo + wordmark)
--------------------------------------------------------------------- */

.brand-link {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  flex-shrink: 0;
  padding-top: 4px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: block;
}
.brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand-poly { color: var(--primary); }
.brand-link:hover .brand-name { color: var(--primary); }

.hero-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 14px;
}
.hero-brand .brand-mark { width: 52px; height: 52px; border-radius: 13px; }
.hero-brand .brand-name {
  font-size: 2.2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 2px 12px rgba(0,0,0,0.6);
}
.hero-brand .brand-poly { color: #8fb8ff; }

@media (max-width: 560px) {
  .hero-brand .brand-mark { width: 40px; height: 40px; border-radius: 10px; }
  .hero-brand .brand-name { font-size: 1.7rem; }
}

/* ---------------------------------------------------------------------
   Hot papers feed
--------------------------------------------------------------------- */

.hot-papers {
  max-width: 1080px;
  margin: 8px auto 40px;
  padding: 0 24px;
}
.hot-papers-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.hot-papers-header h2 {
  margin: 0 0 3px;
  font-size: 1.3rem;
}
.hot-papers-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.hot-papers-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
  padding-top: 3px;
  flex-shrink: 0;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(14, 159, 110, 0.55);
  animation: live-pulse 1.8s ease-out infinite;
}
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(14, 159, 110, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(14, 159, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 159, 110, 0); }
}

.hot-papers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.paper-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--paper-accent, var(--primary));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  text-decoration: none;
  color: var(--text);
  opacity: 0;
  animation: paper-in 0.4s ease forwards;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.paper-card:hover {
  transform: translateY(-3px) rotate(-0.3deg);
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.14);
}
@keyframes paper-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.paper-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.paper-journal {
  display: inline-block;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--paper-accent, var(--primary));
  background: color-mix(in srgb, var(--paper-accent, var(--primary)) 14%, transparent);
  padding: 3px 8px;
  border-radius: 999px;
}
.paper-cites {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #b45309;
  background: color-mix(in srgb, #f2b84b 22%, transparent);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.paper-cites-new {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.paper-title {
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 6px;
}
.paper-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.paper-link-hint {
  font-weight: 600;
  color: var(--paper-accent, var(--primary));
}

.hot-papers-loading, .hot-papers-error {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 0.88rem;
  padding: 20px 0;
  text-align: center;
}

.hot-papers-caption {
  margin: 12px 2px 0;
  font-size: 0.76rem;
  color: var(--text-dim);
  text-align: right;
}

/* ---------------------------------------------------------------------
   Daily trivia
--------------------------------------------------------------------- */

.trivia {
  max-width: 1080px;
  margin: 8px auto 40px;
  padding: 0 24px;
}
.trivia-header { margin-bottom: 14px; }
.trivia-header h2 { margin: 0 0 3px; font-size: 1.3rem; }
.trivia-subtitle { margin: 0; font-size: 0.85rem; color: var(--text-dim); }

.trivia-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.trivia-tries {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.trivia-tries .try-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.trivia-tries .try-dot.used { background: var(--danger); }
.trivia-tries .try-dot.active { background: var(--primary); }

.trivia-question {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 16px;
  line-height: 1.4;
}

.trivia-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.trivia-option {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.1s;
}
.trivia-option:hover:not(:disabled) {
  border-color: var(--primary);
  transform: translateY(-1px);
}
.trivia-option:disabled { cursor: default; }
.trivia-option.wrong {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--text-dim);
  text-decoration: line-through;
}
.trivia-option.correct {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  font-weight: 700;
}
.trivia-option.neutral-disabled { opacity: 0.55; }

.trivia-feedback {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.trivia-feedback.win { color: var(--accent); }
.trivia-feedback.lose { color: var(--danger); }
.trivia-explanation {
  font-size: 0.86rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}

/* ---------------------------------------------------------------------
   Saved recipe presets
--------------------------------------------------------------------- */

.preset-bar h3 { margin-bottom: 10px; }
.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.preset-row + .preset-row { margin-top: 10px; }
.preset-select {
  flex: 1;
  min-width: 160px;
}
.preset-name-input {
  flex: 1;
  min-width: 160px;
}
.preset-row .copy-btn { flex-shrink: 0; }

/* ---------------------------------------------------------------------
   Kinetics plot
--------------------------------------------------------------------- */

.kin-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 4px;
}
.kin-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.kin-row input {
  flex: 1;
  min-width: 0;
}
.kin-row-remove {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kin-row-remove:hover { border-color: var(--danger); color: var(--danger); }

.kin-chart-wrap {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-x: auto;
}
.kin-chart { display: block; width: 100%; height: auto; min-width: 420px; }
.kin-chart .kin-axis { stroke: var(--text-dim); stroke-width: 1; }
.kin-chart .kin-grid { stroke: var(--border); stroke-width: 1; }
.kin-chart .kin-tick-label { fill: var(--text-dim); font-size: 10px; }
.kin-chart .kin-axis-label { fill: var(--text-dim); font-size: 11px; font-weight: 600; }
.kin-chart .kin-fit-line { stroke: var(--accent); stroke-width: 2; fill: none; stroke-dasharray: 5,4; }
.kin-chart .kin-point { fill: var(--primary); stroke: var(--card-bg); stroke-width: 1.5; }
.kin-chart .kin-empty { fill: var(--text-dim); font-size: 12px; }

/* ---------------------------------------------------------------------
   Generic dynamic row list (Tg predictor, recipe scaling)
--------------------------------------------------------------------- */

.dyn-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 4px;
}
.dyn-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.dyn-row input, .dyn-row select { flex: 1; min-width: 90px; }
.dyn-row-remove {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.dyn-row-remove:hover { border-color: var(--danger); color: var(--danger); }
.dyn-row-labels {
  display: flex;
  gap: 8px;
  font-size: 0.76rem;
  color: var(--text-dim);
  font-weight: 600;
  padding: 0 2px;
}
.dyn-row-labels span { flex: 1; min-width: 90px; }
.dyn-row-labels span.dyn-label-spacer { flex: 0 0 30px; min-width: 30px; }

/* ---------------------------------------------------------------------
   Generic chart (composition diagram, etc.)
--------------------------------------------------------------------- */

.chart-wrap {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-x: auto;
}
.chart-svg { display: block; width: 100%; height: auto; min-width: 320px; }
.chart-svg .axis { stroke: var(--text-dim); stroke-width: 1; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .tick-label { fill: var(--text-dim); font-size: 10px; }
.chart-svg .axis-label { fill: var(--text-dim); font-size: 11px; font-weight: 600; }
.chart-svg .curve-line { stroke: var(--primary); stroke-width: 2.5; fill: none; }
.chart-svg .ref-line { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 4,4; fill: none; }
.chart-svg .ref-line-label { fill: var(--text-dim); font-size: 10px; font-style: italic; }
.chart-svg .marker-point { fill: var(--accent); stroke: var(--card-bg); stroke-width: 2; }
.chart-svg .azeo-point { fill: var(--danger); stroke: var(--card-bg); stroke-width: 2; }
.chart-svg .azeo-line { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 2,3; }
.chart-svg .area-included { fill: color-mix(in srgb, var(--primary) 38%, transparent); }
.chart-svg .area-excluded { fill: var(--text-dim); opacity: 0.22; }
.chart-svg .bound-line { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 4,3; }

.stat-group-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  margin: 14px 0 8px;
}
.stat-group-label:first-child { margin-top: 0; }

/* ---------------------------------------------------------------------
   Trace image uploader
--------------------------------------------------------------------- */

.upload-dropzone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.upload-dropzone:hover, .upload-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-dim);
}
.upload-dropzone input[type="file"] { display: none; }
.upload-hint { font-size: 0.8rem; color: var(--text-dim); margin-top: 6px; }

.trace-canvas-wrap {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--bg);
  padding: 8px;
}
#trace-canvas { display: block; max-width: 100%; height: auto; }

.trace-findings { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.trace-finding-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--primary-dim);
  font-size: 0.86rem;
  line-height: 1.45;
}
.trace-finding-item.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ---------------------------------------------------------------------
   Polymer chain game
--------------------------------------------------------------------- */

.game-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.game-hud .stat { flex: 1; min-width: 130px; }

.game-stage {
  position: relative;
  display: flex;
  justify-content: center;
  background: #0b0f1a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  overflow-x: auto;
}
#game-canvas { display: block; image-rendering: crisp-edges; }

.game-overlay {
  position: absolute;
  inset: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  background: rgba(6, 9, 16, 0.86);
  border-radius: calc(var(--radius) - 2px);
  color: #fff;
  padding: 20px;
}
.game-overlay h4 { margin: 0; font-size: 1.3rem; }
.game-overlay p { margin: 0; font-size: 0.9rem; color: rgba(255, 255, 255, 0.78); max-width: 360px; }
.game-overlay button {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}
.game-overlay button:hover { filter: brightness(1.1); }

.game-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.game-dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  gap: 4px;
}
.game-dpad button {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.game-dpad button:active { background: var(--primary-dim); border-color: var(--primary); }
.game-dpad .dpad-up { grid-column: 2; grid-row: 1; }
.game-dpad .dpad-left { grid-column: 1; grid-row: 2; }
.game-dpad .dpad-down { grid-column: 2; grid-row: 2; }
.game-dpad .dpad-right { grid-column: 3; grid-row: 2; }

.game-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.game-legend span { display: inline-flex; align-items: center; gap: 6px; }
.game-legend .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ---------------------------------------------------------------------
   Print
--------------------------------------------------------------------- */

@media print {
  :root, :root[data-theme="dark"], :root[data-theme="light"] {
    --bg: #ffffff;
    --card-bg: #ffffff;
    --text: #000000;
    --text-dim: #444444;
    --border: #bbbbbb;
    --primary: #1d4ed8;
    --primary-dim: #f0f4ff;
    --accent: #0e7a54;
    --danger: #b3261e;
    --shadow: none;
  }
  body { background: #fff; }

  .topbar, .tabs, .footer, .home-footnote,
  .preset-bar, .guide-links, .theme-toggle-btn, .theme-toggle-fixed,
  .copy-btn, #bcp-add-block, .bcp-remove-block,
  .hero, .home-links, .hot-papers {
    display: none !important;
  }

  .print-btn { display: none !important; }

  #app, #guide, main {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }
  .card {
    box-shadow: none;
    border: 1px solid var(--border);
    break-inside: avoid;
    page-break-inside: avoid;
  }
  a[href]::after { content: ""; }
}
