@import url("https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:wght@600;700;800&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap");

/* =========================================================
   RETRO-POP / RISOGRAPH STREET POSTER DESIGN SYSTEM
   Warm Cream Paper + Crisp Ink Outlines + Tactile 3D Offset
   ========================================================= */
:root {
  --paper: #fdf6e3;
  --paper-2: #f6ebd1;
  --card: #fffdf7;
  --ink: #1a1614;
  --muted: #5c534a;
  --orange: #ff5a1f;
  --yellow: #ffd43b;
  --mint: #00b894;
  --blue: #2d7ff9;
  --red: #e63946;
  --shadow: 4px 4px 0px #1a1614;
  --shadow-lg: 6px 6px 0px #1a1614;
  --border: 3px solid #1a1614;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-sans: "Plus Jakarta Sans", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  color: var(--ink);
  font-family: var(--font-sans);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(26, 22, 20, 0.085) 1.3px, transparent 1.3px);
  background-size: 18px 18px;
  overflow-x: hidden;
}

button,
input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* Tactile Retro-Pop Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: var(--border);
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0px var(--ink);
}

.btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0px var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: 2px 2px 0px var(--ink);
}

.btn-orange {
  background: var(--orange);
  color: #fff;
}

.btn-yellow {
  background: var(--yellow);
  color: var(--ink);
}

.btn-mint {
  background: var(--mint);
  color: #fff;
}

.btn-blue {
  background: var(--blue);
  color: #fff;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 11px;
  box-shadow: 3px 3px 0px var(--ink);
}

.btn-lg {
  padding: 15px 26px;
  font-size: 18px;
  border-radius: 16px;
}

/* Badges & Stickers */
.sticker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 2px 2px 0px var(--ink);
}

.sticker-mint {
  background: var(--mint);
  color: #fff;
}

.sticker-orange {
  background: var(--orange);
  color: #fff;
}

.sticker-blue {
  background: var(--blue);
  color: #fff;
}

.sticker-red {
  background: var(--red);
  color: #fff;
}

/* Landing Page */
.landing-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}

.hero-badge {
  transform: rotate(-2deg);
  margin-bottom: 14px;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(46px, 8vw, 82px);
  line-height: 0.96;
  margin: 0 0 12px;
  text-align: center;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-shadow: 4px 4px 0px var(--yellow);
}

.hero-sub {
  color: var(--muted);
  font-size: clamp(15px, 2vw, 18px);
  max-width: 560px;
  text-align: center;
  margin: 0 0 32px;
  line-height: 1.5;
  font-weight: 600;
}

.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 22px;
  width: 100%;
  max-width: 760px;
}

.poster-card {
  background: var(--card);
  border: var(--border);
  border-radius: 22px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.poster-card h2 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0;
}

.poster-card p {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  flex: 1;
}

.lan-strip {
  margin-top: 26px;
  padding: 10px 18px;
  background: var(--paper-2);
  border: 2.5px dashed var(--ink);
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
}

