* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1d6b2b;
  color: #222;
  font-family: "Comic Sans MS", "Chalkboard SE", "Comic Neue", system-ui, sans-serif;
  touch-action: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: none;
}

/* ---------- Menus ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vh;
  padding: 2vh 3vw;
  background: rgba(255, 253, 244, 0.93);
  overflow-y: auto;
}

.screen.dim {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

h1.logo {
  margin: 0;
  font-size: 11vh;
  letter-spacing: 0.05em;
  color: #222;
  text-shadow: 4px 4px 0 #f2b01c;
}

h1.logo span {
  color: #d93030;
}

h2 {
  margin: 0;
  font-size: 6vh;
}

.credit {
  margin: 0;
  font-size: 2.6vh;
  color: #555;
}

.title-art {
  display: flex;
  align-items: flex-end;
  gap: 2vw;
  height: 30vh;
}

.title-art img {
  height: 100%;
  object-fit: contain;
}

.title-art img.car {
  height: 55%;
}

.row {
  display: flex;
  gap: 2vw;
  align-items: center;
  justify-content: center;
}

.row.small {
  font-size: 3vh;
}

.big,
.pill {
  border: 4px solid #222;
  border-radius: 18px;
  background: #f2b01c;
  color: #222;
  font-weight: bold;
  box-shadow: 0 6px 0 #222;
}

.big {
  font-size: 5vh;
  padding: 1.5vh 4vw;
}

.big.alt {
  background: #7ec8f2;
}

.pill {
  font-size: 3.2vh;
  padding: 1vh 2.5vw;
  background: #fff;
}

.big:active,
.pill:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #222;
}

.cards {
  display: flex;
  gap: 2vw;
  justify-content: center;
  flex-wrap: wrap;
}

.card {
  width: 20vw;
  min-height: 46vh;
  border: 4px solid #999;
  border-radius: 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 1.5vh 1vw;
  font-size: 3.2vh;
}

.card.selected {
  border-color: #d93030;
  background: #fff4d6;
  box-shadow: 0 0 0 4px #f2b01c;
}

.card img {
  max-width: 100%;
  height: 30vh;
  object-fit: contain;
}

.card.car {
  width: 16.5vw;
  min-height: 40vh;
  padding: 1vh 0.6vw;
}

.card.car .stat {
  font-size: 2.1vh;
}

.card.car .stat .name {
  width: 3.6em;
}

.card.car img {
  height: 18vh;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.6vw;
  width: 100%;
  font-size: 2.6vh;
}

.stat .name {
  width: 5.5em;
  text-align: left;
}

.stat .bar {
  flex: 1;
  height: 1.8vh;
  border: 2px solid #222;
  border-radius: 6px;
  background: #eee;
  overflow: hidden;
}

.stat .bar div {
  height: 100%;
  background: #2e9e44;
}

/* ---------- Garage ---------- */
.garage {
  display: flex;
  gap: 3vw;
  align-items: flex-start;
}

.garage-car {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1vh;
  width: 26vw;
}

#garage-stats {
  width: 100%;
}

#garage-preview {
  width: 20vw;
  height: auto;
  background: #8fd3ff;
  border: 4px solid #222;
  border-radius: 12px;
}

.label {
  font-size: 2.8vh;
  font-weight: bold;
}

.paints {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8vw;
  justify-content: center;
}

.paint {
  width: 5.5vh;
  height: 5.5vh;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 0 0 2px #222;
}

.paint.selected {
  box-shadow: 0 0 0 5px #d93030;
}

.items {
  display: grid;
  grid-template-columns: repeat(3, 17vw);
  gap: 1.2vw;
}

.item {
  border: 4px solid #999;
  border-radius: 14px;
  background: #fff;
  padding: 0.8vh 0.6vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 2.6vh;
}

.item img {
  height: 11vh;
  max-width: 100%;
  object-fit: contain;
}

.item .effect {
  color: #2e7d32;
  font-size: 2.2vh;
}

.item .state {
  margin-top: 0.5vh;
  font-weight: bold;
  padding: 0.3vh 1vw;
  border-radius: 10px;
  border: 3px solid #222;
}

.item.locked .state {
  background: #f2b01c;
}

.item.locked.poor .state {
  background: #ddd;
  color: #777;
}

.item.on {
  border-color: #2e9e44;
  background: #eaffea;
}

.item.on .state {
  background: #2e9e44;
  color: #fff;
}

.item.off .state {
  background: #fff;
}

.coins {
  font-size: 4vh;
  color: #8a6400;
}

.result-body {
  font-size: 4vh;
  text-align: center;
  line-height: 1.5;
}

.result-body .unlock {
  color: #d93030;
  font-weight: bold;
}

.result-body img {
  height: 12vh;
  vertical-align: middle;
}

.lava-text {
  color: #ff7a1a;
  font-size: 9vh;
  text-shadow: 3px 3px 0 #7a0000;
}

