:root {
  color-scheme: light;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ink: #17202a;
  --muted: #5d6d7e;
  --paper: #fffaf2;
  --road: #687788;
  --road-edge: #445364;
  --sky: #9ee7ff;
  --grass: #91dd8f;
  --food: #ff6b6b;
  --book: #4dabf7;
  --gift: #cc5de8;
  --sports: #51cf66;
  --tech: #ffd43b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: #f7fbff;
  color: var(--ink);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.host-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #9ee7ff 0%, #d7f8ff 42%, #91dd8f 42%, #7ccd7b 100%);
}

.host-topbar {
  min-height: 76px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(260px, 1fr);
  align-items: center;
  gap: 16px;
  background: rgba(255, 250, 242, 0.92);
  border-bottom: 3px solid rgba(23, 32, 42, 0.14);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: conic-gradient(from 45deg, #ff6b6b, #ffd43b, #51cf66, #4dabf7, #cc5de8, #ff6b6b);
  border: 4px solid white;
  box-shadow: 0 8px 20px rgba(23, 32, 42, 0.14);
  display: grid;
  place-items: center;
  font-size: 25px;
  font-weight: 900;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 2rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p,
.status-pill p,
.mini-stat span,
.event-feed p {
  margin: 0;
  color: var(--muted);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill {
  min-width: 112px;
  padding: 8px 12px;
  border-radius: 8px;
  background: white;
  border: 2px solid rgba(23, 32, 42, 0.1);
  text-align: center;
}

.status-pill strong {
  display: block;
  font-size: 1.2rem;
  line-height: 1.05;
}

.host-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-btn,
.ghost-btn,
.danger-btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
  color: var(--ink);
  background: white;
  border: 2px solid rgba(23, 32, 42, 0.12);
  box-shadow: 0 5px 0 rgba(23, 32, 42, 0.08);
}

.primary-btn {
  color: white;
  background: #188753;
}

.danger-btn {
  color: white;
  background: #d9480f;
}

.primary-btn:active,
.ghost-btn:active,
.danger-btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(23, 32, 42, 0.08);
}

.host-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.race-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
}

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

.lobby-overlay,
.finish-overlay,
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 250, 242, 0.5);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.lobby-panel,
.finish-panel {
  width: min(940px, calc(100vw - 40px));
  max-height: calc(100vh - 160px);
  overflow: auto;
  padding: 24px;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid rgba(23, 32, 42, 0.12);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(23, 32, 42, 0.18);
  pointer-events: auto;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 24px;
  align-items: center;
}

.qr-box {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border: 10px solid white;
  box-shadow: 0 10px 24px rgba(23, 32, 42, 0.14);
}

.room-code {
  display: grid;
  place-items: center;
  min-height: 92px;
  border-radius: 8px;
  background: #17202a;
  color: white;
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 4.5rem);
  letter-spacing: 0.08em;
}

.join-url {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef6ff;
  color: #154360;
  font-weight: 800;
  overflow-wrap: anywhere;
  text-align: center;
}

.lobby-copy h2,
.finish-panel h2 {
  margin: 0 0 12px;
  font-size: clamp(1.8rem, 3.4vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.lobby-copy p {
  margin: 0 0 16px;
  font-size: 1.08rem;
  color: var(--muted);
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mini-stat {
  padding: 12px;
  border-radius: 8px;
  background: #fff5d6;
  border: 2px solid rgba(23, 32, 42, 0.08);
}

.mini-stat strong {
  display: block;
  font-size: 1.7rem;
}

.countdown-card {
  min-width: 340px;
  padding: 24px 34px;
  text-align: center;
  border-radius: 8px;
  background: white;
  border: 4px solid rgba(23, 32, 42, 0.15);
  box-shadow: 0 18px 50px rgba(23, 32, 42, 0.18);
}

.countdown-word {
  font-size: clamp(3rem, 10vw, 8rem);
  line-height: 0.95;
  font-weight: 1000;
  letter-spacing: 0;
}

.lights {
  margin-top: 18px;
  display: flex;
  gap: 12px;
  justify-content: center;
}

.light {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #d0d7de;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.18);
}

.light.red.on {
  background: #ff3b30;
}

.light.green.on {
  background: #2fce68;
}

.side-panel {
  min-width: 0;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  border-left: 3px solid rgba(23, 32, 42, 0.1);
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  overflow: hidden;
}

.prompt-board {
  padding: 14px;
  border-radius: 8px;
  background: #17202a;
  color: white;
}

.prompt-board small {
  display: block;
  margin-bottom: 5px;
  color: #b9d8ff;
  font-weight: 800;
  text-transform: uppercase;
}

.prompt-board h2 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 2.4vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.lane-list {
  display: grid;
  gap: 8px;
}

.lane-chip {
  min-height: 42px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 900;
}

.class-card,
.event-feed {
  padding: 12px;
  border-radius: 8px;
  background: white;
  border: 2px solid rgba(23, 32, 42, 0.08);
}

.class-card h3,
.event-feed h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.progress-track {
  height: 16px;
  overflow: hidden;
  border-radius: 8px;
  background: #eaf1f8;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #51cf66, #ffd43b);
}

.event-feed {
  min-height: 0;
  overflow: auto;
}

.event-feed ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.event-feed li {
  padding: 9px 10px;
  border-radius: 8px;
  background: #f4f8fb;
  font-weight: 700;
}

.host-bottom {
  min-height: 66px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 250, 242, 0.92);
  border-top: 3px solid rgba(23, 32, 42, 0.12);
  overflow-x: auto;
}

.shop-badge {
  flex: 0 0 auto;
  min-width: 150px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #17202a;
  background: white;
  border: 2px solid rgba(23, 32, 42, 0.12);
  font-weight: 1000;
  text-align: center;
}

.shop-badge.food {
  background: #ffe3e3;
}

.shop-badge.book {
  background: #d0ebff;
}

.shop-badge.gift {
  background: #f3d9fa;
}

.shop-badge.sports {
  background: #d3f9d8;
}

.shop-badge.tech {
  background: #fff3bf;
}

.finish-table {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.finish-row {
  display: grid;
  grid-template-columns: 70px 1fr 140px 120px 160px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: #f4f8fb;
  font-weight: 800;
}

.controller-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 255, 255, 0.7), transparent 28%),
    linear-gradient(135deg, #9ee7ff, #c7f9cc 42%, #fff3bf);
  overflow: hidden;
}

.join-screen {
  width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
}

.join-card {
  width: min(520px, 100%);
  padding: 20px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 8px;
  border: 3px solid rgba(23, 32, 42, 0.12);
  box-shadow: 0 18px 40px rgba(23, 32, 42, 0.16);
}

.join-card h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 10vw, 3.3rem);
  line-height: 0.95;
}

