:root {
  --bg: #f2f4ff;
  --surface: #ffffff;
  --ink: #17153b;
  --muted: #5d5b84;
  --line: #d4d8f2;
  --up: #0a9a5b;
  --down: #e0306a;
  --accent: #4b3cf0;
  --gold: #ffb800;
  --radius-lg: 22px;
  --radius-sm: 10px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, sans-serif;
  color-scheme: light;
}

body.rugged {
  --bg: #fff3f4;
  --ink: #3b0d1c;
  --muted: #8a4a5c;
  --line: #f2c9d3;
  --accent: #e0306a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  transition: background-color 1.2s ease, color 1.2s ease;
}

h1, h2 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.75rem; }
[hidden] { display: none !important; }
a { color: inherit; }

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- header */
.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 40px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.mark { width: 34px; height: 34px; flex: none; }
.mark rect { fill: var(--ink); }
.mark path { fill: none; stroke: var(--bg); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.wordmark { font-family: var(--display); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; }
.token-tag {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  padding-left: 20px;
  border-left: 1.5px solid var(--line);
}
.ticker { font-family: var(--display); font-weight: 800; font-size: 1.35rem; }
.token-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 16px; margin-left: auto; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1.5px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
body.mode-soon .pill { color: var(--accent); border-color: currentColor; }
body.mode-live .pill { background: var(--ink); border-color: var(--ink); color: #fff; }
body.mode-live .pill::before { background: #ff4d7e; animation: pulse 1s infinite alternate; }
body.mode-ended .pill { color: var(--ink); border-color: var(--ink); }
body.rugged .pill { background: var(--down); border-color: var(--down); color: #fff; }

.clock { text-align: right; line-height: 1.1; }
.clock-label { display: block; font-size: 0.8rem; color: var(--muted); }
.clock-value { font-family: var(--display); font-weight: 800; font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.clock.urgent .clock-value { color: var(--down); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; }
  .token-tag { order: 3; width: 100%; border-left: 0; padding-left: 0; }
  .wordmark { display: none; }
}

/* ---------- buttons */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--down); color: #fff; font-family: var(--display); font-weight: 800; padding: 10px 28px; }
.btn-ghost { background: transparent; border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-wide { width: 100%; padding: 14px; font-size: 1.05rem; }

main { padding: 0 clamp(16px, 3vw, 40px) 56px; }

/* ---------- admin */
.admin {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 20px;
  border: 1.5px dashed var(--muted);
  border-radius: var(--radius-sm);
}
.admin-tag { font-weight: 600; color: var(--muted); margin-right: 4px; }
.status { color: var(--muted); margin: 0; }
.status.error { color: var(--down); }

/* ---------- hero */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr);
  grid-template-areas: "title rules" "lede rules" "status rules";
  column-gap: clamp(32px, 5vw, 72px);
  align-items: start;
  padding: clamp(12px, 3vh, 36px) 0 clamp(20px, 4vh, 36px);
}
.hero h1 {
  grid-area: title;
  font-size: clamp(2.4rem, 5.2vw, 4.6rem);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: -0.035em;
}
.hero .lede { grid-area: lede; font-size: 1.1rem; color: var(--muted); max-width: 56ch; margin: 16px 0 0; }
.rules {
  grid-area: rules;
  align-self: center;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 18px;
}
.rules li { display: grid; grid-template-columns: 40px 1fr; column-gap: 14px; }
.rules svg {
  grid-row: span 2;
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.rules b { font-family: var(--display); font-size: 1.05rem; }
.rules span { color: var(--muted); font-size: 0.95rem; }
.hero-status {
  grid-area: status;
  justify-self: start;
  margin: 22px 0 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
}
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; grid-template-areas: "title" "lede" "rules" "status"; }
  .rules { margin-top: 24px; }
}

/* ---------- stage */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: start;
}
@media (max-width: 960px) { .stage { grid-template-columns: 1fr; } }

