@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --bg: linear-gradient(170deg, #fdf6e3 0%, #e8f5d6 50%, #d4edbc 100%);
  --field: #c8e6a0;
  --field-border: #8cc063;
  --panel: #fffef9;
  --panel-shadow: 0 2px 12px rgba(80, 100, 60, 0.10);
  --text: #2b3926;
  --muted: #6b7e5f;
  --accent: #5da33a;
  --accent-hover: #4a8a2d;
  --danger: #d4553a;
  --warm: #e8a735;
  --hot: #e05535;
  --cold: #4a90d9;
  --freezing: #7baaf7;
  --found: #4caf50;
  --radius: 14px;
}

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

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Hero (home page) ────────────── */
.home-app {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  gap: 20px;
}

.hero {
  text-align: center;
  padding: 10px 0 0;
}

.hero-animals {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.hero-emoji {
  font-size: 2.6rem;
  display: inline-block;
  opacity: 0;
  transform: translateX(30px);
  animation: walk-in 0.5s ease-out forwards, gentle-sway 3s ease-in-out infinite;
  animation-delay: calc(var(--d, 0) * 0.35s), calc(var(--d, 0) * 0.35s + 0.5s);
}

@keyframes walk-in {
  0%   { opacity: 0; transform: translateX(30px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes gentle-sway {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.hero-title {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.hero-sub {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 380px;
  margin: 0 auto;
}

/* ── Play choice buttons (home) ─── */
.play-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
}

.play-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-radius: 12px;
  border: 1.5px solid #d5d0bc;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.play-btn:hover {
  background: rgba(0,0,0,0.02);
}

.play-btn:active {
  transform: scale(0.98);
}

.play-btn-primary {
  border-color: var(--accent);
}

.play-btn-primary:hover {
  border-color: var(--accent-hover);
  background: rgba(93, 163, 58, 0.05);
}

.play-btn-duo {
  border-color: #d5d0bc;
}

.play-btn-duo:hover {
  border-color: var(--warm);
  background: rgba(232, 167, 53, 0.04);
}

.play-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.play-text {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.play-label {
  font-weight: 800;
  font-size: 1.1rem;
}

.play-desc {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 1px;
}

/* ── Panels ─────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid #e0dcc8;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--panel-shadow);
}

.panel h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.panel .subtitle {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
  margin-bottom: 14px;
}

/* ── Buttons & inputs ─────────────── */
.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

input[type="text"], input[type="password"], input {
  border-radius: 10px;
  border: 2px solid #d5d0bc;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.95rem;
  background: #fafaf5;
  color: var(--text);
  outline: none;
  transition: border 0.2s;
}

input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  padding: 9px 18px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, opacity 0.15s;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: #d5d0bc;
}
.btn-secondary:hover {
  background: rgba(0,0,0,0.03);
  border-color: #b8b3a0;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-lg {
  padding: 12px 26px;
  font-size: 1rem;
  border-radius: 10px;
}

.btn-full {
  width: 100%;
  margin-top: 6px;
}

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 7px;
}

/* ── Home Leaderboard ───────────── */
.home-leaderboard {
  width: 100%;
  max-width: 420px;
  margin-top: 4px;
  animation: fadeSlideUp 0.5s ease-out both;
  animation-delay: 0.15s;
}

/* ── How to play (collapsible) ──── */
.how-to-details {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid #e0dcc8;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--panel-shadow);
}

.how-to-details summary {
  padding: 14px 20px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}

.how-to-details summary::before {
  content: "▸";
  transition: transform 0.2s;
  font-size: 0.85rem;
}

.how-to-details[open] summary::before {
  transform: rotate(90deg);
}

.how-to-details .how-to {
  padding: 0 20px 16px;
}

.how-to {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.how-step {
  flex: 1;
  min-width: 140px;
  text-align: center;
  padding: 12px 8px;
}

.how-step .num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.how-step p {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.3;
}

/* ── Game field ──────────────────── */
.field {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  border: 3px solid var(--field-border);
  background: var(--field);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.field-inner {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 12% 30%, rgba(130,195,80,0.22) 0, transparent 100px),
    radial-gradient(ellipse at 80% 15%, rgba(145,210,95,0.18) 0, transparent 120px),
    radial-gradient(ellipse at 50% 65%, rgba(115,185,70,0.2) 0, transparent 140px),
    radial-gradient(ellipse at 85% 80%, rgba(125,190,75,0.16) 0, transparent 100px),
    radial-gradient(ellipse at 20% 80%, rgba(110,180,65,0.18) 0, transparent 110px),
    radial-gradient(ellipse at 65% 40%, rgba(140,200,90,0.14) 0, transparent 130px),
    radial-gradient(ellipse at 35% 15%, rgba(120,188,72,0.12) 0, transparent 100px),
    radial-gradient(ellipse at 75% 70%, rgba(135,195,82,0.1) 0, transparent 120px),
    repeating-linear-gradient(
      0deg,
      transparent 0, transparent 32px,
      rgba(75,135,42,0.04) 32px, rgba(75,135,42,0.04) 64px
    );
}

/* Tree shadow */
.tree-svg {
  filter: drop-shadow(0 8px 4px rgba(40,70,25,0.1));
}

/* SVG farm decorations */
.farm-svg {
  position: absolute;
  pointer-events: none;
  opacity: 0.55;
  z-index: 1;
}
.farm-svg.flip {
  transform: scaleX(-1);
}
.barn-svg {
  opacity: 0.5;
}
.windmill-svg {
  opacity: 0.45;
}
.cargo-svg {
  opacity: 0.45;
}

/* CSS fences */
.fence {
  position: absolute;
  width: 52px;
  height: 3px;
  background: rgba(170, 130, 75, 0.3);
  pointer-events: none;
  z-index: 1;
}
.fence::before,
.fence::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 16px;
  background: rgba(170, 130, 75, 0.3);
  top: -7px;
  border-radius: 1px;
}
.fence::before { left: 5px; }
.fence::after { right: 5px; }

/* CSS hay bales */
.hay {
  position: absolute;
  width: 22px;
  height: 15px;
  background: linear-gradient(135deg, rgba(215,185,105,0.45), rgba(195,165,85,0.35));
  border-radius: 4px 4px 2px 2px;
  pointer-events: none;
  z-index: 1;
}
.hay::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(180,150,60,0.2);
  border-radius: 2px;
}
.hay-sm { transform: scale(0.7); }

/* Dirt path */
.dirt-path {
  position: absolute;
  right: 8%;
  bottom: 10%;
  width: 55%;
  height: 18px;
  background: rgba(170,140,90,0.08);
  border-radius: 50%;
  transform: rotate(-3deg);
  pointer-events: none;
}
.dirt-path-2 {
  right: 2%;
  bottom: 6%;
  width: 35%;
  height: 14px;
  transform: rotate(5deg);
  background: rgba(170,140,90,0.1);
}
.dirt-path-3 {
  right: 30%;
  bottom: 18%;
  width: 25%;
  height: 12px;
  transform: rotate(-8deg);
  background: rgba(170,140,90,0.06);
}

/* Wildflowers */
.flowers {
  position: absolute;
  width: 24px;
  height: 12px;
  pointer-events: none;
  z-index: 1;
}
.flowers::before,
.flowers::after {
  content: "";
  position: absolute;
  border-radius: 50%;
}
.flowers::before {
  width: 4px; height: 4px;
  background: rgba(245,220,80,0.6);
  left: 2px; top: 2px;
  box-shadow:
    8px 3px 0 rgba(245,220,80,0.5),
    16px 1px 0 rgba(245,220,80,0.45);
}
.flowers::after {
  width: 3px; height: 3px;
  background: rgba(255,255,255,0.55);
  left: 6px; top: 7px;
  box-shadow:
    10px -2px 0 rgba(255,255,255,0.45),
    4px -5px 0 rgba(255,255,255,0.4);
}
.flowers-b::before {
  background: rgba(200,160,220,0.55);
  box-shadow:
    8px 3px 0 rgba(200,160,220,0.45),
    16px 1px 0 rgba(200,160,220,0.4);
}
.flowers-b::after {
  background: rgba(245,220,80,0.5);
  box-shadow:
    10px -2px 0 rgba(245,220,80,0.4),
    4px -5px 0 rgba(245,220,80,0.35);
}
.flowers-c::before {
  background: rgba(255,180,180,0.5);
  box-shadow:
    8px 3px 0 rgba(255,180,180,0.4),
    16px 1px 0 rgba(255,255,255,0.45);
}
.flowers-c::after {
  background: rgba(245,220,80,0.45);
  box-shadow:
    10px -2px 0 rgba(200,160,220,0.4),
    4px -5px 0 rgba(245,220,80,0.35);
}

/* Decorative pond */
.pond {
  position: absolute;
  width: 65px;
  height: 36px;
  background: radial-gradient(ellipse at 40% 40%, rgba(130,195,235,0.35) 0%, rgba(100,170,220,0.25) 60%, rgba(80,150,200,0.15) 100%);
  border-radius: 50%;
  border: 2px solid rgba(80, 150, 200, 0.2);
  pointer-events: none;
  box-shadow: inset 0 1px 4px rgba(60,130,180,0.12);
}
.pond::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 12px;
  width: 22px;
  height: 10px;
  background: rgba(160, 210, 240, 0.3);
  border-radius: 50%;
}

/* Grass base strip */
.grass {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20px;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0, transparent 4px,
      rgba(65,125,38,0.14) 4px, rgba(65,125,38,0.14) 6px,
      transparent 6px, transparent 12px,
      rgba(80,140,45,0.12) 12px, rgba(80,140,45,0.12) 14px,
      transparent 14px, transparent 20px,
      rgba(55,115,32,0.1) 20px, rgba(55,115,32,0.1) 22px
    ),
    linear-gradient(to top, rgba(70,135,42,0.22), rgba(85,150,48,0.08), transparent);
  pointer-events: none;
}

