/* ============================================
   MURDEROUS MATHS — GAME BRANDING
   Visual style: Graph-paper classroom, warm & playful
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand palette */
  --mm-red: #e74c3c;
  --mm-red-dark: #c0392b;
  --mm-orange: #f39c12;
  --mm-orange-light: #fdebd0;
  --mm-yellow: #f1c40f;
  --mm-yellow-light: #fef9e7;
  --mm-green: #2ecc71;
  --mm-green-dark: #27ae60;
  --mm-blue: #3498db;
  --mm-blue-dark: #2980b9;
  --mm-purple: #9b59b6;
  --mm-pink: #e91e8b;
  --mm-teal: #1abc9c;

  /* Neutrals */
  --mm-bg: #fdf6e3;
  --mm-grid: #e8dcc8;
  --mm-grid-major: #d4c5a9;
  --mm-text: #2c3e50;
  --mm-text-light: #7f8c8d;
  --mm-white: #ffffff;
  --mm-shadow: rgba(0,0,0,0.1);

  /* Typography */
  --font-main: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Fredoka One', 'Nunito', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;

  /* Sizing */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
}

body {
  font-family: var(--font-main);
  color: var(--mm-text);
  background: var(--mm-bg);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- Graph Paper Background --- */
.graph-paper {
  background-image:
    linear-gradient(var(--mm-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--mm-grid) 1px, transparent 1px),
    linear-gradient(var(--mm-grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--mm-grid-major) 1px, transparent 1px);
  background-size:
    20px 20px,
    20px 20px,
    100px 100px,
    100px 100px;
  background-position: -1px -1px;
}

/* --- Top Navigation --- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--mm-white);
  border-bottom: 3px solid var(--mm-red);
  box-shadow: 0 2px 8px var(--mm-shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--mm-text);
}

.top-bar .logo-icon {
  font-size: 32px;
}

.top-bar .logo-text {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--mm-red);
}

.top-bar .logo-sub {
  font-size: 13px;
  color: var(--mm-text-light);
  font-weight: 400;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--mm-orange);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}
.back-btn:hover { background: var(--mm-red); transform: scale(1.05); }

/* --- Main Content Container --- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* --- Cards --- */
.card {
  background: var(--mm-white);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 4px 20px var(--mm-shadow);
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: white;
  min-width: 120px;
}

.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

.btn-red { background: var(--mm-red); }
.btn-red:hover { background: var(--mm-red-dark); }
.btn-orange { background: var(--mm-orange); }
.btn-green { background: var(--mm-green); }
.btn-green:hover { background: var(--mm-green-dark); }
.btn-blue { background: var(--mm-blue); }
.btn-blue:hover { background: var(--mm-blue-dark); }
.btn-purple { background: var(--mm-purple); }
.btn-teal { background: var(--mm-teal); }

.btn-outline {
  background: transparent;
  border: 3px solid var(--mm-blue);
  color: var(--mm-blue);
}
.btn-outline:hover {
  background: var(--mm-blue);
  color: white;
}

.btn-lg { font-size: 20px; padding: 18px 36px; border-radius: var(--radius-lg); }
.btn-sm { font-size: 14px; padding: 8px 16px; min-width: auto; }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 6px;
  background: #ecf0f1;
  padding: 6px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.tab {
  flex: 1;
  min-width: 140px;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--mm-text-light);
  transition: all 0.25s ease;
  text-align: center;
}

