* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  max-width: 425px;
  margin: 0 auto;
  padding: 1rem;
  background: #1a1a1a;
  color: #e0e0e0;
}

header {
  position: relative;
  margin-bottom: 1.5rem;
  padding-right: 6rem;
}

.leaderboard-best-btn {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: #888;
  border: 1px solid #555;
  border-radius: 4px;
  background: #333;
  cursor: pointer;
}

.leaderboard-best-btn:hover {
  background: #444;
  color: #ccc;
  border-color: #666;
}

.leaderboard-best-icon {
  width: 1rem;
  height: 1rem;
  object-fit: contain;
  flex-shrink: 0;
}

h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
}

#status {
  margin: 0 0 0.5rem 0;
  font-size: 0.9rem;
  color: #888;
}

#status.connected {
  color: #6b9;
}

#status.error {
  color: #e66;
}

.challenge-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}

.challenge-goal {
  font-size: 0.95rem;
  color: #aaa;
}

.challenge-timer {
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #e0e0e0;
  min-width: 3.5rem;
}

.restart-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid #555;
  border-radius: 6px;
  background: #333;
  color: #e0e0e0;
  cursor: pointer;
}

.restart-btn:hover {
  background: #444;
  border-color: #666;
}

.wallet-summary {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.wallet-cash {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.25rem;
  font-weight: 500;
}

.balance-cash-icon {
  width: 1.5rem;
  height: 1.5rem;
  object-fit: contain;
}

.wallet-profit {
  font-size: 0.95rem;
  color: #aaa;
}

.wallet-profit .profit-value.positive {
  color: #6b9;
  font-weight: 500;
}

.wallet-profit .profit-value.negative {
  color: #e66;
  font-weight: 500;
}

.trading-desk {
  display: flex;
  flex-direction: column;
  margin-bottom: 1.5rem;
}

.trading-table-wrap {
  background: #252525;
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
}

.trading-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.trading-table th,
.trading-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #333;
  vertical-align: middle;
}

.trading-table th {
  color: #888;
  font-weight: 500;
}

.trading-table .col-resource {
  background: rgba(0, 0, 0, 0.2);
  width: 1%;
  white-space: nowrap;
  vertical-align: middle;
}

.trading-table tbody tr:first-child .col-resource {
  border-radius: 6px 0 0 0;
}

.resource-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.resource-cell .resource-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: #e0e0e0;
  order: 1;
}

.resource-cell .resource-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  order: 2;
}

.resource-cell .resource-icon.resource-icon--has-stock {
  box-shadow: 0 0 0 2px #4ad44c;
}

.resource-cell .resource-qty {
  font-size: 0.9rem;
  font-weight: 500;
  color: #aaa;
  order: 3;
}

.trading-table .col-market {
  min-width: 10rem;
}

.market-cell-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.sparkline-wrap {
  flex: 1;
  min-width: 0;
  height: 72px;
}

.price-sparkline {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.market-right-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.current-price-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.current-price-icon {
  width: 1rem;
  height: 1rem;
  object-fit: contain;
  flex-shrink: 0;
}

.current-price {
  font-weight: 600;
  font-size: 1.05rem;
  color: #e0e0e0;
}

.trade-buttons {
  display: flex;
  gap: 0.4rem;
}

main section {
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem 0;
  color: #aaa;
}

#orderbook-tables {
  display: block;
}

.trading-table .price-sell {
  color: #e88;
}

.trading-table .price-buy {
  color: #8e8;
}

.trading-table button {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.trading-table .buy-btn {
  background: #2a5a2a;
  color: #cec;
}

.trading-table .buy-btn:hover {
  background: #3a6a3a;
}

.trading-table .sell-btn {
  background: #5a2a2a;
  color: #ecc;
}

.trading-table .sell-btn:hover {
  background: #6a3a3a;
}

.resource-label {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.trading-table .resource-label {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.trading-table .resource-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  display: block;
}

.resource-icon {
  width: 4rem;
  height: 4rem;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}

.trading-table .resource-name {
  font-size: 0.75rem;
  color: #ccc;
}

.resource-name {
  font-size: 0.8rem;
  color: #ccc;
}

.trading-table .offers-cell {
  vertical-align: top;
}

.offers-lines {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.offer-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}


#log {
  font-size: 0.85rem;
}

#log-entries {
  margin: 0;
  padding-left: 1.25rem;
  max-height: 200px;
  overflow-y: auto;
  background: #252525;
  border-radius: 6px;
  padding: 0.75rem 0.75rem 0.75rem 2rem;
}

#log-entries li {
  margin-bottom: 0.25rem;
}

#log-entries li.error {
  color: #e88;
}

#log-entries li.success {
  color: #8e8;
}

/* Congrats modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  background: #252525;
  border-radius: 12px;
  padding: 2rem;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.intro-content h2 {
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
  color: #e0e0e0;
}

.intro-content p {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: #ccc;
  line-height: 1.4;
}

.intro-content .best-time-line {
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  color: #aaa;
}

.intro-content .best-time-line span {
  color: #6b9;
  font-weight: 600;
}

.play-btn {
  padding: 0.6rem 2rem;
  font-size: 1.1rem;
  border: none;
  border-radius: 8px;
  background: #2a5a2a;
  color: #cec;
  cursor: pointer;
}

.play-btn:hover {
  background: #3a6a3a;
}

.congrats-content h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
  color: #6b9;
}

.congrats-content p {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
  color: #e0e0e0;
}

.congrats-content .new-best-line {
  margin: 0 0 1.25rem 0;
  font-size: 1rem;
  color: #6b9;
  font-weight: 600;
}

.congrats-name-form {
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.congrats-name-form label {
  font-size: 0.9rem;
  color: #aaa;
}

.congrats-name-form input {
  width: 100%;
  max-width: 16rem;
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  border: 1px solid #555;
  border-radius: 6px;
  background: #1a1a1a;
  color: #e0e0e0;
}

.submit-score-btn {
  width: 100%;
  max-width: 16rem;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 6px;
  background: #2a4a5a;
  color: #cee;
  cursor: pointer;
}

.submit-score-btn:hover {
  background: #3a5a6a;
}

.congrats-submitted {
  margin: 0.5rem 0;
  font-size: 0.95rem;
  color: #aaa;
}

.leaderboard-block {
  margin: 1rem 0;
  width: 100%;
}

.leaderboard-block h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  color: #888;
}

.leaderboard-list {
  margin: 0;
  padding-left: 1.5rem;
  font-size: 0.9rem;
  color: #ccc;
}

.leaderboard-block .leaderboard-list {
  max-height: 8rem;
  overflow-y: auto;
}

.leaderboard-list li {
  margin-bottom: 0.25rem;
}

.leaderboard-modal-content {
  min-width: 14rem;
}

.leaderboard-modal-content h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  color: #e0e0e0;
}

.leaderboard-full-list {
  list-style: decimal;
  text-align: left;
  max-height: 20rem;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding-left: 2rem;
}

.close-leaderboard-btn {
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 6px;
  background: #444;
  color: #e0e0e0;
  cursor: pointer;
}

.close-leaderboard-btn:hover {
  background: #555;
}

.leaderboard-empty {
  list-style: none;
  padding-left: 0;
  color: #666;
}

.play-again-btn {
  padding: 0.6rem 1.25rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  background: #2a5a2a;
  color: #cec;
  cursor: pointer;
}

.play-again-btn:hover {
  background: #3a6a3a;
}