/* ── CSS Grass clumps ── */
.gc {
  position: absolute;
  pointer-events: none;
  z-index: 1;
  animation: grass-sway 4s ease-in-out infinite;
}
.gc:nth-child(odd)  { animation-delay: -1.5s; }
.gc:nth-child(3n)   { animation-duration: 5s; }
.gc:nth-child(4n+1) { animation-delay: -3s; animation-duration: 4.5s; }

@keyframes grass-sway {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(2deg); }
  75%      { transform: rotate(-2deg); }
}

/* Blade base (::before = left blade, ::after = right blade) */
.gc::before,
.gc::after {
  content: "";
  position: absolute;
  bottom: 0;
  border-radius: 2px 2px 1px 1px;
  transform-origin: bottom center;
}

/* Centre blade via <span> child */
.gc > span {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 2px 2px 1px 1px;
}

/* ── Large clumps (accent) ── */
.gc-lg {
  width: 20px;
  height: 28px;
}
.gc-lg::before {
  left: 1px;
  width: 3.5px;
  height: 24px;
  background: linear-gradient(to top, rgba(72,140,42,0.5), rgba(95,170,55,0.35));
  transform: rotate(-18deg);
}
.gc-lg::after {
  right: 1px;
  width: 3px;
  height: 20px;
  background: linear-gradient(to top, rgba(65,130,38,0.45), rgba(105,180,60,0.3));
  transform: rotate(14deg);
}
.gc-lg > span {
  width: 3px;
  height: 26px;
  background: linear-gradient(to top, rgba(78,145,45,0.5), rgba(110,185,65,0.25));
}

