:root {
  --maxw: 980px;
  --radius: 18px;
  --bg: #0b0c0f;
  --bg-alt: #0e1117;
  --panel: #12141a;
  --text: #e9ecf1;
  --muted: #aab3c4;
  --link: #90caf9;
  --accent: #b4ff39;
  --ink-on-accent: #0b0c0f;
  --border: #232733;
  --ghost-border: #2b2f3a;
  --code-bg: #0a0c11;
  --code-fg: #e9ecf1;
  --status-negative: #ff7a7a;
  --status-positive: color-mix(in srgb, var(--accent) 70%, var(--text));
  color-scheme: light dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --bg-alt: #eef2f7;
    --panel: #ffffff;
    --text: #0b1220;
    --muted: #5b667a;
    --link: #1d4ed8;
    --accent: #3BD16F;
    --ink-on-accent: #001510;
    --border: #e5e7eb;
    --ghost-border: #d0d4dd;
    --code-bg: #f3f4f6;
    --code-fg: #0b1220;
    --status-negative: #c02626;
    --status-positive: color-mix(in srgb, var(--accent) 70%, var(--text));
  }
}

html[data-theme="light"] {
  --bg: #f8fafc;
  --bg-alt: #eef2f7;
  --panel: #ffffff;
  --text: #0b1220;
  --muted: #5b667a;
  --link: #1d4ed8;
  --accent: #3BD16F;
  --ink-on-accent: #001510;
  --border: #e5e7eb;
  --ghost-border: #d0d4dd;
  --code-bg: #f3f4f6;
  --code-fg: #0b1220;
  --status-negative: #c02626;
  --status-positive: color-mix(in srgb, var(--accent) 70%, var(--text));
}

html[data-theme="dark"] {
  --bg: #0b0c0f;
  --bg-alt: #0e1117;
  --panel: #12141a;
  --text: #e9ecf1;
  --muted: #aab3c4;
  --link: #90caf9;
  --accent: #b4ff39;
  --ink-on-accent: #0b0c0f;
  --border: #232733;
  --ghost-border: #2b2f3a;
  --code-bg: #0a0c11;
  --code-fg: #e9ecf1;
  --status-negative: #ff7a7a;
  --status-positive: color-mix(in srgb, var(--accent) 70%, var(--text));
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: linear-gradient(180deg, var(--bg), var(--bg-alt));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 18px 72px;
}

header.hero {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.title {
  font-size: clamp(28px, 4.2vw, 44px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.title br {
  display: none;
}

@media (min-width: 640px) {
  .title br {
    display: block;
  }
}

.subtitle {
  font-size: clamp(16px, 2vw, 20px);
  color: var(--muted);
}

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  text-decoration: none;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn.primary {
  background: var(--accent);
  color: var(--ink-on-accent);
}

.btn.ghost {
  border: 1px solid var(--ghost-border);
  color: var(--text);
}

.btn.disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.authors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  font-size: 15px;
}

.authors a {
  color: var(--link);
  text-decoration: none;
}

.affil {
  color: var(--muted);
  flex-basis: 100%;
  text-align: center;
  margin-top: 2px;
}

.venue {
  font-size: 15px;
  text-transform: none;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 2px 0 0;
}

.abstract-section {
  margin-top: 28px;
}

.abstract-card {
  position: relative;
  padding: 28px 26px;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--panel)), var(--panel));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.abstract-card::before {
  content: "";
  position: absolute;
  inset: -120px 40% auto -80px;
  height: 220px;
  border-radius: 70%;
  background: radial-gradient(circle at center, color-mix(in srgb, var(--accent) 40%, transparent) 0%, transparent 70%);
  opacity: 0.6;
  pointer-events: none;
  filter: blur(4px);
  z-index: 0;
}

.abstract-card>* {
  position: relative;
  z-index: 1;
}

.abstract-card h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.abstract-card p {
  margin: 14px 0 0;
  font-size: 15.5px;
}

section {
  margin-top: 36px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(20px, 2.8vw, 26px);
  letter-spacing: -0.01em;
}

p {
  margin: 10px 0;
}

a {
  color: var(--link);
}

.two {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  align-items: start;
}

.two> :nth-child(n+3) {
  grid-column: 1 / -1;
}

.two.two-pairs> :nth-child(n+3) {
  grid-column: auto;
}

@media (max-width: 860px) {
  .two {
    grid-template-columns: 1fr;
  }
}

.video-frame {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel);
}

.video-frame video {
  display: block;
  width: 100%;
  height: auto;
  background: var(--panel);
}

.video-frame figcaption {
  margin: 12px 14px 0;
  padding-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}

figure {
  margin: 0;
}

figcaption {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.checks {
  list-style: none;
  padding: 0;
  margin: 14px 0;
}

.checks li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.checks li>span,
.checks li>div,
.checks li>p {
  margin: 0;
}

.check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px;
  margin-top: 2px;
  flex-shrink: 0;
}

.check-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.math-block {
  margin: 4px 0 0;
}

h3 {
  margin: 18px 0 10px;
  font-size: 20px;
}

.result-block {
  margin-top: 24px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0;
  align-items: stretch;
  /* Safari compatibility: ensure proper grid layout */
  width: 100%;
  box-sizing: border-box;
}

.image-grid figure {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  padding: 12px;
  display: grid;
  /* Safari compatibility: use fixed min height instead of clamp in grid-template-rows */
  grid-template-rows: minmax(150px, 220px) auto;
  gap: 10px;
  margin: 0;
  /* Safari compatibility: ensure proper box model */
  box-sizing: border-box;
  min-width: 0;
}

