:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a3042;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b9cff;
  --accent-dim: #3d6fbf;
  --baseline: #c9a227;
  --insight: #4ec9a0;
  --danger: #f07178;
  --ok: #4ec9a0;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
  --page-max: 1320px;
}

html {
  font-size: 93%;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

.page-shell {
  width: min(100%, var(--page-max));
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-height: 100vh;
  background: var(--bg);
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.header h1 {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.2;
}

.title-tooltip {
  display: inline-flex;
  align-items: center;
}

.title-info {
  width: 1.25rem;
  height: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: help;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
}

.title-info:hover,
.title-info:focus-visible {
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}

.title-tooltip-content {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  z-index: 50;
  width: min(calc(100vw - 2rem), 34rem);
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0e1220;
  color: var(--text);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.42);
  font-size: 0.9rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.15rem);
  transition: opacity 120ms ease, transform 120ms ease;
}

.title-tooltip:hover .title-tooltip-content,
.title-tooltip:focus-within .title-tooltip-content {
  opacity: 1;
  transform: translateY(0);
}

.controls { display: flex; gap: 0.65rem; align-items: center; flex-wrap: wrap; }

.example-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.example-picker select {
  max-width: min(42vw, 360px);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.92rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
#btnRun {
  width: 9.6rem;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); }
.btn.fast-forward {
  background: rgba(201, 162, 39, 0.18);
  border-color: var(--baseline);
  color: var(--text);
}

.input-panel {
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.question-block h2 {
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 1rem;
}

#questionText {
  margin-top: 0.45rem;
  font-size: 1.05rem;
  white-space: normal;
  word-break: break-word;
}

#questionText strong {
  font-weight: 700;
  color: #f2f5fb;
}

.meta { margin-top: 0.45rem; font-size: 0.92rem; color: var(--muted); }

.pdf-viewer-block {
  margin-top: 0;
}

.pdf-viewer-block h3 {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.pdf-thumb-grid {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .pdf-thumb-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  .pdf-thumb-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

.pdf-thumb {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101524;
  padding: 0.22rem;
  cursor: zoom-in;
}

.thumb-image-frame {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  background: #0e1220;
}

.thumb-image-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent),
    linear-gradient(135deg, #111827, #182033);
  background-size: 220% 100%, 100% 100%;
  animation: thumb-shimmer 1.2s ease-in-out infinite;
}

.thumb-image-frame.is-loaded::before,
.thumb-image-frame.is-error::before {
  display: none;
}

.thumb-image-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  opacity: 0;
  transition: opacity 120ms ease;
}

.thumb-image-frame.is-loaded img {
  opacity: 1;
}

.thumb-image-frame.is-error {
  border: 1px dashed var(--danger);
}

.thumb-image-frame.is-error::after {
  content: "Image unavailable";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 0.75rem;
  text-align: center;
  padding: 0.3rem;
}

@keyframes thumb-shimmer {
  from { background-position: 180% 0, 0 0; }
  to { background-position: -80% 0, 0 0; }
}

.pdf-thumb-label {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.thumb-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.65rem auto 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0.35rem 0.55rem;
}

.thumb-toggle::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 0.28rem solid transparent;
  border-right: 0.28rem solid transparent;
  border-top: 0.34rem solid currentColor;
  transform-origin: center;
}

.thumb-toggle.is-expanded::after {
  transform: rotate(180deg);
}

.thumb-toggle:hover {
  border-color: var(--accent);
}

.thumb-toggle[hidden] {
  display: none;
}

.pdf-viewer-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1rem;
}

.pdf-viewer-modal[hidden] {
  display: none;
}

.pdf-viewer-dialog {
  background: #0e1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(92vw, 1100px);
  max-height: 92vh;
  overflow: auto;
  padding: 0.75rem;
  position: relative;
}

.pdf-viewer-modal[data-viewer="tool"] .pdf-viewer-dialog {
  width: fit-content;
  max-width: calc(100vw - 2rem);
}

.pdf-viewer-close {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.6rem;
  cursor: pointer;
}

.pdf-viewer-caption {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
  padding-right: 2rem;
}

.pdf-viewer-image {
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.pdf-viewer-modal[data-viewer="tool"] .pdf-viewer-image {
  width: auto;
  max-width: calc(100vw - 3.5rem);
  max-height: calc(92vh - 4rem);
}

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
@media (max-width: 900px) {
  .panes { grid-template-columns: 1fr; }
}

.pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: clamp(680px, 82vh, 1100px);
  min-height: 0;
}

.pane-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.pane-header h2 { font-size: 1.1rem; flex: 1; }

.badge {
  font-size: 0.88rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(201, 162, 39, 0.2);
  color: var(--baseline);
  font-family: var(--mono);
}
.badge.accent {
  background: rgba(78, 201, 160, 0.15);
  color: var(--insight);
}

.status {
  font-size: 0.88rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.status.running { color: var(--accent); }
.status.waiting { color: #f6c177; }
.status.done { color: var(--ok); }
.status.error { color: var(--danger); }

.stream {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem;
  font-family: var(--mono);
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 900px) {
  .pane {
    height: clamp(560px, 78vh, 920px);
  }
}

.stream.interleaved {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.insight-round-view,
.insight-live-round {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  border-left: 3px solid rgba(78, 201, 160, 0.55);
  padding-left: 0.55rem;
  margin-bottom: 0.65rem;
}

.insight-round-view[hidden] {
  display: none;
}

.insight-round-title,
.insight-live-round-title {
  color: var(--insight);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.event-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: var(--surface);
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.event-card h4 {
  font-family: var(--font);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
  color: var(--muted);
}

.event-card.answer {
  background: rgba(91, 156, 255, 0.08);
}

.event-card.summary {
  background: rgba(201, 162, 39, 0.08);
}

.event-card.summary .event-body {
  font-family: var(--font);
  font-size: 0.98rem;
  line-height: 1.55;
  white-space: normal;
}

.event-card.summary .event-body div + div {
  margin-top: 0.25rem;
}

.event-card.summary .event-body strong {
  color: var(--text);
  font-weight: 700;
}

.answer-result {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
  vertical-align: 0.08em;
}

.answer-result.correct {
  background: rgba(78, 201, 160, 0.16);
  color: var(--ok);
}

.answer-result.wrong {
  background: rgba(255, 95, 86, 0.16);
  color: var(--danger);
}

.answer-result.unknown {
  background: rgba(153, 162, 181, 0.16);
  color: var(--muted);
}

.event-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.event-body.rich-text {
  white-space: normal;
}

.event-body.rich-text strong {
  font-weight: 700;
  color: #f2f5fb;
}

.event-card img {
  display: block;
  margin-top: 0.4rem;
  width: min(100%, 360px);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.tool-image-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin-top: 0;
  border: 0;
  border-radius: inherit;
  object-fit: contain;
}

.tool-images-grid {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.45rem;
  align-items: start;
}

@media (max-width: 700px) {
  .tool-images-grid { grid-template-columns: 1fr; }
}

.tool-image-item {
  background: #101524;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem;
}

.tool-image-frame {
  margin-top: 0.4rem;
}

.tool-image-item.bbox-item .tool-image-frame {
  width: 100%;
  max-width: 180px;
}

.tool-image-item.crop-item .tool-image-frame {
  width: 100%;
  max-width: 360px;
}

.tool-image-item img {
  cursor: zoom-in;
}

.tool-image-item img:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tool-image-item .tool-image-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}

.event-meta {
  color: var(--muted);
  margin-top: 0.2rem;
  font-size: 0.85rem;
}
