.tab-btn,
.viz-tab {
  border-radius: 999px;
  border: 1px solid oklch(0.91 0.008 265);
  background: oklch(0.97 0.006 265);
  color: oklch(0.5 0.02 265);
  padding: 0.55rem 0.95rem;
  min-height: 2.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.is-active,
.viz-tab.is-active {
  background: #EEF2FF;
  border-color: #C7D2FE;
  color: #4F46E5;
}

.field-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.field-input {
  width: 100%;
  max-width: 100%;
  border: 1px solid oklch(0.91 0.008 265);
  border-radius: 0.75rem;
  background: oklch(0.985 0.003 265);
  color: oklch(0.20 0.02 265);
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-size: 1rem; /* avoid iOS zoom on focus */
  box-sizing: border-box;
}

.field-input:focus {
  outline: 2px solid rgba(13, 107, 84, 0.25);
  border-color: #4F46E5;
}

.field-input[type="file"] {
  font-size: 0.875rem;
  padding: 0.55rem 0.65rem;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  border-radius: 9px;
  padding: 0.7rem 1.05rem;
  min-height: 2.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .btn-primary:hover,
  .btn-secondary:hover,
  .btn-ghost:hover {
    transform: translateY(-1px);
  }
}

.btn-primary {
  background: #4F46E5;
  color: #fff;
}

.btn-secondary {
  background: oklch(0.97 0.006 265);
  color: oklch(0.20 0.02 265);
}

.btn-ghost {
  background: transparent;
  color: oklch(0.5 0.02 265);
  border: 1px solid oklch(0.91 0.008 265);
}

.status {
  min-height: 0;
  font-size: 0.875rem;
  color: oklch(0.5 0.02 265);
  overflow-wrap: anywhere;
}

.status-badge {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: 0.65rem;
  border: 1px solid transparent;
  line-height: 1.4;
  font-size: 0.8125rem;
}

.status-badge-label {
  font-weight: 600;
}

.status-list {
  margin: 0.45rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
}

.status-list li {
  padding: 0.35rem 0.5rem;
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(20, 33, 43, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 400;
  word-break: break-all;
}

.status-warn {
  background: #fff8e8;
  border-color: #f6d98a;
  color: #7a4d0b;
}

.status-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #9f1239;
}

.prose-summary {
  color: oklch(0.20 0.02 265);
  line-height: 1.65;
}

.prose-summary > :first-child {
  margin-top: 0;
}

.prose-summary > :last-child {
  margin-bottom: 0;
}

.prose-summary h1,
.prose-summary h2,
.prose-summary h3,
.prose-summary h4 {
  margin: 1em 0 0.45em;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: #4F46E5;
}

.prose-summary h1 {
  font-size: 1.2rem;
  padding-bottom: 0.35em;
  border-bottom: 1px solid #c6e9d8;
}

.prose-summary h2 {
  font-size: 1.05rem;
}

.prose-summary h3,
.prose-summary h4 {
  font-size: 0.98rem;
  color: #145a48;
}

.prose-summary p {
  margin: 0.65em 0;
}

.prose-summary ul,
.prose-summary ol {
  margin: 0.65em 0;
  padding-left: 1.35rem;
}

.prose-summary li {
  margin: 0.35em 0;
  padding-left: 0.15rem;
}

.prose-summary li::marker {
  color: #4F46E5;
}

.prose-summary strong {
  font-weight: 700;
  color: oklch(0.20 0.02 265);
}

.prose-summary em {
  font-style: italic;
  color: #3d4d5c;
}

.prose-summary a {
  color: #4F46E5;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose-summary code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 0.3rem;
  padding: 0.1rem 0.35rem;
  overflow-wrap: anywhere;
}

.prose-summary pre {
  overflow: auto;
  border-radius: 0.75rem;
  background: oklch(0.20 0.02 265);
  color: #e8eef3;
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  -webkit-overflow-scrolling: touch;
}

.prose-summary blockquote {
  margin: 0.85em 0;
  padding: 0.45rem 0 0.45rem 0.9rem;
  border-left: 3px solid #4F46E5;
  color: #3d4d5c;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 0 0.5rem 0.5rem 0;
}

.matrix-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid oklch(0.91 0.008 265);
  border-radius: 0.75rem;
  background: #fff;
  max-width: 100%;
}

