:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #f2f0ea;
  --surface-hover: #ece9e0;
  --ink: #1e2430;
  --ink-2: #4b5565;
  --ink-3: #7b8494;
  --line: #e4e2da;
  --line-strong: #d1cec2;
  --brand: #3c5482;
  --brand-hover: #2f446b;
  --brand-soft: #edf1f8;
  --ok: #1e7a4c;
  --ok-soft: #eaf6ef;
  --warn: #b45309;
  --warn-soft: #fef5e7;
  --danger: #b83232;
  --danger-soft: #fdeeee;
  --stage-build: #46608a;
  --stage-algo: #567a60;
  --stage-verify: #b4533c;
  --stage-express: #7a5c8a;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 28, 42, 0.05);
  --shadow: 0 8px 24px rgba(20, 28, 42, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.08s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: #bcb7a8;
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: #f1c1c1;
  background: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-ok {
  color: var(--ok);
  border-color: #b7e2c9;
  background: var(--ok-soft);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-soft);
}

/* ---- Badges & Seals ---- */
.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  letter-spacing: 0;
}

.seal-sm {
  width: 22px;
  height: 22px;
  font-size: 12px;
  border-radius: 6px;
}

.seal[data-stage="build"] { background: var(--stage-build); }
.seal[data-stage="algo"] { background: var(--stage-algo); }
.seal[data-stage="verify"] { background: var(--stage-verify); }
.seal[data-stage="express"] { background: var(--stage-express); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink-2);
}

.badge-ok {
  background: var(--ok-soft);
  border-color: #b7e2c9;
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  border-color: #f4d29c;
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  border-color: #f3c1c1;
  color: var(--danger);
}

.badge-brand {
  background: var(--brand-soft);
  border-color: #c8d6ee;
  color: var(--brand);
}

/* ---- Cards & Forms ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(60, 84, 130, 0.12);
}

/* ---- Header ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-grid {
  display: grid;
  grid-template-columns: repeat(2, 10px);
  gap: 3px;
}

.brand-grid span {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: block;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-3);
}

/* ---- Stage Tabs ---- */
.stage-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.stage-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.stage-tab:hover {
  background: var(--surface-soft);
}

.stage-tab.active {
  color: #fff;
  border-color: transparent;
}

.stage-tab.active[data-stage="build"] { background: var(--stage-build); }
.stage-tab.active[data-stage="algo"] { background: var(--stage-algo); }
.stage-tab.active[data-stage="verify"] { background: var(--stage-verify); }
.stage-tab.active[data-stage="express"] { background: var(--stage-express); }

.stage-tab .tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}

.stage-tab.active .tab-dot {
  background: #fff;
  opacity: 1;
}

/* ---- Modal & Overlay ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(18, 24, 38, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-panel.modal-lg {
  max-width: 920px;
}

.modal-panel.modal-full {
  max-width: 1280px;
  height: 92vh;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Markdown Rendering ---- */
.md-body {
  word-break: break-word;
}

.md-body p {
  margin: 0 0 8px;
}

.md-body p:last-child {
  margin-bottom: 0;
}

.md-body ul,
.md-body ol {
  margin: 4px 0 8px 20px;
  padding: 0;
}

.md-body li {
  margin: 3px 0;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
  margin: 10px 0 6px;
  font-size: 14px;
  font-weight: 700;
}

.md-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

.md-body pre {
  background: #1d2430;
  color: #edf1f7;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.md-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.md-body .math-inline {
  font-family: "Times New Roman", "STIXGeneral", Georgia, serif;
  font-style: italic;
  background: rgba(60, 84, 130, 0.06);
  padding: 0 4px;
  border-radius: 4px;
}

/* ---- Toast ---- */
.toast-stack {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e2430;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: 92vw;
  text-align: center;
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-ok {
  background: var(--ok);
}