.price-block { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.price {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.2rem, 8vw, 6.5rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
body.mode-preview .price { color: var(--muted); }
.price-sub { display: flex; flex-direction: column; color: var(--muted); }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.price.flash { animation: flash 0.9s ease; }
@keyframes flash { 0% { color: var(--up); } 100% { color: var(--ink); } }

.chart-wrap {
  position: relative;
  height: clamp(280px, 48vh, 520px);
  margin: 18px 0 10px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 10px 6px;
  border: 1px solid var(--line);
}
.chart-note {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 1;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 3px 10px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0 8px;
}
@media (max-width: 600px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stats div { padding: 4px 0; border-top: 2px solid var(--ink); }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.4rem; font-variant-numeric: tabular-nums; }

.feed-wrap { margin-top: 24px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.feed li.fresh { animation: arrive 1.2s ease; }
@keyframes arrive { from { background: rgba(10, 154, 91, 0.16); } to { background: transparent; } }
.feed .who { font-weight: 600; }
.feed .ago { color: var(--muted); }
.feed li.empty { display: block; color: var(--muted); }
.token-facts { color: var(--muted); font-size: 0.9rem; margin: 16px 0 0; }
.token-facts .warn { color: var(--down); font-weight: 600; }

/* ---------- side */
.side { display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.amount {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 4px;
}
.amount input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}
.amount input:focus-visible { outline: none; }
.amount:focus-within { border-color: var(--accent); }
.amount span { color: var(--muted); }
.quick { display: flex; gap: 6px; margin: 12px 0; }
.quick button {
  flex: 1;
  border: 1.5px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 0.9rem;
}
.quick button:hover { border-color: var(--ink); }
.cost { margin: 0 0 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cost strong { color: var(--ink); }

.pending { list-style: none; margin: 12px 0 0; padding: 0; font-size: 0.9rem; }
.pending li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.pending .ok { color: var(--up); }
.pending .err { color: var(--down); text-align: right; }
.pending .wait::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1s infinite alternate;
}
@keyframes pulse { to { opacity: 0.2; } }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.checklist li::before {
  content: "";
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 50%;
  border: 2px solid var(--line);
}
.checklist li.done::before {
  border-color: var(--up);
  background: var(--up) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' stroke='white' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.checklist small { display: block; color: var(--muted); }
.checklist button {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.position { margin: 0; font-variant-numeric: tabular-nums; }

.board { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.board li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.board li::before { content: counter(rank); color: var(--muted); }
.board li.empty { display: block; color: var(--muted); }
.board li.empty::before { content: none; }
.board li.me { font-weight: 600; }
.board li.top { background: linear-gradient(90deg, rgba(255, 184, 0, 0.22), transparent); }

/* ---------- winner banner */
.banner { border-radius: var(--radius-lg); padding: 20px; background: var(--gold); color: #2b1d00; }
.banner h2 { margin-bottom: 4px; font-size: 1.5rem; }
.banner p { margin: 0; }
.banner .addr { font-family: var(--display); font-weight: 800; font-size: 1.35rem; word-break: break-all; }
body.rugged .banner { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }

/* ---------- post-mortem */
.postmortem { margin-top: 36px; max-width: 920px; border-top: 4px solid var(--down); padding-top: 20px; }
.postmortem h2 { font-size: 2.2rem; font-weight: 800; }
.pm-you { font-size: 1.25rem; max-width: 60ch; }
.pm-you strong { color: var(--down); }
.flags { padding-left: 1.2em; max-width: 70ch; }
.flags li { margin-bottom: 14px; }
.flags b { font-family: var(--display); font-size: 1.1rem; display: block; }

/* ---------- setup dialog */
.setup {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(23, 21, 59, 0.35);
}
.setup::backdrop { background: rgba(23, 21, 59, 0.55); }
.deploy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px 18px;
  padding: 28px;
}
.setup-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }
.setup-head h2 { font-size: 1.8rem; font-weight: 800; margin: 0; }
.close { border: 0; background: none; font-size: 2rem; line-height: 1; cursor: pointer; color: var(--muted); }
.setup-lede { grid-column: 1 / -1; color: var(--muted); margin: 0 0 6px; }
.deploy-grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.92rem; }
.deploy-grid small { font-weight: 400; color: var(--muted); }
.deploy-grid input {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg);
}
.deploy-summary { grid-column: 1 / -1; color: var(--muted); font-size: 0.95rem; margin: 0; }
.setup-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* ---------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  max-width: calc(100vw - 32px);
  z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
