:root {
  --background: #f7f9fb;
  --background-low: #eff4f8;
  --surface: #ffffff;
  --surface-soft: #eaf7f1;
  --surface-muted: #f2f5f7;
  --text: #0b1220;
  --text-muted: #5f6b7a;
  --accent: #087a4d;
  --accent-contrast: #ffffff;
  --blue: #255fdb;
  --border: #d7e0e8;
  --negative: #b3261e;
  --neutral: #475569;
  --warning: #b7791f;
  --radius: 8px;
  --shadow: 0 18px 48px rgba(11, 18, 32, 0.14);
  color: var(--text);
  background: var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
}

body {
  overflow-x: hidden;
}

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

.app-shell {
  width: min(100%, 460px);
  min-height: 100svh;
  margin: 0 auto;
  background: var(--background);
}

.screen {
  min-height: 100svh;
  padding: max(16px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.has-drawer .screen {
  padding-bottom: 288px;
}

.setup-screen,
.trading-screen,
.result-screen,
.history-screen,
.final-screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setup-screen {
  justify-content: flex-start;
}

.setup-hero {
  padding-top: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: 42px;
  line-height: 1.05;
  font-weight: 900;
}

h2,
.section-title {
  color: var(--text);
  font-size: 20px;
  line-height: 1.15;
  font-weight: 900;
}

.setup-hero p,
.muted-strong,
.meta-line,
.asset-sub,
.signal-price,
.news-meta span,
.leader-main span,
.final-row span,
.move-main span,
.drawer-meta,
.chart-legend {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.setup-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 14px;
}

.metric {
  display: grid;
  gap: 2px;
}

.metric span,
.setup-section h2 {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 800;
}

.metric strong {
  font-size: 20px;
  line-height: 1.15;
  font-weight: 900;
}

.setup-section {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.segmented,
.action-row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: 10px;
}

.setup-section .segmented {
  --cols: 3;
}

.setup-section:nth-of-type(3) .segmented {
  --cols: 2;
}

.btn {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn.secondary {
  background: var(--surface);
  color: var(--text-muted);
}

.btn.compact {
  min-height: 38px;
  padding: 0 16px;
}

.btn.wide {
  width: 100%;
  min-height: 54px;
  font-size: 17px;
}

.btn.segment.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn.danger {
  color: var(--negative);
}

.top-game-bar {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-label {
  flex: 1;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 900;
}

.account-value {
  color: var(--accent);
  font-size: 42px;
  line-height: 1.05;
  font-weight: 950;
}

.account-value.small {
  display: block;
  font-size: 28px;
}

.player-name {
  font-size: 22px;
}

.account-sparkline {
  width: 100%;
  height: 48px;
  color: var(--accent);
}

.turn-progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  background: var(--surface-muted);
  border-radius: 999px;
}

.turn-progress::before {
  display: block;
  width: calc(var(--progress) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  content: "";
}

.signal-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.asset-signal-strip {
  display: grid;
  grid-auto-columns: 132px;
  grid-auto-flow: column;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.asset-signal-strip::-webkit-scrollbar {
  display: none;
}

.asset-signal {
  display: grid;
  width: 132px;
  min-height: 92px;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface-muted);
  border-radius: var(--radius);
  color: var(--neutral);
}

.asset-signal.positive {
  color: var(--accent);
}

.asset-signal.negative {
  color: var(--negative);
}

.asset-signal-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.asset-signal-top strong {
  flex: 1;
  color: var(--text);
  font-size: 14px;
  font-weight: 950;
}

.asset-signal-top span {
  font-size: 14px;
  font-weight: 950;
}

.mini-spark {
  width: 100%;
  height: 30px;
}

.news-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  background: var(--surface-muted);
  border-radius: var(--radius);
}

.news-body {
  flex: 1;
  min-width: 0;
}

.news-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.news-meta strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 950;
  white-space: nowrap;
}

.news-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.news-card p {
  margin-top: 4px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.28;
  font-weight: 850;
}

.publisher-logo,
.asset-icon,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  color: white;
  background: var(--accent);
  border-radius: 50%;
}

.publisher-logo svg,
.asset-icon svg {
  width: 22px;
  height: 22px;
}

.publisher-logo.trend,
.publisher-logo.crypto,
.publisher-logo.bars,
.publisher-logo.flow {
  background: var(--blue);
}

.publisher-logo.rates,
.publisher-logo.commodity,
.publisher-logo.ledger {
  background: var(--warning);
}

.publisher-logo.wire,
.publisher-logo.housing {
  background: var(--neutral);
}

.asset-icon {
  width: 40px;
  height: 40px;
  background: var(--surface-soft);
  color: var(--accent);
}

.asset-icon.btc,
.asset-icon.alt {
  background: #eaf0ff;
  color: var(--blue);
}

.asset-icon.gld,
.asset-icon.col {
  background: #fff5df;
  color: var(--warning);
}

.asset-icon.cash {
  color: var(--neutral);
}

.player-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.player-pill {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 64px;
  padding: 8px 6px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.player-pill.active {
  background: var(--surface-soft);
  border-color: var(--accent);
}

.player-pill strong,
.player-pill span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-pill strong {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 900;
}

.player-pill span {
  color: var(--accent);
  font-size: 14px;
  font-weight: 950;
}

.asset-list {
  display: grid;
  gap: 8px;
}

.asset-row {
  display: flex;
  width: 100%;
  min-height: 82px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
}

.asset-row.selected {
  border: 2px solid var(--accent);
}

.asset-row.disabled {
  cursor: default;
}

.asset-main {
  flex: 1;
  min-width: 0;
}

.asset-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.asset-title strong {
  font-size: 17px;
  line-height: 1.1;
  font-weight: 950;
}

.asset-title span {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-values {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.asset-values strong {
  font-size: 17px;
  font-weight: 950;
}

.asset-values span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}

.order-drawer {
  position: fixed;
  z-index: 20;
  right: max(0px, calc((100vw - 460px) / 2));
  bottom: 0;
  left: max(0px, calc((100vw - 460px) / 2));
  display: grid;
  gap: 10px;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
  touch-action: none;
  transition: transform 0.16s ease;
  user-select: none;
}

.order-drawer.dragging {
  transition: none;
}

.drawer-handle {
  justify-self: center;
  width: 42px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
}

.drawer-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-heading strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-heading span {
  font-size: 23px;
  line-height: 1.1;
  font-weight: 950;
}

.drawer-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.drawer-message {
  overflow: hidden;
  color: var(--warning);
  font-size: 14px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.result-summary {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.result-summary h1 {
  color: var(--accent);
}

.positive-text {
  color: var(--accent);
}

.negative-text {
  color: var(--negative);
}

.leaderboard,
.movement-board {
  display: grid;
  gap: 8px;
}

.leader-row,
.final-row,
.move-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rank {
  width: 36px;
  color: var(--blue);
  font-size: 18px;
  font-weight: 950;
}

.avatar {
  color: var(--accent);
  background: var(--surface-soft);
  font-weight: 950;
}

.leader-main,
.move-main {
  flex: 1;
  min-width: 0;
  display: grid;
}

.leader-main strong,
.move-main strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movement-board {
  padding: 14px;
}

.move-row {
  background: var(--surface-muted);
  border: 0;
}

.history-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-head h1 {
  flex: 1;
}

.history-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.value-chart {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.value-chart svg {
  width: 100%;
  height: 150px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  background: var(--dot);
  border-radius: 50%;
}

.history-matrix {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.matrix-row {
  display: grid;
  grid-template-columns: 34px repeat(10, minmax(0, 1fr));
  gap: 4px;
  align-items: center;
}

.matrix-row.header {
  color: var(--text-muted);
}

.matrix-row.header strong {
  overflow: hidden;
  font-size: 14px;
  line-height: 1.05;
  font-weight: 900;
  text-align: center;
}

.year-num {
  color: var(--blue);
  font-size: 14px;
  font-weight: 950;
  text-align: center;
}

.matrix-cell {
  display: grid;
  min-height: 38px;
  place-items: center;
  overflow: hidden;
  background: var(--surface-muted);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 950;
}

.matrix-cell.positive {
  background: var(--surface-soft);
  color: var(--accent);
}

.matrix-cell.negative {
  background: #ffedea;
  color: var(--negative);
}

.winner-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px;
}

.winner-card .avatar {
  width: 54px;
  height: 54px;
}

.final-row {
  background: var(--surface);
}

.toast {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: 20px;
  left: 16px;
  max-width: 428px;
  margin: auto;
  padding: 10px 12px;
  transform: translateY(24px);
  opacity: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 850;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (min-width: 700px) {
  .app-shell {
    border-right: 1px solid var(--border);
    border-left: 1px solid var(--border);
  }

  .screen {
    padding-right: 16px;
    padding-left: 16px;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 36px;
  }

  .account-value {
    font-size: 36px;
  }

  .btn.compact {
    padding: 0 10px;
  }

  .asset-values span {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .matrix-row {
    grid-template-columns: 28px repeat(10, minmax(0, 1fr));
    gap: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
