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

html, body {
  margin: 0;
  padding: 0;
  background: #cdeffd;
  font-family: "Trebuchet MS", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  color: #2b2b2b;
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}

.hidden { display: none !important; }

h1 { font-size: 2rem; text-align: center; color: #ff5e57; margin: 10px 0; text-shadow: 2px 2px 0 #fff; }
h2 { font-size: 1.3rem; text-align: center; margin: 14px 0 8px; color: #2b6cb0; }

/* ---------- 게임 설명 화면 ---------- */
#tutorialScreen { width: 100%; text-align: center; }
.tutorialGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  padding: 0 8px;
  max-width: 640px;
  margin: 0 auto;
}
.tutorialCard {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 3px solid #ddd;
  border-radius: 14px;
  padding: 10px 12px;
  text-align: left;
}
.tutorialIcon { font-size: 1.8rem; flex: 0 0 auto; width: 36px; text-align: center; }
.tutorialText { font-size: 0.95rem; line-height: 1.4; word-break: keep-all; overflow-wrap: normal; }
.tutorialText b { color: #2b6cb0; }
.tutorialText .good { color: #1a8f4c; font-weight: bold; }
.tutorialText .bad { color: #c73e39; font-weight: bold; }

/* ---------- 시작 화면 ---------- */
#startScreen { width: 100%; text-align: center; }

#mapList, #charList, #diffList, #modeList {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding: 0 8px;
  max-width: 560px;
  margin: 0 auto;
}

.charCard, .diffCard {
  border: 4px solid #ddd;
  background: #fff;
  border-radius: 16px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 1rem;
  width: 100%;
  transition: transform 0.1s;
}
.charCard:active, .diffCard:active { transform: scale(0.96); }
.charCard.selected, .diffCard.selected { border-color: #ffb703; background: #fff6e0; }

.charSwatch {
  width: 36px; height: 36px;
  border-radius: 50%;
  margin: 0 auto 6px;
  border: 3px solid #333;
}
.charName { font-weight: bold; font-size: 1.1rem; word-break: keep-all; overflow-wrap: normal; white-space: nowrap; }
.charDesc { font-size: 0.85rem; color: #555; margin-top: 4px; word-break: keep-all; overflow-wrap: normal; }

.bigBtn {
  font-size: 1.4rem;
  font-weight: bold;
  padding: 16px 36px;
  margin: 16px 8px 6px;
  border: none;
  border-radius: 20px;
  background: #ff5e57;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 #c73e39;
}
.bigBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #c73e39; }
.secondaryBtn { background: #4c7fe0; box-shadow: 0 5px 0 #33579c; }
.secondaryBtn:active { box-shadow: 0 2px 0 #33579c; }

.howto { font-size: 1rem; line-height: 1.7; margin: 14px auto; max-width: 560px; color: #333; }

.blogFooter { font-size: 0.9rem; margin: 18px auto 4px; color: #777; }
.blogFooter a { color: #2b6cb0; font-weight: bold; text-decoration: none; }
.blogFooter a:hover, .blogFooter a:active { text-decoration: underline; }

/* ---------- 레이싱 화면 ---------- */
#raceScreen { width: 100%; }

#hud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 6px;
}
.hudBox {
  background: #fff;
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 1rem;
  font-weight: bold;
  border: 3px solid #ffd166;
}
#muteBtn { cursor: pointer; font-size: 1.1rem; }

#canvasWrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: #7ec850;
  border-radius: 16px;
  overflow: hidden;
  border: 4px solid #4a934a;
}
#gameCanvas { display: block; width: 100%; height: auto; }

/* 화면 상단 구석에 작게 떠서 레이스 화면(내 차)을 가리지 않게 한다 */
#boostBanner, #slowBanner {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translate(-50%, 0);
  font-size: 1.15rem;
  font-weight: bold;
  color: #fff;
  padding: 6px 16px;
  border-radius: 16px;
  pointer-events: none;
  white-space: nowrap;
}

/* 부스터: 밝고 경쾌하게 통통 튀는 느낌 */
#boostBanner {
  background: rgba(255, 94, 87, 0.92);
  text-shadow: 1px 1px 0 #c73e39;
  animation: pulse 0.4s infinite alternate;
}
@keyframes pulse { from { transform: translate(-50%,0) scale(1); } to { transform: translate(-50%,0) scale(1.06); } }

/* 감속: 칙칙한 색 + 아래로 처지는 느낌으로 부스터와 확실히 다르게 */
#slowBanner {
  background: rgba(90, 100, 115, 0.92);
  text-shadow: 1px 1px 0 #333;
  animation: droop 0.6s ease-in-out infinite alternate;
}
@keyframes droop { from { transform: translate(-50%,0) scale(1); } to { transform: translate(-50%, 4px) scale(0.96); } }

#finishBanner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: bold;
  color: #2b6cb0;
  background: rgba(255,255,255,0.92);
  padding: 14px 26px;
  border-radius: 20px;
  pointer-events: none;
}

/* 우주 정거장에서 낙하했을 때 잠깐 뜨는 안내 배너 */
#fallBanner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
  background: rgba(60, 40, 110, 0.92);
  padding: 12px 22px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
}

/* 번개 아이템을 사용했을 때 화면이 살짝 번쩍이는 연출 */
#screenFlash {
  position: absolute;
  inset: 0;
  background: #fff9c4;
  opacity: 0;
  pointer-events: none;
}
#screenFlash.flashAnim { animation: flashPulse 0.35s ease-out; }
@keyframes flashPulse { 0% { opacity: 0.85; } 100% { opacity: 0; } }

#mathPopup {
  position: absolute;
  inset: 0;
  background: rgba(20, 30, 60, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
#mathTimerBar {
  width: 80%;
  max-width: 380px;
  height: 14px;
  background: #444;
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 14px;
}
#mathTimerFill {
  height: 100%;
  width: 100%;
  background: #ffd166;
}
#mathQuestion {
  font-size: 2.6rem;
  font-weight: bold;
  color: #fff;
  margin-bottom: 18px;
  text-align: center;
}
#mathAnswers { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.answerBtn {
  font-size: 1.8rem;
  font-weight: bold;
  padding: 14px 28px;
  border-radius: 16px;
  border: none;
  background: #ffd166;
  cursor: pointer;
  min-width: 90px;
  box-shadow: 0 5px 0 #cf9f2f;
}
.answerBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #cf9f2f; }

