/* Minesweeper Online Free - Comprehensive Stylesheet */

/* --- Custom Properties & Theme --- */
:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #273549;
  --bg-window: #cbd5e1;
  --border-window-outer: #475569;
  --border-light: #ffffff;
  --border-dark: #64748b;
  
  --cell-unrevealed: #94a3b8;
  --cell-unrevealed-hover: #a1b0c4;
  --cell-revealed: #e2e8f0;
  --cell-border-color: #cbd5e1;
  --cell-focus-ring: #3b82f6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #0f172a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #10b981;
  --border: #334155;
  --radius: 12px;

  /* Classic Minesweeper Number Colors */
  --num-1: #1d4ed8; /* Blue */
  --num-2: #15803d; /* Green */
  --num-3: #b91c1c; /* Red */
  --num-4: #4338ca; /* Dark Navy/Indigo */
  --num-5: #7f1d1d; /* Maroon */
  --num-6: #0f766e; /* Teal */
  --num-7: #0f172a; /* Black/Slate */
  --num-8: #64748b; /* Gray */

  --font-main: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-lcd: 'Courier New', Courier, monospace;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* --- Site Header --- */
.site-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.15s ease;
  min-height: 44px;
  padding: 0.25rem 0.5rem;
}

.back-link:hover, .back-link:focus-visible {
  color: var(--accent);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.game-icon {
  font-size: 1.5rem;
}

.brand-title {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.icon-button {
  background: var(--bg-surface-hover);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 1.25rem;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-button:hover, .icon-button:focus-visible {
  background: var(--border);
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Main Game Container --- */
.game-container {
  flex: 1;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header-text {
  text-align: center;
  margin-bottom: 1.25rem;
}

.game-title {
  font-size: 2rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.game-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 580px;
  margin: 0 auto;
}

/* --- Difficulty Selector Bar --- */
.difficulty-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.diff-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.diff-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.diff-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Retro Minesweeper Window Frame --- */
.mine-window {
  background-color: var(--bg-window);
  border: 4px solid var(--border-window-outer);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 1rem;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  user-select: none;
}

/* --- HUD Header with LCDs and Smiley --- */
.mine-hud {
  background-color: #94a3b8;
  border: 3px solid #64748b;
  border-top-color: #475569;
  border-left-color: #475569;
  border-right-color: #ffffff;
  border-bottom-color: #ffffff;
  width: 100%;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  border-radius: 6px;
}

/* Vintage LCD Counter */
.lcd-counter {
  background-color: #000000;
  border: 2px solid #334155;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  display: inline-flex;
  gap: 2px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.9);
}

.lcd-digit {
  font-family: var(--font-lcd);
  font-size: 1.75rem;
  font-weight: 900;
  color: #ef4444;
  letter-spacing: 2px;
  line-height: 1;
  text-shadow: 0 0 6px rgba(239, 68, 68, 0.8);
}

/* Smiley Reset Face */
.face-button {
  background-color: #cbd5e1;
  border: 3px solid #ffffff;
  border-right-color: #64748b;
  border-bottom-color: #64748b;
  width: 50px;
  height: 50px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.05s ease;
}

.face-button:hover {
  background-color: #e2e8f0;
}

.face-button:active, .face-button.pressed {
  border-color: #64748b;
  border-right-color: #ffffff;
  border-bottom-color: #ffffff;
  transform: translateY(1px);
}

.face-emoji {
  font-size: 1.75rem;
  line-height: 1;
}

/* --- Viewport for Grid (Responsive scrolling on smaller viewports) --- */
.grid-viewport {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  justify-content: center;
  padding: 0.25rem 0;
  scrollbar-width: thin;
  scrollbar-color: #64748b #cbd5e1;
}

.grid-viewport::-webkit-scrollbar {
  height: 8px;
}

.grid-viewport::-webkit-scrollbar-track {
  background: #cbd5e1;
}

.grid-viewport::-webkit-scrollbar-thumb {
  background-color: #64748b;
  border-radius: 4px;
}

/* --- Minefield Grid --- */
.minefield {
  display: grid;
  background-color: #64748b;
  border: 4px solid #475569;
  border-top-color: #334155;
  border-left-color: #334155;
  border-right-color: #ffffff;
  border-bottom-color: #ffffff;
  gap: 1px;
  border-radius: 4px;
  outline: none;
}

/* Preset grid dimensions */
.grid-beginner {
  grid-template-columns: repeat(9, 36px);
  grid-template-rows: repeat(9, 36px);
}

.grid-intermediate {
  grid-template-columns: repeat(16, 32px);
  grid-template-rows: repeat(16, 32px);
}

.grid-expert {
  grid-template-columns: repeat(30, 28px);
  grid-template-rows: repeat(16, 28px);
}

/* Grid Cell Styles */
.cell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-main);
  font-size: 1.15rem;
  font-weight: 900;
  cursor: pointer;
  position: relative;
  background-color: var(--cell-unrevealed);
  border: 3px solid #f8fafc;
  border-right-color: #475569;
  border-bottom-color: #475569;
  transition: background-color 0.08s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell:hover:not(.revealed):not(.flagged) {
  background-color: var(--cell-unrevealed-hover);
}

/* Keyboard active cursor focus */
.cell.focused {
  outline: 2px solid #2563eb !important;
  outline-offset: -2px;
  z-index: 5;
}

/* Revealed Cell */
.cell.revealed {
  background-color: var(--cell-revealed);
  border: 1px solid #94a3b8;
  cursor: default;
}

.cell.revealed.has-number {
  cursor: pointer; /* Can chord */
}

/* Depressed state when holding chord or mouse click */
.cell.depressed {
  background-color: var(--cell-revealed);
  border: 1px solid #94a3b8;
}

/* Number Colors */
.cell[data-num="1"] { color: var(--num-1); }
.cell[data-num="2"] { color: var(--num-2); }
.cell[data-num="3"] { color: var(--num-3); }
.cell[data-num="4"] { color: var(--num-4); }
.cell[data-num="5"] { color: var(--num-5); }
.cell[data-num="6"] { color: var(--num-6); }
.cell[data-num="7"] { color: var(--num-7); }
.cell[data-num="8"] { color: var(--num-8); }

/* Flags & Explosions */
.cell.flagged {
  color: #dc2626;
}

.cell.mine-triggered {
  background-color: #ef4444 !important;
  border: 1px solid #991b1b !important;
  animation: pulse-mine 0.4s ease-out;
}

.cell.mine-revealed {
  background-color: #f1f5f9;
  border: 1px solid #94a3b8;
}

.cell.wrong-flag {
  background-color: #fee2e2;
  color: #991b1b;
  text-decoration: line-through;
}

@keyframes pulse-mine {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* --- Mobile Action Bar --- */
.mobile-action-bar {
  width: 100%;
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: center;
}

.mode-btn {
  flex: 1;
  max-width: 220px;
  min-height: 48px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  border: 2px solid #475569;
  transition: all 0.15s ease;
}

.mode-btn.mode-dig {
  background-color: #1e293b;
  color: #f8fafc;
}

.mode-btn.mode-flag {
  background-color: #dc2626;
  color: #ffffff;
  border-color: #b91c1c;
  box-shadow: 0 0 10px rgba(220, 38, 38, 0.4);
}

.action-btn {
  background-color: #334155;
  color: #f8fafc;
  border: 2px solid #475569;
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.action-btn:hover {
  background-color: #475569;
}

/* --- Best Times Stats Panel --- */
.stats-panel {
  width: 100%;
  max-width: 600px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 0.75rem 0.5rem;
  border-radius: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-val {
  font-family: var(--font-lcd);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

/* --- Modal Overlay & Card --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  animation: modal-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-badge {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.modal-title {
  font-size: 1.625rem;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 0.5rem;
}

.modal-desc {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin-bottom: 1.25rem;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.5rem;
  margin-bottom: 1.5rem;
}

.modal-stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.m-stat-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.m-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
}

.record-tag {
  color: #10b981 !important;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 0.9375rem;
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  flex: 1;
  background: var(--bg-surface-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9375rem;
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  background: var(--border);
}

/* --- SEO Content Block --- */
.content-block {
  max-width: 800px;
  width: 100%;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.article-header {
  margin-bottom: 1.5rem;
}

.article-header h2 {
  font-size: 1.625rem;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 0.35rem;
}

.freshness-tag {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.article-section {
  margin-bottom: 2rem;
}

.article-section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 0.85rem;
}

.article-section h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #e2e8f0;
  margin: 1.25rem 0 0.6rem;
}

.article-section p {
  color: #cbd5e1;
  margin-bottom: 1rem;
  line-height: 1.7;
}

.rules-list {
  padding-left: 1.25rem;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.rules-list strong {
  color: #ffffff;
}

/* Strategy Cards Grid */
.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.strategy-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.strategy-card h4 {
  color: var(--accent);
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

.strategy-card p {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-bottom: 0;
  line-height: 1.6;
}

/* FAQ Accordion */
.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.faq-item[open] {
  border-color: var(--accent);
}

.faq-question {
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: "+";
  font-size: 1.25rem;
  color: var(--accent);
  transition: transform 0.2s ease;
}

.faq-item[open] .faq-question::after {
  content: "−";
}

.faq-answer {
  padding: 0 1.25rem 1.25rem;
  color: #cbd5e1;
  font-size: 0.925rem;
  line-height: 1.6;
}

/* Cross-links */
.cross-links {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.related-games-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.related-games-list li a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s ease;
}

.related-games-list li a:hover {
  color: #60a5fa;
  text-decoration: underline;
}

/* --- Site Footer --- */
.site-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.footer-links {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent);
}

/* --- Mobile Responsiveness Adjustments --- */
@media (max-width: 640px) {
  .game-title {
    font-size: 1.65rem;
  }

  .mine-window {
    padding: 0.65rem;
  }

  .mine-hud {
    padding: 0.5rem 0.65rem;
  }

  .lcd-digit {
    font-size: 1.4rem;
  }

  .face-button {
    width: 44px;
    height: 44px;
  }

  .face-emoji {
    font-size: 1.4rem;
  }

  .grid-beginner {
    grid-template-columns: repeat(9, 32px);
    grid-template-rows: repeat(9, 32px);
  }

  .grid-intermediate {
    grid-template-columns: repeat(16, 28px);
    grid-template-rows: repeat(16, 28px);
  }

  .grid-expert {
    grid-template-columns: repeat(30, 26px);
    grid-template-rows: repeat(16, 26px);
  }

  .cell {
    font-size: 0.95rem;
  }
}
