/* ═══════════════════════════════════════════════════════════════════════════
   cards.minesweeper.org — main stylesheet
   Skin system: data-skin="dark" (default) | "light"
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS variables by skin ───────────────────────────────────────────────── */
:root,
[data-skin="dark"] {
  --bg:          #0f1923;
  --surface:     #162030;
  --surface2:    #1e2d40;
  --surface3:    #253548;
  --text:        #e2e8f0;
  --text-muted:  #7a94ad;
  --accent:      #c8a64a;     /* gold — card game feel */
  --accent-dim:  #9a7d35;
  --accent-glow: rgba(200,166,74,0.25);
  --border:      #253548;
  --border-soft: #1e2d40;
  --header-bg:   #0a1118;
  --input-bg:    #1a2535;
  --btn-primary-bg:   #c8a64a;
  --btn-primary-text: #0f1923;
  --link:        #c8a64a;
  --link-hover:  #e0c070;
  --danger:      #e05050;
  --success:     #4caf82;
  --felt:        #0d4a1e;     /* poker table green */
  --felt-dark:   #0a3517;
  --shadow:      rgba(0,0,0,0.6);
  --shadow-soft: rgba(0,0,0,0.3);
}

[data-skin="light"] {
  --bg:          #f2ead8;
  --surface:     #faf6ec;
  --surface2:    #ede5d0;
  --surface3:    #e0d4bc;
  --text:        #2c1f14;
  --text-muted:  #7a6040;
  --accent:      #8b4513;
  --accent-dim:  #6b350f;
  --accent-glow: rgba(139,69,19,0.2);
  --border:      #c8b090;
  --border-soft: #ddd0b8;
  --header-bg:   #3d2010;
  --input-bg:    #fff8ee;
  --btn-primary-bg:   #8b4513;
  --btn-primary-text: #fff8ee;
  --link:        #8b4513;
  --link-hover:  #a0522d;
  --danger:      #c0392b;
  --success:     #27ae60;
  --felt:        #2d6a3f;
  --felt-dark:   #1e4f2c;
  --shadow:      rgba(0,0,0,0.3);
  --shadow-soft: rgba(0,0,0,0.15);
}

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }

/* ── Site header ─────────────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  z-index: 100;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-logo:hover { color: var(--accent); text-decoration: none; opacity: 0.85; }
.site-logo .suit-icons { font-size: 1.1rem; letter-spacing: -2px; }

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.header-nav a {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 4px 10px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.header-nav a:hover,
.header-nav a.active {
  color: var(--text);
  background: var(--surface2);
}

.header-spacer { flex: 1; }

/* Timer & moves bar in header */
.hud-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.hud-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}
.hud-stat strong {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  min-width: 3.5ch;
}
.hud-stat.timer-active strong { color: var(--accent); }

/* Auth bar */
.auth-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  object-fit: cover;
}
.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-auth {
  font-size: 0.8rem;
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s;
  border: none;
}
.btn-auth:hover { opacity: 0.85; text-decoration: none; color: var(--btn-primary-text); }

