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

/* ── Variables ── */
:root {
  --bg:       #070e1b;
  --surface:  #0e1a2e;
  --surface2: #152236;
  --text:     #e8edf5;
  --muted:    #8892aa;
  --accent:   #7c6af7;
  --border:   rgba(255,255,255,0.07);
  --light-on: #fbbf24;
  --light-glow: rgba(251,191,36,0.5);
}

/* ── Base ── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.back-btn {
  color: var(--muted);
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.back-btn svg { width: 22px; height: 22px; }

.logo {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.logo span { color: var(--accent); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.streak {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 4px 10px;
  background: rgba(251,191,36,0.12);
  border-radius: 20px;
}

.header-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}
.header-btn--icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
}

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 16px;
}

/* ── Difficulty picker ── */
#diff-picker {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 4px;
}

.diff-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 18px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.diff-btn.active {
  background: var(--accent);
  color: #fff;
}

.diff-btn:not(.active):hover { color: var(--text); }

/* ── Move counter ── */
#move-counter {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
#moves {
  color: var(--text);
  font-weight: 800;
  font-size: 1.05rem;
}

.best-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.win-record {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 4px;
  min-height: 1.4em;
}

/* ── Grid ── */
#grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
}

/* ── Cells ── */
.cell {
  aspect-ratio: 1;
  border-radius: 12px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.08s ease;
}

.cell.on {
  background: var(--light-on);
  border-color: rgba(253,211,77,0.7);
  box-shadow: 0 0 20px var(--light-glow), 0 0 6px rgba(251,191,36,0.8);
}

.cell.off {
  background: var(--surface);
  border-color: var(--border);
}

.cell:active { transform: scale(0.88); }

@keyframes cellFlash {
  0%   { filter: brightness(2); }
  100% { filter: brightness(1); }
}
.cell--flash { animation: cellFlash 0.18s ease-out; }

/* Win pulse on all cells */
@keyframes winPulse {
  0%, 100% { box-shadow: 0 0 20px var(--light-glow); }
  50%       { box-shadow: 0 0 40px rgba(251,191,36,0.9), 0 0 60px rgba(251,191,36,0.4); }
}
.cell.on.win-anim { animation: winPulse 0.6s ease-in-out; }

/* ── Overlays ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(7,14,27,0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  position: relative;
}

.overlay-emoji { font-size: 3rem; margin-bottom: 12px; line-height: 1; }

.overlay-card h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.overlay-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.streak-msg {
  font-size: 1rem;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 4px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  margin-top: 20px;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }

.btn-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--surface2);
  border: none;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Info modal ── */
.overlay-card--info {
  text-align: left;
  padding-top: 44px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}
.overlay-card--info h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.4rem;
}

.info-section {
  display: flex;
  flex-direction: column;
}

.info-section > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.info-section > div:last-child { border-bottom: none; }

.info-icon { font-size: 1.4rem; }

.info-section > div > strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  margin-top: 2px;
}

.info-section p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}
.info-section p strong { display: inline; font-weight: 700; color: var(--text); }
