:root {
  /* BACKGROUNDS: Deep Red/Black Void */
  --md-bg: #050202;
  --md-panel: #140808; 
  
  /* ACCENT: The Arcade Red */
  --md-accent: #FF4F70; 
  --md-accent-dim: #991b2c;
  
  /* GAME STATES */
  --md-safe: #148CFF;   /* Blue */
  --md-warn: #FFE83D;   /* Yellow */
  --md-danger: #FF4F70; /* Red */
  
  /* LEVEL COLORS (Green/Orange/Red) */
  --md-lvl-norm: #59FF84;
  --md-lvl-hard: #FF9F2E;
  --md-lvl-hardest: #FF4F70;

  /* TILE COLORS */
  --md-tile-hidden: #2a3044; 
  --md-tile-rev: #0a0505;    
  
  /* TEXT */
  --md-text-main: #f5f5f7;
  --md-text-muted: #a2a7c2;
  
  /* BORDERS & SHADOWS */
  --md-border: #331111;
  --md-border-highlight: rgba(255, 79, 112, 0.4);
  --md-shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.6);
  
  --md-radius: 20px;
}

/* RESET */
*, *::before, *::after { box-sizing: border-box; }
html, body { 
  margin: 0; padding: 0; min-height: 100vh; 
  font-family: system-ui, -apple-system, sans-serif; 
  background-color: var(--md-bg); color: var(--md-text-main); 
  display: flex; flex-direction: column; 
}

/* CENTER WRAPPER */
.center-wrapper { margin: auto; width: 100%; display: flex; flex-direction: column; align-items: center; padding: 20px 8px; position: relative; z-index: 1; }

/* FIXED BACKGROUND (Continuous Stars - No Nebula) */
.fixed-background { 
  position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; 
  background-color: #050202; 
  overflow: hidden; pointer-events: none; 
}

.fixed-background::before {
  content: ""; position: absolute; inset: 0;
  background-image: 
    radial-gradient(circle at 25px 5px, white 1px, transparent 1.5px),
    radial-gradient(circle at 50px 25px, rgba(255,255,255,0.9) 1px, transparent 1.5px),
    radial-gradient(circle at 300px 10px, white 1px, transparent 1.5px);
  background-size: 400px 400px; opacity: 0.8; 
  animation: starIntro 30s linear infinite;
}

.fixed-background::after {
  content: ""; position: absolute; inset: 0;
  background-image: 
    radial-gradient(circle at 75px 100px, rgba(255,255,255,0.8) 1.5px, transparent 2.5px),
    radial-gradient(circle at 150px 250px, rgba(255,255,255,0.6) 1px, transparent 2px),
    radial-gradient(circle at 320px 380px, white 1.5px, transparent 2.5px);
  background-size: 550px 550px; 
  opacity: 0.6;
  animation: starIntroFast 25s linear infinite;
}

@keyframes starIntro { 
  from { background-position: 0 0; } 
  to { background-position: 0 400px; } 
}

@keyframes starIntroFast { 
  from { background-position: 0 0; } 
  to { background-position: 0 550px; } 
}

/* GAME SHELL */
.game-shell.md-shell {
  width: 100%; max-width: 460px; padding: 18px 14px 22px; margin: 0;
  background: rgba(20, 22, 26, 0.95); 
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 26px; position: relative; z-index: 1; 
  box-shadow: 0 0 0 1px rgba(255, 79, 112, 0.25), 0 0 18px rgba(0, 0, 0, 0.9);
  overflow: hidden; 
}

.md-confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 15; }
.hidden { display: none !important; }

