:root {
  --lego-red: #e11d48;
  --lego-yellow: #fbbf24;
  --lego-blue: #1d4ed8;
  --lego-green: #16a34a;
  --dark: #0f172a;
  --light: #f8fafc;
  --track: #364152;
  --track-line: #e2e8f0;
}

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

.hidden {
  display: none !important;
}

body {
  font-family: 'Segoe UI', 'Pretendard', sans-serif;
  background: radial-gradient(circle at top left, #1f2937 0%, #0f172a 45%, #020617 100%);
  color: var(--light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(148, 163, 184, 0.12) 18%, transparent 22%),
    radial-gradient(rgba(30, 58, 138, 0.18) 12%, transparent 18%);
  background-size: 48px 48px, 64px 64px;
  mix-blend-mode: screen;
  opacity: 0.35;
  pointer-events: none;
  z-index: -1;
}

.layout {
  flex: 1;
  display: flex;
  max-width: 1200px;
  margin: 2rem auto;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.9), rgba(30, 41, 59, 0.78));
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 24px 60px rgba(8, 16, 28, 0.55);
  position: relative;
}

.layout::after {
  content: '';
  position: absolute;
  inset: 12px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.08);
  pointer-events: none;
}

.sidebar {
  width: 320px;
  padding: 2rem 1.5rem;
  background: linear-gradient(160deg, rgba(15, 23, 42, 0.95), rgba(17, 24, 39, 0.78));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border-right: 1px solid rgba(148, 163, 184, 0.16);
}

.logo {
  font-size: 1.8rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--lego-yellow);
  text-shadow: 0 5px 20px rgba(251, 191, 36, 0.45);
  position: relative;
}

.logo::after {
  content: '브릭 서킷 2024';
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.6);
  margin-left: 0.4rem;
}

.race-info h2,
.controls h2,
.hud h2 {
  font-size: 1.2rem;
  margin-bottom: 0.6rem;
  color: var(--lego-blue);
  text-transform: uppercase;
}

.position-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-left: 0.25rem;
}

.position-list li {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.24), rgba(59, 130, 246, 0.08));
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  font-weight: 600;
  position: relative;
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.18);
}

.position-list li.player-entry {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.35), rgba(234, 179, 8, 0.15));
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.25);
}

.position-list li.rival-entry {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.38), rgba(59, 130, 246, 0.16));
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.35);
}

.position-list .pos-rank {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--light);
  text-align: center;
}

.position-list .pos-driver {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: rgba(226, 232, 240, 0.95);
}

.position-list .pos-gap {
  justify-self: end;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: rgba(226, 232, 240, 0.85);
}

.position-list .pos-chip {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.55);
}

.controls ul {
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.controls li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(30, 41, 59, 0.6);
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  border: 1px solid rgba(100, 116, 139, 0.18);
}

.controls li strong {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  background: rgba(248, 250, 252, 0.1);
  border-radius: 6px;
}

.hud {
  display: grid;
  gap: 0.75rem;
}

.hud-item {
  padding: 0.8rem 1rem;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.28), rgba(16, 185, 129, 0.12));
  border-radius: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(134, 239, 172, 0.18);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.18);
}

.hud-item.studs {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.35), rgba(253, 230, 138, 0.18));
  border: 1px solid rgba(250, 204, 21, 0.25);
  box-shadow: inset 0 0 0 1px rgba(161, 98, 7, 0.22);
}

.hud-item.boost {
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.32), rgba(56, 189, 248, 0.16));
  border: 1px solid rgba(96, 165, 250, 0.28);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.boost-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.boost-percent {
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  color: rgba(226, 232, 240, 0.9);
}

.boost-meter {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: inset 0 0 10px rgba(15, 23, 42, 0.75);
}

.boost-meter.ready {
  box-shadow: inset 0 0 12px rgba(15, 23, 42, 0.85), 0 0 18px rgba(56, 189, 248, 0.55);
}

.boost-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8 0%, #22d3ee 40%, #a855f7 100%);
  transition: width 0.25s ease;
}

.boost-fill[data-ready='true'] {
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.55);
}

.boost-percent.ready {
  color: #facc15;
  text-shadow: 0 0 12px rgba(250, 204, 21, 0.4);
}

.boost-tip {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.3;
  color: rgba(226, 232, 240, 0.7);
}

.hud-item span.label {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 1px;
  color: rgba(226, 232, 240, 0.75);
}

.hud-item span.value {
  font-size: 1.1rem;
  color: #ecfccb;
}

.hud-item span.value small {
  font-size: 0.7rem;
  margin-left: 0.35rem;
  color: rgba(226, 232, 240, 0.6);
}

.stage {
  flex: 1;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at top, rgba(30, 41, 59, 0.7), rgba(15, 23, 42, 0.92));
}

#raceCanvas {
  border-radius: 20px;
  border: 14px solid rgba(15, 23, 42, 0.92);
  background: var(--track);
  box-shadow: inset 0 0 40px rgba(15, 23, 42, 0.7), 0 20px 50px rgba(2, 6, 23, 0.55);
}

.countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4.5rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--lego-yellow);
  padding: 1rem 3rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.4);
  text-shadow: 0 16px 40px rgba(251, 191, 36, 0.45);
  box-shadow: 0 24px 55px rgba(2, 6, 23, 0.65);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.countdown.go {
  color: #4ade80;
  text-shadow: 0 16px 40px rgba(74, 222, 128, 0.55);
  border-color: rgba(74, 222, 128, 0.5);
}

.moment-announcer {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.85rem 1.6rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.95), rgba(14, 165, 233, 0.8));
  color: #0f172a;
  border: 1px solid rgba(125, 211, 252, 0.9);
  box-shadow: 0 18px 45px rgba(14, 116, 144, 0.55);
  text-transform: uppercase;
  animation: moment-pop 0.4s ease;
  pointer-events: none;
  white-space: nowrap;
}

.moment-announcer.boost {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.95), rgba(134, 239, 172, 0.85));
  border-color: rgba(134, 239, 172, 0.9);
  box-shadow: 0 20px 50px rgba(34, 197, 94, 0.45);
}

.moment-announcer.rival {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.95), rgba(37, 99, 235, 0.85));
  border-color: rgba(59, 130, 246, 0.9);
}

.moment-announcer.hazard {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.95), rgba(248, 150, 112, 0.85));
  border-color: rgba(248, 113, 113, 0.9);
  box-shadow: 0 20px 50px rgba(239, 68, 68, 0.45);
}

.moment-announcer.collect {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.95), rgba(253, 230, 138, 0.85));
  border-color: rgba(234, 179, 8, 0.9);
  box-shadow: 0 18px 45px rgba(202, 138, 4, 0.45);
}

.finish-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.88));
  padding: 2rem 3rem;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.6);
  animation: float 3s ease-in-out infinite;
}

.finish-banner h2 {
  font-size: 2rem;
  color: var(--lego-yellow);
  margin-bottom: 1rem;
}

.finish-banner p {
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.finish-banner.hidden {
  display: none;
}

.btn {
  background: linear-gradient(135deg, var(--lego-red), #fb7185);
  color: var(--light);
  border: none;
  border-radius: 10px;
  padding: 0.8rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(225, 29, 72, 0.5);
}

.credits {
  text-align: center;
  padding: 1rem;
  font-size: 0.9rem;
  color: rgba(226, 232, 240, 0.7);
}

@keyframes float {
  0%,
  100% {
    transform: translate(-50%, -52%);
  }
  50% {
    transform: translate(-50%, -48%);
  }
}

@media (max-width: 1024px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .sidebar > * {
    flex: 1 1 200px;
  }

  .stage {
    padding: 1rem;
  }

  #raceCanvas {
    width: 100%;
    height: auto;
  }
}

@keyframes moment-pop {
  0% {
    transform: translate(-50%, -40%) scale(0.85);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}
