:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #66717f;
  --line: #d8dee7;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --blue: #1769aa;
  --blue-strong: #0f4f84;
  --green: #23845f;
  --amber: #b66a08;
  --red: #c83e35;
  --shadow: 0 12px 32px rgba(23, 32, 42, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  background: #eef2f6;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: #eef2f6;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--blue-strong);
  border-color: var(--blue-strong);
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button.secondary {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

button.secondary:hover:not(:disabled) {
  color: var(--blue-strong);
  border-color: #99b9d4;
  background: #f7fbff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  padding: 10px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 12px;
}

.topbar-actions,
.stage-pill {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 10px;
}

.stage-pill {
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
  white-space: nowrap;
}

.stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(182, 106, 8, 0.12);
}

body[data-stage="ready"] .stage-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(35, 132, 95, 0.12);
}

body[data-stage="blocked"] .stage-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(200, 62, 53, 0.12);
}

.icon-command {
  width: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
  font-size: 22px;
  line-height: 1;
}

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
}

.challenge-band,
.workspace-band,
.submit-band {
  padding: clamp(22px, 4vw, 48px);
}

.challenge-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  min-height: calc(100vh - 60px);
  align-items: center;
  background: var(--surface);
}

.challenge-main {
  width: min(960px, 100%);
  margin: 0 auto;
}

.challenge-main,
.attestation-panel,
.data-workspace,
.leaderboard-panel,
.submit-band {
  min-width: 0;
}

.attestation-panel,
.leaderboard-panel {
  border-left: 1px solid var(--line);
  padding-left: 28px;
}

.section-heading,
.toolbar,
.leaderboard-title,
.challenge-actions,
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading.compact {
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.challenge-state {
  display: flex;
  align-items: baseline;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.challenge-state strong {
  color: var(--ink);
  font-size: 20px;
}

.challenge-prompt {
  min-height: 24px;
  margin-bottom: 14px;
  color: #344050;
  font-size: 16px;
  font-weight: 650;
}

.canvas-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

#challengeCanvas {
  display: block;
  width: 100%;
  min-height: 260px;
  cursor: crosshair;
  touch-action: manipulation;
}

#challengeCanvas.is-locked {
  cursor: wait;
}

.canvas-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.65);
}

.challenge-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.risk-score {
  color: var(--muted);
  font-size: 12px;
}

.risk-score strong {
  color: var(--green);
  font-size: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  border-top: 1px solid var(--line);
}

.metric-grid div {
  min-width: 0;
  padding: 15px 4px;
  border-bottom: 1px solid var(--line);
}

.metric-grid div:nth-child(odd) {
  padding-right: 16px;
}

.metric-grid dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.metric-grid dd {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 32px;
  background: #eef2f6;
}

.data-workspace,
.leaderboard-panel {
  padding-top: 8px;
}

.toolbar {
  margin-bottom: 18px;
}

.toolbar > span,
.leaderboard-title span {
  color: var(--muted);
  font-size: 12px;
}

.number-list-wrap {
  position: relative;
  min-height: 360px;
}

.number-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.value-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 62px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.value-index {
  color: var(--muted);
  font-size: 11px;
}

.value-num {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 750;
}

.empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 360px;
  padding: 40px 28px;
  border: 1px solid #cbd4de;
  border-radius: 6px;
  color: #536171;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.6;
  text-align: center;
}

.page-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  place-items: center;
  background: rgba(238, 242, 246, 0.78);
  backdrop-filter: blur(3px);
}

.page-loading.is-active {
  display: grid;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #c8d3df;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.pager {
  margin-top: 18px;
}

.pages {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 224px;
}

.page-btn {
  width: 40px;
  min-height: 40px;
  padding: 0;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.page-btn.is-active {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

.leaderboard-title {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 750;
}

.leaderboard-list {
  display: grid;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.leaderboard-rank {
  color: var(--blue);
  font-weight: 800;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-time,
.leaderboard-empty {
  color: var(--muted);
}

.leaderboard-empty {
  padding: 24px 0;
  font-size: 13px;
}

.submit-band {
  display: grid;
  grid-template-columns: minmax(180px, 0.55fr) minmax(420px, 1fr);
  gap: 24px 40px;
  align-items: end;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.submit-row {
  display: grid;
  grid-template-columns: minmax(140px, 0.7fr) minmax(180px, 1fr) auto;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #bdc7d2;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

.result {
  grid-column: 1 / -1;
  min-height: 28px;
  padding-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.result.success { color: var(--green); }
.result.warn { color: var(--amber); }
.result.error { color: var(--red); }

body:not(.challenge-passed) .workspace-band,
body:not(.challenge-passed) .submit-band {
  filter: grayscale(0.6);
}

body:not(.challenge-passed) .workspace-band {
  opacity: 0.68;
}

@media (max-width: 980px) {
  .challenge-band,
  .workspace-band,
  .submit-band {
    grid-template-columns: 1fr;
  }

  .challenge-band {
    min-height: auto;
  }

  .attestation-panel,
  .leaderboard-panel {
    padding-top: 24px;
    padding-left: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .number-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .submit-band {
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 9px 12px;
  }

  .brand > span:last-child {
    display: none;
  }

  .stage-pill {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .challenge-band,
  .workspace-band,
  .submit-band {
    padding: 22px 14px;
  }

  h1 {
    font-size: 32px;
  }

  #challengeCanvas {
    min-height: 210px;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

  .number-list {
    grid-template-columns: 1fr;
  }

  .number-list-wrap,
  .empty {
    min-height: 260px;
  }

  .empty {
    padding: 32px 20px;
    font-size: 14px;
  }

  .pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .pages {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
  }

  .pager > button {
    grid-row: 2;
  }

  .submit-row {
    grid-template-columns: 1fr;
  }

  .submit-row button {
    width: 100%;
  }
}