/* HEADER */
.md-header { text-align: center; margin-bottom: 6px; }
.md-header h1 { 
    margin: 0 0 4px; 
    letter-spacing: 0.22em; 
    font-weight: 900; 
    font-size: 1.7rem; 
    color: #fff; 
    text-shadow: 0 0 20px rgba(255, 79, 112, 0.6); 
}
.md-tagline { margin: 0; font-size: 0.78rem; color: var(--md-text-muted); text-transform: uppercase; }
.md-howto-btn { margin-top: 6px; background: transparent; border: none; color: var(--md-text-muted); font-size: 0.75rem; cursor: pointer; text-decoration: underline; padding: 0; }
.md-howto-btn:hover { color: #fff; }

/* TOOLTIP BOX */
.md-howto-tooltip { 
  margin: 6px 0 10px; font-size: 0.75rem; 
  background: rgba(20, 22, 26, 0.98); 
  border-radius: 10px; padding: 12px; 
  border: 1px solid var(--md-border); 
  color: var(--md-text-muted); 
  text-align: center; 
  box-shadow: var(--md-shadow-soft);
}
.md-btn-mini { 
  margin-top: 10px; padding: 6px 12px; border-radius: 999px; border: none; 
  background: #ffffff; color: #000000; cursor: pointer; 
  font-weight: 800; font-size: 0.75rem; text-transform: uppercase; 
  display: block; margin-left: auto; margin-right: auto;
  transition: transform 0.1s;
}
.md-btn-mini:hover { transform: scale(1.05); }

/* TOP BAR */
.top-bar.md-top-bar { 
  display: flex; align-items: center; justify-content: space-between; 
  background: rgba(14, 16, 20, 0.8); border-radius: 999px; 
  padding: 8px 12px; 
  border: 1px solid var(--md-border); 
  box-shadow: var(--md-shadow-soft); margin-bottom: 10px; font-size: 0.7rem; gap: 6px; 
}
.top-item { flex: 1; display: flex; flex-direction: column; align-items: center; }

.top-label { 
    text-transform: uppercase; 
    letter-spacing: 0.12em; 
    color: var(--md-text-muted); 
    font-size: 0.65rem; 
    font-weight: 900;   
    white-space: nowrap; 
}
.top-value { 
    margin-top: 2px; 
    font-weight: 600; 
    font-size: 0.85rem; 
    color: #fff; 
    font-variant-numeric: tabular-nums; 
}

/* SOUND TOGGLE */
.md-sound-toggle { 
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--md-border); 
  color: var(--md-text-muted); border-radius: 50%; 
  width: 42px; height: 42px; 
  font-size: 1.2rem; 
  display: flex; align-items: center; justify-content: center; cursor: pointer; 
  margin-left: 2px; flex-shrink: 0; transition: 0.2s;
}
.md-sound-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* MODE SWITCH */
.mode-switch.md-mode-switch { 
  display: inline-flex; background: rgba(14, 16, 20, 0.9); border-radius: 999px; 
  padding: 3px; border: 1px solid var(--md-border); margin: 0 auto 10px; 
  position: relative; left: 50%; transform: translateX(-50%); 
}
.mode-btn { 
  border: none; background: transparent; color: var(--md-text-muted); 
  padding: 8px 14px; border-radius: 999px; cursor: pointer; transition: 0.2s;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
}
.mode-btn.active { 
  background: var(--md-accent); /* RED */
  color: #000000;      
  font-weight: 800; 
  box-shadow: 0 0 10px rgba(255, 79, 112, 0.4); 
}

/* DIFFICULTY SWITCH */
.difficulty-switch { 
  display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; text-align: center; 
}
.diff-btn { 
  border: 1px solid var(--md-border); background: transparent; 
  color: var(--md-text-muted); padding: 4px 10px; border-radius: 99px; 
  font-size: 0.65rem; cursor: pointer; text-transform: uppercase; 
}
.diff-btn.active { 
  background: var(--md-accent); /* RED */
  color: #000000;      
  border-color: var(--md-accent); 
  font-weight: 700; 
  box-shadow: 0 0 8px rgba(255, 79, 112, 0.3);
}

