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

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(180deg, #5bb8f5 0%, #87CEEB 40%, #b8e4ff 100%);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* Subtle cloud shapes */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 200px 80px at 15% 15%, rgba(255,255,255,0.35) 0%, transparent 70%),
    radial-gradient(ellipse 160px 60px at 80% 8%,  rgba(255,255,255,0.25) 0%, transparent 70%),
    radial-gradient(ellipse 120px 50px at 55% 20%, rgba(255,255,255,0.20) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Snow ground */
body::after {
  content: '';
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 70px;
  background: linear-gradient(transparent, rgba(255,255,255,0.5) 60%, rgba(255,255,255,0.75) 100%);
  pointer-events: none;
  z-index: 0;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.screen.active { display: flex; }

/* ===== CARD (home / win / lose) ===== */
.card {
  background: rgba(255,255,255,0.92);
  border-radius: 28px;
  padding: 36px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,80,160,0.18);
  max-width: 380px;
  width: 90%;
}
.card h1 {
  font-size: 2.2rem;
  color: #1a6bbf;
  margin-bottom: 12px;
}
.card p {
  font-size: 1.05rem;
  color: #444;
  line-height: 1.65;
  margin-bottom: 24px;
}
.screen-icon {
  font-size: 4rem;
  margin-bottom: 14px;
}

/* Result badge (level name on win/lose) */
.result-badge {
  display: inline-block;
  font-size: 1rem;
  font-weight: 900;
  padding: 2px 16px;
  border-radius: 50px;
  background: rgba(0,80,160,0.08);
  margin-bottom: 6px;
  /* color is set via JS */
}

/* Button group (vertical stack) */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== BUTTONS ===== */
.btn {
  background: linear-gradient(180deg, #44c0f0 0%, #1a99d4 100%);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 14px 36px;
  font-size: 1.25rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #0e6fa0, 0 7px 12px rgba(0,80,160,0.25);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 0.5px;
}
.btn:hover  { background: linear-gradient(180deg, #55ccff 0%, #24aae0 100%); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #0e6fa0; }

/* Outline / secondary button */
.btn-outline {
  background: transparent;
  color: #1a6bbf;
  border: 2.5px solid #1a6bbf;
  box-shadow: none;
  font-size: 1.1rem;
}
.btn-outline:hover  { background: rgba(26,107,191,0.07); }
.btn-outline:active { transform: translateY(2px); box-shadow: none; }

/* Round icon button (Home inside game) */
.btn-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.88);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,80,160,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-icon:active { transform: scale(0.9); box-shadow: 0 1px 4px rgba(0,80,160,0.15); }

/* ===== LEVEL SELECTION SCREEN ===== */
#screen-level-select { justify-content: center; }

.level-select-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  width: 100%;
  max-width: 420px;
  max-height: 100dvh;
  overflow-y: auto;
}
.level-select-title {
  font-size: 1.9rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 2px 10px rgba(0,60,130,0.35);
  margin-bottom: 22px;
}
#level-cards {
  display: flex;
  flex-direction: column;
  gap: 13px;
  width: 100%;
}

/* Individual level card */
.level-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  border: none;
  border-left: 5px solid transparent;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  text-align: left;
  width: 100%;
  background: white;
  box-shadow: 0 4px 16px rgba(0,80,160,0.12);
  transition: transform 0.12s, box-shadow 0.12s;
}
.level-card:hover  { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,80,160,0.18); }
.level-card:active { transform: scale(0.97); }

.level-card[data-level="easy"]   { border-left-color: #27ae60; }
.level-card[data-level="normal"] { border-left-color: #e67e22; }
.level-card[data-level="hard"]   { border-left-color: #e74c3c; }

.level-card-icon { font-size: 2rem; flex-shrink: 0; }

.level-card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 3px;
}
.level-card-name {
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1;
}
.level-card[data-level="easy"]   .level-card-name { color: #27ae60; }
.level-card[data-level="normal"] .level-card-name { color: #e67e22; }
.level-card[data-level="hard"]   .level-card-name { color: #e74c3c; }

.level-card-detail { font-size: 0.85rem; font-weight: 700; color: #666; }
.level-card-arrow  { font-size: 2rem; color: #ccc; flex-shrink: 0; line-height: 1; }

/* ===== GAME SCREEN ===== */
#screen-game {
  justify-content: flex-start;
  padding-top: 10px;
}

/* Tiny title strip */
#game-title-strip {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
  z-index: 2;
  margin-bottom: 4px;
}

/* Game header row: Home | Timer | Status */
#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 12px;
  gap: 10px;
  z-index: 2;
  margin-bottom: 4px;
}

/* ===== TIMER ===== */
#timer-display {
  flex: 1;
  background: rgba(255,255,255,0.9);
  border-radius: 50px;
  padding: 6px 20px;
  font-size: 1.85rem;
  font-weight: 900;
  color: #1a6bbf;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  text-align: center;
  transition: color 0.3s, background 0.3s;
  min-width: 100px;
  max-width: 160px;
}
#timer-display.urgent {
  color: #e53e3e;
  background: rgba(255,245,245,0.95);
  animation: pulse 0.6s ease-in-out infinite alternate;
}
@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.07); }
}

