/* styles.css - paper texture + ink tone */

:root {
  /* Paper tone: warm off-white */
  --bg-body: #f5f0e8;
  --bg-soft: #faf6f0;
  /* Ink tone: deep brown / charcoal */
  --text-main: #2c2419;
  --text-muted: #6b5d4f;
  --primary: #4a3f35;
  --primary-strong: #2e241c;
  --border-strong: #d4c9b8;
  --hero-glow: rgba(214, 194, 162, 0.32);
  --hero-shadow: rgba(44, 36, 25, 0.14);
  --radius-md: 10px;
  /* Requirement 3/5: equal-area example cells; fallback sizes before measuring (9:16 portrait / 16:9 landscape) */
  --example-portrait-width: 160px;
  --example-portrait-height: 284px;
  --example-landscape-width: 284px;
  --example-landscape-height: 160px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-serif, Georgia, "Times New Roman", Times, serif;
  background:
    radial-gradient(circle at top left, rgba(214, 194, 162, 0.18), transparent 24%),
    radial-gradient(circle at top right, rgba(92, 77, 63, 0.08), transparent 20%),
    linear-gradient(180deg, #f8f4ed 0%, var(--bg-body) 100%);
  color: var(--text-main);
  line-height: 1.65;
}

.container {
  width: min(1400px, calc(100% - 64px));
  margin: 0 auto;
}

/* Card blocks */
.card {
  padding: 14px 16px;
  background: var(--bg-soft);
  border: 1px solid rgba(212, 201, 184, 0.9);
  border-radius: 12px;
}

.card-title {
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--primary);
}

/* Top bar and shared styles */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 246, 240, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-strong);
}
.topbar-inner { display: flex; justify-content: space-between; padding: 10px 0; }
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #5c4d3f, #31271f);
  color: #fffdf8;
  font-weight: 700;
  letter-spacing: 0.08em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.brand-title { font-weight: 700; font-size: 18px; }
.brand-subtitle { color: var(--text-muted); font-size: 13px; }
.topnav a { margin-left: 15px; text-decoration: none; color: var(--text-main); font-size: 14px; }
.topnav a:hover { color: var(--primary); }

.skip {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  color: #fffdf8;
  background: var(--primary);
  border-radius: 999px;
  text-decoration: none;
}
.skip:focus {
  top: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid rgba(74, 63, 53, 0.18);
  border-radius: 999px;
  background: #fffdf8;
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(74, 63, 53, 0.35);
  box-shadow: 0 8px 18px rgba(44, 36, 25, 0.08);
}
.btn:focus-visible {
  outline: 2px solid rgba(74, 63, 53, 0.42);
  outline-offset: 3px;
}
.btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.status {
  margin-top: 12px;
  min-height: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.divider {
  height: 1px;
  margin: 14px 0;
  background: rgba(74, 63, 53, 0.12);
}

.toc {
  margin: 0;
  padding-left: 18px;
}
.toc li + li {
  margin-top: 8px;
}
.toc a {
  color: var(--text-main);
  text-decoration: none;
}
.toc a:hover {
  color: var(--primary);
}

.a4-wrap { margin: 20px auto; max-width: 100%; }
.a4-page {
  position: relative;
  margin: 32px auto 40px;
  width: 100%;
  max-width: 100%;
  padding: 24px 28px 28px;
  background: #fffdf8;
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(212, 201, 184, 0.9);
}
/* Requirement 2: Examples and comparison share the same width; do not narrow the content wrapper */
.example-page-fullbleed { width: 100%; }
#Examples.section,
#videoGallery { width: 100%; max-width: none; }

.section-head { margin-bottom: 20px; }
.page-title { font-size: 24px; margin: 0; }
.page-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; max-width: 72ch; }

#page-1 {
  overflow: hidden;
  padding: clamp(28px, 4vw, 42px);
  background:
    radial-gradient(circle at top left, var(--hero-glow), transparent 32%),
    radial-gradient(circle at 88% 8%, rgba(74, 63, 53, 0.08), transparent 18%),
    linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(250, 246, 240, 0.98));
  box-shadow: 0 24px 56px rgba(44, 36, 25, 0.08);
}

