:root {
  --brand: #22c55e;
  --brand-dark: #16a34a;
  --brand-darker: #0f7a37;
  --amber: #e8a23d;
  --amber-dark: #c9871f;

  --page-bg: #0b0d10;
  --header-bg: #101318;
  --card-bg: #14171c;
  --card-bg-alt: #191d23;
  --border: #262b33;
  --text: #eef1f5;
  --muted: #8b93a1;

  --cell-hidden: #202631;
  --cell-hidden-hover: #2a3140;
  --cell-open: #0f1216;
  --danger: #ef4444;
  --flag: #e8a23d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Top bar ---------- */

.topbar {
  width: 100%;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.brand-logo {
  background: var(--brand);
  color: #06210f;
  font-weight: 800;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

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

nav.tabs {
  display: flex;
  gap: 8px;
}

.tab-pill {
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--card-bg);
  border: 1px solid var(--border);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.tab-pill:hover {
  border-color: #39414d;
  color: var(--text);
}

.tab-pill.active {
  background: var(--brand);
  color: #06210f;
  border-color: var(--brand);
}

/* ---------- Page layout ---------- */

.page {
  width: 100%;
  max-width: 900px;
  padding: 22px 16px 40px;
  display: flex;
  justify-content: center;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.ghost-btn {
  background: var(--card-bg-alt);
  color: var(--danger);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.ghost-btn:hover { border-color: #3a2a2a; }

.date-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.date-row .date {
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-row .counter {
  color: var(--brand);
  font-weight: 700;
}

/* ---------- Status bar (mines / face / time) ---------- */

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
  background: var(--card-bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
}

.status-bar .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
}

.status-bar .stat .label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-bar .stat .value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand);
}

#face-btn {
  font-size: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 48px;
  height: 48px;
  cursor: pointer;
  color: var(--text);
}
#face-btn:hover { background: var(--cell-hidden); }

/* ---------- Board ---------- */

#board-wrap {
  overflow-x: auto;
  display: flex;
  justify-content: center;
  background: var(--card-bg-alt);
  border-radius: 12px;
  padding: 10px;
  border: 1px solid var(--border);
}

#board {
  display: grid;
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 4px;
  background: var(--cell-hidden);
  cursor: pointer;
  transition: background 0.06s ease;
}

.cell:hover { background: var(--cell-hidden-hover); }

.cell.open {
  background: var(--cell-open);
  border: 1px solid var(--border);
  cursor: default;
}

.cell.flag { background: #2b2312; border: 1px solid #4a3a17; }
.cell.flag::after { content: "🚩"; font-size: 0.85rem; }

.cell.mine { background: var(--danger); }
.cell.mine::after { content: "💣"; font-size: 0.85rem; }

.cell.exploded { background: #ff6b6f; }

.cell[data-n="1"] { color: #5b9dff; }
.cell[data-n="2"] { color: #4ade80; }
.cell[data-n="3"] { color: #f87171; }
.cell[data-n="4"] { color: #a78bfa; }
.cell[data-n="5"] { color: #fbbf24; }
.cell[data-n="6"] { color: #2dd4bf; }
.cell[data-n="7"] { color: #f1f5f9; }
.cell[data-n="8"] { color: #94a3b8; }

/* ---------- Controls ---------- */

.controls-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

button.btn {
  background: var(--brand);
  color: #06210f;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 700;
}
button.btn:hover { background: var(--brand-dark); }
button.btn.secondary {
  background: var(--card-bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
}
button.btn.secondary:hover { background: var(--cell-hidden); }
button.btn.share {
  background: var(--amber);
  color: #241804;
}
button.btn.share:hover {
  background: var(--amber-dark);
}

.msg {
  text-align: center;
  margin-top: 12px;
  font-weight: 700;
  min-height: 1.4em;
}
.msg.win { color: var(--brand); }
.msg.lose { color: var(--danger); }

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin-top: 12px;
  line-height: 1.5;
}

/* ---------- Practice form ---------- */

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 16px;
  align-items: flex-end;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-row input, .form-row select {
  background: var(--card-bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.95rem;
  width: 90px;
}

.preset-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.preset-buttons button {
  background: var(--card-bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.preset-buttons button:hover { border-color: #39414d; }
.preset-buttons button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #06210f;
}

/* ---------- Footer / toast ---------- */

footer.foot {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 8px 0 30px;
  text-align: center;
  max-width: 640px;
  padding: 0 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg-alt);
  border: 1px solid var(--border);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