/* Theme toggle */
.btn-theme {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.btn-theme:hover { border-color: var(--accent); color: var(--accent); }

/* ── Page layout ─────────────────────────────────────────────────────────── */
.page-body {
  padding-top: 48px;   /* below fixed header */
  min-height: 100vh;
}

/* Full-page game mode — game fills remaining viewport */
.page-body.game-mode {
  overflow: hidden;
  height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.btn-primary:hover { opacity: 0.88; text-decoration: none; color: var(--btn-primary-text); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }

/* ── Cards / surfaces ────────────────────────────────────────────────────── */
.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.period-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 3px;
}
.period-tab {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.period-tab.active,
.period-tab:hover {
  background: var(--surface3);
  color: var(--text);
  text-decoration: none;
}
.period-tab.active { color: var(--accent); }

.lb-table {
  width: 100%;
  border-collapse: collapse;
}
.lb-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.lb-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.9rem;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: var(--surface2); }
.lb-table tr.my-score td { background: var(--accent-glow); }

.lb-rank {
  font-weight: 700;
  color: var(--text-muted);
  width: 40px;
}
.lb-rank.gold   { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }
.lb-name { font-weight: 600; }
.lb-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.lb-moves { color: var(--text-muted); font-size: 0.85rem; }
.lb-date { color: var(--text-muted); font-size: 0.8rem; }

.personal-best-banner {
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.personal-best-banner .pb-label { color: var(--text-muted); font-size: 0.85rem; }
.personal-best-banner .pb-time  { font-size: 1.2rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

/* ── Blog ─────────────────────────────────────────────────────────────────── */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 24px;
}
.blog-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.blog-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow-soft);
}
.blog-card-img img {
  width: 100%;
  height: 160px;
  object-fit: cover;
}
.blog-card-body { padding: 16px; }
.blog-card-title { font-size: 1rem; font-weight: 700; margin: 0 0 6px; }
.blog-card-title a { color: var(--text); }
.blog-card-title a:hover { color: var(--accent); }
.blog-card-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }
.blog-card-excerpt { font-size: 0.875rem; color: var(--text-muted); }

.post-content {
  max-width: 680px;
  line-height: 1.8;
}
.post-content h1, .post-content h2, .post-content h3 { color: var(--text); margin-top: 2em; }
.post-content p { margin: 1em 0; }
.post-content pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 0.875rem;
}
.post-content code {
  background: var(--surface2);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.875em;
}
.post-content pre code { background: none; padding: 0; }
.post-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5em 0;
  padding: 8px 20px;
  color: var(--text-muted);
}

.post-meta { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 24px; }
.post-meta time { color: var(--text-muted); }

/* Comments */
.comments-section { margin-top: 48px; }
.comment {
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.comment-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.comment-author { font-weight: 700; font-size: 0.9rem; }
.comment-date { font-size: 0.78rem; color: var(--text-muted); }
.comment-body { font-size: 0.9rem; color: var(--text); }

.comment-form { margin-top: 24px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 5px; }
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 100px; }

/* ── Profile ─────────────────────────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 32px;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--border);
  object-fit: cover;
}
.profile-name { font-size: 1.4rem; font-weight: 700; }
.profile-email { font-size: 0.85rem; color: var(--text-muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.stat-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.stat-box .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-box .stat-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Admin ────────────────────────────────────────────────────────────────── */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.admin-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.admin-stat .value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.admin-stat .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.admin-section { margin-bottom: 32px; }
.admin-section h2 { font-size: 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px; }

/* Small table for admin */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th { text-align: left; padding: 8px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: 8px; border-bottom: 1px solid var(--border-soft); }
.data-table tr:hover td { background: var(--surface2); }

/* ── Win / about modal (solitaire) ──────────────────────────────────────── */
.solitaire-modal-overlay {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}
.solitaire-modal-overlay.hidden { display: none; }

.solitaire-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 64px var(--shadow);
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--surface3); color: var(--text); }

.win-title {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent);
  text-align: center;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.win-subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; }
.win-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 20px;
}
.win-stat { text-align: center; }
.win-stat .ws-value { font-size: 1.8rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.win-stat .ws-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.win-rank-badge {
  text-align: center;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 8px 16px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--text);
}
.win-rank-badge strong { color: var(--accent); }

.win-leaderboard { margin-top: 16px; }
.win-leaderboard h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 0 0 8px; }
.win-lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.win-lb-row.highlighted { background: var(--accent-glow); }
.win-lb-row .wlb-rank { width: 24px; text-align: right; color: var(--text-muted); font-weight: 700; flex-shrink: 0; }
.win-lb-row .wlb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-lb-row .wlb-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); flex-shrink: 0; }

.win-actions { margin-top: 20px; display: flex; gap: 10px; }
.win-actions .btn { flex: 1; justify-content: center; }