.image-grid img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  align-self: center;
  justify-self: center;
  object-fit: contain;
  background: #ffffff;
  padding: 4px;
  box-sizing: border-box;
  /* Safari compatibility: prevent image overflow */
  max-height: 220px;
}

.image-grid figcaption {
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  align-self: start;
  justify-self: stretch;
  margin: 0;
  line-height: 1.45;
  /* Safari compatibility: ensure caption doesn't overflow or overlap */
  min-height: fit-content;
  padding-top: 2px;
}

.result-figure {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.result-figure img {
  width: 100%;
  height: auto;
  display: block;
  background: #ffffff;
  padding: 4px;
  box-sizing: border-box;
  border-radius: 8px;
}

.result-figure.small {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.result-figure figcaption {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  line-height: 1.45;
}

.flow-list {
  margin: 16px 0 0;
  padding-left: 18px;
}

.flow-list li {
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: flex-start;
}

.flow-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-on-accent);
  background: var(--accent);
  font-weight: 600;
  margin-top: 2px;
}

.flow-list strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.flow-list p {
  margin: 4px 0;
  font-size: 14.5px;
}

.flow-list .table-note {
  margin: 6px 0 0;
  font-size: 14.5px;
  color: var(--status-positive);
  font-weight: 600;
}

.result-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.result-table caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  margin-bottom: 8px;
}

.result-table th,
.result-table td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.result-table th:last-child,
.result-table td:last-child {
  border-right: none;
}

.result-table tbody tr:last-child td {
  border-bottom: none;
}

.result-table thead tr:first-child th:first-child {
  border-top-left-radius: 10px;
}

.result-table thead tr:first-child th:last-child {
  border-top-right-radius: 10px;
}

.result-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 10px;
}

.result-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 10px;
}

.result-table.solver-landscape th:first-child,
.result-table.solver-landscape td:first-child,
.result-table.solver-landscape th:nth-child(2),
.result-table.solver-landscape td:nth-child(2) {
  text-align: left;
}

.result-table.solver-landscape td:first-child a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--link) 50%, transparent);
  transition: text-decoration-color 0.2s ease;
}

.result-table.solver-landscape td:first-child a:hover {
  text-decoration-color: var(--link);
}

.status {
  display: inline-block;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.status-yes {
  color: var(--status-positive);
}

.status-no {
  color: var(--status-negative);
}

.target-ito {
  color: var(--status-positive);
  font-weight: 700;
}

.result-table th {
  background: linear-gradient(180deg, rgba(100, 150, 255, 0.15) 0%, rgba(100, 150, 255, 0.08) 100%);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.result-table tbody tr {
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.result-table tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}

.result-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.01);
}

.result-table tbody tr:hover {
  background: rgba(100, 150, 255, 0.08) !important;
  transform: scale(1.002);
}

.result-table td:first-child,
.result-table th:first-child {
  text-align: left;
}

.table-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.method-group {
  font-weight: 600;
}

.subrow {
  padding-left: 16px;
}

pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
  font-size: 13px;
}

.bibtex-block {
  position: relative;
  margin-top: 14px;
}

.bibtex-block pre {
  padding: 14px 60px 14px 14px;
}

.copy-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--ghost-border);
  background: color-mix(in srgb, var(--panel) 92%, var(--accent) 8%);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, background 0.2s ease, transform 0.1s ease;
}

.copy-btn svg {
  width: 18px;
  height: 18px;
}

.copy-btn:hover {
  background: color-mix(in srgb, var(--panel) 80%, var(--accent) 20%);
}

.copy-btn:active {
  transform: scale(0.95);
}

.copy-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 2px;
}

.bibtex-block:hover .copy-btn,
.bibtex-block:focus-within .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.copy-feedback {
  position: absolute;
  top: -34px;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(6px);
  background: var(--accent);
  color: var(--ink-on-accent);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  visibility: hidden;
}

.copy-feedback.is-visible {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.copy-feedback.is-error {
  background: color-mix(in srgb, #ff3b3b 70%, var(--panel));
  color: #fff;
}

/* --- Results accordion --- */
.results-accordion details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin: 12px 0;
  overflow: hidden;
}

.results-accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  user-select: none;
}

.results-accordion summary::-webkit-details-marker {
  display: none;
}

.results-accordion .summary-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.results-accordion .summary-right {
  font-size: 12px;
  color: var(--muted);
}

.results-accordion .chev {
  width: 20px;
  height: 20px;
  border: 1px solid var(--ghost-border);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.results-accordion details[open] .chev {
  transform: rotate(90deg);
}

.results-accordion .panel-inner {
  padding: 0 18px 18px;
}

/* Adjust spacing for result blocks inside accordion */
.results-accordion .result-block {
  margin: 0;
  border: none;
  padding: 0;
}

.results-accordion .result-block>*:first-child {
  margin-top: 0;
}

.results-accordion .result-block>*:last-child {
  margin-bottom: 0;
}

/* Expand/collapse all buttons */
.results-toolbar {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin: 8px 0 12px;
}

.results-toolbar .btn.small {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--ghost-border);
  text-decoration: none;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

/* Prevent equation overflow for SVG output */
mjx-container[jax="SVG"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Fit SVG to parent width */
mjx-container[jax="SVG"]>svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Slightly smaller equations on mobile */
@media (max-width: 640px) {
  mjx-container[jax="SVG"] {
    font-size: 0.95em;
  }
}

/* Invert grayscale SVGs in dark mode */
@media (prefers-color-scheme: dark) {
  .invert-dark {
    filter: invert(1);
  }
}

html[data-theme="dark"] .invert-dark {
  filter: invert(1);
}
