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

/* iJeeto brand palette, copied locally so this game remains independent. */
:root {
  --purple: #4A1A63;
  --purple-soft: #6B3A85;
  --amber: #FFC42E;
  --orange: #FF7A2F;
  --orange-dark: #DD5E15;
  --teal: #2FAFAF;
  --teal-dark: #218A8A;
  --cream: #FFF7EA;
  --cream-2: #FCEBD2;
  --white: #FFFFFF;
  --ink: var(--purple);
  --shadow: #DFCBAE;
  --font-brand: ui-rounded, "SF Pro Rounded", Nunito, Quicksand,
                "Hiragino Maru Gothic ProN", "Trebuchet MS", system-ui, sans-serif;
}

html, body {
  min-height: 100%;
  font-family: var(--font-brand);
  color: var(--ink);
  background: var(--cream);
}

body { min-height: 100vh; min-height: 100dvh; overflow: hidden; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 4px solid var(--amber);
  outline-offset: 3px;
}

#app { min-height: 100vh; min-height: 100dvh; }
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; }
.hidden { display: none !important; }

.menu-screen {
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: clamp(16px, 4vh, 36px) 16px;
}

.brand-mark { width: clamp(88px, 24vw, 126px); height: auto; display: block; }
h1 { margin-top: 10px; font-size: clamp(30px, 8vw, 48px); text-align: center; }
.tagline {
  width: min(480px, 94vw);
  margin: 12px 0 26px;
  color: var(--purple-soft);
  font-size: clamp(16px, 4vw, 20px);
  line-height: 1.5;
  text-align: center;
}
.menu-buttons { display: grid; gap: 14px; width: min(340px, 92vw); }

.big-btn {
  min-height: 56px;
  border: 0;
  border-radius: 16px;
  padding: 10px 18px;
  color: var(--white);
  background: var(--orange);
  box-shadow: 0 5px 0 var(--orange-dark);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--orange-dark); }
.big-btn.ghost { color: var(--purple); background: var(--white); box-shadow: 0 5px 0 var(--shadow); }
.big-btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.reset-btn { background: var(--purple-soft); box-shadow: 0 5px 0 var(--purple); }

.portal-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 24px;
  padding: 10px 20px;
  border-radius: 999px;
  color: var(--purple);
  background: var(--white);
  box-shadow: 0 3px 0 var(--shadow);
  font-weight: 700;
  text-decoration: none;
}
.build { margin-top: 14px; color: var(--purple-soft); font-size: 12px; }

.menu-header {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(680px, 100%);
  margin-bottom: 18px;
}
.menu-header h2 { font-size: clamp(21px, 5vw, 30px); }
.subtle { margin-top: 4px; color: var(--purple-soft); font-size: 14px; }
.icon-btn {
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  color: var(--purple);
  background: var(--white);
  box-shadow: 0 3px 0 var(--shadow);
  font-size: 20px;
  cursor: pointer;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

.stage-grid { display: grid; gap: 14px; width: min(680px, 100%); }
.stage-card {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 86px;
  border: 0;
  border-radius: 18px;
  padding: 12px;
  color: var(--purple);
  background: var(--white);
  box-shadow: 0 4px 0 var(--shadow);
  text-align: left;
  cursor: pointer;
}
.stage-card:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--shadow); }
.stage-card:disabled { opacity: 0.55; cursor: default; }
.stage-emoji { font-size: 42px; text-align: center; }
.stage-copy strong { display: block; font-size: 18px; }
.stage-copy span { display: block; margin-top: 4px; color: var(--purple-soft); font-size: 14px; line-height: 1.35; }
.stage-state { font-size: 22px; }

#screen-game { flex-direction: column; overflow: hidden; }
.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 0 var(--cream-2);
}
.round-meta { display: flex; flex: 1; min-width: 0; flex-direction: column; text-align: center; }
.round-meta strong { overflow: hidden; font-size: clamp(16px, 4vw, 20px); text-overflow: ellipsis; white-space: nowrap; }
.round-meta span { margin-top: 2px; color: var(--purple-soft); font-size: 13px; }