.about-content { font-size: 0.9rem; color: var(--text-muted); line-height: 1.7; }
.about-content a { color: var(--link); }
.about-content p { margin: 0.6em 0; }
.about-title { font-size: 1.2rem; font-weight: 700; color: var(--text); margin-bottom: 12px; }

/* ── Solitaire HUD (in-page) ─────────────────────────────────────────────── */
.sol-menu-btn {
  position: fixed;
  top: 56px;
  left: 8px;
  z-index: 50;
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.sol-menu-btn:hover { background: var(--surface2); }
.sol-menu-btn img { width: 20px; height: 20px; filter: brightness(0.7); }
.sol-menu-btn:hover img { filter: brightness(1); }

.sol-menu {
  position: fixed;
  top: 48px;
  left: 0;
  bottom: 0;
  width: 180px;
  z-index: 40;
  background: var(--header-bg);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  padding: 56px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sol-menu.open { transform: translateX(0); }

.sol-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.sol-menu-item:hover { background: var(--surface2); color: var(--text); }
.sol-menu-item img { width: 22px; height: 22px; opacity: 0.6; }
.sol-menu-item:hover img { opacity: 1; }

/* ── Game area ────────────────────────────────────────────────────────────── */
.game-area {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

/* ── Misc utilities ──────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-nav { display: none; }
  .hud-bar .hud-stat .hud-label { display: none; }
  .user-name { display: none; }
  .win-stats { gap: 20px; }
  .win-stat .ws-value { font-size: 1.4rem; }
}

/* ── Solitaire card table ────────────────────────────────────────────────── */
.card-table {
  position: absolute;
  inset: 0;
  background-color: var(--felt);
  background-image:
    radial-gradient(ellipse at 50% 50%, var(--felt) 60%, var(--felt-dark) 100%);
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.play-area {
  height: 100%;
  width: 90%;
  max-width: 900px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  /* First row must be explicit — card images are position:absolute so they
     don't contribute to auto height, which collapses the row to 0 and lets
     the tableau cards cover the stock/waste/foundations. */
  grid-template-rows: calc(var(--card-w) * 1.4) 1fr;
  gap: 14px 0;   /* 14px breathing room between the top row and tableau */
  padding: 16px 16px 8px;
  -webkit-user-select: none;
  user-select: none;
}

.play-area > div { display: flex; }

.tableau { flex-direction: column; }

:root { --card-w: min(calc(12vw), 120px); }

.card {
  width: var(--card-w);
  max-width: 120px;
  height: auto;
  position: absolute;
  transition: 150ms;
  border-radius: 4px;
}
.card:hover { filter: drop-shadow(0 0 4px rgba(255,255,255,0.5)); margin-top: -2px; }
.not-animated:hover { transition: 0; margin-top: 0; }

.moving-cards {
  position: fixed;
  width: 100px;
  height: 100px;
  z-index: 1000;
  pointer-events: none;
  filter: drop-shadow(6px 8px 4px rgba(0,0,0,.6));
  transition: margin ease-out 150ms;
}

.separator {
  display: flex;
  flex: 1 1 0;
  justify-content: center;
  overflow: hidden;
}
.tableau > .separator {
  transition: max-height 3s;
  max-height: 90px;
}
.sep-hidden {
  display: flex;
  flex: 1 1 0;
  justify-content: center;
  transition: 3s;
  max-height: 0;
}

.invisible { transition: 0ms; opacity: 0; }

.animation-intro {
  /* Must be absolute (not fixed) so offsetLeft/offsetTop calculations in JS
     are relative to the same .card-table ancestor as the target cards. */
  position: absolute;
  transition: ease-out 400ms;
  z-index: -1;
}

@media (max-width: 700px) {
  .play-area { width: 100%; padding: 8px 4px; }
  :root { --card-w: calc(14vw); }
}
@media (max-width: 480px) {
  :root { --card-w: calc(13.5vw); }
}
