:root {
  --purple: #5a3fd6;
  --purple-mid: #7b5cff;
  --purple-light: #efe9ff;
  --purple-line: #d9ccff;
  --purple-soft: #f7f4ff;
  --ink: #2d2350;
  --muted: #7a70a0;
  --orange: #ff9800;
  --orange-dark: #d97f00;
  --red: #e53935;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Baloo 2", -apple-system, system-ui, "Segoe UI", sans-serif;
  touch-action: manipulation;
  user-select: none;
  background: var(--purple-mid);
}

button { font-family: inherit; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: radial-gradient(circle at 50% 0%, #a98bff 0%, #7b5cff 45%, #5a3fd6 100%);
}

.hidden { display: none !important; }

/* The game board only shows while playing, so menus sit on a clean background. */
#app:not(.playing) :is(#hud, #timer-track, #game-area, #options) {
  visibility: hidden;
}

/* ---------- Floating background symbols (menus only) ---------- */

#deco {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#app.playing #deco { display: none; }

#deco span {
  position: absolute;
  font-size: 3.5rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.1);
  animation: float 9s ease-in-out infinite;
}

#deco span:nth-child(1) { top: 6%; left: 8%; }
#deco span:nth-child(2) { top: 12%; right: 10%; font-size: 5.5rem; animation-delay: -2s; }
#deco span:nth-child(3) { top: 40%; left: 4%; font-size: 3.5rem; animation-delay: -4s; }
#deco span:nth-child(4) { top: 46%; right: 6%; animation-delay: -1s; }
#deco span:nth-child(5) { bottom: 18%; left: 12%; font-size: 5rem; animation-delay: -6s; }
#deco span:nth-child(6) { bottom: 8%; right: 14%; font-size: 3.5rem; animation-delay: -3s; }
#deco span:nth-child(7) { bottom: 34%; right: 30%; font-size: 3rem; animation-delay: -5s; }
#deco span:nth-child(8) { top: 26%; left: 34%; font-size: 3rem; animation-delay: -7s; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-18px) rotate(8deg); }
}

/* ---------- Game HUD ---------- */

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 0;
  pointer-events: none;
}

.pill {
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

#quit-btn {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

#quit-btn:active {
  background: rgba(255, 255, 255, 0.36);
}

/* ---------- Screens and cards ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem calc(env(safe-area-inset-bottom, 0px) + 1rem);
}


.card {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
  background: #fff;
  border-radius: 32px;
  box-shadow: 0 8px 0 rgba(40, 20, 110, 0.25), 0 20px 40px rgba(20, 0, 60, 0.3);
  animation: card-in 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
}

.card h1 {
  margin: 0 0 0.75rem;
  font-size: 1.9rem;
  line-height: 1.1;
  color: var(--purple);
}

.card h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.15;
  color: var(--ink);
}

.card .hint {
  margin: 0.5rem 0;
  font-size: 1rem;
  line-height: 1.3;
  color: var(--muted);
}

.card .small {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  line-height: 1.25;
  color: var(--muted);
}

.card .error {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--red);
  background: #fdecea;
  border-radius: 12px;
}

.section-label {
  margin: 1.1rem 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9a8ad6;
  text-align: left;
}

.screen-icon {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.4rem;
  font-size: 1.1rem;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.15s ease;
}

.btn:active {
  transform: translateY(4px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-wide {
  display: flex;
  width: 100%;
  margin-top: 1rem;
}

.btn-primary {
  font-size: 1.3rem;
  color: #fff;
  background: linear-gradient(180deg, #ffce4a, var(--orange));
  box-shadow: 0 5px 0 var(--orange-dark);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
  box-shadow: 0 1px 0 var(--orange-dark);
}

.btn-secondary {
  color: var(--purple);
  background: var(--purple-light);
  box-shadow: 0 5px 0 var(--purple-line);
}

.btn-secondary:active {
  box-shadow: 0 1px 0 var(--purple-line);
}

.btn-ghost {
  font-size: 1rem;
  color: var(--purple);
  background: #fff;
  border: 2px solid var(--purple-line);
  box-shadow: 0 3px 0 var(--purple-line);
}

.btn-ghost:active {
  box-shadow: 0 0 0 var(--purple-line);
  transform: translateY(3px);
}

.btn-danger {
  color: var(--red);
  border-color: #f6c9c7;
  box-shadow: 0 3px 0 #f6c9c7;
}

.card > .btn-ghost {
  margin-top: 1rem;
}

.button-row {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.button-row .btn {
  flex: 1;
}

/* ---------- Icon buttons ---------- */

.card {
  position: relative;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--purple);
  background: var(--purple-light);
  border: none;
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--purple-line);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--purple-line);
}