/* Game status: level name + block progress (right side) */
#game-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
#game-level-name {
  font-size: 0.88rem;
  font-weight: 900;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
#game-progress {
  font-size: 0.92rem;
  font-weight: 900;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ===== IGLOO AREA ===== */
#igloo-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px;
  z-index: 2;
}
#igloo-container {
  position: relative;
  width: 320px;
  height: 255px;
}
#igloo-dome {
  position: absolute;
  left: 20px; right: 20px;
  top: 8px;
  height: 192px;
  background: rgba(220,242,255,0.45);
  border-radius: 140px 140px 0 0;
  border: 3px solid rgba(140,200,235,0.55);
  border-bottom: none;
}
#igloo-base-bg {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 58px;
  background: rgba(210,238,255,0.35);
  border-radius: 0 0 10px 10px;
}
#igloo-entrance {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 32px;
  background: rgba(100,170,220,0.25);
  border-radius: 24px 24px 0 0;
  border: 2px solid rgba(120,190,235,0.5);
  border-bottom: none;
}

/* ===== IGLOO SLOTS ===== */
.igloo-slot {
  position: absolute;
  width: 72px;
  height: 46px;
  border-radius: 10px;
  border: 3px dashed rgba(100,170,220,0.65);
  background: rgba(180,225,255,0.18);
  transition: border-color 0.2s, background 0.2s;
}
.igloo-slot.highlight {
  border-color: #4caf50;
  background: rgba(76,175,80,0.2);
  border-style: solid;
}
.igloo-slot.filled { border: none; background: transparent; }

/* ===== TRAY ===== */
#tray-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
  margin-bottom: 5px;
  z-index: 2;
}
#blocks-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.28);
  border-radius: 20px;
  margin: 0 14px 14px;
  min-height: 68px;
  z-index: 2;
  max-width: 360px;
  width: calc(100% - 28px);
}

/* ===== SNOW BLOCKS ===== */
.snow-block {
  width: 72px;
  height: 46px;
  background: linear-gradient(145deg, #f5fbff 0%, #daeeff 100%);
  border-radius: 10px;
  border: 2px solid #a8d4f0;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 3px 8px rgba(0,80,160,0.14), inset 0 1px 0 rgba(255,255,255,0.85);
  transition: transform 0.12s, box-shadow 0.12s;
  touch-action: none;
  flex-shrink: 0;
}
.snow-block:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,80,160,0.2), inset 0 1px 0 rgba(255,255,255,0.85);
}
.snow-block.dragging {
  cursor: grabbing;
  transform: scale(1.1) rotate(-3deg);
  box-shadow: 0 10px 24px rgba(0,80,160,0.28);
  transition: none;
}
.snow-block.placed {
  cursor: default;
  background: linear-gradient(145deg, #e0f4ff 0%, #b8dcf5 100%);
  border-color: #7bbfe8;
  transform: none !important;
}
.snow-block.placed:hover { transform: none; }

/* Snap-in animation */
.snow-block.snap-anim {
  animation: snapIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes snapIn {
  0%   { transform: scale(1.25); }
  60%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

/* ===== BONUS POPUP ===== */
.bonus-popup {
  position: fixed;
  color: #27ae60;
  font-size: 1.2rem;
  font-weight: 900;
  font-family: 'Nunito', sans-serif;
  text-shadow: 0 1px 4px rgba(0,0,0,0.15);
  pointer-events: none;
  animation: floatUp 0.9s ease-out forwards;
  z-index: 9999;
  white-space: nowrap;
}
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0)    scale(1); }
  20%  { opacity: 1; transform: translateY(-10px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-60px) scale(1); }
}