/* every other large clump: different angles */
.gc-lg:nth-child(even)::before { transform: rotate(-12deg); height: 22px; }
.gc-lg:nth-child(even)::after  { transform: rotate(20deg); height: 18px; }

/* ── Medium clumps (fill) ── */
.gc-md {
  width: 14px;
  height: 20px;
}
.gc-md::before {
  left: 1px;
  width: 2.5px;
  height: 17px;
  background: linear-gradient(to top, rgba(70,135,40,0.45), rgba(100,175,58,0.28));
  transform: rotate(-15deg);
}
.gc-md::after {
  right: 1px;
  width: 2.5px;
  height: 14px;
  background: linear-gradient(to top, rgba(62,125,36,0.4), rgba(108,180,62,0.25));
  transform: rotate(12deg);
}
.gc-md > span {
  width: 2.5px;
  height: 18px;
  background: linear-gradient(to top, rgba(75,142,44,0.45), rgba(115,190,68,0.2));
}
.gc-md:nth-child(odd)::before { transform: rotate(-20deg); }
.gc-md:nth-child(odd)::after  { transform: rotate(8deg); height: 16px; }

/* ── Small clumps (texture) ── */
.gc-sm {
  width: 8px;
  height: 12px;
}
.gc-sm::before {
  left: 0;
  width: 2px;
  height: 10px;
  background: rgba(75,140,45,0.32);
  transform: rotate(-12deg);
}
.gc-sm::after {
  right: 0;
  width: 2px;
  height: 8px;
  background: rgba(85,150,50,0.25);
  transform: rotate(10deg);
}
.gc-sm:nth-child(even)::before { height: 9px; transform: rotate(-8deg); }
.gc-sm:nth-child(even)::after  { height: 7px; transform: rotate(16deg); }

