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

:root {
  --bg-primary: #0d1b2a;
  --bg-secondary: #1b2d40;
  --bg-card: #1e3a5f;
  --cell-bg: #2a4a6e;
  --cell-hover: #3a5a7e;
  --ad-bg: #1b2d40;
  --ad-border: #2a4a6e;
  --gold: #d4a843;
  --gold-light: #f0d080;
  --green: #4caf50;
  --green-glow: rgba(76, 175, 80, 0.4);
  --blue: #2196f3;
  --blue-glow: rgba(33, 150, 243, 0.3);
  --red: #f44336;
  --text-primary: #f5efe0;
  --text-secondary: #b8a88a;
  --board-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --cell-size: 36px;
  --cell-gap: 2px;
  --board-padding: 12px;
  --radius: 8px;
}

:root[data-theme="light"] {
  --bg-primary: #f4f4f8;
  --bg-secondary: #fafafe;
  --bg-card: #ffffff;
  --cell-bg: #efeff5;
  --cell-hover: #e4e4ee;
  --ad-bg: #f7f7fb;
  --ad-border: #d0d0d8;
  --gold: #b8862d;
  --gold-light: #c99a3e;
  --green: #388e3c;
  --green-glow: rgba(56, 142, 60, 0.3);
  --blue: #1976d2;
  --blue-glow: rgba(25, 118, 210, 0.25);
  --red: #d32f2f;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a6e;
  --board-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 12px;
}

header {
  text-align: center;
  padding: 16px 0 12px;
  flex-shrink: 0;
}

h1 {
  font-size: 2rem;
  letter-spacing: 4px;
  margin-bottom: 12px;
  font-weight: 800;
}

.all-gold {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(212, 168, 67, 0.5);
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
}

.controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.toggle-label input {
  display: none;
}

.toggle-slider {
  width: 40px;
  height: 22px;
  background: #444;
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #888;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-label input:checked + .toggle-slider {
  background: var(--green);
}

.toggle-label input:checked + .toggle-slider::after {
  transform: translateX(18px);
  background: white;
}

.toggle-text {
  color: var(--text-primary);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 2px solid var(--gold);
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
  padding: 0;
}

#theme-btn::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: linear-gradient(to right, #e8e8f0 50%, #1b2d40 50%);
  transition: opacity 0.15s;
}

[data-theme="light"] #theme-btn::before {
  background: linear-gradient(to right,
    rgba(232,232,240,1) 0%, rgba(232,232,240,1) 50%,
    rgba(27,45,64,0.2) 50%, rgba(27,45,64,0.2) 100%);
}

[data-theme="dark"] #theme-btn::before {
  background: linear-gradient(to right,
    rgba(232,232,240,0.2) 0%, rgba(232,232,240,0.2) 50%,
    rgba(27,45,64,1) 50%, rgba(27,45,64,1) 100%);
}

.icon-btn:hover {
  border-color: var(--gold-light);
}

#new-game-btn {
  padding: 8px 20px;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

#new-game-btn:hover {
  background: var(--gold);
  color: var(--bg-primary);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

#board-container {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#board {
  display: inline-grid;
  gap: var(--cell-gap);
  padding: var(--board-padding);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(212, 168, 67, 0.15);
  box-shadow: var(--board-shadow);
  position: relative;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.55);
  font-weight: 700;
  background: var(--cell-bg);
  color: var(--text-primary);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  position: relative;
}

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

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

.cell.start {
  background: var(--blue);
  box-shadow: 0 0 10px var(--blue-glow);
  transform: scale(1.05);
  z-index: 2;
}

.cell.preview {
  background: rgba(33, 150, 243, 0.35);
  box-shadow: inset 0 0 6px var(--blue);
}

.cell.found {
  background: var(--green);
  box-shadow: 0 0 10px var(--green-glow);
  animation: foundPulse 0.4s ease-out;
}

.cell.found.inactive {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.cell.wrong {
  background: var(--red);
  animation: wrongFlash 0.3s ease-out;
}

.cell.claimed {
  background: #3a3a3a;
  color: #666;
  cursor: default;
}

@keyframes foundPulse {
  0% { transform: scale(1.3); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes wrongFlash {
  0%, 100% { background: var(--cell-bg); }
  50% { background: var(--red); }
}

#message {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 8px;
  color: var(--gold);
  transition: opacity 0.2s;
}

#message.success {
  color: var(--green);
}

#message.error {
  color: var(--red);
}

#message.complete {
  color: var(--gold);
  font-size: 1.1rem;
  animation: levelUp 0.5s ease-out;
}

@keyframes levelUp {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

#ad-banner {
  width: 100%;
  padding: 8px 0;
  flex-shrink: 0;
}

.seo-text {
  max-width: 640px;
  margin: 20px auto 12px;
  padding: 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  text-align: center;
}

.seo-text p {
  margin-bottom: 8px;
}

.copyright {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 0 4px;
}

.ad-inner {
  background: var(--ad-bg);
  border: 1px solid var(--ad-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  position: relative;
}

.ad-label {
  font-size: 0.6rem;
  letter-spacing: 2px;
  color: #555;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.ad-text {
  font-size: 0.9rem;
  color: #555;
  font-weight: 600;
}

.ad-size {
  font-size: 0.7rem;
  color: #444;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.2s;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 28px 32px 24px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  min-width: 260px;
}

:root[data-theme="light"] .modal-box {
  background: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-btn {
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--gold);
  transition: all 0.2s;
  letter-spacing: 1px;
}

.modal-cancel {
  background: transparent;
  color: var(--gold);
}

.modal-cancel:hover {
  background: var(--gold);
  color: var(--bg-primary);
}

.modal-confirm {
  background: var(--gold);
  color: var(--bg-primary);
}

.modal-confirm:hover {
  background: var(--gold-light);
  border-color: var(--gold-light);
}

@media (max-width: 600px) {
  h1 {
    font-size: 1.5rem;
    letter-spacing: 2px;
  }

  .stats-row {
    gap: 16px;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  #board {
    padding: 8px;
    gap: 1px;
  }

  .ad-inner {
    min-height: 60px;
    padding: 12px;
  }
}