/* ---------- Race HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: 1.5vh;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 2.2vw;
  font-size: 3.6vh;
  font-weight: bold;
  color: #fff;
  text-shadow:
    2px 2px 0 #000,
    -1px -1px 0 #000;
}

.hud-btn {
  pointer-events: auto;
  font-size: 3.4vh;
  border: 3px solid #222;
  border-radius: 10px;
  background: #fff;
  padding: 0 1.2vw;
}

#banner {
  position: absolute;
  top: 22vh;
  width: 100%;
  text-align: center;
  font-size: 16vh;
  font-weight: bold;
  color: #fff;
  text-shadow:
    5px 5px 0 #d93030,
    -2px -2px 0 #000;
}

#hint {
  position: absolute;
  top: 12vh;
  width: 100%;
  text-align: center;
  font-size: 7vh;
  font-weight: bold;
  color: #ffeb3b;
  text-shadow: 3px 3px 0 #000;
}

#toast {
  position: absolute;
  top: 8vh;
  width: 100%;
  text-align: center;
  font-size: 4vh;
  font-weight: bold;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

/* ---------- Touch controls (layout from Ivan's drawing) ---------- */
#controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.ctl {
  pointer-events: auto;
  position: absolute;
  border: 4px solid #222;
  background: rgba(255, 255, 255, 0.82);
  font-weight: bold;
  color: #222;
}

.ctl.pressed {
  background: #f2b01c;
}

/* One-finger joystick: appears where the left finger lands. */
#joy-zone {
  pointer-events: auto;
  position: absolute;
  left: 0;
  bottom: 0;
  width: 45vw;
  height: 82vh;
  touch-action: none;
}

#joy-base {
  position: absolute;
  width: 30vh;
  height: 30vh;
  margin: -15vh 0 0 -15vh;
  border-radius: 50%;
  border: 4px solid rgba(34, 34, 34, 0.6);
  background: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

#joy-base.active {
  background: rgba(255, 255, 255, 0.45);
}

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13vh;
  height: 13vh;
  margin: -6.5vh 0 0 -6.5vh;
  border-radius: 50%;
  border: 4px solid #222;
  background: rgba(242, 176, 28, 0.95);
}

.actions {
  position: absolute;
  right: 2vw;
  bottom: 3vh;
  width: 44vh;
  height: 46vh;
}

.bubble {
  border-radius: 45%;
  width: 15vh;
  height: 13vh;
  font-size: 3vh;
  line-height: 1.1;
}

.seat {
  left: 0;
  top: 7vh;
}

.jump {
  right: 0;
  top: 4vh;
  width: 18vh;
  height: 22vh;
  border-radius: 22px;
  font-size: 4.5vh;
  background: rgba(255, 235, 59, 0.92);
}

.stop {
  right: 0;
  bottom: 0;
  width: 26vh;
  height: 15vh;
  border-radius: 16px;
  font-size: 5vh;
  background: rgba(240, 80, 70, 0.92);
}

#rotate {
  display: none;
}

@media (orientation: portrait) {
  #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 10;
    align-items: center;
    justify-content: center;
    background: #1d6b2b;
    color: #fff;
    font-size: 6vw;
    text-align: center;
  }
}

#car-list {
  gap: 1.2vw;
  flex-wrap: nowrap;
}

.garage-cars {
  display: flex;
  gap: 0.6vw;
  justify-content: center;
}

.garage-cars button {
  width: 5.4vw;
  height: 5.4vw;
  padding: 0.3vw;
  border: 3px solid #999;
  border-radius: 10px;
  background: #fff;
}

.garage-cars button.selected {
  border-color: #d93030;
  background: #fff4d6;
  box-shadow: 0 0 0 3px #f2b01c;
}

.garage-cars img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- Club board ---------- */
.board {
  display: flex;
  flex-direction: column;
  gap: 0.6vh;
  width: 60vw;
  max-height: 64vh;
  overflow-y: auto;
  font-size: 3.4vh;
}

.board .row-score {
  display: flex;
  align-items: center;
  gap: 1.5vw;
  padding: 0.4vh 1.5vw;
  border: 3px solid #999;
  border-radius: 12px;
  background: #fff;
}

.board .row-score.me {
  border-color: #d93030;
  background: #fff4d6;
}

.board .rank {
  width: 2.5em;
  font-weight: bold;
}

.board .who {
  flex: 1;
  font-weight: bold;
}

.board img {
  height: 6vh;
  width: 8vh;
  object-fit: contain;
}

.board .time {
  font-weight: bold;
  color: #1d6b2b;
}

.board .empty {
  text-align: center;
  font-size: 3.6vh;
}

#name-input {
  font: inherit;
  font-size: 6vh;
  width: 40vw;
  padding: 1vh 1vw;
  border: 4px solid #222;
  border-radius: 14px;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

.note {
  margin: 0;
  font-size: 3vh;
  color: #555;
}

body:not(.in-club) .board-only {
  display: none;
}
