/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Arial Rounded MT Bold', 'Nunito', sans-serif;
  background: #1a1a2e;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

/* ===== LOADING SCREEN ===== */
#screen-loading {
  background: #1a1a2e;
  z-index: 1000;
}
.loading-illustration {
  width: min(90vw, 500px);
  margin-bottom: 30px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-20px); }
}
.loading-bar-container {
  width: min(80vw, 300px);
  height: 10px;
  background: #333;
  border-radius: 5px;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff6b6b, #ffd93d, #6bcb77);
  transition: width 0.1s;
}

/* ===== WATERMARK ===== */
.game-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(60vw, 400px);
  pointer-events: none;
  z-index: -1;
  opacity: 0.5;
}

/* ===== ICON LIST ===== */
.reward-icons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
  justify-content: center;
}
.reward-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid #4d96ff;
  padding: 4px;
  background: rgba(255,255,255,0.05);
  transition: transform 0.2s;
}
.reward-icon:hover {
  transform: scale(1.2) rotate(10deg);
  background: rgba(255,255,255,0.1);
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh; width: 100vw;
  padding: 20px;
  position: absolute; top: 0; left: 0;
  animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* ===== HOME SCREEN ===== */
.app-title {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}
.app-subtitle {
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: #aaa;
  margin-bottom: 30px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 400px;
  width: 100%;
}

.game-tile {
  background: linear-gradient(145deg, #16213e, #0f3460);
  border: 3px solid #4d96ff;
  border-radius: 20px;
  padding: 20px 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.game-tile:active { transform: scale(0.93); }
.game-tile:not(.coming-soon):hover {
  box-shadow: 0 0 20px rgba(77,150,255,0.4);
  transform: scale(1.03);
}
.game-tile.coming-soon {
  opacity: 0.35;
  border-color: #555;
  cursor: default;
}
.tile-icon { font-size: 2.2rem; }
.tile-label { font-size: 1.3rem; font-weight: 700; }
.tile-desc { font-size: 0.85rem; color: #aaa; }

/* ===== BACK BUTTON ===== */
.back-btn {
  position: absolute;
  top: 16px; left: 16px;
  background: none;
  border: 2px solid #4d96ff;
  color: #4d96ff;
  font-size: 1.2rem;
  padding: 6px 16px;
  border-radius: 12px;
  cursor: pointer;
}
.back-btn:active { background: rgba(77,150,255,0.2); }

/* Home button on game screen */
.hud-home-btn {
  position: static;
  padding: 4px 12px;
  font-size: 1rem;
}

/* Sandbox nav buttons - high z-index to stay above draggable blocks */
.sb-nav-btn {
  z-index: 500;
}
.sb-home-btn {
  left: auto;
  right: 16px;
}

/* ===== SUBITIZE MENU ===== */
.screen-subtitle {
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
  color: #aaa;
  margin: 10px 0 16px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 380px;
  width: 100%;
}

.menu-btn {
  background: linear-gradient(145deg, #16213e, #0f3460);
  border: 2px solid #4d96ff;
  color: #fff;
  border-radius: 16px;
  padding: 14px 10px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.12s;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.menu-btn:active { transform: scale(0.93); }
.variant-btn.selected {
  border-color: #6bcb77;
  background: linear-gradient(145deg, #1a3a2a, #0f3460);
  box-shadow: 0 0 12px rgba(107,203,119,0.3);
}
.menu-num { font-size: 1.3rem; font-weight: 700; }
.menu-detail { font-size: 0.8rem; color: #aaa; }

/* custom input */
.custom-input {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.custom-input label {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.custom-input input {
  width: 60px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 2px solid #4d96ff;
  background: #16213e;
  color: #fff;
  font-size: 1rem;
  text-align: center;
}
.custom-input .menu-btn { padding: 8px 20px; }
.hidden { display: none !important; }

/* skip toggle */
.skip-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 1rem;
  color: #aaa;
  cursor: pointer;
}
.skip-toggle input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #4d96ff;
  cursor: pointer;
}

/* difficulty */
.difficulty-section { margin-top: 20px; text-align: center; width: 100%; max-width: 400px; }
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.diff-btn {
  border: none;
  border-radius: 16px;
  padding: 16px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s;
  color: #fff;
}
.diff-btn:active { transform: scale(0.92); }
.diff-label { font-size: 1.1rem; font-weight: 700; }
.diff-detail { font-size: 0.8rem; opacity: 0.8; }
.diff-free { background: linear-gradient(135deg, #4d96ff, #2563eb); }
.diff-beg { background: linear-gradient(135deg, #6bcb77, #38a169); }
.diff-adv { background: linear-gradient(135deg, #ffd93d, #e6a817); color: #333; }
.diff-adv .diff-detail { color: #555; }
.diff-exp { background: linear-gradient(135deg, #ff6b6b, #c0392b); }

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

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 6px 10px;
}
.hud-level { font-size: 1.3rem; font-weight: 700; }
.hud-strikes { display: flex; gap: 6px; }
.strike-dot { font-size: 1.5rem; transition: opacity 0.3s; }
.strike-dot.used { opacity: 0.2; filter: grayscale(1); }

/* timer */
.timer-bar-container {
  width: 100%;
  height: 8px;
  background: #333;
  border-radius: 4px;
  margin: 6px 0 10px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #6bcb77, #ffd93d, #ff6b6b);
  border-radius: 4px;
  transition: width linear;
}

/* blocks */
.blocks-area {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  width: 100%;
  max-width: 600px;
  padding: 4px 10px;
  min-height: 0;
  overflow: hidden;
}

.number-block {
  border-radius: 14px;
  aspect-ratio: 1;
  animation: popIn 0.25s ease-out both;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@keyframes popIn {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

/* ===== CHERRY DIAGRAM (Number Bonds) ===== */
.cherry-layout {
  align-items: center;
  justify-content: center;
}

.cherry-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  animation: popIn 0.35s ease-out both;
}

.cherry-node {
  width: clamp(70px, 18vw, 110px);
  height: clamp(70px, 18vw, 110px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 6vw, 3rem);
  font-weight: 900;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.cherry-whole {
  background: linear-gradient(135deg, #4d96ff, #339af0);
  color: #fff;
  z-index: 2;
}

.cherry-stems {
  width: clamp(160px, 45vw, 260px);
  height: clamp(50px, 12vw, 80px);
  margin: -4px 0 -4px;
  z-index: 1;
}

.cherry-parts {
  display: flex;
  justify-content: center;
  gap: clamp(40px, 12vw, 80px);
  z-index: 2;
}

.cherry-part {
  background: linear-gradient(135deg, #6bcb77, #38a169);
  color: #fff;
}

.cherry-missing {
  background: linear-gradient(135deg, #ffd93d, #e6a817);
  color: #333;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,217,61,0.4); }
  50%      { box-shadow: 0 0 0 12px rgba(255,217,61,0); }
}

/* answer options */
.answer-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 500px;
  padding: 0 4px;
}

.answer-btn {
  background: linear-gradient(145deg, #16213e, #0f3460);
  border: 3px solid #4d96ff;
  color: #fff;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 900;
  border-radius: 18px;
  padding: 16px 0;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.answer-btn:active { transform: scale(0.9); }
.answer-btn.correct {
  background: #6bcb77 !important;
  border-color: #6bcb77 !important;
  transform: scale(1.08);
}
.answer-btn.wrong {
  background: #ff6b6b !important;
  border-color: #ff6b6b !important;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* feedback overlay */
.feedback-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(4rem, 15vw, 8rem);
  z-index: 100;
  pointer-events: none;
  animation: feedbackPop 0.6s ease both;
}
@keyframes feedbackPop {
  0%   { transform: scale(0); opacity: 0; }
  40%  { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* ===== GAME OVER ===== */
.gameover-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
#gameover-title {
  font-size: clamp(2rem, 7vw, 3.5rem);
  font-weight: 900;
}
.gameover-stars { font-size: 2.5rem; }
#gameover-msg { font-size: 1.2rem; color: #aaa; }
#gameover-level { font-size: 1.5rem; font-weight: 700; color: #ffd93d; }
.play-again-btn {
  font-size: 1.2rem !important;
  padding: 14px 40px !important;
  border-color: #6bcb77 !important;
}
.home-btn {
  font-size: 1rem !important;
  padding: 10px 30px !important;
  border-color: #888 !important;
}

/* ===== SHARING (How Many Each?) ===== */
.sharing-drag-area {
  position: relative !important;
  display: block !important;
  overflow: hidden;
  order: 2;
}
#screen-game .answer-options {
  order: 1;
}
#screen-game .blocks-area {
  order: 2;
}

.sharing-person {
  border-radius: 50%;
  position: relative;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
/* Simple face on the person circle */
.sharing-person::after {
  content: '';
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translateX(-50%);
  width: 55%;
  height: 26%;
  border-bottom: 3px solid rgba(255,255,255,0.6);
  border-radius: 0 0 50% 50%;
}
.sharing-person::before {
  content: '\2022 \2022';
  position: absolute;
  top: 18%;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: inherit;
  color: rgba(255,255,255,0.75);
  letter-spacing: 0.3em;
}

.sharing-question {
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: 900;
  color: #ffd93d;
  text-align: center;
  animation: pulse 1s ease-in-out infinite;
}

.share-drag-block {
  transition: opacity 0.1s;
}

/* ===== SANDBOX ===== */
#screen-sandbox {
  justify-content: center;
  align-items: center;
  padding: 40px 10px 10px;
  overflow: hidden;
}

.sb-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}
.sb-setup-label {
  font-size: 1.2rem;
  font-weight: 600;
}
.sb-input {
  width: 100px;
  padding: 10px;
  border-radius: 12px;
  border: 3px solid #4d96ff;
  background: #16213e;
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}
.sb-go-btn {
  padding: 14px 50px !important;
  font-size: 1.3rem !important;
}

.sb-square {
  --size: min(80vw, 60vh);
  width: var(--size);
  height: var(--size);
  border: 3px dashed rgba(77, 150, 255, 0.35);
  border-radius: 16px;
  background: rgba(77, 150, 255, 0.04);
  flex-shrink: 0;
  pointer-events: none;
}

.sb-bottom-bar {
  position: absolute;
  bottom: 10px;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 300;
}
.sb-bottom-bar > * { pointer-events: auto; }

.sb-counter {
  font-size: 1.3rem;
  font-weight: 700;
  background: rgba(26, 26, 46, 0.85);
  padding: 4px 16px;
  border-radius: 10px;
}

.sb-split-btn {
  background: linear-gradient(135deg, #ff8c42, #e6591e);
  border: none;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 10px 30px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s;
}
.sb-split-btn:active { transform: scale(0.92); }

/* Pieces */
.sb-piece {
  position: absolute;
  display: flex;
  flex-direction: row;
  gap: 3px;
  cursor: grab;
  z-index: 10;
  border-radius: 8px;
  transition: filter 0.15s;
}
.sb-piece.sb-selected {
  filter: drop-shadow(0 0 10px rgba(255, 217, 61, 0.9));
  outline: 2px solid #ffd93d;
  outline-offset: 3px;
  border-radius: 8px;
}
.sb-piece.sb-dragging {
  opacity: 0.8;
  cursor: grabbing;
  z-index: 200 !important;
  transition: none;
}

.sb-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sb-block {
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.sb-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  background: #222;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #4d96ff;
  padding: 0 4px;
  z-index: 5;
}

/* ===== RESPONSIVE ===== */
@media (max-height: 600px) {
  .blocks-area { padding: 4px; gap: 5px; }
  .answer-btn { padding: 10px 0; }
  .game-hud { padding: 2px 10px; }
  .timer-bar-container { margin: 2px 0 6px; }
}

@media (min-width: 768px) {
  .game-grid { max-width: 500px; }
  .blocks-area { max-width: 600px; }
}
