:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f6f8;
  color: #111827;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
body.dark {
  background: #0b1220;
  color: #e5edf7;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 42px);
  background: #0f172a;
  color: white;
}

.brand { display: grid; gap: 3px; }
.brand h1 { margin: 0; font-size: clamp(24px, 4vw, 40px); letter-spacing: 0; }
.brand p { margin: 0; color: #cbd5e1; }

.status-pill {
  border-radius: 999px;
  padding: 9px 13px;
  font-weight: 800;
  background: #334155;
  color: white;
  white-space: nowrap;
}
.status-pill.live { background: #15803d; }
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-toggle {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  font-weight: 900;
}

.layout {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 38px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.player-layout {
  width: min(1180px, 100%);
  grid-template-columns: 1fr;
}

.host-layout { grid-template-columns: 360px minmax(0, 1fr) 360px; }
.host-layout .market-grid { grid-template-columns: 1fr; }

.panel, .asset-card, .join-box {
  background: #ffffff;
  border: 1px solid #d9e1ea;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.07);
}

.panel { padding: 16px; align-self: start; }
.panel h2, .panel h3 { margin: 0 0 12px; }
.panel p { color: #5b6777; }
.control-block {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}
.control-block:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}
.control-block h2 {
  margin: 0 0 12px;
  font-size: 21px;
}

.join-box {
  width: min(460px, calc(100% - 28px));
  margin: 56px auto;
  padding: 24px;
}
.join-box h1 { margin: 0 0 8px; font-size: 34px; }
.join-box p { margin: 0 0 18px; color: #5b6777; }

.field { display: grid; gap: 7px; margin-bottom: 12px; }
.field span, .field label { font-weight: 800; color: #334155; }
input, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: #111827;
}

.button-row { display: flex; flex-wrap: wrap; gap: 9px; }
.btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  font-weight: 900;
  color: white;
  background: #2563eb;
}
.btn.secondary { background: #475569; }
.btn.danger { background: #dc2626; }
.btn.buy { background: #15803d; }
.btn.sell { background: #b45309; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.market-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.asset-card { padding: 15px; display: grid; gap: 12px; }
.asset-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.asset-name { display: flex; align-items: center; gap: 9px; font-weight: 950; font-size: 19px; }
.dot { width: 13px; height: 13px; border-radius: 50%; background: var(--asset-color); }
.symbol { color: #64748b; font-size: 13px; font-weight: 900; }
.price { font-size: 27px; font-weight: 950; text-align: right; white-space: nowrap; }
.change { text-align: right; font-weight: 900; color: #64748b; }
.change.up { color: #15803d; }
.change.down { color: #dc2626; }

.sparkline {
  width: 100%;
  height: 72px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.graph-panel { margin-bottom: 14px; }
.graph-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
.graph-head h2 { margin: 0; }
.portfolio-graph {
  width: 100%;
  height: 180px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}
.portfolio-graph line {
  stroke: #dbe4ee;
  stroke-width: 1;
}
.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 6px 9px;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  font-weight: 900;
}
.graph-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.benchmark-panel {
  margin-bottom: 14px;
}
.benchmark-value {
  font-size: 34px;
  font-weight: 950;
  line-height: 1;
  margin-bottom: 8px;
}
.benchmark-panel p {
  margin: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.metric {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px;
}
.metric span { display: block; color: #64748b; font-size: 12px; font-weight: 800; }
.metric strong { display: block; margin-top: 2px; }
.trade-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}
.quick-amounts {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.quick-amount {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 6px;
  background: #f8fafc;
  color: #334155;
  font-weight: 900;
}
.quick-amount:hover { background: #e2e8f0; }
.sell-all-one { grid-column: 1 / -1; }
.portfolio-actions {
  display: flex;
  justify-content: flex-end;
  margin: -2px 0 14px;
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.leader-list, .event-list { display: grid; gap: 8px; }
.leader-item, .event-item {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}
.leader-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.leader-name { display: flex; align-items: center; gap: 7px; font-weight: 900; }
.leader-money { font-weight: 950; }
.leader-score { text-align: right; white-space: nowrap; }
.rank-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.ranking-asset {
  background: #fffaf0;
}

.event-item { display: grid; gap: 7px; }
.event-item strong { color: #111827; }
.event-item p { margin: 0; font-size: 13px; }
.log-panel h2, .log-block h3 { margin-bottom: 10px; }
.log-list { display: grid; gap: 8px; }
.log-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 9px;
  background: #f8fafc;
}
.log-item time {
  color: #64748b;
  font-size: 12px;
  font-weight: 900;
}
.log-item strong, .log-item span { display: block; }
.log-item span { color: #475569; font-size: 13px; margin-top: 2px; }
.host-log-embed {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}

.last-event {
  border-left: 4px solid #2563eb;
  background: #eff6ff;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}
.last-event strong { display: block; }
.last-event span { color: #475569; }

.host-assets { display: grid; gap: 10px; }
.stability-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 9px;
}

.cashline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.cashline.player-summary { grid-template-columns: repeat(5, minmax(0, 1fr)); }

@media (max-width: 1080px) {
  .layout, .host-layout { grid-template-columns: 1fr; }
  .player-layout { grid-template-columns: 1fr; }
  .market-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: space-between; }
  .cashline, .metrics, .player-summary, .info-grid { grid-template-columns: 1fr; }
  .preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trade-row { grid-template-columns: 1fr 1fr; }
  .trade-row input { grid-column: 1 / -1; }
}

body.dark .topbar { background: #07101f; }
body.dark .panel,
body.dark .asset-card,
body.dark .join-box {
  background: #111827;
  border-color: #263244;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
body.dark .control-block,
body.dark .host-log-embed { border-color: #263244; }
body.dark .panel p,
body.dark .join-box p,
body.dark .brand p,
body.dark .event-item p,
body.dark .last-event span,
body.dark .log-item span { color: #9fb0c6; }
body.dark .field span,
body.dark .field label,
body.dark .symbol,
body.dark .metric span,
body.dark .log-item time { color: #94a3b8; }
body.dark input,
body.dark select {
  background: #0b1220;
  border-color: #334155;
  color: #e5edf7;
}
body.dark .metric,
body.dark .event-item,
body.dark .leader-item,
body.dark .ranking-asset,
body.dark .log-item,
body.dark .quick-amount,
body.dark .sparkline,
body.dark .portfolio-graph,
body.dark .graph-legend span {
  background: #0f172a;
  border-color: #263244;
  color: #e5edf7;
}
body.dark .quick-amount:hover { background: #1e293b; }
body.dark .last-event {
  background: #12213a;
  border-left-color: #60a5fa;
}
body.dark .portfolio-graph line { stroke: #263244; }
body.dark .change { color: #94a3b8; }
body.dark .change.up { color: #22c55e; }
body.dark .change.down { color: #f87171; }
