:root {
  --bg: #060b21;
  --bg2: #0f1a47;
  --panel: rgba(16, 27, 69, 0.72);
  --panel-border: rgba(154, 176, 255, 0.28);
  --cell: #2a3569;
  --cell-open: #e8eeff;
  --cell-border: #8190cc;
  --text: #f3f6ff;
  --accent: #7cf3ff;
  --pf-top-offset: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 50% -10%, #283f95 0%, transparent 70%),
    radial-gradient(700px 380px at 100% 0%, #5f32a1 0%, transparent 80%),
    linear-gradient(160deg, var(--bg2), var(--bg));
  min-height: 100vh;
}

body.embedded { --pf-top-offset: 106px; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(var(--pf-top-offset) + env(safe-area-inset-top, 0px)) 16px 18px;
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  background: linear-gradient(130deg, rgba(126, 92, 235, 0.25), rgba(45, 173, 255, 0.14));
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(4px);
}

.hero-art {
  width: 68px;
  height: 68px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
}

.hero h1 { margin: 0; font-size: 1.25rem; }
.hero p { margin: 2px 0 0; opacity: .85; font-size: .9rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 12px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: calc(var(--pf-top-offset) + 4px);
}

.game-area { min-width: 0; }

.topbar { padding: 10px; margin-bottom: 10px; }

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

.controls.vertical {
  flex-direction: column;
  align-items: stretch;
}

label { font-weight: 600; font-size: .95rem; }

select, button {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #6977b8;
  background: #111a46;
  color: var(--text);
}
label select { margin-left: 8px; }
.controls.vertical label select { margin-left: 0; margin-top: 6px; width: 100%; }
.controls.vertical button { width: 100%; }
.mode-badge {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(134, 154, 232, 0.5);
  background: rgba(22, 34, 85, 0.9);
  font-size: .92rem;
}
button {
  cursor: pointer;
  font-weight: 700;
  background: linear-gradient(180deg, #2f4ec7, #21358d);
}

.hud {
  margin: 10px 0;
  padding: 11px 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.sidebar-hud {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}

.board {
  display: grid;
  gap: var(--cell-gap, 2px);
  padding: 10px;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
  background: linear-gradient(180deg, rgba(13, 22, 56, .85), rgba(9, 16, 40, .9));
}

.cell {
  width: var(--cell-size, 28px);
  height: var(--cell-size, 28px);
  display: grid;
  place-items: center;
  font-size: var(--glyph-size, 15px);
  line-height: 1;
  font-weight: 800;
  border-radius: 6px;
  border: 1px solid var(--cell-border);
  background: linear-gradient(180deg, #344282, var(--cell));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  overflow: visible;
}

.cell:not(.open):hover {
  transform: translateY(-1px) scale(1.03);
  filter: brightness(1.08);
  box-shadow: 0 4px 10px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.22);
}

.cell.open {
  background: linear-gradient(180deg, #f8fbff, var(--cell-open));
  color: #0f1b43;
  border-color: #bcc7f0;
}
.cell.mine.open { background: linear-gradient(180deg, #ffcad6, #ff9eae); }
.cell.flagged { background: linear-gradient(180deg, #2f66bd, #274a87); }

.mine-icon, .flag-icon {
  display: inline-grid;
  place-items: center;
  width: 1em;
  height: 1em;
  font-size: 0.9em;
}

.mine-icon { transform: translateY(-0.02em); }
.flag-icon { transform: translateY(-0.04em); }

.n1 { color: #1f4de0; }
.n2 { color: #15803d; }
.n3 { color: #c11245; }
.n4 { color: #5b21b6; }
.n5 { color: #9a3412; }
.n6 { color: #0f766e; }
.n7 { color: #111827; }
.n8 { color: #334155; }

.help {
  margin: 12px 2px 0;
  opacity: .88;
  font-size: .92rem;
}

.reveal-pop {
  animation: revealPop .18s cubic-bezier(.2,.9,.2,1);
}

@keyframes revealPop {
  0% { transform: scale(.78); filter: brightness(1.15); }
  65% { transform: scale(1.08); }
  100% { transform: scale(1); filter: brightness(1); }
}

@media (max-width: 900px) {
  body.embedded { --pf-top-offset: 124px; }
  .hero { margin-bottom: 8px; }
  .hero-art { width: 58px; height: 58px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .board { --cell-gap: 1px; }
}