/* Click ripple */
.click-ripple {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  animation: ripple-out 0.9s ease-out forwards;
  border: 3px solid currentColor;
}

@keyframes ripple-out {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(3); opacity: 0; }
}

.click-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: dot-fade 3s ease-out forwards;
}

@keyframes dot-fade {
  0%, 50% { opacity: 0.6; }
  100%    { opacity: 0; }
}

/* Reveal */
.reveal {
  position: absolute;
  transform: translate(-50%, -50%) scale(0);
  font-size: 48px;
  pointer-events: none;
  animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.25));
  z-index: 10;
}

@keyframes pop-in {
  0%   { transform: translate(-50%, -50%) scale(0) rotate(-15deg); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

/* Found celebration */
.found-burst {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(76, 175, 80, 0.4) 0%, transparent 70%);
  pointer-events: none;
  animation: burst 0.6s ease-out forwards;
  z-index: 9;
}

@keyframes burst {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(3); opacity: 0; }
}

/* ── Status bar ──────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #f5f3e8;
  font-size: 0.9rem;
  min-height: 42px;
  transition: background 0.3s;
}

.status-bar.status-found {
  background: #e6f5e6;
}

.warmth-label {
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.warmth-freezing { background: #dce8f7; color: #3a6fb0; }
.warmth-cold     { background: #d0e4f5; color: #2d6da8; }
.warmth-cool     { background: #e0f0d0; color: #4a7a30; }
.warmth-warm     { background: #fcecc8; color: #9a6a10; }
.warmth-hot      { background: #fdd8c8; color: #b84020; }
.warmth-found    { background: #c8f0c8; color: #2d7a30; }

/* ── Round info ──────────────────── */
.round-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.round-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f0ede2;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
}

.animal-badge { font-size: 1.6rem; }

/* ── Progress dots ───────────────── */
.progress-dots {
  display: flex;
  gap: 6px;
}

.progress-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #d5d0bc;
  background: #f5f3e8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.3s;
}

.progress-dot.active {
  border-color: var(--accent);
  background: #e8f5d6;
  box-shadow: 0 0 0 3px rgba(93, 163, 58, 0.2);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(93, 163, 58, 0.2); }
  50%      { box-shadow: 0 0 0 6px rgba(93, 163, 58, 0.1); }
}

.progress-dot.done {
  border-color: var(--found);
  background: var(--found);
}

/* ── Leaderboard ─────────────────── */
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.lb-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 2px solid #e0dcc8;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.lb-table td {
  padding: 8px 8px;
  border-bottom: 1px solid #f0ede2;
}

.lb-table tr:last-child td { border-bottom: none; }

.lb-table .rank {
  font-weight: 800;
  color: var(--accent);
  width: 28px;
}

/* Table scroll wrapper for mobile */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Share link ──────────────────── */
.share-box {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 12px;
}

.share-label {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.share-box a {
  color: var(--accent);
  font-weight: 500;
  word-break: break-all;
}

/* Copy button (minimalistic icon-only) */
.copy-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s;
  position: relative;
  top: 2px;
}
.copy-btn:hover { color: var(--accent); }
.copy-btn:active { transform: scale(0.92); }
.copy-btn svg { flex-shrink: 0; }

/* ── Lobby ───────────────────────── */
.lobby-app {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}

.lobby-panel {
  width: 100%;
  max-width: 440px;
  padding: 28px 24px;
  position: relative;
}