#page-1::before,
#page-1::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

#page-1::before {
  width: 260px;
  height: 260px;
  top: -120px;
  left: -70px;
  background: radial-gradient(circle, rgba(214, 194, 162, 0.28), transparent 70%);
}

#page-1::after {
  width: 220px;
  height: 220px;
  right: -60px;
  bottom: -80px;
  background: radial-gradient(circle, rgba(92, 77, 63, 0.08), transparent 70%);
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(290px, 360px);
  gap: clamp(24px, 3vw, 40px);
  align-items: start;
}

.hero-left {
  min-width: 0;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.hero-right {
  position: sticky;
  top: 96px;
  z-index: 1;
}

.hero-kicker-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(74, 63, 53, 0.14);
  background: rgba(255, 253, 248, 0.85);
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 8px 18px rgba(44, 36, 25, 0.05);
}

.hero-kicker-muted {
  background: rgba(212, 201, 184, 0.3);
  color: var(--text-muted);
}

.h1 {
  margin: 0;
  max-width: 100%;
  font-size: clamp(1.05rem, 1.35vw, 1.2rem);
  line-height: 1.12;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.hero-deck {
  margin: 0;
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.85;
  color: var(--text-muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.github-mark {
  width: 18px;
  height: 18px;
}

.hero-primary-btn,
.resource-btn {
  gap: 10px;
  min-height: 48px;
  padding: 0 20px;
  border-color: rgba(46, 36, 28, 0.5);
  background: linear-gradient(180deg, #4f4134, #2e241c);
  color: #fffdf8;
  box-shadow: 0 14px 30px rgba(44, 36, 25, 0.18);
  text-decoration: none;
}

.hero-primary-btn:hover,
.resource-btn:hover {
  border-color: rgba(46, 36, 28, 0.8);
  box-shadow: 0 18px 36px rgba(44, 36, 25, 0.22);
}

.hero-secondary-btn,
.abstract-link-btn {
  text-decoration: none;
  background: rgba(255, 253, 248, 0.8);
  backdrop-filter: blur(10px);
}

.hero-secondary-btn {
  min-height: 48px;
  padding: 0 20px;
}

.abstract {
  position: relative;
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(22px, 3vw, 30px);
  border: 1px solid rgba(212, 201, 184, 0.95);
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(214, 194, 162, 0.22), transparent 34%),
    linear-gradient(180deg, rgba(255, 253, 248, 0.99), rgba(250, 246, 240, 0.98));
  box-shadow:
    0 24px 48px rgba(44, 36, 25, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.abstract::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 18px;
  border: 1px solid rgba(212, 201, 184, 0.38);
  pointer-events: none;
}

.abstract-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.notice-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.abstract-chip {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(74, 63, 53, 0.16);
  background: rgba(255, 253, 248, 0.84);
  color: var(--primary-strong);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 20px rgba(44, 36, 25, 0.06);
}

.abstract-chip:hover {
  border-color: rgba(74, 63, 53, 0.28);
  box-shadow: 0 14px 24px rgba(44, 36, 25, 0.08);
}

.abstract-copy {
  margin: 0;
  position: relative;
  z-index: 1;
  font-size: 15px;
  line-height: 1.95;
}

.abstract-copy.is-collapsed {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
}

.abstract-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.abstract-toggle {
  margin-top: 0;
}

.card.hero-panel {
  padding: 20px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(248, 242, 233, 0.98));
  box-shadow: 0 22px 44px rgba(44, 36, 25, 0.08);
}

.resource-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.resource-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(180deg, #4b3d31, #2f261d);
  color: #fffdf8;
  box-shadow: 0 12px 24px rgba(44, 36, 25, 0.16);
  flex: 0 0 auto;
}

.resource-icon svg {
  width: 28px;
  height: 28px;
}

.resource-copy {
  min-width: 0;
}

.resource-eyebrow,
.hero-panel-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.card-title.resource-title {
  margin: 5px 0 8px;
  font-size: 22px;
}

.resource-summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.72;
}

.resource-btn {
  width: 100%;
  margin-top: 18px;
}

.hero-panel .divider {
  margin: 18px 0 16px;
}

.hero-panel-label {
  margin-bottom: 12px;
}

.hero-nav {
  display: grid;
  gap: 10px;
}

.hero-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(74, 63, 53, 0.12);
  background: rgba(255, 253, 248, 0.72);
  color: var(--text-main);
  text-decoration: none;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.hero-nav-link:hover {
  transform: translateY(-1px);
  border-color: rgba(74, 63, 53, 0.24);
  background: #fffdf8;
  box-shadow: 0 12px 24px rgba(44, 36, 25, 0.08);
}

.hero-nav-meta {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.hero-panel-footer {
  margin-top: 18px;
}

.hero-reload-btn {
  background: rgba(255, 253, 248, 0.55);
}

.hero-panel .status {
  margin-top: 12px;
  line-height: 1.5;
  min-height: 1.5em;
}

/* Avoid double "paper card" on pages that already contain inner paper blocks */
#page-2.a4-page,
#page-3.a4-page {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

/* Fullbleed page: no outer paper chrome */
.a4-page.example-page-fullbleed {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

/* Video play state icon */
.grid-video-wrap {
  position: relative;
  background: #000;
  cursor: pointer;
  overflow: hidden;
  border-radius: 6px; /* Rounded corners soften dense layouts */
}

/* Lazy loading optimization: only create GPU layer when video is loaded */
.lazy-video {
  will-change: contents;
}

.lazy-video video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover; /* Fill the box (no letterboxing) */
  transform: translateZ(0); /* Fix Chrome flicker only for loaded videos */
}

.grid-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.2s;
}
.grid-video-wrap:hover .grid-play-icon { opacity: 1; }
.grid-play-icon::before {
  content: "Play";
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.grid-play-icon.is-playing::before { content: "Pause"; }

.loading-indicator {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(44, 36, 25, 0.08), rgba(44, 36, 25, 0.18));
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fffdf8;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* -------------------------------------------
   New Example Grid System (video, image, audio, text, two Ours columns)
------------------------------------------- */

.category-title {
  font-size: 18px;
  color: var(--primary);
  margin: 0 0 18px;
  padding-left: 4px;
  border-left: 3px solid var(--primary);
  font-weight: 700;
}

/* Requirement 2: Examples and comparison share the same width; do not create a narrower wrapper.
   Each category, the comparison section, and the first-page paper area are placed on separate "paper sheets". */
.example-category,
#tbCompare,
.page-paper {
  position: relative;
  margin: 32px auto 40px;
  width: 100%;
  max-width: 100%;
  padding: 24px 28px 28px;
  background: #fffdf8;
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(212, 201, 184, 0.9);
}

.example-category {
  content-visibility: auto;
  contain-intrinsic-size: 900px;
}

.example-category:first-of-type {
  margin-top: 16px;
}

.category-title::after {
  content: "";
  display: block;
  margin-top: 10px;
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
}

/* Row layout: video, image, audio, text, plus two Ours columns */
.example-header-row {
  margin-bottom: 10px;
}

.example-header-row .example-row-cells {
  justify-content: center;
}

.example-row {
  margin-bottom: 14px;
}

.example-row-cells {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2fr 1fr 1fr; /* input video, input image, audio, text, Ours BGM, Ours Vocal */
  gap: 14px;
  align-items: stretch;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding-left: 0;
  padding-right: 0;
}

/* Equal area: landscape rows are short+wide, portrait rows are tall+narrow, matching the comparison cell area.
   Use min-height; actual height is driven by each media element's aspect-ratio. */
.example-row-cells.mode-landscape {
  min-height: 180px;
  /* Slightly narrower text column; column 1 matches columns 5/6 so each Ours video matches the input video size */
  grid-template-columns: 1.7fr 1.7fr 1fr 1.6fr 1.7fr 1.7fr;
}
.example-row-cells.mode-portrait {
  min-height: 320px;
  /* In portrait, keep column 1 equal to columns 5/6 and narrow the text column */
  grid-template-columns: 0.9fr 0.9fr 1fr 1.6fr 0.9fr 0.9fr;
}
.example-row-cells.mode-landscape .example-ours-wrapper,
.example-row-cells.mode-portrait .example-ours-wrapper {
  grid-column: span 2;
}

/* Header row: no fixed height; reuse column ratios */
.example-header-row .example-row-cells.mode-landscape,
.example-header-row .example-row-cells.mode-portrait {
  height: auto;
  min-height: 0;
}

/* Make media fill the grid cell */
.example-media-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.example-media-cell .grid-video-wrap,
.example-media-cell .grid-image-wrap,
.example-media-cell .ex-placeholder {
  width: 100%;
  min-width: 0;
  min-height: 0;
}
.example-media-cell .grid-video-wrap video,
.example-media-cell .grid-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* In Examples rows: let video/image wrappers derive height from their aspect-ratio */
.example-row .example-media-cell .grid-video-wrap,
.example-row .example-media-cell .grid-image-wrap {
  height: auto;
}

/* Examples data rows: height is driven by media cells (no fixed 200px) */
.example-row .example-row-cells {
  align-items: stretch;
}

/* Header row: no outer border, visually consistent with data rows */
.example-header-row .example-row-cells {
  padding: 10px 0;
  background: transparent;
  border: none;
  border-radius: 0;
}

.ex-header-cell {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  padding: 10px 6px;
  background: transparent;
  border-radius: 4px;
}

/* Ours wrapper: BGM left, Vocal right, consistent gap */
.example-ours-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

.example-row .example-ours-wrapper {
  align-items: stretch;
  min-height: 0;
}

.example-ours-wrapper .grid-video-wrap,
.example-ours-wrapper .ex-placeholder {
  min-width: 0;
}

.example-row .example-ours-wrapper .grid-video-wrap,
.example-row .example-ours-wrapper .ex-placeholder {
  min-height: 0;
}

/* Images: preserve aspect ratio (Examples controlled by CSS; elsewhere JS may set aspectRatio on load) */
.grid-image-wrap {
  position: relative;
  background: var(--bg-soft);
  overflow: hidden;
  border-radius: 8px;
  aspect-ratio: 16 / 9; /* Fallback before loading */
  border: 1px solid var(--border-strong);
}

.grid-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Audio: aligned to image sizing; Examples remove borders (see .example-row overrides below) */
.grid-audio-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 10px;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border-strong);
}

.grid-audio-wrap audio {
  width: 100%;
  max-width: 100%;
  height: 32px;
}

.audio-btn {
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.audio-btn:hover {
  background: var(--border-strong);
}
.audio-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Text block: aligned with image sizing; Examples remove borders (see .example-row overrides below) */
.grid-text-wrap {
  display: flex;
  align-items: flex-start;
  padding: 14px;
  background: var(--bg-soft);
  border-radius: 8px;
  min-height: 100px;
  border: 1px solid var(--border-strong);
}

.grid-text-content {
  font-size: 13px;
  line-height: 1.75;
  color: var(--text-main);
  white-space: pre-wrap;
  word-break: break-word;
  width: 100%;
}

/* Requirement 1 & 3: Examples have no outer border; spacing separates sections.
   Input video and input image keep equal visible pixel area and matching corner radius. */
.example-row .grid-video-wrap,
.example-row .grid-image-wrap,
.example-row .ex-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.example-row .grid-video-wrap video,
.example-row .grid-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}


/* Borderless Examples: text/audio/placeholders float over the page background */
.example-row .grid-text-wrap,
.example-row .grid-audio-wrap,
.example-row .ex-placeholder {
  min-height: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.example-row .grid-text-wrap {
  align-items: center;
  justify-content: flex-start;
}
.example-row .grid-audio-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.example-row .grid-audio-wrap audio {
  display: none;
}
.example-row .grid-text-content {
  text-align: left;
}

/* Placeholder (when content is missing); borderless styling overridden within .example-row .ex-placeholder */
.ex-placeholder {
  aspect-ratio: 16 / 9;
  background: var(--bg-soft);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  border: 1px dashed var(--border-strong);
}
.ex-placeholder-missing-modality .ex-placeholder-icon {
  font-size: 18px;
  opacity: 0.7;
}
.ex-placeholder-missing-modality .ex-placeholder-text {
  font-size: 11px;
  text-align: center;
  padding: 0 8px;
}

/* Requirement 2: unify example media-cell visible sizes by orientation so input video and image have equal area */
.example-category.landscape .example-media-cell .grid-video-wrap,
.example-category.landscape .example-media-cell .grid-image-wrap,
.example-category.landscape .example-media-cell .ex-placeholder {
  aspect-ratio: 16 / 9;
}

.example-category.portrait .example-media-cell .grid-video-wrap,
.example-category.portrait .example-media-cell .grid-image-wrap,
.example-category.portrait .example-media-cell .ex-placeholder {
  aspect-ratio: 9 / 16;
}

/* Responsive: keep column ratios on narrow screens */
@media (max-width: 1400px) {
  .example-row-cells:not(.mode-portrait):not(.mode-landscape) {
    grid-template-columns: 1fr 1fr 1fr 1.5fr 1fr 1fr;
  }
  .example-row-cells.mode-landscape {
    /* Keep ratios consistent: narrower text, each Ours video matches input video width */
    grid-template-columns: 1.6fr 1.6fr 1fr 1.4fr 1.6fr 1.6fr;
  }
  .example-row-cells.mode-portrait {
    grid-template-columns: 0.85fr 0.85fr 1fr 1.6fr 0.85fr 0.85fr;
  }
}

@media (max-width: 1200px) {
  .example-row-cells {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .example-header-row .example-row-cells {
    display: grid;
    white-space: normal;
  }

  .example-row-cells > * {
    display: inline-block;
    vertical-align: top;
    width: 180px;
    margin-right: 12px;
  }

  .grid-text-wrap {
    width: 300px;
  }

  .example-ours-wrapper {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    width: 360px;
  }
}

/* TB Comparison Matrix Styles (Existing) */
.compare-grid-container {
  display: grid;
  gap: 15px;
}
.compare-grid-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 10px;
  align-items: start; /* Each cell sizes by its own media ratio; avoid stretched letterboxing */
}
/* Comparison Results: keep original ratio; JS sets the true ratio on loadedmetadata */
.compare-cell .grid-video-wrap {
  aspect-ratio: 16 / 9; /* Fallback ratio */
  background: var(--bg-body); /* Match page background in case of contain */
}
.compare-cell .grid-video-wrap video {
  object-fit: contain; /* No letterboxing when ratios match */
}
.grid-label {
  font-size: 12px;
  text-align: center;
  padding: 4px;
  background: var(--bg-soft);
  color: var(--text-muted);
}
.compare-cell.has-separator {
  border-right: 1px dashed var(--border-strong);
  padding-right: 8px;
  margin-right: -4px;
}

.examples-placeholder {
  margin: 24px auto 0;
  padding: 28px 24px;
  border: 1px dashed rgba(74, 63, 53, 0.22);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.7);
  text-align: center;
  color: var(--text-muted);
}

.examples-placeholder-title {
  margin-bottom: 8px;
  color: var(--primary);
  font-weight: 700;
}

.examples-placeholder-copy {
  max-width: 54ch;
  margin: 0 auto;
}

.examples-sentinel {
  height: 1px;
}

/* Disclaimer page helpers */
.disclaimer-center {
  text-align: center;
  line-height: 1.75;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#page-4 .section-head {
  text-align: center;
  margin-bottom: 16px;
}

#page-4 .page-subtitle {
  margin-left: auto;
  margin-right: auto;
  max-width: 70ch;
}

