/* SciDEX Shared Stylesheet */

/* ── CSS Variables (Dark Theme) ──────────────────────── */
:root {
  /* Colors */
  --color-bg-primary: #0a0a14;
  --color-bg-secondary: #151525;
  --color-bg-tertiary: rgba(255, 255, 255, 0.02);
  --color-text-primary: #e0e0e0;
  --color-text-secondary: #adb5bd;
  --color-text-muted: #888;
  --color-text-dark: #555;

  /* Accent colors */
  --color-accent-blue: #4fc3f7;
  --color-accent-green: #81c784;
  --color-accent-yellow: #ffd54f;
  --color-accent-purple: #ce93d8;
  --color-accent-red: #f44336;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-faint: rgba(255, 255, 255, 0.04);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  /* Typography */
  --font-family: -apple-system, sans-serif;
  --font-size-base: 1rem;
  --font-size-sm: 0.85rem;
  --font-size-xs: 0.75rem;
  --line-height: 1.6;
}

/* ── Base Styles ───────────────────────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, sans-serif;
  background: #0a0a14;
  color: #e0e0e0;
  line-height: 1.6;
  overflow-x: hidden;
  /* Safe area insets for notched phones */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a {
  color: #4fc3f7;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Navigation ───────────────────────────────────────── */
nav {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}

nav a {
  color: #81c784;
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
}

nav a:hover {
  background: rgba(129, 199, 132, 0.1);
  text-decoration: none;
}

/* ── Layout ───────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.hero {
  padding: 2rem;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.hero h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, #4fc3f7, #81c784);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Stats Grid ───────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0;
}

.stat {
  text-align: center;
  padding: 1rem;
  background: #151525;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat a {
  text-decoration: none;
}

.stat b {
  font-size: 1.8rem;
  color: #4fc3f7;
  display: block;
}

.stat span {
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
}

/* ── Typography ───────────────────────────────────────── */
h2 {
  color: #e0e0e0;
  font-size: 1.2rem;
  margin: 1.5rem 0 0.8rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* ── Tables ───────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  color: #888;
  font-size: 0.75rem;
  text-transform: uppercase;
}

td {
  padding: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.9rem;
}

tr:hover {
  background: rgba(79, 195, 247, 0.05);
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  display: block;
  background: #151525;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 1.2rem;
  margin: 0.8rem 0;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
}

.card:hover {
  border-color: #4fc3f7;
  transform: translateY(-2px);
  text-decoration: none;
}

.card h3 {
  color: #4fc3f7;
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}

.card p {
  color: #888;
  font-size: 0.85rem;
}

/* ── Evidence Cards ─────────────────────────────────── */
.ev-card {
  background: #151525;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 3px solid #4fc3f7;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin: 0.4rem 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* Keyboard focus indicator for evidence cards */
.ev-card:focus-visible,
.ev-card details:focus-visible {
  outline: 2px solid #4fc3f7;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.2);
}

/* Summary (clickable header) of evidence card details */
.ev-card summary {
  cursor: pointer;
  border-radius: 4px;
  padding: 0.2rem;
  margin: -0.2rem;
  transition: background 0.2s;
}

.ev-card summary:hover {
  background: rgba(79, 195, 247, 0.08);
}

.ev-card summary:focus-visible {
  outline: 2px solid #4fc3f7;
  outline-offset: 2px;
  background: rgba(79, 195, 247, 0.1);
}

/* Evidence meta info styling */
.ev-meta {
  color: #888;
  font-size: 0.8rem;
  margin-top: 0.3rem;
}

/* ── Tags ───────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  margin: 0.1rem;
  background: rgba(255, 213, 79, 0.15);
  color: #ffd54f;
}

.tag-green {
  background: rgba(129, 199, 132, 0.15);
  color: #81c784;
}

/* ── Footer ───────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: #555;
  font-size: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 2rem;
}

/* ── Table Wrapper ───────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

.btn-primary {
  background: #4fc3f7;
  color: #0a0a14;
}

.btn-primary:hover {
  background: #81e5fe;
}

/* ── Modal ───────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #151525;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h3 {
  color: #4fc3f7;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: #e0e0e0;
}

/* ── Forms ───────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  color: #888;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}

.form-group textarea {
  width: 100%;
  background: #0a0a14;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.8rem;
  color: #e0e0e0;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
}

.form-group textarea:focus {
  outline: none;
  border-color: #4fc3f7;
}

/* ── Progress Bar ───────────────────────────────────── */
.progress-box {
  display: none;
  background: rgba(79, 195, 247, 0.08);
  border: 1px solid rgba(79, 195, 247, 0.2);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}

.progress-box.show {
  display: block;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.8rem 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4fc3f7, #81c784);
  transition: width 0.3s;
}

.progress-text {
  color: #adb5bd;
  font-size: 0.85rem;
}

/* ── Responsive (Tablet — 768px) ─────────────────────── */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .hero {
    padding: 1.2rem;
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  h1 {
    font-size: 1.5rem !important;
  }

  h2 {
    font-size: 1.1rem;
    margin: 1rem 0 0.6rem;
  }

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

  .stat {
    padding: 0.7rem;
  }

  .stat b {
    font-size: 1.3rem;
  }

  .stat span {
    font-size: 0.65rem;
  }

  nav {
    gap: 0.3rem;
    padding: 0.5rem;
  }

  nav a {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  /* Tables — scrollable on mobile via wrapper */
  .table-wrapper,
  .card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.85rem;
    min-width: 100%;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  thead, tbody {
    display: table;
    width: 100%;
  }

  tr {
    display: table-row;
  }

  th,
  td {
    padding: 0.4rem;
    font-size: 0.8rem;
    min-width: unset !important;
    white-space: nowrap;
  }

  /* Allow long cell content to wrap */
  td a,
  td span {
    white-space: normal;
    word-break: break-word;
  }

  .card {
    padding: 1rem;
    margin: 0.6rem 0;
  }

  .card h3 {
    font-size: 0.95rem;
  }

  .card p {
    font-size: 0.8rem;
  }

  .tag {
    font-size: 0.7rem;
    padding: 0.12rem 0.4rem;
  }

  /* Touch-friendly buttons (44px minimum per Apple HIG) */
  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    min-height: 44px;
  }

  .modal-content {
    padding: 1.5rem;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .footer {
    padding: 1rem;
    font-size: 0.75rem;
  }

  /* Navigation hamburger menu */
  .nav-hamburger {
    display: inline-block !important;
  }

  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0.3rem !important;
    padding: 0.5rem !important;
  }

  #nav-toggle:checked ~ .nav-links {
    display: flex;
  }

  /* Filter bars — stack inputs vertically */
  .filter-bar {
    flex-direction: column !important;
    gap: 0.4rem !important;
  }

  .filter-bar input,
  .filter-bar select,
  .filter-bar button {
    width: 100% !important;
    min-width: unset !important;
    min-height: 44px;
  }

  /* Inline flex stat rows — tighter gap */
  [style*="display:flex"][style*="gap:2rem"],
  [style*="display:flex"][style*="gap: 2rem"],
  [style*="display:flex"][style*="gap:1.5rem"],
  [style*="display:flex"][style*="gap: 1.5rem"] {
    gap: 0.5rem !important;
    flex-wrap: wrap !important;
  }

  /* SVGs — prevent overflow */
  svg {
    max-width: 100% !important;
    height: auto;
  }

  /* Containers — full width on mobile */
  [style*="max-width:1000px"],
  [style*="max-width: 1000px"],
  [style*="max-width:1100px"],
  [style*="max-width: 1100px"],
  [style*="max-width:1200px"],
  [style*="max-width: 1200px"],
  [style*="max-width:900px"],
  [style*="max-width: 900px"],
  [style*="max-width:800px"],
  [style*="max-width: 800px"] {
    max-width: 100% !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Showcase navigation pills — horizontal scroll on mobile */
  .showcase-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .showcase-nav::-webkit-scrollbar {
    display: none;
  }

  /* Type badge pills — touch-friendly */
  [style*="border-radius:16px"] {
    padding: 0.4rem 0.8rem !important;
    font-size: 0.8rem !important;
    min-height: 36px;
    display: inline-flex !important;
    align-items: center;
  }

  /* Horizontal scroll for wide content */
  pre, code {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Prevent images from overflowing */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Inline grid overrides — collapse 3+ column grids to 2 */
  [style*="grid-template-columns: repeat(5"],
  [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns:repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Two-column inline grids to single column */
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Three-column explicit grids (1fr 1fr 1fr) to 2 columns */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Large minmax grids — prevent overflow */
  [style*="minmax(460px"],
  [style*="minmax(400px"],
  [style*="minmax(350px"],
  [style*="minmax(340px"],
  [style*="minmax(320px"],
  [style*="minmax(300px"],
  [style*="minmax(280px"],
  [style*="minmax(260px"],
  [style*="minmax(220px"] {
    grid-template-columns: 1fr !important;
  }

  /* Large min-width elements — allow shrink on mobile (with and without spaces) */
  [style*="min-width:600px"],
  [style*="min-width: 600px"],
  [style*="min-width:500px"],
  [style*="min-width: 500px"],
  [style*="min-width:400px"],
  [style*="min-width: 400px"],
  [style*="min-width:360px"],
  [style*="min-width: 360px"],
  [style*="min-width:300px"],
  [style*="min-width: 300px"],
  [style*="min-width:280px"],
  [style*="min-width: 280px"],
  [style*="min-width:200px"],
  [style*="min-width: 200px"] {
    min-width: auto !important;
  }

  /* Card grid — stack cards on mobile */
  .card-grid {
    grid-template-columns: 1fr !important;
  }

  /* Analysis grid — responsive on tablet */
  .analysis-grid {
    grid-template-columns: 1fr !important;
  }

  /* Analysis page debate rounds — full width */
  [style*="border-left:3px solid"] {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Mermaid/pathway diagrams — scroll on mobile */
  .mermaid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.75rem;
    max-width: 100%;
  }
  .mermaid svg {
    min-width: auto !important;
  }

  /* Prevent body overflow from inline content */
  body {
    overflow-x: hidden;
  }

  /* Touch-friendly links in navigation sidebar */
  .scidex-sidebar a {
    padding: 0.6rem 1.2rem !important;
    min-height: 44px;
    display: flex !important;
    align-items: center;
  }

  /* Hamburger button touch target */
  .hamburger-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Inline padding reduction for mobile */
  [style*="padding:2rem"],
  [style*="padding: 2rem"] {
    padding: 1rem !important;
  }

  /* Filter grid overflow prevention */
  [style*="minmax(200px"],
  [style*="minmax(180px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Ensure all inputs/selects are touch-friendly */
  input[type="text"],
  input[type="search"],
  input[type="number"],
  select,
  textarea {
    min-height: 44px;
    font-size: max(16px, 0.9rem); /* Prevents iOS zoom on focus */
  }

  /* Score dimension bars — 2 columns on tablet */
  .score-dims {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Persona badges — compact on mobile */
  .persona-badge {
    font-size: 0.6rem !important;
    padding: 0.1rem 0.3rem !important;
  }

  /* Pipeline stages — compact */
  .pipeline-stages {
    gap: 0.2rem !important;
  }
  .pipeline-stage {
    font-size: 0.6rem !important;
    padding: 0.1rem 0.3rem !important;
  }

  /* Metrics row — tighter on mobile */
  .metrics-row {
    gap: 0.5rem !important;
  }
  .metric-val {
    font-size: 0.85rem !important;
  }
}

/* ── Small Phone (480px) ─────────────────────────────── */
@media (max-width: 480px) {
  .hero h1 {
    font-size: 1.3rem;
  }

  .stats {
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  }

  nav a {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }

  .card {
    padding: 0.8rem;
  }

  /* Flex stat rows — wrap instead of forcing column (column breaks tags, badges, button groups) */
  [style*="display:flex"][style*="gap:2rem"],
  [style*="display:flex"][style*="gap: 2rem"],
  [style*="display:flex"][style*="gap:1.5rem"],
  [style*="display:flex"][style*="gap: 1.5rem"] {
    flex-direction: column !important;
    gap: 0.3rem !important;
  }

  /* Other flex containers: ensure wrapping, not column stacking */
  [style*="display:flex"][style*="gap:1rem"],
  [style*="display:flex"][style*="gap: 1rem"],
  [style*="display:flex"][style*="gap:0.8rem"],
  [style*="display:flex"][style*="gap: 0.8rem"] {
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
  }

  /* All grids to single column */
  [style*="grid-template-columns: repeat("],
  [style*="grid-template-columns:repeat("],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  .world-model-viz {
    grid-template-columns: 1fr !important;
  }

  /* All minmax grids to single column */
  [style*="minmax(200px"],
  [style*="minmax(180px"],
  [style*="minmax(150px"],
  [style*="minmax(140px"] {
    grid-template-columns: 1fr !important;
  }

  /* Smaller font for breadcrumbs */
  [style*="font-size:0.8rem"] {
    font-size: 0.75rem !important;
  }

  /* Sidebar narrower on very small screens */
  .scidex-sidebar {
    width: 240px !important;
    left: -250px !important;
  }

  /* Modal full width on small phones */
  .modal-content {
    width: 98% !important;
    padding: 1rem !important;
    margin: 0.5rem;
  }

  /* Stat cards even more compact */
  .stat b {
    font-size: 1.1rem;
  }

  .stat {
    padding: 0.5rem;
  }

  /* Table cells — allow horizontal scroll */
  th, td {
    padding: 0.3rem;
    font-size: 0.75rem;
  }

  /* Ensure inline min-widths don't cause overflow (with and without spaces) */
  [style*="min-width:400px"],
  [style*="min-width: 400px"],
  [style*="min-width:360px"],
  [style*="min-width: 360px"],
  [style*="min-width:300px"],
  [style*="min-width: 300px"],
  [style*="min-width:200px"],
  [style*="min-width: 200px"],
  [style*="min-width:180px"],
  [style*="min-width: 180px"],
  [style*="min-width:150px"],
  [style*="min-width: 150px"],
  [style*="min-width:140px"],
  [style*="min-width: 140px"],
  [style*="min-width:120px"],
  [style*="min-width: 120px"] {
    min-width: auto !important;
  }
}

/* ── Small Phone extras (480px) ─────────────────────── */
@media (max-width: 480px) {
  /* Breadcrumb text overflow */
  nav[style*="font-size:0.85rem"],
  nav[style*="font-size: 0.85rem"] {
    font-size: 0.75rem !important;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  /* Auto-fit grids with large minmax — collapse to single column */
  [style*="minmax(200px"],
  [style*="minmax(180px"],
  [style*="minmax(160px"],
  [style*="minmax(150px"],
  [style*="minmax(140px"],
  [style*="minmax(130px"],
  [style*="minmax(120px"],
  [style*="minmax(110px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Ensure all flex containers wrap */
  [style*="display:flex"],
  [style*="display: flex"] {
    flex-wrap: wrap !important;
  }

  /* KG widget — constrain height on small screens */
  #kg-widget {
    max-height: 280px;
  }
}

/* ── Additional Mobile Fixes (768px) ────────────────── */
@media (max-width: 768px) {
  /* Compare page: hypothesis picker flex layout */
  [style*="display:flex"][style*="align-items:center"][style*="gap:1rem"] {
    flex-wrap: wrap !important;
  }

  /* Compare page: canvas responsive sizing */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Score comparison bars: ensure they don't overflow */
  [style*="display:flex"][style*="align-items:center"][style*="gap:0.5rem"] {
    flex-wrap: wrap !important;
  }

  /* Exchange feed items: allow text to wrap */
  [style*="white-space:nowrap"] {
    white-space: normal !important;
    overflow-wrap: break-word !important;
  }

  /* Ensure breadcrumbs don't overflow */
  .breadcrumbs, [style*="breadcrumb"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  /* Debate section persona labels */
  [style*="display:grid"][style*="gap:1.5rem"] {
    gap: 0.75rem !important;
  }

  /* Long hypothesis titles in cards */
  .card h3, .card h4 {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Select dropdowns: full width on mobile */
  select {
    max-width: 100%;
  }

  /* Evidence sections in compare: single column */
  [style*="grid-template-columns:repeat(auto-fit,minmax(280px"] {
    grid-template-columns: 1fr !important;
  }

  /* Hero layer pills: smaller on mobile */
  .hero-layer, .hl-a, .hl-e, .hl-f, .hl-at, .hl-s {
    font-size: 0.7rem !important;
    padding: 0.2rem 0.6rem !important;
  }

  /* Compare bar: reduce padding on mobile */
  #compareBar {
    padding: 0.6rem 0.75rem !important;
  }

  /* Experiment grid: single column on tablet */
  .exp-grid {
    grid-template-columns: 1fr !important;
  }

  /* Tool chart containers: allow horizontal scroll */
  [style*="min-width:400px"],
  [style*="min-width:360px"] {
    min-width: auto !important;
    overflow-x: auto;
  }
}

/* ── Additional Phone Fixes (480px) ─────────────────── */
@media (max-width: 480px) {
  /* Score table cells need to breathe */
  .score-table td, .score-table th {
    padding: 0.25rem 0.3rem !important;
    font-size: 0.7rem !important;
  }

  /* Remove buttons in compare picker: smaller */
  button[onclick*="removeHypothesis"] {
    font-size: 0.7rem !important;
    padding: 0.2rem 0.4rem !important;
  }

  /* D3/chart containers: constrain height */
  [id*="chart"], [id*="Chart"] {
    max-height: 300px;
  }

  /* Verdict summary: stack vertically */
  [style*="display:flex"][style*="min-width:180px"] {
    min-width: auto !important;
    flex: 1 1 100% !important;
  }

  /* Long text in evidence cards: smaller font */
  [style*="font-size:0.82rem"] {
    font-size: 0.75rem !important;
  }
}

/* ── Additional Tablet Fixes (768px) ────────────────── */
@media (max-width: 768px) {
  /* Search results dropdown: constrain to viewport */
  #navSearchResults {
    width: calc(100vw - 2rem) !important;
    max-width: 380px;
    right: -1rem !important;
  }

  /* Stat boxes in experiments/targets pages */
  .stat-box, .stat-card {
    min-width: auto !important;
    flex: 1 1 calc(50% - 0.5rem);
  }

  /* Sort buttons / filter pills: horizontal scroll */
  .sort-options, .filter-pills {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .sort-options::-webkit-scrollbar,
  .filter-pills::-webkit-scrollbar {
    display: none;
  }

  /* Ensure all overflow-x containers have momentum scroll */
  [style*="overflow-x:auto"],
  [style*="overflow-x: auto"] {
    -webkit-overflow-scrolling: touch !important;
  }

  /* Gene bubble chart: constrain on mobile */
  [style*="viewBox"] {
    max-width: 100%;
  }

  /* Flex containers with many children: allow wrap */
  [style*="display:flex"]:not([style*="flex-direction:column"]) {
    flex-wrap: wrap !important;
  }

  /* Pagination: compact on mobile */
  .pagination {
    gap: 0.5rem !important;
  }
  .pagination a {
    padding: 0.3rem 0.6rem !important;
    font-size: 0.8rem !important;
  }
}

/* ── Additional Phone Fixes (480px) ────────────────── */
@media (max-width: 480px) {
  /* Search dropdown: full width */
  #navSearchResults {
    left: 0.5rem !important;
    right: 0.5rem !important;
    width: auto !important;
  }

  /* Stat boxes: single column */
  .stat-box, .stat-card {
    flex: 1 1 100%;
  }

  /* Stats row: vertical stack */
  .stats-row, .stats-bar {
    flex-direction: column !important;
    gap: 0.5rem !important;
  }

  /* Search bar: stack inputs */
  .search-bar {
    flex-direction: column !important;
  }
  .search-bar input[type="text"] {
    min-width: auto !important;
    width: 100% !important;
  }

  /* Price chart SVGs: constrain */
  svg[viewBox] {
    max-width: 100% !important;
    height: auto;
  }
}

/* ── Additional inline-style grid overrides (480px) ──── */
@media (max-width: 480px) {
  /* Inline 2-column grids should collapse to 1 */
  [style*="grid-template-columns:repeat(2"],
  [style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
  }

  /* Fixed-width sidebar columns in inline grids */
  [style*="grid-template-columns:200px"],
  [style*="grid-template-columns: 200px"],
  [style*="grid-template-columns:260px"],
  [style*="grid-template-columns: 260px"] {
    grid-template-columns: 1fr !important;
  }

  /* Inline flex with fixed-width children */
  [style*="flex-shrink:0"][style*="width:140px"],
  [style*="flex-shrink:0"][style*="width:130px"] {
    width: auto !important;
    min-width: 60px !important;
    flex-shrink: 1 !important;
  }
}

/* ── Safe Area Insets (notched phones) ──────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }

  .scidex-sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  nav {
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
  }
}

/* ── Mid-Tablet (1024px) — horizontal scroll for nav links ── */
@media (max-width: 1024px) and (min-width: 769px) {
  .nav-links-top {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    max-width: calc(100vw - 300px);
  }
  .nav-links-top::-webkit-scrollbar {
    display: none;
  }
}

/* ── Fixed-height containers — scale on mobile (768px) ── */
@media (max-width: 768px) {
  [style*="height:500px"],
  [style*="height: 500px"] {
    height: 300px !important;
  }

  [style*="height:400px"],
  [style*="height: 400px"] {
    height: 280px !important;
  }

  [style*="height:350px"],
  [style*="height: 350px"] {
    height: 250px !important;
  }

  p, li, td, dd, blockquote {
    overflow-wrap: break-word;
    word-break: break-word;
  }

  [style*="overflow-x:auto"],
  [style*="overflow-x: auto"],
  .table-wrapper {
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin;
  }

  details {
    width: 100%;
  }
  details summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
  }

  [style*="position:absolute"][style*="top:0"][style*="right:0"] {
    position: static !important;
    margin-top: 0.5rem;
  }

  [style*="position:fixed"][style*="bottom:0"] {
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* ── Phone fixed-height overrides (480px) ──────────── */
@media (max-width: 480px) {
  [style*="height:500px"],
  [style*="height: 500px"] {
    height: 220px !important;
  }

  [style*="height:400px"],
  [style*="height: 400px"],
  [style*="height:350px"],
  [style*="height: 350px"] {
    height: 200px !important;
  }

  [style*="height:300px"],
  [style*="height: 300px"] {
    height: 180px !important;
  }

  .infobox, [class*="infobox"] {
    width: 100% !important;
    float: none !important;
    margin: 0.5rem 0 !important;
  }

  iframe {
    max-width: 100% !important;
    height: auto;
    min-height: 200px;
  }

  [style*="display:flex"][style*="justify-content:space-between"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.3rem !important;
  }
}

/* ── Vision Page — Small Phone (480px) ──────────────── */
@media (max-width: 480px) {
  .pitch-hero-section {
    min-height: auto !important;
    padding: 2rem 1rem 3rem !important;
  }

  .pitch-title {
    font-size: 2.5rem !important;
  }

  .layer-pills {
    gap: 0.5rem !important;
  }

  .layer-pill {
    padding: 0.6rem 1rem !important;
    font-size: 0.8rem !important;
  }

  .counter-item {
    min-width: 70px !important;
    padding: 0.6rem 0.8rem !important;
  }

  .world-model-viz {
    grid-template-columns: 1fr !important;
  }

  .layer-card-grid {
    grid-template-columns: 1fr !important;
  }

  .section-title {
    font-size: 1.3rem !important;
  }

  .section-text {
    font-size: 0.92rem !important;
  }

  .cta-section h2 {
    font-size: 1.6rem !important;
  }

  .cta-btn {
    display: block !important;
    margin: 0.4rem auto !important;
    text-align: center;
  }

  .compare-table th,
  .compare-table td {
    padding: 0.4rem !important;
    font-size: 0.75rem !important;
  }

  .epigraph {
    font-size: 0.9rem !important;
    padding-left: 0.8rem !important;
  }
}

/* ── Uncovered Fixed Widths (768px) ────────────────── */
@media (max-width: 768px) {
  /* width:220px progress bar containers */
  [style*="width:220px"],
  [style*="width: 220px"] {
    width: auto !important;
    min-width: 0 !important;
    flex: 1 !important;
  }

  /* width:120px label columns */
  [style*="width:120px"]:not(input):not(select),
  [style*="width: 120px"]:not(input):not(select) {
    width: auto !important;
    min-width: 0 !important;
  }

  /* Ensure long text in flex rows truncates properly */
  [style*="text-overflow:ellipsis"] {
    min-width: 0 !important;
  }

  /* Clinical trials status labels with min-width:100px */
  [style*="min-width:100px"][style*="font-size:0.82rem"] {
    min-width: auto !important;
  }
}

/* ── Comparison/Preview Cards (768px) ──────────────── */
@media (max-width: 768px) {
  [style*="max-width:300px"][style*="min-width:150px"] {
    max-width: 100% !important;
    min-width: auto !important;
    flex: 1 1 100% !important;
  }
}

/* ── Horizontal Scroll Indicators ──────────────────── */
@media (max-width: 768px) {
  .table-wrapper {
    position: relative;
  }

  .table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 24px;
    height: 100%;
    background: linear-gradient(to left, rgba(10, 10, 20, 0.8), transparent);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
  }
}

/* ── Extra Small (360px) ─────────────────────────────── */
@media (max-width: 360px) {
  .container {
    padding: 0.5rem;
  }

  h1 {
    font-size: 1.2rem !important;
  }

  h2 {
    font-size: 1rem;
  }

  .hero {
    padding: 0.8rem;
  }

  .scidex-sidebar {
    width: 220px !important;
    left: -230px !important;
  }

  [style*="gap:0.8rem"],
  [style*="gap: 0.8rem"] {
    gap: 0.3rem !important;
  }

  .stat {
    flex: 1 1 100% !important;
  }

  /* Vision page counter items — prevent overflow */
  .counter-item {
    min-width: auto !important;
    padding: 0.6rem 1rem;
  }

  /* Nav search — even more compact */
  #navSearchInput {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem 0.25rem 1.5rem !important;
  }

  /* Layer pills — compact on extra small */
  .layer-pills {
    flex-direction: column !important;
    align-items: center;
  }

  .layer-pill {
    padding: 0.6rem 1.2rem !important;
    font-size: 0.8rem !important;
    width: 80% !important;
    text-align: center;
  }
}

/* ── Landscape Phone ──────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce hero min-height in landscape */
  .pitch-hero-section {
    min-height: auto !important;
    padding-top: 1rem !important;
    padding-bottom: 2rem !important;
  }

  /* Sidebar full height in landscape */
  .scidex-sidebar {
    max-height: 100vh;
    overflow-y: auto;
  }

  /* Fixed bottom bars — reduce padding in landscape */
  [style*="position:fixed"][style*="bottom:0"] {
    padding-top: 0.4rem !important;
    padding-bottom: 0.4rem !important;
  }
}

/* ── Print styles ─────────────────────────────────────── */
@media print {
  .scidex-sidebar,
  .sidebar-overlay,
  .hamburger-btn,
  nav,
  .footer,
  #compareBar {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .container {
    max-width: 100% !important;
    padding: 0 !important;
  }

  a {
    color: #333 !important;
  }

  .card {
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }
}

/* ── Mobile table scroll hints (768px) ──────────────── */
@media (max-width: 768px) {
  /* Ensure tables inside cards always scroll horizontally */
  .card table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .card table thead,
  .card table tbody {
    display: table;
    width: 100%;
  }

  /* Footer links — stack on mobile */
  .footer {
    text-align: center;
    line-height: 2;
  }

  .footer a {
    display: inline-block;
    padding: 0.2rem 0;
  }

  /* Long IDs/hashes in table cells — truncate with ellipsis */
  td[style*="color:#4fc3f7"] {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ── Phone table improvements (480px) ──────────────── */
@media (max-width: 480px) {
  /* Tables with many columns — allow title columns to wrap */
  .card table td:nth-child(2) {
    white-space: normal !important;
    word-break: break-word;
    min-width: 100px;
  }

  /* Hypothesis title cells — allow wrap for readability */
  td[style*="padding:0.5rem"] {
    white-space: normal !important;
  }

  /* Footer even more compact */
  .footer {
    font-size: 0.7rem !important;
    padding: 0.6rem !important;
  }
}

/* ── Mobile Responsive Enhancements (2026-04-03) ─────── */

/* Tablet (768px): flex items with min-width should shrink */
@media (max-width: 768px) {
  /* Flex children with inline min-width: allow shrink */
  [style*="min-width:180px"],
  [style*="min-width: 180px"],
  [style*="min-width:150px"],
  [style*="min-width: 150px"] {
    min-width: 100px !important;
    flex: 1 1 auto !important;
  }

  /* Nav search input: narrower on tablet */
  [style*="width:180px"][style*="border-radius:16px"] {
    width: 140px !important;
  }

  /* Exchange/market cards: allow wrapping */
  [style*="min-width:180px"][style*="max-width:280px"],
  [style*="min-width: 180px"][style*="max-width: 280px"] {
    min-width: 140px !important;
    max-width: none !important;
    flex: 1 1 calc(50% - 0.5rem) !important;
  }

  /* Score dimension bars: ensure 2-col on tablet */
  [style*="display:grid"][style*="minmax(260px"],
  [style*="display:grid"][style*="minmax(280px"] {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
  }

  /* Tables: always horizontally scrollable */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  thead, tbody, tr {
    max-width: 100%;
  }

  /* Code blocks: horizontal scroll */
  pre, code {
    overflow-x: auto;
    max-width: 100%;
    word-break: break-all;
  }

  /* Mermaid diagrams: constrain */
  .mermaid, [class*="mermaid"] {
    overflow-x: auto;
    max-width: 100%;
  }
  .mermaid svg {
    max-width: 100%;
    height: auto;
  }
}

.mermaid-preview {
  position: relative;
  cursor: zoom-in;
}

.mermaid-preview svg {
  max-width: 100%;
  height: auto;
}

.mermaid-preview::after {
  content: "Click to expand";
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(10, 10, 20, 0.82);
  border: 1px solid rgba(79, 195, 247, 0.22);
  color: #9ecfe5;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.mermaid-lightbox-open {
  overflow: hidden;
}

.mermaid-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 2000;
}

.mermaid-lightbox.is-open {
  display: block;
}

.mermaid-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 18, 0.84);
  backdrop-filter: blur(6px);
}

.mermaid-lightbox__dialog {
  position: absolute;
  inset: 5vh 4vw;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 16px;
  border: 1px solid rgba(79, 195, 247, 0.16);
  background: linear-gradient(180deg, rgba(12, 18, 32, 0.98), rgba(13, 13, 26, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.mermaid-lightbox__close {
  align-self: flex-end;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #e0e0e0;
  cursor: pointer;
}

.mermaid-lightbox__hint {
  color: #8ea0b5;
  font-size: 0.82rem;
}

.mermaid-lightbox__viewport {
  flex: 1;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(79, 195, 247, 0.12);
  background:
    radial-gradient(circle at top left, rgba(79, 195, 247, 0.08), transparent 35%),
    #0b1020;
  cursor: default;
}

.mermaid-lightbox__viewport.is-pannable {
  cursor: grab;
}

.mermaid-lightbox__viewport.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.mermaid-lightbox__surface {
  display: inline-block;
  min-width: 100%;
  min-height: 100%;
  padding: 1.25rem;
}

.mermaid-lightbox__surface svg {
  max-width: none !important;
  height: auto;
}

.mermaid-lightbox__viewport::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.mermaid-lightbox__viewport::-webkit-scrollbar-thumb {
  background: rgba(79, 195, 247, 0.28);
  border-radius: 999px;
}

.commit-hash-button {
  background: none;
  border: none;
  padding: 0;
  color: #4fc3f7;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.commit-hash-button:hover {
  color: #8fd9ff;
}

.commit-lightbox-open {
  overflow: hidden;
}

.commit-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 2100;
}

.commit-lightbox.is-open {
  display: block;
}

.commit-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 18, 0.82);
  backdrop-filter: blur(4px);
}

.commit-lightbox__dialog {
  position: absolute;
  inset: 8vh 8vw;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(16, 20, 36, 0.98), rgba(11, 16, 32, 0.98));
  border: 1px solid rgba(79, 195, 247, 0.16);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.commit-lightbox__close {
  align-self: flex-end;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #e0e0e0;
  cursor: pointer;
}

.commit-lightbox__content {
  overflow: auto;
  padding-right: 0.25rem;
}

.commit-lightbox__header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.commit-lightbox__header h2 {
  margin: 0.2rem 0 0;
  color: #e0e0e0;
  font-size: 1.2rem;
}

.commit-lightbox__hash {
  color: #4fc3f7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.commit-lightbox__external {
  color: #81c784;
  text-decoration: none;
  white-space: nowrap;
}

.commit-lightbox__meta {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
}

.commit-lightbox__meta-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  font-size: 0.88rem;
}

.commit-lightbox__meta-row span:first-child {
  color: #888;
}

.commit-lightbox__meta-row span:last-child {
  color: #e0e0e0;
  text-align: right;
}

.commit-lightbox__body {
  background: #0d0d1a;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.9rem;
  color: #d6dde4;
  white-space: pre-wrap;
  overflow: auto;
}

.commit-lightbox__files {
  background: #0d0d1a;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}

.commit-lightbox__file {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.85rem;
}

.commit-lightbox__file:last-child {
  border-bottom: none;
}

.commit-lightbox__file span:first-child {
  color: #e0e0e0;
  word-break: break-word;
}

.commit-lightbox__file span:last-child {
  color: #888;
  white-space: nowrap;
}

.commit-lightbox__loading,
.commit-lightbox__empty,
.commit-lightbox__error {
  color: #adb5bd;
  padding: 1rem 0;
}

.commit-lightbox__error {
  color: #ef9a9a;
}

.commit-lightbox__muted {
  color: #888;
}

/* Phone (480px): aggressive stacking */
@media (max-width: 480px) {
  /* All flex items with min-width: collapse */
  [style*="min-width:120px"],
  [style*="min-width: 120px"],
  [style*="min-width:140px"],
  [style*="min-width: 140px"],
  [style*="min-width:150px"],
  [style*="min-width: 150px"],
  [style*="min-width:180px"],
  [style*="min-width: 180px"] {
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }

  /* Nav search: make full width on small phones */
  [style*="width:180px"][style*="border-radius:16px"] {
    width: 100% !important;
    max-width: 200px !important;
  }

  /* Exchange/market cards: single column */
  [style*="min-width:180px"][style*="max-width:280px"],
  [style*="min-width: 180px"][style*="max-width: 280px"],
  [style*="min-width:150px"][style*="max-width:300px"],
  [style*="min-width: 150px"][style*="max-width: 300px"] {
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 100% !important;
  }

  /* Score grids: single column on phones */
  [style*="display:grid"][style*="minmax(260px"],
  [style*="display:grid"][style*="minmax(280px"],
  [style*="display:grid"][style*="minmax(200px"] {
    grid-template-columns: 1fr !important;
  }

  /* Stat text centers: stack vertically */
  [style*="text-align:center"][style*="min-width"] {
    min-width: 0 !important;
    flex: 1 1 calc(50% - 0.5rem) !important;
  }

  /* Evidence cards and similar wide items */
  [style*="max-width:600px"],
  [style*="max-width: 600px"],
  [style*="max-width:650px"],
  [style*="max-width: 650px"] {
    max-width: 100% !important;
    padding: 0.5rem !important;
  }

  /* Pathway/mermaid diagrams: scroll container */
  .mermaid, [class*="mermaid"] {
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
  }

  /* Long links/URLs: break */
  a {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* KG chips and tags: smaller on mobile */
  [style*="border-radius:12px"][style*="padding:0.2rem"],
  [style*="border-radius: 12px"][style*="padding: 0.2rem"] {
    font-size: 0.7rem !important;
    padding: 0.15rem 0.4rem !important;
  }
}

/* Prevent any horizontal overflow at any breakpoint */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
  }

  /* Ensure images never overflow */
  img {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Fixed-position elements: respect viewport */
  [style*="position:fixed"] {
    max-width: 100vw;
  }
}

/* ── Global Mobile Table Scroll ──────────────────────── */
/* Ensure ALL tables scroll horizontally on small screens,
   even those not wrapped in .table-wrapper divs */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    scrollbar-width: thin;
  }
  thead, tbody, tfoot {
    display: table;
    width: 100%;
    min-width: 400px;
  }
}

/* ── Hypothesis Card Grid — phone stacking ───────────── */
@media (max-width: 480px) {
  .hyp-grid {
    grid-template-columns: 1fr !important;
    gap: 0.6rem !important;
  }
  .hyp-card {
    padding: 0.8rem !important;
  }
  .hyp-title {
    font-size: 0.88rem !important;
  }
  .hyp-meta {
    gap: 0.4rem !important;
    font-size: 0.72rem !important;
  }
}

/* ── Score bars — prevent overflow on small screens ──── */
@media (max-width: 480px) {
  [style*="width:60px"][style*="height:4px"] {
    width: 40px !important;
  }
  .score-bar-container {
    max-width: 100%;
  }
}

/* ── Evidence sections — full width stacking ─────────── */
@media (max-width: 480px) {
  .evidence-section, [class*="evidence"] {
    padding: 0.6rem !important;
  }
  /* Long URLs and DOIs in evidence */
  a[href*="doi.org"],
  a[href*="pubmed"],
  a[href*="semanticscholar"] {
    word-break: break-all;
    font-size: 0.75rem;
  }
}

/* ── Compare page — responsive charts and bars ───────── */
@media (max-width: 768px) {
  #compareBar {
    flex-wrap: wrap !important;
    gap: 0.3rem !important;
  }
  .compare-card {
    min-width: auto !important;
  }
}

