* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", "Avenir Next", Arial, sans-serif;
  background: #1a2f4a;
  color: #fff;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
  filter: saturate(1.08) contrast(1.04);
}

.game-ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 2;
}

.game-ui * {
  pointer-events: auto;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin: 12px 14px 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 248, 220, 0.88));
  border: 3px solid #fff;
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(20, 40, 80, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  color: #2a3f6b;
}

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

.brand-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.1;
  color: #e85d2a;
  text-shadow: 0 1px 0 #fff;
}

.brand p {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: #5a6f9a;
}

.stat-pills {
  display: flex;
  flex: 1;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.pill {
  background: linear-gradient(180deg, #fff 0%, #f0f6ff 100%);
  border: 2px solid #d8e6ff;
  border-radius: 14px;
  padding: 6px 12px;
  text-align: center;
  min-width: 72px;
  box-shadow: 0 3px 0 #c5d8f5;
}

.pill span {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: #7a8fb8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: #2f4f8f;
}

.pill-gap strong {
  color: #2a9d6e;
}

.pill-time strong {
  color: #d45a2a;
}

.pill-combo strong {
  color: #9b4fd4;
}

.pill-treats strong {
  color: #ff8c2e;
}

.pill-combo.combo-hot {
  animation: combo-glow 0.5s ease-in-out infinite;
  border-color: #ff9a5c;
}

@keyframes combo-glow {
  50% {
    box-shadow: 0 0 14px rgba(255, 154, 92, 0.8);
  }
}

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

.choice-row:empty {
  display: none;
}

.choice-btn {
  border: 3px solid #c5d8f5;
  border-radius: 14px;
  padding: 10px 8px;
  font-family: inherit;
  font-size: clamp(1.05rem, 2.1vw, 1.35rem);
  font-weight: 700;
  color: #1e3a6e;
  background: linear-gradient(180deg, #fff, #eef5ff);
  cursor: pointer;
  box-shadow: 0 5px 0 #b8cae8;
  transition: transform 80ms ease;
}

.choice-btn:hover:not(:disabled) {
  transform: translateY(-2px);
}

.choice-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: none;
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.choice-btn.correct-flash {
  background: linear-gradient(180deg, #b8ffe0, #6ee0a8);
  border-color: #2cb87a;
}

.choice-btn.wrong-flash {
  background: linear-gradient(180deg, #ffd0c8, #ff9a8a);
  border-color: #e85d4a;
}

.answer-row-typing {
  margin-top: 0;
}

.powerup-status {
  min-height: 18px;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #9b4fd4;
}

.pill-level strong {
  color: #e85d2a;
  font-size: 0.92rem;
}

.level-progress-wrap {
  margin: 8px 18px 0;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.55);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.level-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9a5c, #ffd34d, #6cff9a);
  transition: width 90ms linear;
}

.level-banner {
  position: fixed;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 5;
  padding: 18px 34px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 244, 210, 0.94));
  border: 4px solid #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 700;
  color: #e85d2a;
  text-align: center;
  pointer-events: none;
  animation: banner-pop 2.4s ease forwards;
}

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

@keyframes banner-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
  75% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.02);
  }
}

.level-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 12px;
}

.level-chip {
  border: 2px solid #d8e6ff;
  border-radius: 14px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #2f4f8f;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 #c5d8f5;
}

.level-chip.active {
  border-color: #ff9a5c;
  background: linear-gradient(180deg, #fff4e8, #ffe2c4);
  color: #c44e12;
}

.level-chip.locked {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.overlay-badge {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7a8fb8;
}

.overlay-stars {
  font-size: 1.6rem;
  margin-bottom: 14px;
  letter-spacing: 4px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#difficultySelect {
  border: 2px solid #d8e6ff;
  border-radius: 12px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #2f4f8f;
  background: #fff;
  cursor: pointer;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 2px solid #d8e6ff;
  border-radius: 12px;
  background: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #c5d8f5;
}

.icon-btn:active,
.btn-go:active,
.btn-start:active {
  transform: translateY(2px);
  box-shadow: none;
}

.turbo-wrap {
  position: absolute;
  top: 88px;
  right: 18px;
  width: 140px;
  pointer-events: none;
}

.turbo-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.7);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.turbo-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4ee8ff, #6cff9a, #ffe566);
  box-shadow: 0 0 12px rgba(110, 255, 170, 0.9);
  transition: width 100ms linear;
}

.turbo-track.turbo-ready {
  animation: turbo-pulse 0.55s ease-in-out infinite;
  border-color: #9fffe0;
}

