* {
  box-sizing: border-box;
}

:root {
  --ink: #1a1612;
  --paper: #f6f0e6;
  --green: #7ea94c;
  --green-deep: #5d8433;
  --cream: #eadbb3;
  --brown: #8c6440;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(to bottom, rgba(255,255,255,0.12), rgba(255,255,255,0.02)),
    linear-gradient(to right, transparent 0 24px, rgba(0,0,0,0.02) 24px 25px, transparent 25px 100%),
    linear-gradient(to bottom, transparent 0 24px, rgba(0,0,0,0.02) 24px 25px, transparent 25px 100%),
    var(--paper);
  color: var(--ink);
  font-family: 'VT323', monospace;
  image-rendering: pixelated;
}

body.lock-scroll {
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.frame {
  min-height: 100vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud,
.play-layout {
  width: min(1200px, 100%);
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border: 4px solid var(--ink);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 8px 8px 0 var(--ink);
  margin-bottom: 16px;
}

.hud-left,
.hud-right,
.title-row,
.legend,
.overlay-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand,
.hud-pill,
.scorebox span,
.overlay-kicker,
.overlay-note,
.subtitle,
.footer-copy {
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand,
.scorebox strong,
h1,
.overlay h2 {
  font-family: 'Patrick Hand SC', cursive;
}

.brand {
  font-size: 34px;
  font-weight: 700;
}

.hud-pill {
  border: 2px solid var(--ink);
  padding: 5px 9px;
  background: #fff;
  font-size: 14px;
}

.hud-pill.accent {
  background: #dfead0;
}

.hud-right {
  margin-left: auto;
}

.scorebox {
  min-width: 106px;
  border: 2px solid var(--ink);
  background: #fff;
  padding: 6px 10px;
  display: grid;
  gap: 2px;
  justify-items: center;
}

.scorebox span {
  font-size: 12px;
}

.scorebox strong {
  font-size: 30px;
  line-height: 1;
}

.score-panel {
  min-height: auto;
  padding: 10px;
}

.score-panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.scorebox.compact {
  min-width: 0;
  padding: 6px 8px;
}

.scorebox.compact span {
  font-size: 11px;
}

.scorebox.compact strong {
  font-size: 24px;
}

.walletbox {
  min-width: 208px;
  border: 2px solid var(--ink);
  background: transparent;
  padding: 6px 9px;
  display: grid;
  gap: 4px;
  align-items: center;
}

.wallet-actions {
  display: flex;
  gap: 6px;
}

.wallet-actions button {
  flex: 1;
}

.walletbox span {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  justify-self: start;
}

#walletBtn {
  border: 2px solid var(--ink);
  background: #cfe4ad;
  color: var(--ink);
  padding: 7px 10px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  min-height: 34px;
}

#walletBtn:hover {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

#walletBtn:disabled {
  opacity: 0.8;
  cursor: default;
  transform: none;
  box-shadow: none;
}

#musicBtn {
  border: 2px solid var(--ink);
  background: #f1ead5;
  color: var(--ink);
  padding: 8px 12px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  min-height: 38px;
}

#musicBtn:hover {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

#musicBtn.music-on {
  background: #cfe4ad;
}

.x-link {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  text-decoration: none;
  cursor: pointer;
  flex: 0 0 auto;
}

.x-link:hover {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

.x-link svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
}

.walletbox small {
  font-size: 14px;
  line-height: 1;
  color: rgba(26, 22, 18, 0.75);
  min-height: 14px;
}

.walletbox.connected {
  background: rgba(240, 246, 231, 0.72);
}

.walletbox.connected #walletBtn {
  background: #bfd99a;
}

.leaderboard-panel {
  min-height: 220px;
}