.corner-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

/* ---------- Start screen ---------- */

.app-logo {
  width: 76px;
  height: 76px;
  margin: -0.25rem auto 0.25rem;
  display: block;
  border-radius: 22px;
  box-shadow: 0 5px 0 rgba(40, 20, 110, 0.2);
}

.card h1.title {
  font-size: 2.3rem;
  margin-bottom: 1rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9a8ad6;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--purple-light);
}

.best-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 1rem 0 0;
  padding: 0.25rem 0.8rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #8a5a00;
  background: #fff4d6;
  border-radius: 999px;
}

/* ---------- Pickers ---------- */

.game-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.game-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.8rem 0.4rem;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
  background: var(--purple-soft);
  border: 3px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  transition: transform 0.06s ease, border-color 0.15s ease, background 0.15s ease;
}

.game-option:active { transform: scale(0.96); }

.game-option.selected {
  background: #fff;
  border-color: var(--purple);
  box-shadow: 0 4px 0 var(--purple-line);
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--purple-light);
  border-radius: 999px;
}

.segmented button {
  flex: 1;
  padding: 0.55rem 0.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--purple);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmented button.selected {
  color: #fff;
  background: var(--purple);
  box-shadow: 0 3px 0 #3f2a9e;
}

#difficulty-hint {
  min-height: 2.5em;
  margin-top: 0.5rem;
}

/* ---------- Game over ---------- */

.score-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 8.5rem;
  height: 8.5rem;
  margin: 0.25rem auto 0;
  color: #fff;
  background: linear-gradient(180deg, #ffce4a, var(--orange));
  border-radius: 50%;
  box-shadow: 0 6px 0 var(--orange-dark), inset 0 4px 0 rgba(255, 255, 255, 0.35);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  animation: pop 0.5s ease 0.15s;
}

#final-score {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
}

.score-badge small {
  font-size: 1rem;
  font-weight: 700;
}

.new-best {
  margin: 1rem 0 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #10a37f;
  animation: pop 0.6s ease 0.4s;
}

/* ---------- How to play ---------- */

.help-card {
  max-width: 420px;
  text-align: left;
}

.help-card h1 {
  text-align: center;
}

.help-section {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--purple-soft);
  border-radius: 20px;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.35;
}

.help-section h2 {
  margin-bottom: 0.5rem;
  color: var(--purple);
}

.help-section h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.9rem 0 0.4rem;
  font-size: 1.05rem;
  color: var(--ink);
}

.help-section h3:first-of-type {
  margin-top: 0.25rem;
}

.help-section p {
  margin: 0.4rem 0 0;
}

.help-section code {
  padding: 0 0.35rem;
  font-family: inherit;
  font-weight: 800;
  white-space: nowrap;
  color: var(--purple);
  background: #fff;
  border-radius: 6px;
}

.help-section .q {
  color: #e0a800;
}

.help-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.help-list li > span:first-child {
  flex-shrink: 0;
  width: 2.25rem;
  font-size: 1.3rem;
  line-height: 1.2;
  text-align: center;
}

.help-list.levels li {
  padding: 0.5rem 0.6rem;
  background: #fff;
  border-radius: 14px;
}

.help-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

.help-item p {
  margin: 0;
}

/* ---------- Six choices ---------- */

#options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
}

.option {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  max-height: 15vh;
  width: 100%;
  justify-self: center;
  padding: 10%;
  background: #fff;
  border: 3px solid transparent;
  border-radius: 22px;
  box-shadow: 0 5px 0 rgba(40, 20, 110, 0.3);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.option svg {
  width: 100%;
  height: 100%;
}

.option:active {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 1px 0 rgba(40, 20, 110, 0.3);
}

.option.correct {
  border-color: #3ccf5a;
  background: #e8fbe9;
  animation: pop 0.4s ease;
}

.option.reveal {
  border-color: #3ccf5a;
  animation: breathe 0.5s ease-in-out 2;
}

.option.wrong {
  border-color: #ff7043;
  background: #fff0ec;
  animation: shake 0.35s ease;
}

.option:disabled {
  cursor: default;
  opacity: 0.45;
}

.option:disabled::after {
  content: "✗";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  font-weight: 800;
  color: #e53935;
}

/* ---------- Game logos ---------- */

.game-logo {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.45rem;
  line-height: 1;
  border-radius: 14px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15), inset 0 3px 0 rgba(255, 255, 255, 0.35);
}


.game-logo.sm {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.15rem;
  border-radius: 11px;
}

.game-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.final-extra {
  margin: 0.75rem 0 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #e0a800;
}

/* ---------- Play area ---------- */

#game-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 0.5rem 16px calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
}