.tab:hover { background: rgba(255,255,255,0.7); color: var(--mm-text); }
.tab.active {
  background: var(--mm-white);
  color: var(--mm-blue);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.tab .tab-icon { display: block; font-size: 24px; margin-bottom: 4px; }
.tab .tab-check { color: var(--mm-green); margin-left: 6px; }

/* --- Problem Display --- */
.problem-display {
  text-align: center;
  padding: 20px;
  margin-bottom: 20px;
}

.problem-numbers {
  font-family: var(--font-display);
  font-size: 52px;
  color: var(--mm-text);
  letter-spacing: 4px;
}

.problem-numbers .operator {
  color: var(--mm-red);
  margin: 0 12px;
}

.problem-label {
  font-size: 15px;
  color: var(--mm-text-light);
  margin-top: 8px;
}

/* --- Game Area --- */
.game-area {
  min-height: 350px;
  position: relative;
}

/* --- Mascot --- */
.mascot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.mascot-img {
  width: 80px;
  height: 80px;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.3s;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}
.mascot-img:hover { transform: scale(1.1) rotate(-5deg); }

.mascot-bubble {
  background: var(--mm-white);
  border: 3px solid var(--mm-orange);
  border-radius: var(--radius) var(--radius) 0 var(--radius);
  padding: 12px 16px;
  max-width: 260px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  pointer-events: auto;
  animation: bubblePop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bubblePop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.mascot-bubble.hidden { display: none; }

/* --- Level Picker --- */
.level-picker {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.level-picker label {
  font-weight: 700;
  font-size: 15px;
  color: var(--mm-text-light);
}

.level-btn {
  padding: 8px 18px;
  border: 2px solid #ddd;
  border-radius: var(--radius-sm);
  background: var(--mm-white);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--mm-text);
}

.level-btn:hover { border-color: var(--mm-blue); color: var(--mm-blue); }
.level-btn.active {
  background: var(--mm-blue);
  color: white;
  border-color: var(--mm-blue);
}

/* --- Canvas Styling --- */
canvas {
  border-radius: var(--radius);
  display: block;
}

/* --- Confetti Container --- */
.confetti-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 12px;
  height: 12px;
  top: -20px;
  animation: confettiFall 3s ease-in forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* --- Discovery Box --- */
.discovery-box {
  background: linear-gradient(135deg, var(--mm-yellow-light), var(--mm-orange-light));
  border: 3px solid var(--mm-orange);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  margin-top: 20px;
  animation: discoveryPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.discovery-box h3 {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--mm-red);
  margin-bottom: 8px;
}

.discovery-box p {
  font-size: 16px;
  line-height: 1.6;
}

@keyframes discoveryPop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Answer Input --- */
.answer-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.answer-input {
  font-family: var(--font-mono);
  font-size: 28px;
  width: 140px;
  text-align: center;
  padding: 10px 16px;
  border: 3px solid #ddd;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s;
}

.answer-input:focus { border-color: var(--mm-blue); }
.answer-input.correct { border-color: var(--mm-green); background: #e8f8f0; }
.answer-input.wrong { border-color: var(--mm-red); background: #fdeaea; }

/* --- Step Indicator --- */
.steps-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  align-items: center;
}

.step-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  background: #ecf0f1;
  color: var(--mm-text-light);
  transition: all 0.3s;
}

.step-dot.active { background: var(--mm-blue); color: white; transform: scale(1.15); }
.step-dot.done { background: var(--mm-green); color: white; }

.step-line {
  flex: 1;
  height: 3px;
  background: #ecf0f1;
  border-radius: 2px;
  transition: background 0.3s;
}
.step-line.done { background: var(--mm-green); }

/* --- Menu Grid --- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 32px;
}

.menu-card {
  background: var(--mm-white);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 4px 16px var(--mm-shadow);
  border: 3px solid transparent;
  transition: all 0.3s;
  text-decoration: none;
  color: var(--mm-text);
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
}

.menu-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.menu-card.red { border-color: var(--mm-red); }
.menu-card.orange { border-color: var(--mm-orange); }
.menu-card.blue { border-color: var(--mm-blue); }
.menu-card.green { border-color: var(--mm-green); }
.menu-card.purple { border-color: var(--mm-purple); }
.menu-card.teal { border-color: var(--mm-teal); }
.menu-card.locked { opacity: 0.5; cursor: default; }
.menu-card.locked:hover { transform: none; box-shadow: 0 4px 16px var(--mm-shadow); }

.menu-card .card-icon { font-size: 40px; }
.menu-card .card-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.menu-card .card-desc { font-size: 14px; color: var(--mm-text-light); line-height: 1.5; }
.menu-card .card-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: white;
  align-self: flex-start;
}
.card-badge.ready { background: var(--mm-green); }
.card-badge.coming { background: var(--mm-text-light); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .problem-numbers { font-size: 36px; }
  .tabs { flex-direction: column; }
  .tab { min-width: auto; }
  .mascot { bottom: 10px; right: 10px; }
  .mascot-img { width: 60px; height: 60px; }
  .mascot-bubble { max-width: 200px; font-size: 13px; }
}

/* --- Animations --- */
@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.4s ease-out; }

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

.pulse { animation: pulse 0.6s ease; }

/* --- Comparison layout (3-ways side-by-side) --- */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.comparison-card {
  background: var(--mm-white);
  border: 2px solid #ecf0f1;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.comparison-card h4 { font-size: 14px; color: var(--mm-text-light); margin-bottom: 8px; }
.comparison-card .result { font-family: var(--font-display); font-size: 28px; color: var(--mm-green); }

@media (max-width: 768px) {
  .comparison-grid { grid-template-columns: 1fr; }
}
