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

:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --text: #535353;
  --text-light: #8a8a8a;
  --accent: #535353;
  --border: #e0e0e0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.14);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen {
  display: none;
  width: 100%;
  max-width: 900px;
  animation: fadeIn 0.4s ease;
}

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Age Gate ── */

.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 32px;
  text-align: center;
}

.age-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.age-options-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
}

.age-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  user-select: none;
  padding: 0;
  border: none;
  background: none;
}

.age-option:hover {
  border-color: transparent;
}

.age-option:has(input:checked) {
  border-color: transparent;
  background: transparent;
}

.age-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

#age-continue-btn {
  margin-top: 8px;
  width: 100%;
}

.gate-error {
  font-size: 0.85rem;
  color: #c0392b;
  margin: 0;
}

.gate-error.hidden {
  display: none;
}

.countdown-label {
  font-size: 0.85rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 8px;
  margin-bottom: 8px;
}

.countdown-display {
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 16px;
}

.countdown-hint {
  font-size: 0.9rem;
  color: var(--text-light);
}

/* ── Character Selection ── */

.title {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  text-align: center;
}

.subtitle {
  font-size: 1rem;
  color: var(--text-light);
  margin-bottom: 40px;
  text-align: center;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 560px;
}

@media (min-width: 720px) {
  .character-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 900px;
  }
}

.character-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px 18px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  box-shadow: var(--shadow);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.character-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.character-card:active {
  transform: translateY(0);
}

.character-preview {
  display: block;
  width: 100%;
  max-width: 160px;
  aspect-ratio: 160 / 120;
  height: auto;
  border-radius: 10px;
  background: linear-gradient(180deg, #fafafa 0%, #ececec 100%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.character-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: block;
  text-align: center;
  line-height: 1.25;
  min-height: 2.5em;
}

/* ── Place Selection ── */

.place-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  width: 100%;
  max-width: 720px;
}

@media (min-width: 640px) {
  .place-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.place-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  box-shadow: var(--shadow);
  font-family: inherit;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: center;
}

.place-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.place-swatch {
  display: block;
  height: 88px;
  width: 100%;
}

.place-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 14px;
  padding: 0 12px;
}

.place-blurb {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 4px;
  padding: 0 12px;
  line-height: 1.35;
}

/* ── Rules ── */

.rules-card {
  max-width: 420px;
}

.rules-list {
  list-style: none;
  text-align: left;
  margin: 0 auto 28px;
  padding: 0;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rules-list li {
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.4;
  padding-left: 0;
}

.rules-list strong {
  color: var(--accent);
}

#rules-start-btn {
  width: 100%;
  max-width: 220px;
}

/* ── Game Screen ── */

.game-wrapper {
  position: relative;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}

#game-hud {
  position: absolute;
  top: 12px;
  right: 16px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 2px;
  pointer-events: none;
  user-select: none;
}

.hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--text-light);
  pointer-events: none;
  user-select: none;
  opacity: 1;
  transition: opacity 0.5s;
}

.hint.hidden {
  opacity: 0;
}

.game-over-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  z-index: 5;
}

.game-over-panel.hidden {
  display: none;
}

.game-over-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.game-over-hint {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 8px;
}

.game-over-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-top: 4px;
}

.game-over-btn {
  background: transparent;
  color: var(--text-light);
  border: none;
  border-radius: 0;
  padding: 4px 2px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.game-over-btn:hover {
  border-color: transparent;
  background: transparent;
  color: var(--text);
  transform: none;
}

/* ── Win Screen (letter) ── */

#win-screen.active {
  justify-content: center;
  padding: 20px 16px;
}

#win-screen {
  max-width: 520px;
}

.win-content {
  position: relative;
  text-align: left;
  padding: 48px 40px 40px;
  background: #ffffff;
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.04),
    0 16px 48px rgba(0, 0, 0, 0.07);
  width: 100%;
  overflow: auto;
  max-height: min(92vh, 920px);
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 520px) {
  .win-content {
    padding: 36px 24px 32px;
  }
}

.birthday-kicker {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: #666666;
  margin-bottom: 8px;
  text-align: left;
}

.birthday-title {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: clamp(1.5rem, 4.5vw, 1.85rem);
  font-weight: 600;
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: #111111;
  margin: 0 0 36px;
  max-width: none;
  text-align: left;
  background: none;
  -webkit-text-fill-color: unset;
  animation: none;
}

.birthday-message {
  text-align: left;
  max-width: none;
  margin: 0 0 36px;
  color: #1a1a1a;
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-optical-sizing: auto;
}

.birthday-message p {
  font-size: clamp(1.05rem, 2.6vw, 1.15rem);
  font-weight: 400;
  line-height: 1.85;
  letter-spacing: 0.005em;
  color: #1a1a1a;
  margin: 0 0 1.75em;
}

.birthday-message > p:last-of-type {
  margin-bottom: 0;
}

.birthday-closing {
  margin-top: 2.25em;
  padding-top: 0;
  border-top: none;
}

.birthday-signoff {
  font-family: inherit !important;
  font-size: clamp(1.05rem, 2.6vw, 1.15rem) !important;
  font-weight: 400 !important;
  line-height: 1.85 !important;
  color: #1a1a1a !important;
  margin: 0 0 1.75em !important;
}

.birthday-ps {
  font-family: inherit;
  font-size: clamp(0.95rem, 2vw, 1rem) !important;
  font-style: normal;
  font-weight: 400;
  color: #747474 !important;
  margin: 0 !important;
  line-height: 1.85 !important;
}

.play-again-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.play-again-btn:hover {
  background: #333;
  transform: translateY(-1px);
}

.play-again-btn:active {
  transform: translateY(0);
}

/* ── Confetti ── */

.confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(500px) rotate(720deg); opacity: 0; }
}
