:root {
  color-scheme: light dark;
  --background: #ffffff;
  --block: #ffffff;
  --text: #111827;
  --body-text: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #f97316;
  --primary-hover: #ea580c;
  --primary-soft: #fff7ed;
  --success: #15803d;
  --warning: #a16207;
  --danger: #b91c1c;
  --surface: #f9fafb;
  --hover: #f3f4f6;
  --hover-row: #fafafa;
  --skeleton: #e5e7eb;
  --link: #2563eb;
  --shadow: var(--shadow);
  --warning-bg: #fffbeb; --warning-border: #fde68a;
  --error-bg: #fef2f2; --error-border: #fecaca;
  --success-bg: #f0fdf4; --success-border: #bbf7d0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0b0f19;
    --block: #111827;
    --text: #f3f4f6;
    --body-text: #d1d5db;
    --muted: #9ca3af;
    --border: #1f2937;
    --border-strong: #374151;
    --primary-hover: #fb923c;
    --primary-soft: #431407;
    --success: #4ade80;
    --warning: #facc15;
    --danger: #f87171;
    --surface: #0f172a;
    --hover: #1f2937;
    --hover-row: #151d2e;
    --skeleton: #1f2937;
    --link: #60a5fa;
    --shadow: rgba(0, 0, 0, .4);
    --warning-bg: #2a2106; --warning-border: #5c4a0e;
    --error-bg: #2a1010; --error-border: #5c1d1d;
    --success-bg: #0d2415; --success-border: #14532d;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--background); color: var(--text); font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
main { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 36px 0 52px; }

.app-header { max-width: 760px; margin: 0 auto 28px; text-align: center; }
.app-header h1 { margin: 0 0 10px; font-size: 32px; line-height: 1.2; font-weight: 700; }
.tabs { display: flex; justify-content: center; gap: 4px; margin-bottom: 24px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 500; }
.tab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover { color: var(--text); background: var(--hover); }
.tab.active { color: var(--text); background: var(--block); border-color: var(--border); box-shadow: 0 1px 2px var(--shadow); }

.panel { display: none; }
.panel.active { display: block; }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 14px; }
.panel-heading h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.3; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.updated { white-space: nowrap; font-size: 11px !important; }