#page-4 .card + .card {
  margin-top: 12px;
}

#page-4 .card-title {
  text-align: center;
}

#page-4 .card .muted {
  margin: 0;
  line-height: 1.85;
  text-align: left;
  margin-left: auto;
  margin-right: auto;
  max-width: 78ch;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#page-4 .card .muted a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ============================================
   Responsive Design - Mobile First Approach
   ============================================ */

/* Tablet breakpoint (768px - 1024px) */
@media (max-width: 1024px) {
  .container {
    width: min(100%, 98%);
  }

  .topbar-inner {
    flex-wrap: wrap;
    gap: 8px;
  }

  .topnav a {
    font-size: 13px;
    margin-left: 10px;
  }

  /* A4 pages: reduce padding */
  .a4-page {
    padding: 16px 20px 20px;
  }

  .page-title {
    font-size: 20px;
  }

  #page-1 {
    padding: 28px 24px 30px;
  }

  /* Hero section: stack on tablet */
  .hero {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .hero-left {
    width: 100%;
  }

  .hero-right {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    position: static;
  }

  .card.hero-panel {
    max-width: 860px;
    margin: 0 auto;
  }

  /* Comparison grid: reduce gap */
  .compare-grid-container {
    gap: 10px;
  }

  .compare-grid-row {
    gap: 8px;
  }

  .grid-label {
    font-size: 11px;
    padding: 3px;
  }

  /* Examples: reduce gap */
  .example-row-cells {
    gap: 10px;
  }

  .category-title {
    font-size: 16px;
  }
}

