:root {
  --bg-0: #05070f;
  --bg-1: #0d1326;
  --fg: #e8efff;
  --muted: #8290b3;
  --accent: #7ef9b8;
  --accent-2: #59c2ff;
  --danger: #ff6a8b;
  --radius: 18px;
  --shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6),
            0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  color: var(--fg);
  font-family: var(--font);
  background:
    radial-gradient(1200px 800px at 80% -10%, #1a2350 0%, transparent 60%),
    radial-gradient(900px 700px at -10% 110%, #251a4a 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  place-items: center;
  padding: 24px;
}

@media (max-width: 600px) {
  body {
    padding: 8px;
    align-items: start;
  }

  .shell { gap: 10px; }

  .appbar { padding: 10px 12px; gap: 8px; }
  .brand-tagline { display: none; }
  .brand-text { font-size: 17px; }
  .logo-icon { width: 22px; height: 27px; }

  /* Tabs become a single horizontally-scrollable row */
  .tabs {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .tab {
    flex-shrink: 0;
    padding: 7px 13px;
    font-size: 12px;
  }

  /* HUD: tighter spacing so stats don't overflow */
  .hud { padding: 8px 10px; gap: 8px; }
  .stats { gap: 8px; flex-wrap: wrap; }
  .stat { min-width: 42px; }
  .stat-value { font-size: 14px; }

  .game-panel { gap: 10px; }
}

.shell {
  width: min(720px, 100%);
  display: grid;
  gap: 16px;
}

/* ---------------------------- Top app bar ---------------------------- */

.appbar {
  display: grid;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.appbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(126, 249, 184, 0.3));
}

.brand-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.brand-tagline {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}

.brand-glow {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(126, 249, 184, 0.35));
}

/* ---------------------------- Site footer ---------------------------- */

.site-footer {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 0 0 24px;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 24px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  text-align: center;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.footer-tagline {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 1px;
  opacity: 0.8;
}

.footer-copy {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.3px;
  opacity: 0.6;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  width: fit-content;
}

.tab {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  letter-spacing: 0.4px;
  transition: color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.tab:hover { color: var(--fg); }
.tab.active {
  color: #0b1020;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px -8px rgba(126, 249, 184, 0.6);
}

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

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  box-shadow: var(--shadow);
}

.stats { display: flex; gap: 14px; }

.stat {
  display: grid;
  text-align: left;
  min-width: 54px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
}

.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
}

.next-wrap {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px;
  align-items: center;
}
.next-wrap .stat-label { align-self: center; }
#tetris-next {
  width: 56px;
  height: 56px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
}

/* ---------------------------- Board ---------------------------- */

.game-panel { display: grid; gap: 14px; }
.game-panel[hidden] { display: none; }

.board-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #000;
  margin: 0 auto;
  width: 100%;
  touch-action: none; /* let JS handle drag without page scrolling */
}

.board-square {
  aspect-ratio: 1 / 1;
  max-width: 480px;
}
.board-tetris {
  aspect-ratio: 1 / 2;
  width: min(280px, 70%);
}
.board-family,
.board-walker,
.board-mono,
.board-figure,
.board-bloom {
  aspect-ratio: 8 / 5;
  max-width: 720px;
}

/* The wrapper sets a definite aspect-ratio sized box. Absolute-
 * positioning the SVG to fill the wrapper guarantees the board
 * paints at the correct size on its very first frame, in every
 * browser, regardless of whether the panel was initially hidden.
 * (Earlier `width:100%; height:auto` worked everywhere except in
 * some WebKit cases where percentage heights against an
 * aspect-ratio box did not resolve until a later reflow — making
 * the board appear small until the first DOM mutation.) */
.board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------------------------- Overlay ---------------------------- */