/* ===== MATH QUIZ OVERLAY ===== */
#quiz-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,40,100,0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#quiz-overlay.visible { display: flex; }

.quiz-modal {
  position: relative;
  background: white;
  border-radius: 28px;
  padding: 20px 24px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 48px rgba(0,40,120,0.35);
  animation: modalIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  /* Scrollable on very small screens */
  max-height: 90svh;
  max-height: 90vh; /* fallback */
  overflow-y: auto;
}
@keyframes modalIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.quiz-modal.shake { animation: modalShake 0.4s ease-out; }
@keyframes modalShake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-10px); }
  35%  { transform: translateX( 10px); }
  55%  { transform: translateX(-7px); }
  75%  { transform: translateX( 5px); }
  100% { transform: translateX(0); }
}

/* Timer badge inside quiz */
.quiz-timer-badge {
  position: absolute;
  top: 14px; right: 18px;
  font-size: 0.85rem;
  font-weight: 900;
  color: #1a6bbf;
  background: rgba(220,240,255,0.8);
  border-radius: 50px;
  padding: 3px 10px;
  transition: color 0.3s, background 0.3s;
}
.quiz-timer-badge.urgent {
  color: #e53e3e;
  background: rgba(255,235,235,0.9);
}

.quiz-top  { font-size: 2rem; margin-bottom: 2px; }
.quiz-modal h2 {
  font-size: 1.3rem;
  font-weight: 900;
  color: #1a6bbf;
  margin-bottom: 10px;
}
#quiz-problem {
  font-size: 2.6rem;
  font-weight: 900;
  color: #1a3a6b;
  margin-bottom: 14px;
  letter-spacing: 3px;
}
#quiz-input {
  width: 100%;
  font-size: 1.8rem;
  font-weight: 900;
  font-family: 'Nunito', sans-serif;
  text-align: center;
  border: 3px solid #a8d4f0;
  border-radius: 14px;
  padding: 8px;
  margin-bottom: 6px;
  outline: none;
  color: #1a3a6b;
  background: #f0f8ff;
  cursor: default; /* readonly — input via keypad */
  caret-color: transparent;
}
/* Highlight when a value is present */
#quiz-input:not(:placeholder-shown) {
  border-color: #1a99d4;
  background: #e8f4ff;
}

#quiz-feedback {
  min-height: 20px;
  font-size: 1.05rem;
  font-weight: 900;
  margin-bottom: 6px;
}
#quiz-feedback.correct { color: #27ae60; }
#quiz-feedback.wrong   { color: #e53e3e; }

/* ===== NUMBER KEYPAD ===== */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.keypad-btn {
  height: 50px;
  border: none;
  border-radius: 14px;
  font-size: 1.55rem;
  font-weight: 900;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  background: linear-gradient(160deg, #f2f8ff 0%, #d8ecff 100%);
  color: #1a3a6b;
  box-shadow: 0 4px 0 #92c4e8;
  transition: transform 0.07s, box-shadow 0.07s;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.keypad-btn:not([disabled]):active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #92c4e8;
}
.keypad-btn[disabled] {
  opacity: 0.35;
  cursor: default;
}

/* Backspace key */
.keypad-back {
  background: linear-gradient(160deg, #fff5f3 0%, #fdd5c8 100%);
  color: #c0392b;
  box-shadow: 0 4px 0 #e0a898;
}
.keypad-back:not([disabled]):active { box-shadow: 0 0 0 #e0a898; }

/* Confirm (✓) key */
.keypad-confirm {
  font-size: 1.65rem;
  background: linear-gradient(160deg, #f2fff5 0%, #bbeece 100%);
  color: #1e8449;
  box-shadow: 0 4px 0 #7ec89a;
}
.keypad-confirm:not([disabled]):active { box-shadow: 0 0 0 #7ec89a; }

/* ===== RESPONSIVE ===== */
@media (max-width: 340px) {
  #igloo-container { transform: scale(0.88); transform-origin: top center; }
}
@media (max-height: 620px) {
  #game-title-strip { display: none; }
  #igloo-container  { transform: scale(0.82); transform-origin: top center; }
  .card, .quiz-modal { padding: 20px 22px; }
  .card h1  { font-size: 1.8rem; }
  #quiz-problem { font-size: 2.4rem; }
  .level-select-inner { padding-top: 14px; }
}