.turbo-track.turbo-ready .turbo-fill {
  box-shadow: 0 0 18px rgba(120, 255, 200, 1);
}

@keyframes turbo-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}

.turbo-label {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.play-bar {
  margin: 0 14px 14px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(150px, 0.75fr) minmax(190px, 1fr) minmax(280px, 1.35fr) minmax(260px, 1.2fr) auto;
  gap: 8px 10px;
  align-items: center;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.88), rgba(255, 245, 228, 0.84));
  backdrop-filter: blur(7px);
  border: 3px solid #fff;
  border-radius: 20px;
  box-shadow: 0 12px 36px rgba(20, 40, 80, 0.28);
  color: #2a3f6b;
}

.play-bar .level-strip {
  grid-column: 1;
  margin: 0;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
}

.play-bar .level-strip::-webkit-scrollbar {
  display: none;
}

.play-bar .choice-row {
  grid-column: 3;
}

.play-bar .powerup-status {
  grid-column: 1 / 3;
}

.question-card {
  grid-column: 2;
  margin: 0;
}

.question-text {
  margin: 0 0 7px;
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 700;
  text-align: center;
  color: #1e3a6e;
}

.question-timer-track {
  height: 8px;
  border-radius: 999px;
  background: #e8eef8;
  overflow: hidden;
}

.question-timer-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #44e0a8, #ffd34d, #ff7b6b);
  transition: width 80ms linear;
}

.answer-row {
  grid-column: 4;
  display: flex;
  gap: 8px;
}

#answerInput {
  flex: 1;
  min-width: 0;
  border: 3px solid #c5d8f5;
  border-radius: 14px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e3a6e;
  background: #fff;
}

#answerInput:focus {
  outline: none;
  border-color: #5bc4ff;
  box-shadow: 0 0 0 4px rgba(91, 196, 255, 0.35);
}

#answerInput:disabled {
  opacity: 0.55;
}

.btn-go,
.btn-start {
  border: none;
  border-radius: 14px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn-go {
  background: linear-gradient(180deg, #ffb347, #ff8c2e);
  box-shadow: 0 5px 0 #d96a12, 0 8px 20px rgba(255, 140, 46, 0.4);
  min-width: 76px;
}

.btn-go:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-start {
  grid-column: 5;
  align-self: stretch;
  width: auto;
  min-width: 132px;
  margin: 0;
  background: linear-gradient(180deg, #5ee0a8, #2cb87a);
  box-shadow: 0 5px 0 #1a8f5c, 0 8px 20px rgba(46, 184, 122, 0.4);
}

.btn-start:disabled {
  display: none;
}

.feedback {
  grid-column: 3 / 6;
  min-height: 18px;
  margin: 0;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: #2a9d6e;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 30, 55, 0.55);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(360px, 90vw);
  padding: 28px 24px;
  text-align: center;
  background: linear-gradient(160deg, #fff, #fff8ec);
  border: 4px solid #fff;
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  color: #1e3a6e;
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.8rem;
  color: #e85d2a;
}

.overlay-card p {
  margin: 0 0 20px;
  font-weight: 600;
  color: #5a6f9a;
}

@media (max-width: 720px) {
  .top-bar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .brand {
    width: 100%;
    justify-content: center;
  }

  .stat-pills {
    width: 100%;
  }

  .turbo-wrap {
    top: auto;
    bottom: 200px;
    right: 12px;
    width: 110px;
  }
}

@media (max-width: 1180px) {
  .play-bar {
    grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1.2fr) auto;
  }

  .play-bar .level-strip {
    grid-column: 1;
  }

  .question-card {
    grid-column: 2;
  }

  .play-bar .choice-row,
  .answer-row,
  .feedback {
    grid-column: 1 / -1;
  }

  .btn-start {
    grid-column: 3;
  }
}

@media (max-width: 720px) {
  .play-bar {
    grid-template-columns: 1fr;
    margin: 0 10px 10px;
    padding: 10px;
    gap: 8px;
  }

  .play-bar .level-strip,
  .question-card,
  .play-bar .choice-row,
  .answer-row,
  .play-bar .powerup-status,
  .feedback,
  .btn-start {
    grid-column: 1;
  }

  .choice-row {
    gap: 6px;
  }

  .answer-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 6px;
  }

  .choice-btn,
  #answerInput,
  .btn-go,
  .btn-start {
    padding-top: 9px;
    padding-bottom: 9px;
  }

  .btn-go {
    min-width: 0;
    padding-left: 8px;
    padding-right: 8px;
  }
}