/* Mobile breakpoint (below 768px) */
@media (max-width: 768px) {
  /* Topbar mobile styles */
  .topbar {
    position: relative;
  }

  .topbar-inner {
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
  }

  .brand {
    width: 100%;
    justify-content: center;
  }

  .topnav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    margin-top: 10px;
    width: 100%;
  }

  .topnav a {
    margin-left: 0;
    font-size: 14px;
    padding: 4px 8px;
  }

  /* Container adjustments */
  .container {
    width: 100%;
    padding: 0 12px;
  }

  /* A4 pages: minimal padding */
  .a4-page {
    margin: 16px auto 24px;
    padding: 12px 14px 16px;
    border-radius: 12px;
  }

  /* Hero section */
  .hero {
    gap: 20px;
  }

  #page-1 {
    padding: 22px 16px 24px;
  }

  .hero-kicker-row {
    gap: 8px;
  }

  .hero-kicker {
    min-height: 30px;
    padding: 0 12px;
    font-size: 10px;
  }

  .h1 {
    max-width: 100%;
    font-size: clamp(1.45rem, 4.4vw, 2rem);
    line-height: 1.12;
  }

  .hero-deck {
    font-size: 14px;
    line-height: 1.75;
  }

  .hero-actions {
    width: 100%;
  }

  .hero-actions .btn {
    width: 100%;
    max-width: 420px;
  }

  .abstract p {
    font-size: 13px;
    line-height: 1.7;
  }

  .abstract {
    padding: 18px 16px;
    border-radius: 20px;
  }

  .abstract-header {
    flex-direction: column;
    align-items: center;
  }

  .abstract-actions {
    flex-direction: column;
  }

  .abstract-actions .btn {
    width: 100%;
    max-width: 280px;
  }

  .card.hero-panel {
    padding: 18px 16px;
  }

  .resource-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .resource-copy {
    text-align: center;
  }

  /* Comparison grid: horizontal scroll with fixed cell size */
  .compare-grid-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
  }

  .compare-grid-row {
    display: flex;
    flex-direction: row;
    min-width: max-content;
    gap: 8px;
  }

  .compare-cell {
    flex: 0 0 160px;
    min-width: 160px;
  }

  .compare-cell .grid-video-wrap {
    aspect-ratio: 16 / 9;
    height: auto;
  }

  .grid-label {
    font-size: 10px;
    padding: 2px 4px;
  }

  .compare-cell.has-separator {
    border-right: none;
    padding-right: 0;
    margin-right: 0;
  }

  /* Comparison section title */
  #page-2 .section-head {
    margin-bottom: 12px;
  }

  #page-2 .page-title {
    font-size: 18px;
  }

  #page-2 .page-subtitle {
    font-size: 12px;
  }

  /* Examples: mobile layout */
  .example-category {
    padding: 12px 10px;
    margin: 16px auto 20px;
  }

  .example-category:first-of-type {
    margin-top: 12px;
  }

  .category-title {
    font-size: 15px;
    margin-bottom: 12px;
    padding-left: 8px;
  }

  /* Hide header row on mobile */
  .example-header-row {
    display: none;
  }

  .example-row {
    margin-bottom: 12px;
  }

  /* Single column layout for examples on mobile */
  .example-row-cells {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .example-row-cells > * {
    width: 100%;
    min-width: unset;
    margin-right: 0;
  }

  .example-ours-wrapper {
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: 100%;
  }

  .example-ours-wrapper > * {
    flex: 1;
  }

  /* Media cells: maintain aspect ratio */
  .example-media-cell {
    aspect-ratio: 16 / 9;
  }

  .example-category.portrait .example-media-cell {
    aspect-ratio: 9 / 16;
  }

  .example-row .grid-video-wrap,
  .example-row .grid-image-wrap,
  .example-row .ex-placeholder {
    width: 100%;
    height: 100%;
    aspect-ratio: inherit;
  }

  /* Text and audio: adjust sizing */
  .example-row .grid-text-wrap {
    min-height: 80px;
    padding: 10px;
  }

  .example-row .grid-text-content {
    font-size: 12px;
    line-height: 1.6;
  }

  .example-row .grid-audio-wrap {
    height: 60px;
    aspect-ratio: auto;
  }

  /* Page title adjustments */
  .section-head {
    margin-bottom: 14px;
  }

  .page-title {
    font-size: 18px;
  }

  .page-subtitle {
    font-size: 12px;
  }

  /* Card adjustments */
  .card {
    padding: 12px;
  }

  .card-title {
    font-size: 14px;
  }

  /* Disclaimer page */
  #page-4 .card .muted {
    font-size: 13px;
    line-height: 1.7;
  }

  .disclaimer-list {
    font-size: 13px;
  }
}