.join-card label {
  display: block;
  margin-top: 12px;
  font-weight: 900;
}

.join-card input {
  width: 100%;
  height: 54px;
  margin-top: 6px;
  padding: 0 12px;
  border: 2px solid rgba(23, 32, 42, 0.18);
  border-radius: 8px;
  font-size: 1.35rem;
  font-weight: 900;
}

.join-card .primary-btn {
  width: 100%;
  height: 58px;
  margin-top: 16px;
  font-size: 1.2rem;
}

.controller-top {
  min-height: 76px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 3px solid rgba(23, 32, 42, 0.1);
}

.car-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.car-dot {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 4px solid white;
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.2);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 1000;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.car-identity h1 {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.5rem);
  line-height: 1;
}

.car-identity p {
  margin: 2px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.boost-meter {
  justify-self: center;
  display: flex;
  gap: 8px;
}

.boost-cell {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #eaf1f8;
  border: 3px solid white;
  font-size: 1.45rem;
  filter: grayscale(1);
}

.boost-cell.ready {
  background: #fff3bf;
  filter: none;
  box-shadow: 0 0 0 3px rgba(255, 212, 59, 0.35);
}

.controller-status {
  justify-self: end;
  text-align: right;
  font-weight: 900;
}

.controller-status span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.controller-main {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(82px, auto) 1fr;
}

.controller-prompt {
  min-height: 82px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: rgba(23, 32, 42, 0.92);
  color: white;
}

.controller-prompt h2 {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.controller-prompt p {
  margin: 4px 0 0;
  color: #b9d8ff;
  font-weight: 800;
}

.list-count {
  min-width: 92px;
  min-height: 62px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: white;
  color: var(--ink);
  font-weight: 1000;
  font-size: 1.5rem;
}

.drive-pad {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(160px, 0.8fr) 1fr;
  gap: 12px;
  padding: 12px;
}

.pedal {
  min-height: 100%;
  border-radius: 8px;
  color: white;
  font-size: clamp(2rem, 9vw, 4.6rem);
  font-weight: 1000;
  letter-spacing: 0;
  box-shadow: inset 0 -12px rgba(0, 0, 0, 0.12), 0 8px 0 rgba(23, 32, 42, 0.14);
  touch-action: none;
}

.pedal.brake {
  background: #e03131;
}

.pedal.go {
  background: #188753;
}

.pedal.active {
  transform: translateY(5px);
  box-shadow: inset 0 -5px rgba(0, 0, 0, 0.12), 0 3px 0 rgba(23, 32, 42, 0.14);
}

.middle-controls {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
}

.boost-button {
  border-radius: 8px;
  background: #ffd43b;
  color: #17202a;
  font-size: clamp(1.4rem, 5vw, 2.5rem);
  font-weight: 1000;
  box-shadow: inset 0 -10px rgba(0, 0, 0, 0.1), 0 8px 0 rgba(23, 32, 42, 0.13);
  touch-action: none;
}

.boost-button:disabled {
  opacity: 0.46;
  filter: grayscale(1);
}

.tilt-card {
  min-height: 92px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  display: grid;
  gap: 7px;
  align-items: center;
}

.tilt-track {
  height: 26px;
  border-radius: 8px;
  background: #d9edf7;
  position: relative;
  overflow: hidden;
}

.tilt-dot {
  position: absolute;
  top: 3px;
  left: calc(50% - 10px);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #17202a;
}

.tilt-card input {
  width: 100%;
}

.error-text {
  margin: 10px 0 0;
  color: #c92a2a;
  font-weight: 900;
}

@media (max-width: 980px) {
  .host-topbar {
    grid-template-columns: 1fr;
  }

  .host-actions,
  .status-row {
    justify-content: flex-start;
  }

  .host-main {
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: none;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .drive-pad {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 0.8fr 1fr;
  }

  .controller-top {
    grid-template-columns: 1fr;
  }

  .controller-status {
    justify-self: start;
    text-align: left;
  }
}