.play-area {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 10px 12px 18px;
}
.instruction { min-height: 28px; font-size: clamp(16px, 4vw, 20px); font-weight: 800; text-align: center; }
.count-strip {
  display: flex;
  justify-content: center;
  gap: 16px;
  min-height: 32px;
  margin: 4px 0 8px;
  color: var(--purple-soft);
  font-size: 15px;
  font-weight: 700;
}
.timer { color: var(--orange-dark); }
.timer.urgent { animation: pulse 0.65s ease-in-out infinite alternate; font-weight: 900; }

.object-board {
  --columns: 5;
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(48px, 64px));
  justify-content: center;
  align-content: center;
  gap: clamp(7px, 2.5vw, 13px);
  width: min(100%, 420px);
  min-height: 150px;
  padding: 12px;
  border: 3px dashed var(--cream-2);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.58);
  touch-action: manipulation;
}
.object-board.scattered { position: relative; display: block; height: min(43vh, 330px); min-height: 260px; }
.object-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 48px;
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  background: var(--white);
  box-shadow: 0 3px 0 var(--shadow);
  font-size: clamp(28px, 8vw, 40px);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.scattered .object-btn {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(48px, 13vw, 58px);
  height: clamp(48px, 13vw, 58px);
  transform: translate(-50%, -50%) rotate(var(--turn));
}
.object-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.scattered .object-btn:active { transform: translate(-50%, calc(-50% + 2px)) rotate(var(--turn)); }
.object-btn.counted {
  border: 3px solid var(--teal-dark);
  background: #E8FAF7;
  box-shadow: 0 2px 0 var(--teal-dark);
}
.object-btn.counted::after {
  content: "✓";
  position: absolute;
  right: -5px;
  top: -7px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--white);
  border-radius: 50%;
  color: var(--white);
  background: var(--teal-dark);
  font-size: 14px;
  font-weight: 900;
}

.answer-area { margin-top: 10px; text-align: center; }
.answer-area h2 { font-size: clamp(18px, 4.5vw, 23px); }
.number-choices { display: flex; justify-content: center; gap: 12px; margin-top: 8px; }
.number-btn {
  min-width: 64px;
  min-height: 58px;
  border: 0;
  border-radius: 16px;
  color: var(--white);
  background: var(--teal);
  box-shadow: 0 4px 0 var(--teal-dark);
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
}
.number-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-dark); }
.number-btn:disabled { opacity: 0.6; cursor: default; }
.number-btn.wobble { animation: wobble 0.4s ease; }
.feedback { min-height: 28px; margin-top: 10px; font-size: clamp(15px, 3.8vw, 18px); font-weight: 800; text-align: center; }
.feedback.success { color: var(--teal-dark); }

.round-star {
  position: fixed;
  left: 50%;
  top: 48%;
  z-index: 20;
  font-size: clamp(72px, 25vw, 130px);
  pointer-events: none;
  animation: star-pop 0.8s ease forwards;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(74, 26, 99, 0.58);
}
.card {
  width: min(420px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 22px;
  padding: 24px;
  background: var(--white);
  text-align: center;
}
.card h2 { font-size: clamp(23px, 6vw, 31px); }
.card p { margin-top: 10px; color: var(--purple-soft); font-size: 16px; line-height: 1.5; }
.big-star { font-size: 64px; }
.card-buttons { display: grid; gap: 12px; margin-top: 20px; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 4px;
  font-size: 17px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}
.setting-row input { width: 24px; height: 24px; accent-color: var(--teal-dark); }

@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px) rotate(-3deg); }
  75% { transform: translateX(7px) rotate(3deg); }
}
@keyframes star-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-15deg); }
  45% { opacity: 1; transform: translate(-50%, -50%) scale(1.2) rotate(8deg); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1) rotate(0); }
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }

@media (max-width: 390px) {
  .stage-card { grid-template-columns: 52px 1fr auto; padding: 10px; }
  .stage-emoji { font-size: 34px; }
  .object-board { gap: 7px; padding: 9px; }
  .number-btn { min-width: 60px; }
}

@media (orientation: landscape) and (max-height: 590px) {
  .game-header { min-height: 54px; }
  .play-area { padding-top: 5px; }
  .instruction { min-height: 23px; font-size: 15px; }
  .count-strip { min-height: 24px; margin: 1px 0 4px; }
  .object-board { min-height: 115px; padding: 7px; }
  .object-board.scattered { height: 220px; min-height: 220px; }
  .object-btn { min-height: 46px; font-size: 28px; }
  .answer-area { margin-top: 5px; }
  .number-btn { min-height: 48px; }
  .feedback { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