#status {
  margin: 0;
  min-height: 1.6em;
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

#stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

#hearts-pill.shake {
  animation: shake 0.35s ease;
}

/* ---------- Start card with the pickers ---------- */

.start-card .app-logo {
  width: 60px;
  height: 60px;
  border-radius: 18px;
}

.start-card h1.title {
  margin-bottom: 0.25rem;
}

.start-card .game-option {
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  text-align: left;
}

.start-card .game-option .game-logo {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.15rem;
  border-radius: 11px;
}

.start-card #game-hint {
  min-height: 2.6em;
  margin: 0.5rem 0 0;
  font-size: 0.92rem;
}

.start-card #difficulty-hint {
  margin-top: 0.4rem;
}

.start-card .best-chip {
  margin-top: 0.75rem;
}

/* ---------- Timer bar ---------- */

#timer-track {
  margin: 10px 16px 0;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
  flex-shrink: 0;
}

#timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd54a, #ff9800);
  transition: width 1s linear, background 0.3s ease;
}

#timer-fill.low {
  background: linear-gradient(90deg, #ff7043, #e53935);
}

@keyframes breathe {
  50% { transform: scale(1.06); }
}

@keyframes float-up {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -48px); }
}

/* "+1" and similar flashes that float up from where you tapped. */
.float-text {
  position: absolute;
  z-index: 5;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  pointer-events: none;
  animation: float-up 0.8s ease-out forwards;
}

/* ---------- Extras: on/off switches ---------- */

.toggles {
  display: grid;
  gap: 0.5rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.45rem 0.7rem;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--purple-soft);
  border: 2px solid var(--purple-line);
  border-radius: 18px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle.on {
  background: #fff;
  border-color: var(--purple);
  box-shadow: 0 3px 0 var(--purple-line);
}

.toggle-icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.15rem;
  border-radius: 11px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.toggle-icon.wind { background: linear-gradient(135deg, #7cc6ff, #3a86ff); }
.toggle-icon.moving { background: linear-gradient(135deg, #ff9ec4, #ff5a8a); }

.toggle:not(.on) .toggle-icon {
  filter: grayscale(0.7);
  opacity: 0.7;
}

.toggle-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.toggle-text strong {
  font-size: 1rem;
}

.toggle-text small {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

/* The on/off switch: a pill with a sliding knob. */
.switch {
  position: relative;
  flex-shrink: 0;
  width: 2.9rem;
  height: 1.6rem;
  background: #d6cff0;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.2rem;
  height: 1.2rem;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.toggle.on .switch {
  background: #22c55e;
}

.toggle.on .switch::after {
  transform: translateX(1.3rem);
}

/* With 3 games stacked, keep the start card short enough for small phones. */
.start-card .app-logo {
  width: 52px;
  height: 52px;
}

.start-card #game-hint {
  min-height: 0;
}

/* ---------- Field ---------- */

#game-area {
  padding: 0.5rem 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
}

#stage {
  position: relative;
}

#stage #status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  min-height: 0;
  padding: 0.35rem 1rem;
  font-size: 1.1rem;
  color: #fff;
  white-space: nowrap;
  background: rgba(45, 35, 80, 0.55);
  border-radius: 999px;
  pointer-events: none;
}

#stage #status:empty {
  display: none;
}

#stage #status.good {
  background: #22c55e;
  animation: pop 0.45s ease;
}

#stage #status.miss {
  background: rgba(229, 57, 53, 0.9);
  animation: shake 0.35s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

/* ---------- Snacky Snake ---------- */

/* Swipes steer the snake, so the browser mustn't scroll or zoom on them. */
#app.playing { touch-action: none; }

#board {
  display: block;
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(40, 20, 110, 0.25), 0 16px 32px rgba(20, 0, 60, 0.25);
}

.save-form .section-label { text-align: center; }

.board-list {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.board-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.8rem;
  font-weight: 700;
  color: var(--ink);
  border-radius: 14px;
}

.board-list li:nth-child(odd) { background: var(--purple-soft); }

.board-list li.mine {
  color: #fff;
  background: var(--purple);
}

.board-list .rank { width: 1.8rem; text-align: center; }
.board-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .empty { justify-content: center; color: var(--muted); }

#leaderboard .segmented { margin-top: 0.5rem; }

.start-card #difficulty-hint { min-height: 0; }

/* Account prompts on the leaderboard and after a game. */
.join { display: grid; gap: 8px; margin-top: 8px; }
.account-box { margin: 10px 0 4px; padding: 12px; text-align: center; background: rgba(123, 92, 255, 0.08); border-radius: 16px; }
.account-box .small, .save-form .small { margin: 0; }