.overlay .overlay-bg { fill: rgba(5, 8, 20, 0.72); transition: opacity 0.25s ease; }
.overlay .overlay-title {
  font-family: var(--font);
  font-size: 32px;
  font-weight: 800;
  fill: #fff;
  letter-spacing: 1px;
}
.overlay .overlay-sub {
  font-family: var(--font);
  font-size: 14px;
  fill: var(--accent);
}
.overlay .overlay-hint {
  font-family: var(--font);
  font-size: 11px;
  fill: var(--muted);
  letter-spacing: 1px;
}
.overlay.hidden { opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }

/* ---------------------------- Touch pads ---------------------------- */
/* On-screen arrow buttons are intentionally hidden in every viewport.
 * Touch devices use direct drag gestures (handled per-game in JS)
 * which are more natural and don't cover the playfield. */

.touch { display: none !important; }

@media (hover: none) and (pointer: coarse) {
  .hint { display: none; }
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
}
.hint kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  margin: 0 2px;
}

/* ---------------------------- Animations ---------------------------- */

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}
.food-pulse { transform-box: fill-box; transform-origin: center; animation: pulse 0.9s ease-in-out infinite; }

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(-4px, 2px); }
  40%      { transform: translate(3px, -3px); }
  60%      { transform: translate(-2px, 3px); }
  80%      { transform: translate(2px, -1px); }
}
.shake { animation: shake 0.35s ease; }

@keyframes flash {
  0%, 100% { fill-opacity: 1; }
  50%      { fill-opacity: 0.2; }
}
.line-flash { animation: flash 0.18s ease 2; }

/* ---------------------------- Family scene ---------------------------- */

@keyframes drift {
  0%   { transform: translateX(-120px); }
  100% { transform: translateX(900px); }
}
#family-clouds .cloud {
  animation: drift linear infinite;
}
#family-clouds .cloud-1 { animation-duration: 32s; transform-origin: 0 0; }
#family-clouds .cloud-1 { translate: 0 70px; }
#family-clouds .cloud-2 { animation-duration: 26s; animation-delay: -10s; translate: 0 130px; }
#family-clouds .cloud-3 { animation-duration: 40s; animation-delay: -22s; translate: 0 190px; }

@keyframes sun-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
#family-sun {
  transform-box: fill-box;
  transform-origin: center;
  animation: sun-pulse 4.5s ease-in-out infinite;
}

@keyframes target-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50%      { opacity: 0.95; transform: scale(1.18); }
}
.target-ring {
  transform-box: fill-box;
  transform-origin: center;
  animation: target-pulse 0.8s ease-in-out infinite;
}

@keyframes baby-pop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.baby-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: baby-pop 0.6s cubic-bezier(.22,1.4,.36,1) both;
}

@keyframes float-up {
  0%   { transform: translate(0, 0);  opacity: 1; }
  100% { transform: translate(var(--dx, 0), -90px); opacity: 0; }
}
.float-heart {
  animation: float-up 1.1s ease-out forwards;
}

/* ---------------------------- Walker scene ---------------------------- */

.snapshots {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 6px;
  padding: 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  box-shadow: var(--shadow);
  min-height: 76px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.snapshots::-webkit-scrollbar { height: 4px; }
.snapshots::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.snapshots::-webkit-scrollbar-track { background: transparent; }
.snapshots .snap {
  flex: 0 0 72px;
  height: 72px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  overflow: hidden;
  display: block;
}
.snapshots .snap.empty {
  background: rgba(255,255,255,0.03);
  border-style: dashed;
}
.snapshots .snap svg { width: 100%; height: 100%; display: block; }

@keyframes ripple {
  0%   { r: 4;  opacity: 0.9; }
  100% { r: 90; opacity: 0;   }
}
.mutation-ripple {
  fill: none;
  stroke: #fff;
  stroke-width: 1.5;
  animation: ripple 0.7s ease-out forwards;
}

@keyframes star-twinkle {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}
#walker-stars circle { animation: star-twinkle 3s ease-in-out infinite; }

