:root {
  color-scheme: light;
  --cell-size: 28px;
  --hidden-bg: #9aa6b2;
  --revealed-bg: #d8dee4;
  --border: #6b7680;
  --mine-bg: #e35d5d;
  --accent: #4a6cf7;
  --accent-dark: #2f4cd1;
  --ink: #1d2433;
  --page-bg: #eef1f6;
  --surface: #ffffff;
  --surface-alt: #eef1ff;
  --text-muted: #5a6271;
  --border-soft: #e3e7ee;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --hidden-bg: #4b5666;
  --revealed-bg: #2c3543;
  --border: #1c222d;
  --ink: #e7ebf3;
  --page-bg: #161b25;
  --surface: #222a38;
  --surface-alt: #2c3650;
  --text-muted: #aab2c2;
  --border-soft: #333d4f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--page-bg);
  transition: background 0.2s ease, color 0.2s ease;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.topbar-logo {
  font-size: 28px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
  font-weight: 700;
  flex: 1;
}

.account-info {
  position: relative;
}

.avatar-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.account-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  padding: 12px;
  flex-direction: column;
  gap: 8px;
  min-width: 160px;
  z-index: 80;
}

.account-menu[hidden] {
  display: none;
}

.account-menu:not([hidden]) {
  display: flex;
}

.account-menu .menu-name {
  font-weight: 700;
  padding: 4px 8px;
}

.account-menu button {
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--accent-dark);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.account-menu button:hover {
  background: var(--accent);
  color: #fff;
}

.app {
  display: flex;
  justify-content: center;
  padding: 28px 16px 60px;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 640px;
}

.screen.active {
  display: flex;
}

.screen-centered {
  justify-content: center;
  min-height: calc(100vh - 200px);
}

.screen h2 {
  margin: 4px 0;
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 0;
}

.back-btn:hover {
  text-decoration: underline;
}

.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 220px;
}

.menu-btn {
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(74, 108, 247, 0.35);
  transition: transform 0.08s ease, background 0.15s ease;
}

.menu-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 260px;
}

.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
}

.auth-form button {
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.auth-form button:hover {
  background: var(--accent-dark);
}

.form-message {
  min-height: 1.4em;
  font-weight: 600;
}

.form-message.error { color: var(--mine-bg); }
.form-message.success { color: #2e8b3d; }

.play-layout {
  display: flex;
  align-items: flex-start;
  gap: 28px;
  width: 100%;
  max-width: 760px;
}

.play-illustration {
  flex: 0 0 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.illustration-grid {
  display: grid;
  grid-template-columns: repeat(4, 32px);
  grid-auto-rows: 32px;
  gap: 3px;
}

.illustration-grid .ic {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--revealed-bg);
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
}

.illustration-grid .ic.mine,
.illustration-grid .ic.flag {
  background: var(--hidden-bg);
}

.illustration-grid .ic.n1 { color: #1e6fd9; }
.illustration-grid .ic.n2 { color: #2e8b3d; }
.illustration-grid .ic.n3 { color: #d33b3b; }

.play-illustration p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.play-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.setup-hint {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.difficulty-switcher {
  display: flex;
  align-items: center;
  gap: 14px;
}

.diff-arrow {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.diff-arrow:hover {
  background: var(--accent-dark);
}

.diff-label {
  min-width: 130px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.diff-label:hover {
  background: var(--surface-alt);
  color: var(--accent-dark);
}

.diff-description {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

#new-game {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

#new-game:hover {
  background: var(--accent-dark);
}

.status {
  min-height: 1.4em;
  font-weight: 700;
}

.status.won { color: #2e8b3d; }
.status.lost { color: var(--mine-bg); }

#win-menu-btn {
  width: auto;
}

#win-menu-btn[hidden] {
  display: none;
}

.board {
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  background: var(--hidden-bg);
  cursor: pointer;
}

.cell.revealed {
  background: var(--revealed-bg);
  cursor: default;
}

.cell.flagged::after {
  content: "🚩";
  font-size: 14px;
}

.cell.mine {
  background: var(--mine-bg);
}

.cell.mine::after {
  content: "💣";
  font-size: 14px;
}

.cell.n1 { color: #1e6fd9; }
.cell.n2 { color: #2e8b3d; }
.cell.n3 { color: #d33b3b; }
.cell.n4 { color: #1f2f8b; }
.cell.n5 { color: #8b1f1f; }
.cell.n6 { color: #1f8b85; }
.cell.n7 { color: #2b2b2b; }
.cell.n8 { color: #6b6b6b; }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.lb-table th,
.lb-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
}

.lb-table th {
  background: var(--surface-alt);
  font-weight: 700;
}

.lb-pagination {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lb-pagination[hidden] {
  display: none;
}

.lb-page-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-page-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}

.lb-page-btn:disabled {
  background: var(--hidden-bg);
  cursor: default;
  opacity: 0.6;
}

#lb-page-label {
  font-weight: 600;
  color: var(--text-muted);
}

.screen-game {
  position: relative;
  gap: 18px;
  padding-top: 8px;
}

.pause-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 90;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.pause-btn:hover {
  background: #353e52;
}

.game-hud {
  display: flex;
  align-items: center;
  gap: 24px;
  font-weight: 700;
  font-size: 16px;
  background: var(--surface);
  padding: 10px 22px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#timer {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
}

.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 38, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
}

.pause-overlay[hidden] {
  display: none;
}

.pause-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: 220px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3);
}

.pause-card h2 {
  margin: 0;
}

.pause-card button {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.pause-card button:hover {
  background: var(--accent-dark);
}

#quit-btn {
  background: var(--mine-bg);
}

#quit-btn:hover {
  background: #c94c4c;
}

#bomb-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, rgba(227, 93, 93, 0.0) 0%, rgba(227, 93, 93, 0.35) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 50;
}

#bomb-overlay.visible {
  opacity: 1;
}

.undo-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 999px;
  background: var(--mine-bg);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(227, 93, 93, 0.4);
}

.undo-btn:hover {
  background: #c94c4c;
}

.settings-block {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 14px;
  padding: 18px 22px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-block h3 {
  margin: 0;
}

.settings-block[hidden] {
  display: none;
}

.settings-label {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.theme-toggle {
  display: flex;
  gap: 10px;
}

.theme-btn,
.controls-btn {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.theme-btn:hover,
.controls-btn:hover {
  border-color: var(--accent);
}

.theme-btn.active,
.controls-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 8px;
}

.avatar-option {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border-soft);
  border-radius: 10px;
  background: var(--surface-alt);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-option:hover {
  border-color: var(--accent);
}

.avatar-option.selected {
  border-color: var(--accent);
  background: var(--accent);
}