.matrix-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
  font-size: 0.7rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.matrix-table th,
.matrix-table td {
  border-right: 1px solid rgba(217, 225, 234, 0.8);
  border-bottom: 1px solid rgba(217, 225, 234, 0.8);
  padding: 0.4rem 0.4rem;
  text-align: center;
  white-space: nowrap;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: oklch(0.97 0.006 265);
  color: oklch(0.5 0.02 265);
  font-weight: 600;
  max-width: 5.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f8fafb;
  text-align: left;
  color: oklch(0.20 0.02 265);
  font-weight: 600;
  max-width: 6.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table thead th:first-child {
  left: 0;
  z-index: 3;
}

.portal-link {
  color: #4F46E5;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  overflow-wrap: anywhere;
}

a.portal-link:hover,
a.portal-link:focus-visible {
  border-bottom-color: rgba(13, 107, 84, 0.45);
  text-decoration: none;
}

.portal-link.matrix-portal {
  display: inline-block;
  max-width: 5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.span-doc {
  max-height: 18rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}

.span-mark {
  border-radius: 0.25rem;
  padding: 0.05rem 0.15rem;
  font-weight: 600;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.span-mark-0 { background: #fde68a; }
.span-mark-1 { background: #bbf7d0; }
.span-mark-2 { background: #bfdbfe; }
.span-mark-3 { background: #fbcfe8; }
.span-mark-4 { background: #ddd6fe; }
.span-mark-5 { background: #fed7aa; }

.compare-live {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 2.6rem;
  border: 1px solid oklch(0.91 0.008 265);
  border-radius: 0.9rem;
  background: oklch(0.985 0.003 265);
  padding: 0.65rem 0.85rem;
  color: oklch(0.5 0.02 265);
  font-size: 0.875rem;
  font-weight: 600;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.compare-live.is-running {
  border-color: #C7D2FE;
  background: #EEF2FF;
  color: #4F46E5;
}

.compare-live.is-done {
  border-color: #d5e8df;
  background: #f4faf7;
  color: #145a48;
}

.compare-live.is-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.compare-spinner,
.compare-check {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
}

.compare-spinner {
  display: none;
  border: 2px solid rgba(13, 107, 84, 0.25);
  border-top-color: #4F46E5;
  border-radius: 999px;
  animation: compare-spin 0.7s linear infinite;
}

.compare-check {
  display: none;
  border-radius: 999px;
  background: #4F46E5;
  position: relative;
}

.compare-check::after {
  content: "";
  position: absolute;
  left: 0.28rem;
  top: 0.14rem;
  width: 0.28rem;
  height: 0.5rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.compare-live.is-running .compare-spinner { display: inline-block; }
.compare-live.is-done .compare-check { display: inline-block; }
.compare-live.is-error .compare-spinner {
  display: inline-block;
  border-color: rgba(185, 28, 28, 0.25);
  border-top-color: #b91c1c;
  animation: none;
}

.compare-live-text {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.compare-live-text.is-in {
  opacity: 1;
  transform: translateY(0);
}

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

.report-panel {
  border: 1px solid oklch(0.91 0.008 265);
  border-radius: 1rem;
  background: linear-gradient(180deg, #ffffff 0%, #f7faf8 100%);
  padding: 0.85rem;
}

#graph {
  touch-action: pan-y;
}

@media (min-width: 640px) {
  .field-input {
    font-size: inherit;
  }

  .matrix-table {
    font-size: 0.75rem;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 0.45rem 0.5rem;
  }

  .matrix-table thead th {
    max-width: 7rem;
  }

  .matrix-table tbody th {
    max-width: 9rem;
  }

  .portal-link.matrix-portal {
    max-width: 6.5rem;
  }

  .span-doc {
    max-height: 28rem;
  }

  .tab-btn,
  .viz-tab {
    padding: 0.4rem 0.9rem;
    min-height: 0;
  }

  .btn-primary,
  .btn-secondary,
  .btn-ghost {
    padding: 0.6rem 1.05rem;
    min-height: 0;
  }
}