/* Host TV Shell */
.host-shell {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.lobby-screen {
  width: 100%;
  height: 100%;
  padding: 20px 28px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.lobby-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-stamp {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: var(--border);
  background: var(--orange);
  box-shadow: 3px 3px 0px var(--ink);
  display: grid;
  place-items: center;
  transform: rotate(-4deg);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.lobby-main {
  display: grid;
  grid-template-columns: 320px 1fr 310px;
  gap: 20px;
  min-height: 0;
}

.panel {
  background: var(--card);
  border: var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.qr-panel {
  align-items: center;
  text-align: center;
  justify-content: space-between;
  background: #fff9e6;
}

.ticket-code {
  width: 100%;
  background: var(--yellow);
  border: var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 3px 3px 0px var(--ink);
}

.ticket-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.ticket-value {
  font-family: var(--font-display);
  font-size: 50px;
  font-weight: 800;
  letter-spacing: 0.16em;
  margin-left: 0.16em;
  line-height: 1.02;
}

.qr-box {
  background: var(--paper);
  border: var(--border);
  border-radius: 18px;
  padding: 10px;
  width: 200px;
  height: 200px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}

.qr-box img {
  width: 100%;
  height: 100%;
  display: block;
}

.join-url-box {
  width: 100%;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  word-break: break-all;
}

/* Players Grid */
.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
  gap: 14px;
  overflow-y: auto;
  align-content: start;
  padding: 2px 4px 6px 2px;
}

.racer-card {
  position: relative;
  background: var(--paper);
  border: var(--border);
  border-radius: 18px;
  padding: 12px 10px;
  box-shadow: 3px 3px 0px var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: stickerPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes stickerPop {
  from {
    opacity: 0;
    transform: scale(0.84) rotate(-3deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.racer-card .kick-x {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 11px;
  cursor: pointer;
}

.racer-card .kick-x:hover {
  background: var(--red);
  color: #fff;
}

.racer-name {
  font-weight: 800;
  font-size: 14px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-slot {
  border: 2.5px dashed rgba(26, 22, 20, 0.25);
  border-radius: 18px;
  min-height: 132px;
  display: grid;
  place-items: center;
  color: rgba(26, 22, 20, 0.4);
  font-weight: 800;
  font-size: 13px;
}

/* How to play card on Lobby */
.howto-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.howto-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 700;
}

.howto-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--yellow);
  display: grid;
  place-items: center;
  font-size: 17px;
  flex-shrink: 0;
}

.lobby-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--card);
  border: var(--border);
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
}

/* Race Screen */
.game-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #2b2d30;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.race-hud {
  position: absolute;
  top: 14px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.hud-box {
  background: var(--card);
  border: var(--border);
  border-radius: 16px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.progress-track {
  flex: 1;
  max-width: 680px;
  background: var(--card);
  border: var(--border);
  border-radius: 18px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  position: relative;
}

.progress-rail {
  height: 10px;
  border-radius: 999px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  position: relative;
}

.progress-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  transition: left 0.08s linear;
}

.center-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
  z-index: 10;
}

.banner-big {
  font-family: var(--font-display);
  font-size: clamp(68px, 12vw, 130px);
  color: var(--yellow);
  -webkit-text-stroke: 5px var(--ink);
  text-shadow: 8px 8px 0px var(--ink);
  animation: stickerPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.banner-sub {
  background: var(--card);
  border: var(--border);
  border-radius: 16px;
  padding: 10px 20px;
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 18px;
}

/* Results Podium */
.results-overlay {
  position: absolute;
  inset: 0;
  background: rgba(253, 246, 227, 0.92);
  background-image: radial-gradient(rgba(26, 22, 20, 0.08) 1.3px, transparent 1.3px);
  background-size: 18px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 18px;
  z-index: 25;
}

.results-title {
  font-family: var(--font-display);
  font-size: clamp(36px, 6vw, 56px);
  margin: 0;
  text-shadow: 4px 4px 0px var(--yellow);
}

.podium-list {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.podium-row {
  display: grid;
  grid-template-columns: 46px 64px 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: var(--border);
  border-radius: 16px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
}

.podium-row.rank-1 {
  background: #fff3bf;
  box-shadow: var(--shadow-lg);
}

/* =========================================================
   MOBILE CONTROLLER (3-BUTTON TACTILE ARCADE DECK + VIP MENU)
   ========================================================= */
.play-body {
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.join-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  touch-action: pan-y;
}

.join-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  outline: none;
}

.field input:focus {
  background: #fff;
  box-shadow: 3px 3px 0px var(--orange);
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  cursor: pointer;
}

.swatch.active {
  transform: scale(1.16);
  box-shadow: 0 0 0 3px var(--yellow), 0 0 0 5px var(--ink);
}

.vehicle-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.veh-btn {
  padding: 8px 6px;
  border-radius: 12px;
  border: 2.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.veh-btn.active {
  background: var(--yellow);
  box-shadow: 3px 3px 0px var(--ink);
}

.error-toast {
  background: #ffe3e3;
  border: 2.5px solid var(--red);
  color: #a61e22;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 800;
}

.controller-screen {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background-color: var(--paper);
  background-image: radial-gradient(rgba(26, 22, 20, 0.08) 1.3px, transparent 1.3px);
  background-size: 16px 16px;
}

.ctrl-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: var(--border);
}

.ctrl-stats-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--paper-2);
  border-bottom: 2.5px solid var(--ink);
}

.nitro-meter {
  height: 18px;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.nitro-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--yellow), var(--orange));
  transition: width 0.08s linear;
}

.ctrl-deck {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  height: 100%;
  min-height: 0;
}

.steer-pad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: 100%;
}

.steer-btn {
  border: 3.5px solid var(--ink);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 5px 5px 0px var(--ink);
  font-family: var(--font-display);
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 800;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  touch-action: none;
}

.steer-btn:active,
.steer-btn.pressed {
  transform: translate(4px, 4px);
  box-shadow: 1px 1px 0px var(--ink);
  background: var(--yellow);
}

.gas-pad {
  display: grid;
  grid-template-rows: 1.55fr 0.85fr;
  gap: 12px;
  height: 100%;
}

.gas-btn {
  border: 3.5px solid var(--ink);
  border-radius: 24px;
  background: var(--orange);
  color: #fff;
  box-shadow: 5px 5px 0px var(--ink);
  font-family: var(--font-display);
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.gas-btn:active,
.gas-btn.pressed {
  transform: translate(4px, 4px);
  box-shadow: 1px 1px 0px var(--ink);
  background: #e04810;
}

.nitro-btn {
  border: 3.5px solid var(--ink);
  border-radius: 20px;
  background: #e2dac6;
  color: var(--muted);
  box-shadow: 4px 4px 0px var(--ink);
  font-family: var(--font-display);
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 800;
  touch-action: none;
}

.nitro-btn.ready {
  background: var(--yellow);
  color: var(--ink);
  animation: nitroPulse 0.45s infinite alternate;
}

@keyframes nitroPulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.03);
    background: #ffe066;
  }
}

.phone-overlay {
  position: absolute;
  inset: 0;
  background: rgba(253, 246, 227, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  z-index: 15;
}

.vip-remote {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: var(--border);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vip-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 1024px) {
  .lobby-main {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .host-shell {
    overflow-y: auto;
  }
}

@media (orientation: portrait) and (max-width: 640px) {
  .ctrl-deck {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1.15fr;
  }
}
