:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --ink: #162033;
  --muted: #66738a;
  --line: #dbe3f0;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --mint: #10b981;
  --red: #b42318;
  --code-bg: #0c1222;
  --code-gutter: #10192d;
  --code-ink: #dbeafe;
  --shadow: 0 24px 70px rgba(31, 41, 55, 0.12);
  --radius: 22px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 34rem),
    radial-gradient(circle at top right, rgba(16, 185, 129, 0.13), transparent 30rem),
    var(--bg);
}

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 56px; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; color: white; font-weight: 900; background: linear-gradient(135deg, #2563eb, #14b8a6); box-shadow: 0 12px 30px rgba(37, 99, 235, .24); }
.brand strong { display: block; font-size: 1.08rem; }
.brand small { display: block; margin-top: 2px; color: var(--muted); }
.nav { display: flex; gap: 8px; padding: 6px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.7); }
.nav a { padding: 8px 13px; color: #334155; text-decoration: none; border-radius: 999px; font-weight: 700; }
.nav a:hover { background: #eaf1ff; color: var(--blue-dark); }

.hero-card, .identity-card, .editor-card, .lookup-card, .submission-card { border: 1px solid rgba(219, 227, 240, .9); background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.hero-card { border-radius: var(--radius); padding: 28px; margin-bottom: 22px; }
.submit-hero { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: center; }
.eyebrow { margin: 0 0 8px; color: var(--blue); text-transform: uppercase; font-weight: 900; letter-spacing: .11em; font-size: .76rem; }
h2 { margin: 0 0 10px; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1.05; letter-spacing: -.04em; }
h3 { margin: 0 0 8px; font-size: 1rem; }
.hero-copy, .identity-card p, .editor-toolbar p { color: var(--muted); line-height: 1.7; }
.safety-panel { border-radius: 18px; padding: 18px; background: linear-gradient(180deg, #0f172a, #172554); color: white; }
.safety-panel strong { display: block; margin-bottom: 10px; }
.safety-panel ul { margin: 0; padding-left: 20px; color: #dbeafe; line-height: 1.7; }

.submit-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
.identity-card, .editor-card { border-radius: var(--radius); padding: 22px; }
.identity-card { position: sticky; top: 18px; }
label { display: block; margin: 16px 0; font-weight: 800; }
input, textarea, button { font: inherit; }
input { width: 100%; margin-top: 7px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 14px; background: white; color: var(--ink); outline: none; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(37, 99, 235, .13); }
button { border: 0; border-radius: 14px; padding: 10px 13px; font-weight: 900; cursor: pointer; background: #eaf1ff; color: var(--blue-dark); }
button:hover { transform: translateY(-1px); }
.primary-action { width: 100%; margin-top: 8px; padding: 13px 16px; color: white; background: linear-gradient(135deg, var(--blue), #14b8a6); box-shadow: 0 14px 32px rgba(37,99,235,.22); }
.secondary-action { width: 100%; margin-top: 10px; padding: 12px 16px; color: var(--blue-dark); background: #eaf1ff; border: 1px solid #c7d8ff; }
.hint { font-size: .9rem; }
kbd { padding: 2px 6px; border-radius: 7px; border: 1px solid var(--line); background: #f8fafc; font-size: .82em; }
.error, .notice { margin: 0 0 18px; padding: 14px 16px; border-radius: 16px; font-weight: 800; }
.error { color: var(--red); background: #fff1f0; border: 1px solid #fecaca; }
.notice { color: #065f46; background: #ecfdf5; border: 1px solid #a7f3d0; }

.editor-toolbar { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 14px; }
.editor-toolbar h3 { font-size: 1.2rem; }
.editor-toolbar p { margin: 0; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.editor-shell { display: grid; grid-template-columns: 58px minmax(0, 1fr); min-height: 560px; border: 1px solid #1f2a44; border-radius: 20px; overflow: hidden; background: var(--code-bg); box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
.line-numbers { margin: 0; padding: 18px 12px; overflow: hidden; text-align: right; color: #64748b; background: var(--code-gutter); border-right: 1px solid #1f2a44; font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; user-select: none; }
.editor-code-wrap { position: relative; min-width: 0; min-height: 560px; background: linear-gradient(180deg, #0c1222, #0a1020); }
.syntax-layer, textarea[data-code-editor] { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 560px; margin: 0; padding: 18px 20px; overflow: auto; white-space: pre; font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; }
.syntax-layer { pointer-events: none; color: var(--code-ink); background: transparent; }
textarea[data-code-editor] { resize: vertical; border: 0; outline: 0; color: transparent; background: transparent; caret-color: #67e8f9; }
textarea[data-code-editor]::selection { background: rgba(96, 165, 250, .35); color: transparent; }
.tok-keyword { color: #c084fc; font-weight: 800; }
.tok-string { color: #86efac; }
.tok-comment { color: #64748b; font-style: italic; }
.tok-number { color: #fbbf24; }
.tok-function { color: #67e8f9; font-weight: 800; }
.tok-danger { color: #fb7185; font-weight: 900; text-decoration: underline wavy rgba(251, 113, 133, .8); }
.editor-status { display: flex; justify-content: space-between; gap: 12px; margin: 10px 2px 18px; color: var(--muted); font-size: .9rem; }
.status-error { color: var(--red); font-weight: 900; }
.contract-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.contract-grid article { padding: 14px; border-radius: 16px; background: #f8fbff; border: 1px solid var(--line); }
.contract-grid strong { display: block; margin-bottom: 8px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; color: #1d4ed8; overflow-wrap: anywhere; }

/* Leaderboard basics */
.leaderboard-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.leaderboard-hero h2 { margin-bottom: 0; }
.submit-link { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 999px; color: #fff; background: linear-gradient(135deg, var(--blue), #14b8a6); text-decoration: none; font-weight: 900; box-shadow: 0 14px 32px rgba(37,99,235,.22); white-space: nowrap; }
.submit-link:hover { transform: translateY(-1px); }
table { width: 100%; border-collapse: collapse; border-radius: 18px; overflow: hidden; background: var(--panel-strong); box-shadow: var(--shadow); }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #eef5ff; color: #334155; font-size: .86rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.leaderboard-table tbody tr { transition: background .16s ease; }
.leaderboard-table tbody tr:hover { background: #f8fbff; }
.leaderboard-table th { padding: 0; }
.leaderboard-table th button { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 48px; padding: 14px 16px; border: 0; border-radius: 0; background: transparent; color: inherit; text-align: left; text-transform: inherit; letter-spacing: inherit; font: inherit; }
.leaderboard-table th button:hover,
.leaderboard-table th button.is-active { color: var(--blue-dark); background: #e2edff; transform: none; }
.leaderboard-table th button::after { content: "↕"; color: #94a3b8; font-size: .82rem; }
.leaderboard-table th button.is-active[data-direction="asc"]::after { content: "↑"; color: var(--blue-dark); }
.leaderboard-table th button.is-active[data-direction="desc"]::after { content: "↓"; color: var(--blue-dark); }
.leaderboard-table td:first-child { width: 80px; color: var(--muted); font-weight: 900; }
.leaderboard-table td:nth-child(3),
.leaderboard-table td:nth-child(4) { font-variant-numeric: tabular-nums; }
.empty-row td { padding: 34px 18px; color: var(--muted); text-align: center; font-weight: 800; }

/* Owner submissions */
.submissions-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.lookup-card { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 14px; margin-bottom: 22px; padding: 20px; border-radius: var(--radius); }
.lookup-card label { margin: 0; }
.lookup-card .primary-action { width: auto; margin: 0; white-space: nowrap; }
.submission-list { display: grid; gap: 16px; }
.submission-card { border-radius: var(--radius); padding: 20px; }
.submission-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.submission-head h3 { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.submission-head time { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.submission-kicker { margin: 0 0 8px; color: var(--muted); font: 800 .82rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.state-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; font-size: .83rem; font-weight: 900; }
.state-queued { color: #92400e; background: #fef3c7; }
.state-running { color: #1d4ed8; background: #dbeafe; }
.state-succeeded, .state-published { color: #047857; background: #d1fae5; }
.state-failed { color: #b42318; background: #fee2e2; }
.state-cancelled { color: #475569; background: #e2e8f0; }
.submission-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.submission-stats div { padding: 13px 14px; border: 1px solid var(--line); border-radius: 16px; background: #f8fbff; }
.submission-stats dt { margin-bottom: 5px; color: var(--muted); font-size: .82rem; font-weight: 900; }
.submission-stats dd { margin: 0; font-weight: 900; font-variant-numeric: tabular-nums; }
.failure-box { margin: 0 0 14px; padding: 14px 16px; border: 1px solid #fecaca; border-radius: 16px; color: var(--red); background: #fff1f0; }
.failure-box p { margin: 6px 0 0; color: #7f1d1d; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.code-details { border: 1px solid #1f2a44; border-radius: 18px; overflow: hidden; background: var(--code-bg); }
.code-details summary { padding: 13px 16px; color: #dbeafe; cursor: pointer; font-weight: 900; background: #10192d; }
.code-details pre { max-height: 420px; margin: 0; padding: 16px; overflow: auto; color: var(--code-ink); font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.empty-panel { padding: 30px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; background: rgba(255,255,255,.68); font-weight: 900; }
.debug-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.debug-card { max-width: 980px; margin: 0 auto; }

@media (max-width: 860px) {
  .site-header, .editor-toolbar { align-items: stretch; flex-direction: column; }
  .submit-hero, .submit-layout, .contract-grid, .lookup-card, .submission-stats { grid-template-columns: 1fr; }
  .identity-card { position: static; }
  .toolbar-actions { justify-content: flex-start; }
  .leaderboard-hero, .submissions-hero, .debug-hero, .submission-head { align-items: stretch; flex-direction: column; }
  .submit-link { width: 100%; }
  .lookup-card .primary-action { width: 100%; }
  .leaderboard-table { display: block; overflow-x: auto; }
  .leaderboard-table th button,
  .leaderboard-table td { min-width: 120px; }
}