#mathResult {
  margin-top: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  color: #fff;
  background: rgba(0,0,0,0.3);
  padding: 6px 14px;
  border-radius: 10px;
  text-align: center;
}

#mobileControls {
  display: flex;
  gap: 10px;
  margin: 10px auto 0;
  max-width: 480px;
}
.ctrlBtn {
  flex: 2;
  font-size: 2.2rem;
  padding: 18px 0;
  border-radius: 18px;
  border: none;
  background: #4c7fe0;
  color: #fff;
  box-shadow: 0 5px 0 #33579c;
  user-select: none;
}
.ctrlBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #33579c; }
/* 아이템 칸 3개를 좌우 버튼과 같은 줄 가운데에 둔다. 예전엔 화면 맨 위에 작은 글씨로
   "🎁 바나나"라고만 떠서, 무슨 아이템인지도 눈에 안 들어오고 누르는 버튼과도 멀었다. */
#itemSlots { flex: 3; display: flex; gap: 6px; }
.itemSlot {
  flex: 1;
  font-size: 2rem;
  line-height: 1;
  padding: 16px 0;
  border-radius: 16px;
  border: 3px dashed #aab6c6;
  background: #e8edf4;
  box-shadow: none;
  user-select: none;
  transition: background .12s, border-color .12s;
}
/* 아이템이 들어있는 칸만 노란 버튼처럼 튀어나와 보이게 해서 "이건 누르는 것"임을 알린다 */
.itemSlot.filled {
  border: 3px solid #b3800a;
  background: #ffb703;
  box-shadow: 0 5px 0 #b3800a;
}
.itemSlot.filled:active { transform: translateY(3px); box-shadow: 0 2px 0 #b3800a; }

/* ---------- 결과 화면 ---------- */
#resultScreen { width: 100%; text-align: center; }
.resultLine { font-size: 1.3rem; font-weight: bold; margin: 6px; }
#wrongWrap { margin: 12px auto; max-width: 480px; }
.wrongItem {
  background: #fff;
  border: 3px solid #ffb703;
  border-radius: 12px;
  padding: 8px 14px;
  margin: 8px 0;
  font-size: 1.1rem;
  text-align: left;
}

@media (max-width: 560px) {
  h1 { font-size: 1.5rem; }
  .charCard, .diffCard { padding: 8px; }
  #mathQuestion { font-size: 2rem; }
  .answerBtn { font-size: 1.4rem; padding: 12px 18px; min-width: 70px; }
  .hudBox { font-size: 0.85rem; padding: 5px 8px; }
}
