:root {
  --bg: #f3eee4;
  --paper: #fbf7ef;
  --panel: rgba(251, 247, 239, 0.96);
  --panel-strong: #fffdf8;
  --ink: #181613;
  --muted: #736b62;
  --line: rgba(24, 22, 19, 0.12);
  --line-strong: rgba(24, 22, 19, 0.26);
  --accent: #22382f;
  --accent-strong: #13211b;
  --soft-accent: rgba(34, 56, 47, 0.06);
  --warn: #8b2d2d;
  --shadow: 0 18px 40px rgba(61, 48, 27, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 28%),
    repeating-linear-gradient(
      90deg,
      rgba(24, 22, 19, 0.018) 0,
      rgba(24, 22, 19, 0.018) 1px,
      transparent 1px,
      transparent 36px
    ),
    linear-gradient(180deg, var(--paper), var(--bg));
  font-family: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  animation: page-fade 360ms ease-out;
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 72px;
}

.topbar,
.hero,
.panel,
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0 18px;
  border-radius: 0;
  margin-bottom: 26px;
  position: relative;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  box-shadow: none;
}

.topbar::after,
.hero::after,
.panel::after,
.auth-card::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(22, 21, 18, 0.04);
  border-radius: inherit;
  pointer-events: none;
}

.topbar::after {
  display: none;
}

.topbar h1,
.section-head h2,
.section-head h3,
.auth-card h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", "Songti SC", serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.topbar h1 {
  font-size: clamp(32px, 4vw, 44px);
  line-height: 1.04;
}

.subhead {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Baskerville", "Palatino Linotype", "STKaiti", serif;
  font-weight: 600;
  line-height: 1.3;
  font-size: clamp(34px, 4.6vw, 56px);
  max-width: 13ch;
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 11px;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
  padding-top: 10px;
}

a,
.button-link {
  color: var(--accent-strong);
  text-decoration: none;
}

nav a {
  border: 0;
  background: transparent;
  padding: 2px 0 8px;
  border-radius: 0;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid transparent;
  transition: color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

button,
.button-link {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  padding: 10px 13px;
  border-radius: 999px;
  font-size: 13px;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, transform 180ms ease;
}

nav a:hover,
button:hover,
.button-link:hover {
  transform: translateY(-1px);
}

nav a.active {
  background: transparent;
  color: var(--ink);
  border-color: var(--accent);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.9fr);
  gap: 32px;
  padding: 40px;
  border-radius: 12px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
  align-items: start;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 24px 24px auto;
  width: 96px;
  height: 1px;
  background: var(--line-strong);
  transform: none;
  pointer-events: none;
}

.hero-copy p:last-child,
.section-head p,
.hero-panel span {
  color: var(--muted);
}

.hero-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 24px 0 0 24px;
  border-radius: 0;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
}

.hero-panel strong {
  font-size: clamp(26px, 3vw, 34px);
  line-height: 1.08;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
}

.page-intro,
.home-hero {
  min-height: 320px;
}

.hero-copy {
  padding-top: 18px;
}

.hero-copy p {
  max-width: 50ch;
  font-size: 16px;
  color: var(--muted);
}

.hero-copy p + p {
  margin-top: 14px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.editorial-strip,
.terminal-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0 0 24px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: rgba(255, 253, 248, 0.52);
}

.terminal-summary {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.editorial-strip article,
.terminal-stat {
  padding: 18px 18px 16px;
  border-right: 1px solid var(--line);
}

.strip-action {
  display: grid;
  align-items: center;
  justify-items: start;
}

.editorial-strip article:last-child,
.terminal-stat:last-child {
  border-right: 0;
}

.editorial-strip span,
.terminal-stat span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.editorial-strip strong,
.terminal-stat strong {
  font-size: 22px;
  line-height: 1.15;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
  font-weight: 600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 28px;
}

.metric-card,
.flash {
  padding: 20px 22px;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
}

.metric-card span,
.flash {
  color: var(--muted);
  font-size: 14px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
  font-weight: 600;
}

.danger-text {
  color: #b91c1c;
}

.profit-up {
  color: #b91c1c;
  font-weight: 600;
}

.profit-down {
  color: #15803d;
  font-weight: 600;
}

.panel,
.auth-card {
  padding: 26px;
  border-radius: 12px;
  margin-bottom: 24px;
  position: relative;
}

.promo-panel {
  overflow: hidden;
}

.compact {
  padding-bottom: 16px;
}

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

.section-head h3 {
  font-size: 24px;
  line-height: 1.15;
}

.section-head p {
  max-width: 54ch;
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.52);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: -4px 0 20px;
}