.back-link {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 12px;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--accent);
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lobby-form label {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
}

.label-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.82rem;
}

.lobby-form input {
  width: 100%;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
}

.lobby-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.82rem;
}

.lobby-links a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}

.lobby-links a:hover {
  color: var(--accent);
}

.link-sep {
  color: #d5d0bc;
}

/* ── Match result overlay ────────── */
.match-overlay {
  text-align: center;
  padding: 24px;
}

.match-overlay .trophy { font-size: 3rem; margin-bottom: 8px; }
.match-overlay .winner-name { font-size: 1.4rem; font-weight: 800; }
.match-overlay .winner-time { color: var(--muted); margin-top: 4px; }

/* ── Post-game hero ──────────────── */
.postgame-hero {
  text-align: center;
  padding: 28px 20px 20px;
  background: linear-gradient(180deg, #f0fae6 0%, var(--panel) 100%);
  border-radius: 16px;
  border: 1px solid #e0dcc8;
  box-shadow: var(--panel-shadow);
}

.postgame-animals {
  font-size: 2rem;
  letter-spacing: 0.3em;
  margin-bottom: 8px;
  animation: celebrateBounce 0.6s ease-out;
}

.congrats-msg {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 4px;
  line-height: 1.2;
}

.congrats-sub {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.4;
}

.winner-time {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 4px;
}

.postgame-lb {
  animation: fadeSlideUp 0.4s ease-out both;
}
.postgame-lb:nth-child(3) { animation-delay: 0.1s; }
.postgame-lb:nth-child(5) { animation-delay: 0.2s; }

@keyframes celebrateBounce {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

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

/* ── Head-to-head matchup ────────── */
.matchup {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  margin: 12px 0 16px;
}

.matchup-player {
  flex: 1;
  max-width: 180px;
  background: #f8f7f0;
  border: 2px solid #e0dcc8;
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
}

.matchup-winner {
  background: #e8f5d6;
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(93, 163, 58, 0.15);
}

.matchup-me {
  position: relative;
}

.matchup-medal {
  font-size: 1.8rem;
  line-height: 1;
  margin-bottom: 4px;
}

.matchup-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
  margin-bottom: 6px;
}

.matchup-stat {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.matchup-sub {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}

.matchup-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 10px;
  flex-shrink: 0;
}

/* ── Breakdown title ─────────────── */
.breakdown-title {
  margin: 10px 0 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  text-align: left;
}

/* ── Post-game buttons ───────────── */
.postgame-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

.btn-play-again {
  padding: 14px 40px;
  font-size: 1.05rem;
  font-weight: 800;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #4a9e2f);
  border: none;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
  box-shadow: 0 4px 16px rgba(93, 163, 58, 0.35);
  letter-spacing: 0.02em;
}

.btn-back-lobby {
  padding: 14px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 14px;
  background: var(--panel);
  border: 2px solid var(--accent);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.btn-back-lobby:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(93, 163, 58, 0.2);
}

.btn-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(93, 163, 58, 0.4);
  background: linear-gradient(135deg, #4a9e2f, var(--accent));
}

.btn-play-again:active {
  transform: scale(0.97);
}

/* ── Game Layout ─────────────────── */
.game-app {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 12px;
  padding: 10px calc(12px + env(safe-area-inset-left)) 10px calc(12px + env(safe-area-inset-right));
  padding-bottom: env(safe-area-inset-bottom, 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Info Bar (round + dots + timer) ── */
.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid #e0dcc8;
  box-shadow: var(--panel-shadow);
  gap: 10px;
  min-height: 44px;
}
.info-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.round-label {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--accent);
  background: #e8f5d6;
  padding: 3px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.info-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
}
.info-bar .progress-dots { gap: 4px; }
.info-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.timer-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  background: #f0fae6;
  padding: 4px 12px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  transition: background 0.3s;
}
.timer-wrap.found { background: #d4edbc; }
.timer-icon { font-size: 0.82rem; }
.timer-value { min-width: 3em; text-align: right; }

/* ── Control Strip (actions) ─────── */
.control-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.control-left {
  display: flex;
  align-items: center;
}
.back-link {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); }
.control-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.control-actions .btn { padding: 6px 14px; font-size: 0.82rem; }
.btn-reset {
  font-size: 0.76rem !important;
  padding: 5px 12px !important;
  opacity: 0.6;
  transition: opacity 0.15s, border-color 0.15s;
}
.btn-reset:hover:not(:disabled) { opacity: 1; border-color: #b8b3a0; }

/* ── Game Field ──────────────────── */
.game-field {
  flex: 1;
  position: relative;
  border-radius: 16px;
  border: 3px solid var(--field-border);
  background: var(--field);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: min(500px, 60dvh);
  transition: max-height 0.5s ease, min-height 0.5s ease, opacity 0.4s ease, margin 0.4s ease, border-width 0.3s ease;
}

/* Collapse game field after match ends */
.game-field.field-done {
  max-height: 0;
  min-height: 0 !important;
  opacity: 0;
  border-width: 0;
  margin: 0;
  flex: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Hide game chrome (info bar, controls, status) during post-game */
.game-chrome-hidden {
  display: none !important;
}

/* ── Status Bar (below field) ────── */
.status-bar {
  text-align: center;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #e0dcc8;
  box-shadow: var(--panel-shadow);
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Match-related ───────────────── */
.match-standings {
  margin-top: 14px;
  text-align: left;
}
.match-standings .lb-table td,
.match-standings .lb-table th { font-size: 0.85rem; }
.match-standings .highlight { font-weight: 700; background: #f0fae6; }
.results-wrap { display: none; }
.results-wrap.visible { display: block; padding-top: 4px; }

#shareWrap { margin-top: 0; }

/* ── Big centered start overlay ──── */
.field-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 25;
  background: rgba(200, 230, 160, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 14px;
  transition: opacity 0.4s, visibility 0.4s;
}
.field-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.big-start-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.big-start-btn:hover:not(:disabled) {
  transform: scale(1.06);
  border-color: var(--accent-hover);
  background: rgba(255,255,255,0.95);
}
.big-start-btn:active:not(:disabled) {
  transform: scale(0.96);
}
.big-start-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.big-start-icon {
  font-size: 2.4rem;
  line-height: 1;
  color: var(--accent);
}
.big-start-text {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
  letter-spacing: 0.01em;
}
.overlay-hint {
  margin-top: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255,254,249,0.8);
  padding: 5px 14px;
  border-radius: 6px;
  text-align: center;
  max-width: 80%;
  letter-spacing: 0.01em;
}

/* ── Responsive ──────────────────── */

/* Tablet */
@media (max-width: 768px) {
  .app { padding: 16px 10px; }
  .hero-title { font-size: 2.2rem; }
  .hero-emoji { font-size: 2.2rem; }
  .game-app { padding: 8px; }
}

/* Phone */
@media (max-width: 500px) {
  .app {
    padding: 12px 8px;
    padding-left: calc(8px + env(safe-area-inset-left));
    padding-right: calc(8px + env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }
  .panel { padding: 14px; }
  .field { aspect-ratio: 1 / 1; }
  .how-to { flex-direction: column; gap: 8px; }
  .how-step { min-width: unset; padding: 8px 6px; }
  .round-info { flex-direction: column; align-items: flex-start; }
  .lb-table { font-size: 0.8rem; }
  .lb-table th { padding: 4px 6px; font-size: 0.72rem; }
  .lb-table td { padding: 6px 6px; }
  .share-box { font-size: 0.78rem; flex-wrap: wrap; }
  .btn-lg { padding: 12px 22px; font-size: 0.95rem; }
  .panel h2 { font-size: 1.3rem; }
  .lobby-form input { font-size: 16px; /* prevents iOS zoom on focus */ }

  /* Matchup responsive */
  .matchup-player { max-width: 140px; padding: 10px 8px; }
  .matchup-medal { font-size: 1.4rem; }
  .matchup-name { font-size: 0.82rem; }
  .matchup-stat { font-size: 1.2rem; }
  .matchup-sub { font-size: 0.68rem; }
  .matchup-vs { font-size: 0.72rem; padding: 0 6px; }
  .btn-play-again { padding: 10px 24px; font-size: 0.92rem; }

  /* Game screen responsive */
  .game-app { padding: 4px; padding-bottom: env(safe-area-inset-bottom, 4px); }
  .game-field { min-height: min(350px, 55dvh); border-radius: 12px; border-width: 2px; }
  .info-bar { padding: 6px 8px; border-radius: 10px; gap: 6px; min-height: 38px; }
  .info-bar .progress-dots { gap: 3px; }
  .info-bar .progress-dot { width: 22px; height: 22px; font-size: 0.6rem; }
  .round-label { font-size: 0.7rem; padding: 2px 7px; }
  .timer-wrap { font-size: 0.76rem; padding: 3px 8px; }
  .control-actions .btn { padding: 5px 10px; font-size: 0.76rem; }
  .status-bar { font-size: 0.78rem; padding: 6px 12px; min-height: 32px; }
  .results-wrap .panel { padding: 12px; }
  .big-start-btn { width: 110px; height: 110px; }
  .big-start-icon { font-size: 2.2rem; }
  .big-start-text { font-size: 0.75rem; }
  .overlay-hint { font-size: 0.78rem; }

  /* Home */
  .hero-title { font-size: 1.8rem; }
  .hero-emoji { font-size: 1.8rem; }
  .hero-sub { font-size: 0.85rem; }
  .play-btn { padding: 14px 16px; gap: 12px; }
  .play-icon { font-size: 1.6rem; }
  .play-label { font-size: 1rem; }
  .play-desc { font-size: 0.78rem; }
  .how-to-details { max-width: 100%; }

  /* Lobby */
  .lobby-panel { padding: 20px 16px; }

  /* Scale decorations */
  .barn { width: 50px; height: 40px; right: 10px; bottom: 8px; }
  .barn::before { border-left-width: 30px; border-right-width: 30px; border-bottom-width: 20px; left: -5px; top: -18px; }
  .barn::after { width: 14px; height: 22px; }
  .tree { transform: scale(0.7); }
  .tree-sm { transform: scale(0.42); }
  .tree-lg { transform: scale(0.95); }
  .tree-bush { transform: scale(0.65); }
  .grass-tuft { transform: scale(0.7); }
  .pond { width: 40px; height: 22px; }
  .fence { width: 36px; }
  .hay { width: 16px; height: 12px; }
  .progress-dot { width: 24px; height: 24px; font-size: 0.7rem; }
}

/* Very small phones */
@media (max-width: 360px) {
  .app { padding: 8px 6px; }
  .panel { padding: 10px; }
  .panel h2 { font-size: 1.15rem; }
  .btn { font-size: 0.88rem; padding: 8px 14px; }
  .hero-title { font-size: 1.5rem; }
  .game-field { min-height: min(280px, 50dvh); }
  .info-bar .progress-dot { width: 18px; height: 18px; font-size: 0.5rem; }
  .control-actions .btn { padding: 4px 8px; font-size: 0.72rem; }
  .timer-wrap { font-size: 0.7rem; padding: 2px 6px; }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .app { padding: 6px; gap: 8px; }
  .panel { padding: 12px; }
  .field { aspect-ratio: 16 / 9; }
  .game-app { gap: 4px; padding: 4px 8px; }
  .game-field { min-height: min(250px, 70dvh); }
  .info-bar { padding: 4px 8px; min-height: 36px; }
  .info-bar .progress-dot { width: 20px; height: 20px; font-size: 0.55rem; }
  .status-bar { padding: 4px 10px; min-height: 28px; font-size: 0.76rem; }
}

/* ── Backup code nudge banner ────────── */
.backup-nudge {
  position: relative;
  margin-top: 12px;
  padding: 14px 36px 14px 16px;
  background: var(--panel);
  border: 1.5px solid #d5d0bc;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.nudge-text {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.nudge-icon { font-size: 1.4rem; flex-shrink: 0; }
.nudge-text p { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }
.nudge-code-wrap {
  margin-top: 10px;
}
.nudge-code-label {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 4px;
}
.nudge-code {
  font-family: 'Courier New', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--accent);
  background: #fff;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  padding: 8px 16px;
  display: inline-block;
  user-select: all;
}
.nudge-code-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 6px 0 0;
}
.nudge-dismiss {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.nudge-dismiss:hover { color: var(--text); }
