/* Equation Detective Cartoon Stylesheet */
:root {
  --bg-primary: #151433;
  --bg-secondary: #221f4b;
  --bg-card: #2e2a63;
  --panel-bg: #ffffff;
  --ink-dark: #1f1b42;
  --ink-muted: #645f8a;
  --accent-gold: #ffd13b;
  --accent-orange: #ff9326;
  --accent-green: #2ec4b6;
  --accent-pink: #ff477e;
  --accent-blue: #3a86ff;
  --border-light: #443e80;
  --font-family: "Fredoka", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: radial-gradient(circle at top center, #252254 0%, #121026 100%);
  color: #ffffff;
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  transition: background 0.3s ease;
}

/* Flash Celebration Background */
body.flash-correct {
  animation: flashJoy 0.7s ease-out;
}
@keyframes flashJoy {
  0% { background-color: #2ec4b6; }
  50% { background-color: #ff9326; }
  100% { background-color: transparent; }
}

/* Top Navigation Bar */
.top-nav-bar {
  background: rgba(18, 16, 38, 0.95);
  border-bottom: 2px solid #332d66;
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.home-link {
  color: var(--accent-gold);
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s;
}
.home-link:hover {
  transform: translateX(-3px);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}
.nav-links a {
  color: #b8b3e6;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 5px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  transition: all 0.2s;
}
.nav-links a:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.active-badge {
  background: linear-gradient(135deg, #ff9326, #ffd13b);
  color: #121026;
  padding: 5px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(255, 209, 59, 0.4);
}

/* Main Layout Shell */
.app-shell {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.detective-avatar {
  font-size: 2.8rem;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
  animation: floatAvatar 3s ease-in-out infinite alternate;
}
@keyframes floatAvatar {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(-5px) rotate(4deg); }
}

.brand h1 {
  font-size: 2.1rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 3px 0 #1b173d;
  letter-spacing: 0.5px;
}
.brand .tagline {
  color: #bcb8e8;
  font-size: 1rem;
  font-weight: 500;
}

.stats-group {
  display: flex;
  gap: 12px;
}

.stat-badge {
  background: #252152;
  border: 2px solid #433c82;
  border-radius: 14px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 0 #141230;
}
.stat-badge .icon {
  font-size: 1.4rem;
}
.stat-badge .label {
  font-size: 0.85rem;
  color: #aaa5dc;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-badge strong {
  font-size: 1.3rem;
  color: var(--accent-gold);
  font-weight: 700;
}

/* Case Mystery Dossier Card */
.case-card {
  background: linear-gradient(135deg, #2d2866, #201c4a);
  border: 3px solid #ffcc00;
  border-radius: 20px;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35), 0 0 15px rgba(255, 204, 0, 0.15);
  position: relative;
  overflow: hidden;
}
.case-card::before {
  content: "TOP SECRET";
  position: absolute;
  top: 10px;
  right: -25px;
  transform: rotate(20deg);
  background: rgba(255, 71, 126, 0.2);
  border: 1px dashed rgba(255, 71, 126, 0.6);
  color: var(--accent-pink);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 25px;
  letter-spacing: 1px;
}

.case-info {
  flex: 1;
}
.case-tag {
  background: #ff477e;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 8px;
  display: inline-block;
  margin-bottom: 8px;
}
.case-info h2 {
  font-size: 1.35rem;
  color: #fff;
  margin-bottom: 6px;
}
.case-info p {
  color: #d1ccfa;
  font-size: 0.95rem;
  line-height: 1.4;
}

.clue-meter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 170px;
}
.meter-label {
  font-size: 0.85rem;
  color: #aaa5dc;
  font-weight: 600;
}
.clue-dots {
  display: flex;
  gap: 8px;
}
.clue-step {
  background: #1c1840;
  border: 2px solid #4a428c;
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: #8c86be;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.clue-step .step-icon {
  font-size: 1rem;
  opacity: 0.4;
}
.clue-step.solved {
  background: linear-gradient(135deg, #2ec4b6, #219688);
  border-color: #55f2e1;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(46, 196, 182, 0.5);
  transform: scale(1.05);
}
.clue-step.solved .step-icon {
  opacity: 1;
}

/* Settings Panel */
.settings-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.setting {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cbc6fa;
  font-weight: 600;
  font-size: 0.9rem;
}
.setting select {
  background: #252152;
  border: 2px solid #4e4694;
  border-radius: 12px;
  padding: 8px 14px;
  color: #ffffff;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
.setting select:focus {
  border-color: var(--accent-gold);
}

.rank-indicator {
  background: #252152;
  border: 2px solid #4e4694;
  border-radius: 12px;
  padding: 5px 12px;
  gap: 8px;
}
.rank-badge {
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 0.9rem;
}

.streak-dots {
  display: inline-flex;
  gap: 5px;
}
.streak-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #393370;
  border: 1.5px solid #554d9c;
  transition: all 0.25s;
}
.streak-dot.active {
  background: #ffb400;
  border-color: #ff9f1c;
  box-shadow: 0 0 8px #ffd13b;
  transform: scale(1.2);
}

.level-reset-btn {
  border: 0;
  background: #3a3375;
  color: #ddd9ff;
  cursor: pointer;
  font: 600 0.8rem var(--font-family);
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}
.level-reset-btn:hover {
  background: #50479e;
  color: #fff;
}

/* Equation Stage Board */
.equation-board {
  background: #ffffff;
  border-radius: 28px;
  padding: 30px 24px;
  color: var(--ink-dark);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35), 0 0 0 6px #3b357a;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Suspect Dialogue */
.suspect-stage {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 5px;
}
.suspect-bubble {
  background: #f1edff;
  border: 2px solid #d4cbf7;
  border-radius: 18px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #43377a;
  position: relative;
  max-width: 440px;
  text-align: center;
}
.suspect-bubble::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 8px 0 8px 10px;
  border-style: solid;
  border-color: transparent transparent transparent #f1edff;
}
.suspect-avatar {
  font-size: 3.2rem;
  background: #f7f5ff;
  border: 3px solid #dcd4fa;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  animation: suspectWiggle 4s infinite ease-in-out;
}
@keyframes suspectWiggle {
  0%, 100% { transform: scale(1) rotate(0); }
  25% { transform: scale(1.05) rotate(-5deg); }
  75% { transform: scale(1.05) rotate(5deg); }
}

/* Equation Items */
.equation-display {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

.equation-box {
  background: #f8f7ff;
  border: 3px solid #ded9fa;
  border-radius: 18px;
  padding: 16px 20px;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 6px 0 #cfc7f5;
  transition: all 0.2s;
}
.equation-box .box-char {
  font-size: 1.8rem;
}
.equation-box .box-val {
  font-size: 2.4rem;
  font-weight: 700;
  color: #2b2361;
}

.equation-box.operator-box {
  min-width: 72px;
  background: #fcf9ee;
  border-color: #faebba;
  box-shadow: 0 6px 0 #ebd89b;
}
.equation-box.operator-box .box-val {
  color: #c98200;
  font-size: 2.8rem;
  line-height: 1;
}

.equation-box.result-box {
  background: #eefcf8;
  border-color: #bbf0e5;
  box-shadow: 0 6px 0 #95dec9;
}
.equation-box.result-box .box-val {
  color: #008772;
}

.equation-box.mystery-target {
  background: #fff8e8 !important;
  border: 4px dashed #ff9f1c !important;
  box-shadow: 0 8px 20px rgba(255, 159, 28, 0.3) !important;
  animation: mysteryPulse 1.8s infinite alternate ease-in-out;
  cursor: pointer;
}
@keyframes mysteryPulse {
  0% { transform: scale(1); border-color: #ff9f1c; }
  100% { transform: scale(1.06); border-color: #ff3366; }
}
.equation-box.mystery-target .box-val {
  color: #ff3366 !important;
  font-size: 2.8rem;
}

.equation-equals {
  font-size: 2.8rem;
  font-weight: 700;
  color: #8c84b8;
  margin: 0 4px;
}

/* Feedback message */
.feedback {
  font-size: 1.15rem;
  font-weight: 600;
  color: #52478a;
  min-height: 32px;
  text-align: center;
  transition: all 0.2s;
}
.feedback.success {
  color: #0b9e76;
  font-weight: 700;
  transform: scale(1.05);
}
.feedback.try-again {
  color: #d6335e;
}

/* Answers Choices Section */
.answer-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.choices-grid {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
}

.choice-card {
  background: #ffffff;
  border: 3px solid #3b357a;
  border-radius: 20px;
  padding: 16px 26px;
  font-size: 2.1rem;
  font-weight: 700;
  color: #1f1a45;
  cursor: pointer;
  box-shadow: 0 8px 0 #201b4c;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 110px;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}
.choice-card .choice-sub {
  font-size: 0.9rem;
  color: #645f8a;
  font-weight: 600;
}
.choice-card:hover {
  background: #f7f5ff;
  transform: translateY(-2px);
  box-shadow: 0 10px 0 #201b4c;
}
.choice-card:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #201b4c;
}

/* Operator cards distinct colors */
.choice-card.op-add {
  border-color: #3a86ff;
  color: #0050cc;
  box-shadow: 0 8px 0 #00368a;
}
.choice-card.op-sub {
  border-color: #ff477e;
  color: #c9003c;
  box-shadow: 0 8px 0 #850028;
}
.choice-card.op-mult {
  border-color: #ff9326;
  color: #cc6000;
  box-shadow: 0 8px 0 #8a4100;
}

/* Keypad for large number typing when needed */
.numpad-container {
  display: flex;
  justify-content: center;
}
.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 10px;
}
.numpad-grid .key {
  font-family: var(--font-family);
  font-size: 1.6rem;
  font-weight: 700;
  background: #ffffff;
  color: var(--ink-dark);
  border: 2px solid #3b357a;
  border-radius: 16px;
  height: 60px;
  cursor: pointer;
  box-shadow: 0 6px 0 #201b4c;
  transition: all 0.1s;
}
.numpad-grid .key:hover {
  background: #f4f1ff;
  transform: translateY(-2px);
}
.numpad-grid .key:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #201b4c;
}
.numpad-grid .key.clear {
  color: #ff477e;
  font-size: 1.3rem;
}
.numpad-grid .key.backspace {
  color: #8c84b8;
  font-size: 1.3rem;
}

/* Footer controls */
.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.footer-tip {
  font-size: 0.9rem;
  color: #9c95d9;
}
.footer-actions {
  display: flex;
  gap: 12px;
}
.footer-btn {
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid #50479e;
  background: #252152;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 0 #141230;
  transition: all 0.15s;
}
.footer-btn:hover {
  background: #332d6e;
  transform: translateY(-1px);
}
.footer-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #141230;
}
.footer-btn.hint-btn {
  border-color: #ffaa00;
  color: var(--accent-gold);
}

/* Celebration particles & fireworks */
.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
.celebration.playing {
  animation: celebrationPulse 1.2s ease-out;
}
@keyframes celebrationPulse {
  0% { box-shadow: inset 0 0 80px rgba(255, 209, 59, 0.6); }
  100% { box-shadow: inset 0 0 0 rgba(255, 209, 59, 0); }
}

.confetti {
  position: absolute;
  top: -20px;
  left: var(--left);
  width: var(--size);
  height: calc(var(--size) * 1.4);
  background: var(--color);
  opacity: 0.95;
  transform: rotate(var(--tilt));
  animation: confettiFall 1.8s ease-out forwards;
  animation-delay: var(--delay);
  border-radius: 3px;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) translateX(var(--drift)) rotate(720deg); opacity: 0; }
}

.firework {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color);
  animation: fireworkPop 0.9s ease-out forwards;
  animation-delay: var(--delay);
}
@keyframes fireworkPop {
  0% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 var(--color); }
  50% { opacity: 0.9; }
  100% {
    transform: scale(22);
    opacity: 0;
    box-shadow: 0 0 30px var(--color), 0 0 60px #fff;
  }
}

/* Responsive */
@media (max-width: 600px) {
  .app-shell { padding: 16px 12px 40px; }
  .brand h1 { font-size: 1.6rem; }
  .detective-avatar { font-size: 2.2rem; }
  .case-card { flex-direction: column; align-items: flex-start; }
  .clue-meter { align-items: flex-start; }
  .equation-box { min-width: 70px; padding: 12px 14px; }
  .equation-box .box-val { font-size: 1.8rem; }
  .equation-equals { font-size: 2rem; }
  .suspect-bubble { font-size: 0.85rem; max-width: 260px; }
  .choice-card { font-size: 1.6rem; padding: 12px 18px; min-width: 80px; }
  .settings-panel { flex-direction: column; align-items: stretch; }
  .setting { justify-content: space-between; }
  .game-footer { flex-direction: column; text-align: center; }
}