.promo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 24px;
  align-items: stretch;
}

.promo-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.84);
  padding: 20px;
}

.promo-card-qr {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.promo-card-broker {
  display: grid;
  align-items: center;
  min-height: 280px;
}

.promo-qr-image,
.promo-broker-image,
.admin-preview-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
  object-fit: cover;
}

.promo-caption {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.8;
}

.promo-placeholder {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 220px;
  width: 100%;
  text-align: center;
  border: 1px dashed rgba(25, 58, 49, 0.24);
  border-radius: 12px;
  background: rgba(25, 58, 49, 0.035);
  color: var(--muted);
  padding: 20px;
}

.promo-placeholder p {
  margin: 0;
}

.admin-placeholder {
  min-height: 180px;
}

.admin-minimal-panel {
  padding-top: 20px;
  padding-bottom: 20px;
}

.admin-minimal-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 16px;
  align-items: start;
}

.upload-form,
.export-box {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
}

.export-box p {
  margin: 0;
  color: var(--muted);
}

.panel[id] {
  scroll-margin-top: 20px;
}

.th-label {
  display: inline-block;
}

.sort-button {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.95);
  color: var(--accent-strong);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  min-width: 24px;
  height: 22px;
}

.sort-button:hover {
  background: rgba(25, 58, 49, 0.08);
}

.inline-sort {
  margin-left: 4px;
  vertical-align: middle;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
  background: rgba(255, 253, 248, 0.44);
}

th,
td {
  border-bottom: 1px solid rgba(24, 22, 19, 0.08);
  padding: 14px 10px;
  text-align: left;
  font-size: 14px;
}

th {
  color: #5e564e;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: rgba(34, 56, 47, 0.035);
}

.arbitrage-table {
  min-width: 1480px;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.arbitrage-table th,
.arbitrage-table td {
  padding: 10px 8px;
  font-size: 13px;
  white-space: nowrap;
}

.arbitrage-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.arbitrage-table td:nth-child(2),
.arbitrage-table td:nth-child(4),
.arbitrage-table td:nth-child(5),
.arbitrage-table td:nth-child(6),
.arbitrage-table td:nth-child(7),
.arbitrage-table td:nth-child(8),
.arbitrage-table td:nth-child(9),
.arbitrage-table td:nth-child(10),
.arbitrage-table td:nth-child(11) {
  font-family: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
  font-size: 12px;
  letter-spacing: -0.02em;
}

.arbitrage-table th {
  position: sticky;
  top: 0;
  background: rgba(251, 247, 239, 0.99);
  z-index: 1;
  overflow: visible;
  text-overflow: clip;
  box-shadow: inset 0 -1px 0 rgba(24, 22, 19, 0.12);
}

.arbitrage-table th:nth-child(1),
.arbitrage-table td:nth-child(1),
.arbitrage-table th:nth-child(2),
.arbitrage-table td:nth-child(2) {
  position: sticky;
  background: rgba(251, 247, 239, 0.99);
  z-index: 2;
}

.arbitrage-table th:nth-child(1),
.arbitrage-table td:nth-child(1) {
  left: 0;
  box-shadow: 1px 0 0 rgba(28, 27, 24, 0.08);
}

.arbitrage-table th:nth-child(2),
.arbitrage-table td:nth-child(2) {
  left: 132px;
  box-shadow: 1px 0 0 rgba(28, 27, 24, 0.08);
}

.arbitrage-table thead th:nth-child(1),
.arbitrage-table thead th:nth-child(2) {
  z-index: 3;
}

.arbitrage-table th:nth-child(1),
.arbitrage-table td:nth-child(1) {
  width: 132px;
}

.arbitrage-table th:nth-child(2),
.arbitrage-table td:nth-child(2) {
  width: 74px;
}

.arbitrage-table th:nth-child(3),
.arbitrage-table td:nth-child(3) {
  width: 96px;
}

.arbitrage-table th:nth-child(4),
.arbitrage-table td:nth-child(4),
.arbitrage-table th:nth-child(6),
.arbitrage-table td:nth-child(6),
.arbitrage-table th:nth-child(8),
.arbitrage-table td:nth-child(8),
.arbitrage-table th:nth-child(9),
.arbitrage-table td:nth-child(9),
.arbitrage-table th:nth-child(10),
.arbitrage-table td:nth-child(10),
.arbitrage-table th:nth-child(11),
.arbitrage-table td:nth-child(11),
.arbitrage-table th:nth-child(13),
.arbitrage-table td:nth-child(13),
.arbitrage-table th:nth-child(14),
.arbitrage-table td:nth-child(14) {
  width: 92px;
}

.arbitrage-table th:nth-child(5),
.arbitrage-table td:nth-child(5) {
  width: 128px;
}

.arbitrage-table th:nth-child(7),
.arbitrage-table td:nth-child(7) {
  width: 116px;
}

.arbitrage-table th:nth-child(12),
.arbitrage-table td:nth-child(12) {
  width: 120px;
}

.arbitrage-table th:nth-child(15),
.arbitrage-table td:nth-child(15),
.arbitrage-table th:nth-child(16),
.arbitrage-table td:nth-child(16) {
  width: 82px;
}

.arbitrage-table th:nth-child(17),
.arbitrage-table td:nth-child(17) {
  width: 96px;
}

.arbitrage-table th:nth-child(18),
.arbitrage-table td:nth-child(18) {
  width: 136px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.88);
}

