* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 12px;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background-color: #0a0a1a;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding-top: 48px; /* room for back-link */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Title ── */
.title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: #c4d0ff;
  letter-spacing: 0.02em;
}

/* ── Back link ── */
.back-link {
  position: fixed;
  top: 8px;
  left: 8px;
  font-size: 0.85rem;
  text-decoration: none;
  color: #9aa8d4;
  padding: 6px 12px;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: color 0.2s, background-color 0.2s;
  z-index: 10;
}
.back-link:hover {
  color: #c4d0ff;
  background-color: rgba(255, 255, 255, 0.12);
}

/* ── Game area wrapper ── */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 520px;
}

/* ── Controls bar ── */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.flag-toggle,
.new-game {
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  min-height: 44px; /* accessible tap target */
  min-width: 120px;
}

/* Reveal mode (default) */
.flag-toggle {
  background-color: rgba(255, 255, 255, 0.08);
  color: #e0e0e0;
}
.flag-toggle:hover {
  background-color: rgba(255, 255, 255, 0.14);
}

/* Flag mode (active) */
.flag-toggle.active {
  background-color: rgba(220, 40, 40, 0.25);
  border-color: rgba(220, 40, 40, 0.4);
  color: #ff8888;
}
.flag-toggle.active:hover {
  background-color: rgba(220, 40, 40, 0.35);
}

/* New game button */
.new-game {
  background-color: rgba(255, 255, 255, 0.06);
  color: #9aa8d4;
}
.new-game:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #c4d0ff;
}

/* ── Canvas ── */
canvas {
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(100, 120, 200, 0.15);
  max-width: 100%;
  height: auto;
  display: block;
}

/* ── Mobile hint ── */
.mobile-hint {
  font-size: 0.78rem;
  color: #6a7090;
  margin: 0;
  line-height: 1.4;
}
.mobile-hint strong {
  color: #9aa8d4;
}

/* ── Credit link ── */
.credit-link {
  font-size: 0.72rem;
  text-decoration: none;
  color: #6a7090;
  transition: color 0.2s;
  margin-top: auto;
  padding-bottom: 12px;
}
.credit-link:hover {
  color: #9aa8d4;
}

/* ── Responsive: smaller phones (< 400px) ── */
@media (max-width: 399px) {
  body {
    padding: 6px;
    padding-top: 44px;
    gap: 8px;
  }
  .title {
    font-size: 1.1rem;
  }
  .controls {
    gap: 6px;
  }
  .flag-toggle,
  .new-game {
    font-size: 0.9rem;
    padding: 10px 14px;
    min-width: 100px;
    min-height: 42px;
  }
  .mobile-hint {
    font-size: 0.7rem;
  }
}

/* ── Tablets and larger phones (400 – 767px) ── */
@media (min-width: 400px) and (max-width: 767px) {
  body {
    padding-top: 44px;
    gap: 12px;
  }
}

/* ── Desktop (768px+) ── */
@media (min-width: 768px) {
  body {
    padding-top: 48px;
    gap: 16px;
    justify-content: center;
  }
  .title {
    font-size: 1.6rem;
  }
  .mobile-hint {
    display: none; /* hide hint on desktop */
  }
}

/* ── Light theme override ── */
@media (prefers-color-scheme: light) {
  body {
    background-color: #f0f0f0;
    color: #222;
  }
  .title {
    color: #334;
  }
  .back-link {
    color: #555;
    background-color: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.06);
  }
  .back-link:hover {
    color: #222;
    background-color: rgba(0, 0, 0, 0.08);
  }
  .credit-link {
    color: #888;
  }
  .credit-link:hover {
    color: #444;
  }
  canvas {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  }
  .flag-toggle {
    background-color: rgba(0, 0, 0, 0.06);
    color: #333;
  }
  .flag-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
  }
  .flag-toggle.active {
    background-color: rgba(220, 40, 40, 0.15);
    border-color: rgba(220, 40, 40, 0.35);
    color: #c0392b;
  }
  .new-game {
    background-color: rgba(0, 0, 0, 0.04);
    color: #555;
  }
  .new-game:hover {
    background-color: rgba(0, 0, 0, 0.08);
    color: #333;
  }
  .mobile-hint {
    color: #888;
  }
  .mobile-hint strong {
    color: #555;
  }
}