.block, .toolbar, .table-shell, .queue-card { background: var(--block); border: 1px solid var(--border); border-radius: 10px; }
.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto auto; gap: 10px; align-items: end; padding: 12px; margin-bottom: 12px; }
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--block); }
.search > span { color: var(--muted); font-size: 18px; }
.search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.select-control { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.select-control select { height: 38px; min-width: 130px; padding: 0 28px 0 10px; border: 1px solid var(--border-strong); border-radius: 7px; outline: 0; background: var(--block); color: var(--text); font-size: 13px; }
.toggle { display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 9px; color: var(--body-text); font-size: 12px; white-space: nowrap; }
.toggle input { width: 15px; height: 15px; accent-color: var(--primary); }

.table-shell { position: relative; overflow-x: auto; }
.table-shell.is-empty { min-height: 180px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 42px; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--muted); text-align: right; font-size: 11px; font-weight: 600; line-height: 1.3; }
th:first-child, th:nth-child(2), td:first-child, td:nth-child(2) { text-align: left; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover, th.active-sort { color: var(--text); }
td { height: 54px; padding: 0 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; width: 42px; min-width: 42px; }
th:nth-child(2), td:nth-child(2) { position: sticky; left: 42px; z-index: 1; box-shadow: inset -1px 0 0 var(--border); }
td:first-child, td:nth-child(2) { background: var(--block); }
tbody tr:hover td:first-child, tbody tr:hover td:nth-child(2) { background: var(--hover-row); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover-row); }
.rank { width: 42px; color: var(--muted); }
.rank.top, .score.primary { color: var(--primary-hover); font-weight: 600; }
.model-cell a { display: inline-flex; align-items: center; gap: 5px; max-width: 290px; overflow: hidden; color: var(--text); font-weight: 600; text-decoration: none; text-overflow: ellipsis; }
.model-cell small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.model-cell a::after { content: "↗"; color: var(--muted); font-size: 10px; }
.model-cell a:hover { color: var(--primary-hover); }
.pill { display: inline-flex; padding: 3px 7px; border-radius: 6px; background: var(--hover); color: var(--body-text); font-size: 11px; }
.availability { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.availability.yes { background: var(--success); }
.table-footer { display: flex; justify-content: space-between; padding: 8px 3px 0; color: var(--muted); font-size: 11px; }
.empty-state { position: absolute; inset: 43px 0 0; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state h3 { margin: 0 0 4px; color: var(--body-text); font-size: 14px; }
.empty-state p { margin: 0; font-size: 12px; }
.skeleton { display: block; width: 48px; height: 10px; border-radius: 4px; background: var(--skeleton); }
.skeleton.wide { width: 160px; }

.queue-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.queue-card { padding: 14px; }
.queue-card header { display: flex; align-items: center; justify-content: space-between; }
.queue-card h3 { margin: 0; font-size: 13px; }
.queue-card strong { font-size: 18px; }
.queue-card p { margin: 7px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.queue-card.finished strong { color: var(--success); }
.queue-card.running strong { color: var(--primary-hover); }
.queue-card.pending strong { color: var(--warning); }

.submit-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); gap: 14px; align-items: start; }
.submit-card, .guidance-card, .about-copy, .citation-card { padding: 18px; }
.block-heading { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.block-heading h3, .guidance-card > h3 { margin: 0 0 4px; font-size: 15px; }
.block-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; padding: 16px 0; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field > span { color: var(--body-text); font-size: 12px; font-weight: 500; }
.field b { margin-left: 3px; color: var(--muted); font-size: 10px; font-weight: 400; }
.field small { color: var(--muted); font-weight: 400; }
.field input, .field select { width: 100%; height: 39px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 7px; outline: 0; background: var(--block); color: var(--text); font-size: 13px; }
.field input:focus, .field select:focus, .search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.primary-button { min-height: 38px; padding: 0 14px; border: 1px solid var(--primary-hover); border-radius: 7px; background: var(--primary); color: #fff; font-weight: 600; }
.primary-button:hover { background: var(--primary-hover); }
.primary-button:disabled { opacity: .6; cursor: wait; }
.guidance-card { max-height: 560px; overflow: auto; }

.prose { color: var(--body-text); font-size: 13px; line-height: 1.6; }
.prose h2, .prose h3 { color: var(--text); }
.prose h2 { margin: 20px 0 6px; font-size: 17px; }
.prose h3 { margin: 16px 0 5px; font-size: 14px; }
.prose p { margin: 7px 0; }
.prose ul { margin: 7px 0; padding-left: 20px; }
.prose li { margin: 3px 0; }
.prose pre { margin: 10px 0; overflow-wrap: anywhere; white-space: pre-wrap; padding: 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.prose pre code { font-size: inherit; }
.prose a { color: var(--link); }
.about-copy { min-height: 160px; }
.about-copy h2:first-child { margin-top: 0; }
.citation-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin-top: 12px; }
.citation-card h3 { margin: 5px 0 0; font-size: 14px; }
.citation-card button { align-self: start; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--block); color: var(--text); }
.citation-card pre { grid-column: 1 / -1; overflow: auto; margin: 0; padding: 10px; border-radius: 6px; background: var(--surface); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }

.notice { margin: 10px 0; padding: 10px 12px; border: 1px solid; border-radius: 7px; font-size: 12px; line-height: 1.45; }
.notice.warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.notice.error { color: var(--danger); background: var(--error-bg); border-color: var(--error-border); }
.notice.success { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.hidden { display: none !important; }
@media (max-width: 820px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search { grid-column: 1 / -1; }
  .submit-layout { grid-template-columns: 1fr; }
  .guidance-card { max-height: none; }
}

@media (max-width: 560px) {
  main { width: min(100% - 24px, 1180px); padding-top: 24px; }
  .app-header h1 { font-size: 26px; }
  .tabs { justify-content: stretch; }
  .tab { flex: 1; padding-inline: 8px; }
  .panel-heading { display: block; }
  .updated { margin-top: 6px !important; }
  .toolbar { grid-template-columns: 1fr; }
  .search { grid-column: auto; }
  .select-control select { width: 100%; }
  .queue-grid, .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .table-footer span:last-child { display: none; }
}