/* Small mobile (below 480px) */
@media (max-width: 480px) {
  /* Further reduce padding */
  .a4-page {
    padding: 10px 10px 14px;
    margin: 12px auto 16px;
  }

  #page-1 {
    padding: 18px 12px 20px;
  }

  .h1 {
    font-size: clamp(1.2rem, 5.4vw, 1.55rem);
    line-height: 1.14;
  }

  .hero-deck {
    font-size: 13px;
  }

  .abstract p {
    font-size: 12px;
  }

  .hero-nav-link {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* Topbar */
  .brand-title {
    font-size: 16px;
  }

  .brand-subtitle {
    font-size: 11px;
  }

  .topnav a {
    font-size: 13px;
    padding: 3px 6px;
  }

  /* Comparison: smaller cells */
  .compare-cell {
    flex: 0 0 140px;
    min-width: 140px;
  }

  .grid-label {
    font-size: 9px;
  }

  /* Examples */
  .category-title {
    font-size: 14px;
  }

  .example-row-cells {
    gap: 6px;
  }

  .ex-placeholder-text {
    font-size: 10px;
  }

  /* Section titles */
  .page-title {
    font-size: 16px;
  }

  .page-subtitle {
    font-size: 11px;
  }

  /* Audio button */
  .audio-btn {
    font-size: 12px;
    padding: 4px 10px;
  }
}

/* Landscape mobile: adjust comparison grid */
@media (max-width: 768px) and (orientation: landscape) {
  .compare-cell {
    flex: 0 0 180px;
    min-width: 180px;
  }

  .example-row-cells {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .example-row-cells > * {
    flex: 0 0 calc(50% - 4px);
  }

  .example-ours-wrapper {
    flex: 0 0 100%;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .grid-video-wrap:hover .grid-play-icon {
    opacity: 1;
  }

  .audio-btn:hover {
    background: var(--bg-soft);
  }

  /* Larger touch targets */
  .audio-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .topnav a {
    padding: 8px 12px;
  }

  /* Scrollbar styling for touch */
  .compare-grid-container::-webkit-scrollbar {
    height: 6px;
  }

  .compare-grid-container::-webkit-scrollbar-track {
    background: var(--bg-soft);
    border-radius: 3px;
  }

  .compare-grid-container::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
  }
}