button {
  cursor: pointer;
  color: white;
  background: var(--accent);
}

button.danger {
  background: var(--warn);
}

.stack-form,
.grid-form,
.filter-row,
.inline-form {
  display: grid;
  gap: 12px;
}

.grid-form,
.filter-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

.inline-form {
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  margin-bottom: 8px;
}

.auth-card {
  max-width: 420px;
  margin: 80px auto 0;
}

.error,
.bad {
  color: var(--warn);
}

.ok {
  color: var(--accent-strong);
}

.backtest-overview {
  display: flex;
  justify-content: space-between;
  padding: 12px 0 18px;
  font-size: 15px;
  color: var(--muted);
}

.status-badge {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.status-live {
  color: var(--accent-strong);
  background: rgba(34, 56, 47, 0.06);
  border: 1px solid rgba(34, 56, 47, 0.14);
}

.status-offline {
  color: #7f3f10;
  background: rgba(183, 110, 18, 0.08);
  border: 1px solid rgba(183, 110, 18, 0.18);
}

.fallback-badge {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.fallback-live {
  color: #0f766e;
  background: rgba(15, 118, 110, 0.08);
  border: 1px solid rgba(15, 118, 110, 0.16);
}

.fallback-cached {
  color: #9a6700;
  background: rgba(202, 138, 4, 0.12);
  border: 1px solid rgba(202, 138, 4, 0.24);
}

.fallback-offline {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.08);
  border: 1px solid rgba(185, 28, 28, 0.18);
}

.mini-note {
  color: var(--muted);
  font-size: 14px;
}

.admin-anchors {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.anchor-note {
  color: var(--muted);
  font-size: 14px;
}

.rollback-form {
  margin-bottom: 18px;
}

.next-plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
}

.next-plan-date {
  margin-bottom: 16px;
  font-size: 16px;
}

.next-plan-card {
  padding: 22px 20px;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.84);
  border: 1px solid var(--line);
}

.next-plan-card p {
  margin: 0 0 10px;
  font-weight: 600;
}

.next-plan-card p span {
  color: var(--muted);
  margin-left: 6px;
}

.next-plan-card strong {
  display: block;
  margin-bottom: 12px;
  font-size: 22px;
}

.next-plan-numbers {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.home-hero .hero-panel strong,
.metrics .metric-card strong {
  line-height: 1.3;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
}

.wide-table {
  min-width: 1480px;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.note-card {
  padding: 18px;
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid var(--line);
}

.note-card strong {
  display: block;
  margin-bottom: 8px;
  font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif;
}

.note-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

@keyframes page-fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .hero,
  .metrics {
    grid-template-columns: 1fr;
  }

  .editorial-strip,
  .terminal-summary {
    grid-template-columns: 1fr;
  }

  .editorial-strip article,
  .terminal-stat {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .editorial-strip article:last-child,
  .terminal-stat:last-child {
    border-bottom: 0;
  }

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

  .tool-grid,
  .next-plan-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-head,
  .backtest-overview {
    flex-direction: column;
    align-items: start;
  }

  .page-shell {
    width: min(1160px, calc(100% - 24px));
    padding-top: 18px;
  }

  .topbar,
  .panel,
  .hero,
  .auth-card {
    padding: 18px;
  }

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