* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(230, 57, 70, 0.28), transparent 50%),
    radial-gradient(ellipse at 90% 80%, rgba(45, 106, 79, 0.35), transparent 45%),
    linear-gradient(160deg, #1a120c 0%, #2d1b14 45%, #1b2e22 100%);
  font-family: 'Press Start 2P', monospace;
  color: #fff8ef;
  image-rendering: pixelated;
}

#game-container {
  position: relative;
  border: 4px solid #e9c46a;
  border-radius: 8px;
  box-shadow:
    0 0 0 4px #14080c,
    0 0 40px rgba(230, 57, 70, 0.28),
    inset 0 0 60px rgba(0, 0, 0, 0.3);
  background: #14080c;
}

#home-link {
  position: absolute;
  top: -28px;
  left: 0;
  font-size: 7px;
  color: #e9c46a;
  text-decoration: none;
}

#home-link:hover {
  color: #fff;
}

#fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  width: 34px;
  height: 34px;
  border: 2px solid #e9c46a;
  border-radius: 4px;
  background: rgba(20, 8, 12, 0.88);
  color: #e9c46a;
  font: 12px 'Press Start 2P', monospace;
  line-height: 1;
  cursor: pointer;
}

#fullscreen-btn:hover,
#fullscreen-btn:focus-visible {
  background: #e9c46a;
  color: #1a120c;
}

#game-container:fullscreen,
#game-container:-webkit-full-screen {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: #1a120c;
}

#game-container:fullscreen #game,
#game-container:-webkit-full-screen #game {
  width: min(100vw, calc(100vh * 800 / 480));
  height: min(100vh, calc(100vw * 480 / 800));
}

#game {
  display: block;
  background: #7ec8e3;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 52px;
  pointer-events: none;
  text-shadow: 2px 2px 0 #000;
}

#hud.hidden {
  display: none;
}

.hud-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 9px;
  line-height: 1.6;
  margin-bottom: 8px;
}

#time-label {
  color: #ffd166;
}

#apples-label {
  color: #ff8fa3;
}

#money-label {
  color: #8eed8e;
}

#board {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.board-chip {
  font-size: 6px;
  line-height: 1.5;
  padding: 4px 6px;
  border: 2px solid #000;
  background: rgba(0, 0, 0, 0.45);
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 6, 4, 0.72);
  z-index: 15;
}

#overlay.hidden {
  display: none;
}

#overlay-content {
  width: min(420px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 22px 18px 18px;
  border: 4px solid #e9c46a;
  background: linear-gradient(180deg, #3d2914 0%, #1a120c 100%);
  box-shadow: 4px 4px 0 #000;
  text-align: center;
}

#overlay-content h2 {
  font-size: 13px;
  line-height: 1.5;
  color: #ffd166;
  margin-bottom: 12px;
}

#overlay-content p,
#overlay-content label {
  font-size: 7px;
  line-height: 1.8;
  color: #fff8ef;
  margin-bottom: 10px;
}

#overlay-content .muted {
  color: #d4b896;
}

#overlay-content .error {
  color: #ff8fa3;
}

#overlay-content input {
  width: 100%;
  font-family: inherit;
  font-size: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 2px solid #e9c46a;
  background: #1a120c;
  color: #fff8ef;
  text-align: center;
}

#overlay-content input.name-input {
  text-transform: none;
  letter-spacing: 0;
}

#overlay-content input.code-input {
  text-transform: uppercase;
  letter-spacing: 2px;
}

#overlay-content .actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

#overlay-content button {
  font-family: inherit;
  font-size: 8px;
  padding: 10px 12px;
  border: 2px solid #e9c46a;
  background: #e9c46a;
  color: #1a120c;
  cursor: pointer;
}

#overlay-content button.ghost {
  background: transparent;
  color: #fff8ef;
}

#overlay-content button:hover,
#overlay-content button:focus-visible {
  background: #fff8ef;
  color: #1a120c;
}

#overlay-content .prices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0 14px;
  text-align: left;
}

#overlay-content .prices span {
  font-size: 6px;
  line-height: 1.6;
  color: #fff8ef;
}

#overlay-content .invite {
  font-size: 6px;
  line-height: 1.6;
  word-break: break-all;
  color: #d4b896;
}

#overlay-content .roster {
  list-style: none;
  text-align: left;
  margin: 8px 0 14px;
}

#overlay-content .roster li {
  font-size: 7px;
  line-height: 1.7;
  margin-bottom: 6px;
  padding-left: 8px;
  border-left: 6px solid #e9c46a;
}

#overlay-content .rank {
  list-style: none;
  text-align: left;
  margin: 10px 0 14px;
}

#overlay-content .rank li {
  font-size: 7px;
  line-height: 1.7;
  margin-bottom: 8px;
  padding: 8px;
  border: 2px solid #000;
  background: rgba(0, 0, 0, 0.28);
}

#overlay-content .rank li.win {
  border-color: #e9c46a;
  background: rgba(233, 196, 106, 0.18);
}

#overlay-content .rank .who {
  color: #ffd166;
}

#controls-help {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -26px;
  font-size: 6px;
  line-height: 1.6;
  color: #d4b896;
  text-align: center;
}

#controls-help kbd {
  display: inline-block;
  padding: 2px 4px;
  border: 1px solid #e9c46a;
  color: #e9c46a;
}

@media (max-width: 840px) {
  #game {
    width: min(100vw - 24px, 800px);
    height: auto;
  }

  #controls-help {
    position: static;
    margin-top: 10px;
  }

  #home-link {
    top: 8px;
    left: 8px;
    z-index: 20;
    background: rgba(20, 8, 12, 0.8);
    padding: 6px 8px;
  }
}