.round-timer-box {
  border: 3px solid var(--ink);
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

.round-timer-box span {
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.round-timer-box strong {
  font-family: 'Patrick Hand SC', cursive;
  font-size: 34px;
  line-height: 1;
}

.round-bonus {
  margin-top: 10px;
  border: 2px solid var(--ink);
  background: linear-gradient(135deg, #efe3c0 0%, #d9ebbd 100%);
  padding: 10px 12px;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  box-shadow: 0 3px 0 rgba(26, 22, 18, 0.12);
}

.round-subtext {
  margin-top: 12px;
  font-size: 19px;
  line-height: 1.15;
}

.leaderboard-head {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin: 2px 0 8px;
}

.leaderboard-head small {
  font-size: 16px;
  color: rgba(26, 22, 18, 0.72);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 20px;
  line-height: 1;
  list-style: none;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.8);
  padding: 7px 9px;
}

.leaderboard-entry-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.leaderboard-rank {
  display: inline-flex;
  min-width: 28px;
  justify-content: center;
  border: 2px solid var(--ink);
  background: #dfead0;
  font-size: 15px;
  padding: 2px 4px;
}

.leaderboard-name {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.leaderboard-score {
  font-family: 'Patrick Hand SC', cursive;
  font-size: 22px;
}

.leaderboard-list li.empty {
  font-size: 18px;
  color: rgba(26, 22, 18, 0.72);
  justify-content: flex-start;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(560px, 760px) minmax(220px, 1fr);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.left-rail,
.right-rail {
  display: grid;
  gap: 16px;
}

.payouts-panel {
  min-height: 220px;
}

.payout-subtext {
  margin-top: 0;
  font-size: 18px;
  line-height: 1.1;
}

.payout-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.payout-list li {
  border: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.82);
  padding: 8px;
  display: grid;
  gap: 5px;
}

.payout-line-top,
.payout-line-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.payout-tx {
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.payout-time,
.payout-meta {
  font-size: 14px;
  color: rgba(26, 22, 18, 0.72);
}

.payout-amount {
  font-family: 'Patrick Hand SC', cursive;
  font-size: 22px;
}

.payout-list li.empty {
  font-size: 18px;
  color: rgba(26, 22, 18, 0.72);
}

.stage-shell {
  display: grid;
  gap: 14px;
}

.info-panel {
  border: 4px solid var(--ink);
  background: rgba(255, 252, 246, 0.92);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 16px;
  min-height: 180px;
}

.info-panel.score-panel {
  min-height: 0;
  padding: 10px;
}

.panel-title {
  font-family: 'Patrick Hand SC', cursive;
  font-size: 30px;
  line-height: 1;
  margin-bottom: 8px;
}

.info-panel p {
  margin: 12px 0 0;
  font-size: 24px;
  line-height: 1.1;
}

.info-panel strong {
  color: var(--green-deep);
}

.legend.stacked {
  margin-top: 12px;
  justify-content: flex-start;
  flex-direction: column;
  align-items: stretch;
}

.legend.stacked span {
  width: 100%;
}

.stage-copy {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
}

.subtitle {
  font-size: 16px;
  color: rgba(26, 22, 18, 0.78);
}

.legend {
  justify-content: flex-end;
  font-size: 14px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--ink);
  background: rgba(255,255,255,0.8);
  padding: 6px 10px;
}

.dot {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  display: inline-block;
}

.dot.green { background: var(--green); }
.dot.cream { background: var(--cream); }
.dot.blue { background: #63a9d2; }
.dot.brown { background: var(--brown); }

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 4px solid var(--ink);
  box-shadow: 10px 10px 0 var(--ink);
  background: var(--paper);
  overflow: hidden;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(to bottom, rgba(246, 240, 230, 0.32), rgba(246, 240, 230, 0.72));
  transition: opacity 180ms ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  width: min(520px, calc(100% - 36px));
  padding: 22px 20px;
  border: 4px solid var(--ink);
  background: rgba(255, 252, 246, 0.96);
  box-shadow: 8px 8px 0 var(--ink);
  text-align: center;
}

.overlay-kicker,
.overlay-note,
.footer-copy {
  font-size: 13px;
  color: rgba(26, 22, 18, 0.72);
}

.overlay h2 {
  margin: 8px 0 10px;
  font-size: 42px;
  line-height: 0.95;
}

.run-wallet {
  margin: 2px 0 8px;
  font-size: 13px;
  color: rgba(26, 22, 18, 0.62);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.run-score {
  margin: 2px 0 12px;
  font-size: 28px;
  line-height: 1;
  text-transform: uppercase;
}

.run-score strong {
  font-family: 'Patrick Hand SC', cursive;
  font-size: 40px;
  line-height: 1;
  color: #18120c;
}

.overlay p {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.overlay strong {
  color: var(--green-deep);
}

.overlay-actions {
  justify-content: center;
  margin-top: 8px;
}

#startBtn {
  border: 3px solid var(--ink);
  background: var(--green);
  color: #111;
  padding: 10px 18px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

#startBtn:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 var(--ink);
}

#doubleBtn {
  border: 3px solid var(--ink);
  background: #eadbb3;
  color: #111;
  padding: 10px 14px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

#doubleBtn:hover {
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 var(--ink);
}

#doubleBtn:disabled {
  opacity: 0.75;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.hidden {
  display: none !important;
}

.footer-copy {
  text-align: center;
}

@media (max-width: 900px) {
  .hud,
  .stage-copy {
    flex-direction: column;
    align-items: flex-start;
  }

  .play-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .right-rail {
    width: 100%;
  }

  .left-rail {
    width: 100%;
  }

  .hud-right {
    margin-left: 0;
  }

  .walletbox {
    width: 100%;
  }

  #musicBtn {
    width: 100%;
  }

  .wallet-actions {
    width: 100%;
  }

  .legend {
    justify-content: flex-start;
  }

  h1 {
    font-size: 34px;
  }

  .overlay h2 {
    font-size: 34px;
  }

  .overlay p {
    font-size: 20px;
  }
}