/* GRID AREA */
.md-game-area {
  margin-top: 8px;
  background: radial-gradient(circle at top, #2b2f3a, #14161a);
  padding: 8px; 
  border-radius: 20px;
  box-shadow: var(--md-shadow-soft);
  border: 1px solid rgba(120, 120, 120, 0.2); 
  display: flex; justify-content: center;
}

/* COMPACT 6x6 GRID */
.md-grid-container { 
  display: grid; 
  grid-template-columns: 24px repeat(5, 1fr); 
  grid-template-rows: 24px repeat(5, 1fr); 
  gap: 3px; 
  width: 100%; aspect-ratio: 1/1;
}

/* SCANNER STYLES - NEUTRAL/TECH */
.md-scanner-header {
    background: rgba(255, 255, 255, 0.05); /* Transparent Grey */
    color: var(--md-text-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; 
    font-weight: 700;
    font-family: monospace; 
    border-radius: 4px;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.md-scanner-corner {
    background: transparent;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; 
    color: var(--md-accent); /* Red */
}

/* TILES */
.md-tile { 
  background: var(--md-tile-hidden); 
  border: 1px solid rgba(255,255,255,0.1); 
  border-radius: 6px; 
  cursor: pointer; position: relative; 
  display: flex; align-items: center; justify-content: center; 
  font-size: 1.2rem; font-weight: 800; user-select: none; 
  transition: transform 0.1s, background 0.2s; 
  box-shadow: 0 3px 0 rgba(0,0,0,0.4); 
}
.md-tile:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.4); }

.md-tile.revealed { 
  background: var(--md-tile-rev); 
  border-color: #1a0505; 
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8); 
  transform: translateY(3px); 
  cursor: default; 
}

