:root {
  --bg-top: #bfe6ff;
  --bg-bot: #fff3da;
  --ink: #34323d;
  --accent: #ff6a3d;
  --accent-2: #2ec4b6;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-stroke: rgba(255, 255, 255, 0.9);
  --shadow: 0 10px 30px rgba(73, 96, 140, 0.22);
  --shadow-sm: 0 4px 12px rgba(73, 96, 140, 0.18);
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ---------- 운전 HUD ---------- */
#hud {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 14px;
  z-index: 10;
  pointer-events: none;
}
#hearts {
  font-size: 26px;
  letter-spacing: 2px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}
.stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.chip {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 17px;
  padding: 6px 14px;
  background: var(--panel);
  border: 2px solid var(--panel-stroke);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ---------- 색칠 HUD (터치 통과) ---------- */
#paintHud {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(360px, 88%);
}
.paint-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--panel);
  border: 2px solid var(--panel-stroke);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: dropIn 0.4s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.paint-chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: var(--shadow-sm);
}
.paint-msg {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 17px;
}
.timer-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd23f, var(--accent));
  transition: width 0.1s linear;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-16px); }
}

/* ---------- 둥근 버튼 ---------- */
.round-btn {
  width: 56px;
  height: 56px;
  border: 2px solid var(--panel-stroke);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 30px;
  font-family: "Fredoka", sans-serif;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.08s ease;
  line-height: 1;
  padding-bottom: 3px;
}
.round-btn:active {
  transform: scale(0.88);
}
.round-btn.save {
  font-size: 24px;
  background: linear-gradient(180deg, #ff8c6b, var(--accent));
  color: #fff;
  border-color: rgba(255, 255, 255, 0.85);
}

/* ---------- 시작 / 게임오버 화면 ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(
    120% 90% at 50% 10%,
    rgba(255, 255, 255, 0.35),
    rgba(95, 130, 180, 0.35)
  );
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.4s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; }
}
.title {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: clamp(40px, 13vw, 68px);
  margin: 0;
  color: #fff;
  text-shadow: 0 4px 0 var(--accent), 0 8px 18px rgba(0, 0, 0, 0.25);
  letter-spacing: -1px;
}
.title span {
  color: #ffd23f;
  text-shadow: 0 4px 0 #c98a00, 0 8px 18px rgba(0, 0, 0, 0.25);
}
.sub {
  margin: 0;
  font-weight: 800;
  font-size: 16px;
  color: #2c3a52;
  max-width: 320px;
}
.car-pick {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}
.car-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 24px;
  padding: 10px 22px;
  min-width: 150px;
  justify-content: center;
  background: var(--panel);
  border: 2px solid var(--panel-stroke);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.big-btn {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 16px 40px;
  background: linear-gradient(180deg, #ff8c5a, var(--accent));
  box-shadow: 0 6px 0 #c8451f, var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  animation: pulse 1.6s ease-in-out infinite;
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #c8451f, var(--shadow-sm);
}
@keyframes pulse {
  50% { transform: scale(1.04); }
}
.howto {
  font-weight: 800;
  color: #3a4760;
  font-size: 15px;
  margin: 4px 0 0;
}
.over-title {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(44px, 14vw, 72px);
  margin: 0;
  color: #fff;
  text-shadow: 0 4px 0 #d63a3a, 0 8px 18px rgba(0, 0, 0, 0.25);
}
.score-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 22px;
  color: #2c3a52;
  background: var(--panel);
  border: 2px solid var(--panel-stroke);
  border-radius: 22px;
  padding: 18px 32px;
  box-shadow: var(--shadow);
}
.score-box b {
  color: var(--accent);
  font-size: 26px;
}
.over-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 30px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 38, 48, 0.92);
  color: #fff;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-8px);
}
