/* Ensure [hidden] always wins regardless of CSS specificity */
[hidden] { display: none !important; }

/* ── Variables & Reset ───────────────────────────────────────────────────── */
:root {
  --bg:            #111827;
  --bg-card:       #1f2937;
  --bg-hover:      #2d3748;
  --bg-active:     #374151;
  --primary:       #3b82f6;
  --primary-dark:  #2563eb;
  --primary-glow:  rgba(59, 130, 246, 0.2);
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --text-faint:    #475569;
  --danger:        #ef4444;
  --success:       #22c55e;
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --radius:        6px;
  --font:          'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition:    150ms ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  transition: background var(--transition), opacity var(--transition);
}
button:active  { transform: scale(0.97); }
button:disabled { opacity: 0.6; cursor: default; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

/* ── Header ──────────────────────────────────────────────────────────────── */
#site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo      { font-size: 24px; line-height: 1; }
.site-name { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.puzzle-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.streak-badge {
  background: rgba(249, 115, 22, 0.15);
  color: #fb923c;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ── Main Layout ─────────────────────────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  min-height: calc(100vh - 52px);
}

#game-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* ── Minesweeper Board ───────────────────────────────────────────────────── */
.ms-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ms-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.ms-daily-badge {
  background: rgba(255, 215, 0, 0.12);
  color: #ffd700;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

.ms-header-stats {
  display: flex;
  gap: 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}

.ms-board-info {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

.ms-grid {
  display: inline-grid;
  gap: 2px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  user-select: none;
  touch-action: none;
}

.ms-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  cursor: pointer;
  background: var(--bg-hover);
  border-radius: 3px;
  transition: background 0.08s;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.ms-cell:hover:not(.revealed):not(.mine-hit) { background: var(--bg-active); }
.ms-cell.revealed   { background: var(--bg); cursor: default; }
.ms-cell.flagged    { background: var(--bg-hover); }
.ms-cell.mine-hit   { background: #c0392b; }
.ms-cell.wrong-flag { background: #8b0000; color: #fff; }

/* Number colours */
.ms-cell[data-n="1"] { color: #5b9bd5; }
.ms-cell[data-n="2"] { color: #4caf50; }
.ms-cell[data-n="3"] { color: #e74c3c; }
.ms-cell[data-n="4"] { color: #9b59b6; }
.ms-cell[data-n="5"] { color: #e67e22; }
.ms-cell[data-n="6"] { color: #1abc9c; }
.ms-cell[data-n="7"] { color: var(--text); }
.ms-cell[data-n="8"] { color: var(--text-muted); }

.ms-inline-result {
  margin-top: 12px;
  min-height: 28px;
  text-align: center;
}
.ms-result-win  { color: var(--success); font-weight: 700; font-size: 16px; }
.ms-result-loss { color: var(--danger);  font-weight: 700; font-size: 16px; }

/* Flag mode toggle */
.ms-controls {
  margin-top: 12px;
}
.flag-mode-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 20px;
}
.flag-mode-btn:hover  { background: var(--bg-hover); color: var(--text); }
.flag-mode-btn.active {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}

/* ── Result Panel ────────────────────────────────────────────────────────── */
#result-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 480px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-heading {
  font-size: 30px;
  font-weight: 800;
  text-align: center;
}
.result-heading.result-win  { color: var(--success); }
.result-heading.result-loss { color: var(--danger); }

.result-time {
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
  margin-top: -12px;
}

/* Stats row */
.stats-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}
.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 6px;
  flex: 1;
  max-width: 84px;
  text-align: center;
}
.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}
.stat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* Share card */
.share-card-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.share-card-text {
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', monospace;
  font-size: 13px;
  line-height: 1.25;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  width: 100%;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#copy-btn { min-width: 160px; }

/* Countdown */
.next-label {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}
.countdown {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── How-to Modal ────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-body ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-body li       { font-size: 14px; color: var(--text-muted); }
.modal-body strong   { color: var(--text); }
.modal-body p        { font-size: 14px; color: var(--text-muted); }

/* Small ghost button variant for header */
.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 20px;
}

.btn-archive {
  background: rgba(99, 102, 241, 0.12);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.btn-archive:hover {
  background: rgba(99, 102, 241, 0.22);
  color: #c7d2fe;
}

/* ── Start Screen ────────────────────────────────────────────────────────── */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 24px;
  text-align: center;
  max-width: 340px;
  margin: 0 auto;
}

.start-badge {
  background: rgba(255, 215, 0, 0.12);
  color: #ffd700;
  font-size: 14px;
  font-weight: 700;
  padding: 5px 16px;
  border-radius: 20px;
}

.start-date {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.start-info {
  font-size: 14px;
  color: var(--text-muted);
}

.start-btn {
  font-size: 17px;
  padding: 12px 40px;
  border-radius: 50px;
  margin-top: 4px;
}

.start-hint {
  font-size: 12px;
  color: var(--text-faint);
}

/* ── Previous Puzzles Modal ──────────────────────────────────────────────── */
.prev-modal-box {
  max-width: 460px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.prev-list {
  overflow-y: auto;
  padding: 8px 0;
  flex: 1;
}

.prev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.prev-row:last-child { border-bottom: none; }
.prev-row:hover { background: var(--bg-hover); }

.prev-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}

.prev-num {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

.prev-date {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.prev-date em {
  font-style: normal;
  color: var(--primary);
  font-size: 11px;
}

.prev-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.prev-won  { background: rgba(34, 197, 94, 0.15);  color: var(--success); }
.prev-lost { background: rgba(239, 68, 68, 0.12);  color: var(--danger); }

.prev-play-btn {
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .site-name   { font-size: 16px; }
  .puzzle-label { display: none; }

  .stats-row   { gap: 5px; }
  .stat-box    { padding: 10px 4px; }
  .stat-value  { font-size: 18px; }
  .stat-label  { font-size: 9px; }

  #result-panel  { gap: 16px; }
  .result-heading { font-size: 24px; }
  .share-card-text { font-size: 11px; }
}