/* ── Wiki / entity pages — infobox and content ───────── */
@media (max-width: 768px) {
  .infobox, [class*="infobox"] {
    width: 100% !important;
    float: none !important;
    margin: 0.5rem 0 !important;
  }
  .wiki-content img, .entity-content img {
    max-width: 100% !important;
    height: auto !important;
  }
  /* TOC sidebar collapses on mobile */
  .wiki-toc, .toc-sidebar {
    position: static !important;
    width: 100% !important;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1rem;
  }
}

/* ── Debate rounds — compact on mobile ───────────────── */
@media (max-width: 480px) {
  [style*="border-left:3px solid"] {
    padding-left: 0.6rem !important;
    margin-left: 0 !important;
  }
  .debate-persona {
    font-size: 0.8rem !important;
  }
}

/* ── Bottom fixed bars (compare bar, etc.) ───────────── */
@media (max-width: 768px) {
  [style*="position:fixed"][style*="bottom:0"] {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    border-radius: 0 !important;
    padding: 0.5rem 0.75rem !important;
  }
}

/* ── Long text overflow prevention ───────────────────── */
@media (max-width: 480px) {
  h1, h2, h3, h4 {
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
  }
  /* Prevent any element from exceeding viewport */
  * {
    max-width: 100vw;
  }
  body, .container {
    overflow-x: hidden;
  }
}

/* ── Global Touch & Overflow Safety ──────────────────── */
@media (max-width: 768px) {
  /* Ensure all images are responsive */
  img:not([width]) {
    max-width: 100%;
    height: auto;
  }

  /* Inline code blocks: prevent overflow */
  pre, code {
    max-width: 100%;
    overflow-x: auto;
  }
  pre {
    word-break: normal;
    white-space: pre-wrap;
  }

  /* Ensure all containers respect viewport */
  .container, [class*="container"] {
    max-width: 100vw;
    overflow-x: hidden;
  }
}
  }
}