/* NUMBER COLORS */
.md-tile[data-num="1"] { color: var(--md-safe); }
.md-tile[data-num="2"] { color: #59FF84; }
.md-tile[data-num="3"] { color: var(--md-warn); }
.md-tile[data-num="4"], .md-tile[data-num="5"] { color: #d946ef; }
.md-tile[data-num="6"] { color: var(--md-danger); }

/* SPECIAL STATES */
.md-tile.flagged { border-color: var(--md-warn); }
.md-tile.flagged::after { content: "🚩"; font-size: 1.1rem; filter: drop-shadow(0 0 4px orange); }

.md-tile.mine { background: #500000; border-color: #ff0000; }
.md-tile.mine::after { content: "💣"; font-size: 1.2rem; }
.md-tile.exploded { background: var(--md-danger) !important; animation: shake 0.4s; }

/* CONTROLS */
.md-bottom { margin-top: 15px; }

.md-tool-toggle-wrapper { 
  display: flex; 
  background: rgba(255, 255, 255, 0.03); 
  padding: 6px; border-radius: 12px; 
  border: 1px solid var(--md-border); margin-bottom: 12px; 
}
.md-tool-btn { 
  flex: 1; 
  border-radius: 999px; 
  padding: 10px; margin: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.2); 
  background: rgba(14, 18, 35, 0.96); 
  color: var(--md-text-muted); 
  font-weight: 700; cursor: pointer; 
  display: flex; align-items: center; justify-content: center; gap: 8px; 
  transition: 0.2s; font-size: 0.9rem; 
}

.md-tool-btn.active { 
  background: var(--md-accent); 
  color: #000000; /* Black Text */
  border-color: var(--md-accent);
  box-shadow: 0 2px 8px rgba(255, 79, 112, 0.4); 
}

.md-status-bar { text-align: center; margin-bottom: 10px; height: 1.2em; }
.md-status-text { font-size: 0.9rem; color: var(--md-text-muted); transition: color 0.2s; }
.md-status-text.win { color: #ffffff; font-weight: bold; text-shadow: 0 0 10px rgba(255, 255, 255, 0.4); }
.md-status-text.lose { color: var(--md-danger); font-weight: bold; }

.md-controls { display: flex; gap: 8px; margin-top: 10px; }

.md-btn-std { 
  flex: 1; padding: 12px; border-radius: 999px; 
  border: 1px solid rgba(255, 255, 255, 0.2); 
  background: rgba(14, 18, 35, 0.96); 
  color: #fff; cursor: pointer; 
  font-weight: 700; text-transform: uppercase; font-size: 0.75rem; 
  transition: 0.2s; white-space: nowrap;
}
.md-btn-std:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.4); }

.md-bottom-actions { display: flex; gap: 8px; margin-top: 10px; }
.md-bottom-btn { 
  flex: 1; padding: 10px; border-radius: 999px; 
  background: rgba(14, 18, 35, 0.96); 
  border: 1px solid rgba(255, 255, 255, 0.2); 
  color: var(--md-text-muted); cursor: pointer; 
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; transition: 0.2s; 
}
.md-bottom-btn:hover:enabled { transform: translateY(-1px); border-color: #fff; color: #fff; }
.md-bottom-btn:disabled { opacity: 0.4; cursor: default; }

.md-share-btn:enabled { 
  background: var(--md-accent) !important; 
  color: #000000 !important; 
  border: none !important; 
  box-shadow: 0 0 15px rgba(255, 79, 112, 0.4); 
}
.md-share-btn:hover:enabled { background: #ff7892 !important; }

/* MODAL & STATS NEW */
.md-modal-overlay { position: fixed; inset: 0; background: rgba(1, 3, 10, 0.9); z-index: 20; display: flex; align-items: center; justify-content: center; }
.md-modal { background: #050712; width: 90%; max-width: 440px; padding: 22px; border-radius: 20px; border: 1px solid rgba(255,255,255,0.1); position: relative; text-align: center; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.9); }
.md-modal-title { margin: 0 0 10px; color: #fff; letter-spacing: 0.15em; text-transform: uppercase; font-size: 1.4rem; font-weight: 900; }
.md-modal-close { position: absolute; top: 15px; right: 15px; background: none; border: none; color: #9ca3af; font-size: 1.5rem; cursor: pointer; }

/* UPDATED: Center text here */
.md-stats-explainer { background: rgba(255,255,255,0.03); border-radius: 8px; padding: 12px; margin-bottom: 12px; font-size: 0.75rem; color: #a0a6c0; text-align: center; }
.md-stats-explainer h3 { margin: 0 0 4px; color: var(--md-accent); font-size: 0.8rem; letter-spacing: 0.1em; text-align: center; }
.md-stats-explainer p { margin: 0; line-height: 1.4; }

.md-level-banner { 
    background: var(--md-accent); color: #000; padding: 8px; 
    border-radius: 8px; margin-bottom: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; 
    display: flex; justify-content: space-between; align-items: center;
}
.md-level-banner .sub { font-size: 0.7rem; background: rgba(0,0,0,0.2); padding: 2px 6px; border-radius: 4px; }

/* Dynamic Level Colors */
.md-level-banner.normal { background: var(--md-lvl-norm); color: #000; }
.md-level-banner.hard { background: var(--md-lvl-hard); color: #000; }
.md-level-banner.hardest { background: var(--md-lvl-hardest); color: #000; }

/* STATS GRID */
.md-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 15px; }
.md-stat-box { background: rgba(255,255,255,0.05); padding: 8px; border-radius: 8px; border: 1px solid var(--md-border); display: flex; flex-direction: column; }
.md-stat-box .label { font-size: 0.65rem; color: #7f86a0; text-transform: uppercase; letter-spacing: 0.05em; }
.md-stat-box .value { font-size: 1.1rem; color: #fff; font-weight: 700; margin-top: 2px; }

/* Utility Text Colors */
.text-norm { color: var(--md-lvl-norm) !important; }
.text-hard { color: var(--md-lvl-hard) !important; }
.text-hardest { color: var(--md-lvl-hardest) !important; }

/* HEATMAP */
.md-heatmap-section { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--md-border); }
.md-heatmap-section h3 { margin: 0 0 8px; font-size: 0.75rem; color: #7f86a0; letter-spacing: 0.1em; text-align: center; }
.md-heatmap-container { display: flex; gap: 4px; justify-content: center; margin-bottom: 8px; }

.md-heatmap-box { width: 14px; height: 14px; border-radius: 2px; background: rgba(255,255,255,0.1); }

/* HEATMAP COLORS */
.md-heatmap-box.normal { background: var(--md-lvl-norm); box-shadow: 0 0 4px var(--md-lvl-norm); }
.md-heatmap-box.hard { background: var(--md-lvl-hard); box-shadow: 0 0 4px var(--md-lvl-hard); }
.md-heatmap-box.hardest { background: var(--md-lvl-hardest); box-shadow: 0 0 4px var(--md-lvl-hardest); }
.md-heatmap-box.loss { background: var(--md-danger); opacity: 0.5; }

.md-stats-row.small { margin-top: 6px; justify-content: space-around; font-size: 0.75rem; color: #a0a6c0; display: flex; }
.md-stats-row.small strong { color: #fff; margin-left: 4px; }

/* INFINITE */
.md-infinite-section { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--md-border); }
.md-infinite-section h3 { margin: 0; font-size: 0.8rem; color: var(--md-accent); letter-spacing: 0.1em; text-align: center; }
.md-infinite-section p { margin: 2px 0 10px; font-size: 0.7rem; color: #7f86a0; }
.md-stats-row.detailed { margin-top: 8px; display: flex; justify-content: space-around; font-size: 0.7rem; color: #a0a6c0; }
.md-stats-row.detailed strong { color: #fff; }

/* FLASH ANIMATIONS */
@keyframes duel-flash-anim {
  0% { transform: scale(1); background-color: rgba(255, 255, 255, 0.1); }
  50% { transform: scale(1.1); background-color: rgba(255, 255, 255, 0.3); border-color: #fff; box-shadow: 0 0 15px rgba(255,255,255,0.5); }
  100% { transform: scale(1); background-color: rgba(255, 255, 255, 0.1); }
}
.duel-flash { animation: duel-flash-anim 0.4s ease-out; }

@keyframes share-flash-anim {
  0% { transform: scale(1); background-color: var(--md-accent); }
  50% { transform: scale(1.1); background-color: #ff7892; border-color: #fff; box-shadow: 0 0 20px rgba(255, 79, 112, 0.8); }
  100% { transform: scale(1); background-color: var(--md-accent); }
}
.share-flash { animation: share-flash-anim 0.4s ease-out; }

/* FOOTER & NAV UNCHANGED */
.content-section { width: 100%; max-width: 600px; margin-top: 20px; padding: 0 14px; color: var(--md-text-muted); font-size: 0.95rem; line-height: 1.6; z-index: 5; text-align: left; }
.content-section h2 { color: #fff; font-size: 1.6rem; margin-bottom: 16px; margin-top: 10px; border-bottom: 1px solid var(--md-border); padding-bottom: 8px; text-align: center; }
.content-section h3 { color: var(--md-accent); font-size: 1.1rem; margin-bottom: 10px; margin-top: 24px; }

/* ADDED: Color for Step headings (h4) */
.content-section h4 {
  color: #ffffff;
  margin-top: 18px;
  margin-bottom: 6px;
  font-size: 0.95rem;
  font-weight: 700;
}

.content-section p { margin-bottom: 16px; }
.content-section strong { color: #fff; }
.md-footer { margin-top: 40px; padding: 20px; border-top: 1px solid var(--md-border); text-align: center; color: var(--md-text-muted); font-size: 0.8rem; z-index: 10; width: 100%; max-width: 600px; }
.md-footer-links { display: flex; justify-content: center; gap: 12px; margin-bottom: 4px; }
.md-footer-link { color: var(--md-accent); text-decoration: none; font-size: 0.78rem; }
.md-footer-link:hover { text-decoration: underline; color: #fff; }
.arcade-return-nav { width: 100%; max-width: 460px; margin: 20px auto 10px; display: flex; justify-content: center; z-index: 5; position: relative; }
.return-link { display: flex; align-items: center; gap: 12px; text-decoration: none; background: rgba(13, 17, 30, 0.6); border: 1px solid rgba(255, 255, 255, 0.08); padding: 12px 28px; border-radius: 999px; color: var(--md-text-muted); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase; transition: 0.3s; backdrop-filter: blur(4px); }
.return-link:hover { background: rgba(255, 79, 112, 0.15); border-color: var(--md-accent); color: #fff; transform: translateY(-2px); box-shadow: 0 0 15px rgba(255, 79, 112, 0.2); }
.return-icon { font-size: 1.1em; transition: transform 0.3s ease; }
.return-link:hover .return-icon { transform: translateX(-4px); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }