* {
  box-sizing: border-box;
}

:root {
  --cream: #fdf3e0;
  --straw: #f0dcae;
  --brown: #6b4a2f;
  --brown-dark: #4a3220;
  --egg: #ffd97d;
  --egg-dark: #f2b134;
  --green: #7a9e5c;
  --dna: #8a5ec9;
  --dna-dark: #6b3fa0;
}

html {
  /* Paints behind the body so iOS Safari's collapsing address bar never
     reveals unpainted white below the gradient as it scrolls. */
  background: var(--straw);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--cream), var(--straw));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--brown-dark);
  display: flex;
  justify-content: center;
  /* This whole page is meant for fast repeated tapping — double-tap-zoom
     firing on any of it (collect, sell, buy) would be a bug, not a feature. */
  touch-action: manipulation;
}

.wrap {
  width: 100%;
  max-width: 420px;
  padding: 24px 16px 48px;
}

/* Only Time and Coins get top billing — those are what you're actually
   racing on. Egg count/rate are engine-room detail, demoted below. A fixed
   min-height on both rows keeps the click zone from shifting as digits
   change width mid-session. */
.stats-primary {
  display: flex;
  justify-content: center;
  gap: 28px;
  min-height: 2.6rem;
}

.stat-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.15;
}

#timeLeft.urgent {
  color: #c9432f;
}

.stat-unit {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brown);
  opacity: 0.7;
}

.stats-secondary {
  text-align: center;
  font-size: 0.85rem;
  color: var(--brown);
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
  margin-bottom: 20px;
}

.vs-chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: #fffaf0;
  border: 2px solid var(--straw);
  border-radius: 999px;
  padding: 8px 16px;
}

.vs-chip-me,
.vs-chip-opp {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.vs-chip-me { color: var(--egg-dark); }
.vs-chip-opp { color: var(--brown); }

.vs-chip-sep {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--brown);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

.click-zone {
  position: relative;
  margin: 0 auto 32px;
  width: 160px;
}

.collect-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 160px;
  height: 160px;
  margin: 0;
  border-radius: 50%;
  /* Rapid taps in the same spot otherwise read as double-tap-to-zoom on
     mobile. This kills that (and the old 300ms tap delay) without
     disabling pinch-zoom anywhere else on the page. */
  touch-action: manipulation;
  border: none;
  background: radial-gradient(circle at 35% 30%, var(--egg), var(--egg-dark));
  box-shadow: 0 6px 0 #c98a1e, 0 8px 16px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.06s ease;
  user-select: none;
}

.collect-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #c98a1e, 0 4px 8px rgba(0,0,0,0.15);
}

.collect-btn .egg-icon {
  font-size: 3.2rem;
  line-height: 1;
}

.collect-btn .collect-label {
  font-weight: 700;
  color: var(--brown-dark);
}

.collect-btn.pop .egg-icon {
  animation: pop 0.18s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.floater {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translate(-50%, 0);
  font-weight: 700;
  color: var(--egg-dark);
  pointer-events: none;
  white-space: nowrap;
  animation: rise 0.7s ease-out forwards;
}

@keyframes rise {
  0% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -46px); }
}

.shop {
  animation: reveal 0.35s ease;
}

@keyframes reveal {
  0% { opacity: 0; transform: translateY(-6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.shop h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brown);
  margin-bottom: 8px;
}

.market-price {
  font-size: 0.9rem;
  color: var(--brown);
  margin-bottom: 6px;
}

.price-chart {
  display: block;
  width: 100%;
  height: 48px;
  margin-bottom: 12px;
}

.shop-item {
  width: 100%;
  display: block;
  text-align: left;
  background: #fffaf0;
  border: 2px solid var(--straw);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.06s ease;
  font: inherit;
  color: inherit;
}

.shop-item:hover {
  border-color: var(--egg-dark);
}

.shop-item:active {
  transform: scale(0.98);
}

.shop-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.shop-item:disabled:hover {
  border-color: var(--straw);
}

.shop-item-main {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  margin-bottom: 4px;
}

.shop-item-count {
  color: var(--green);
}

.shop-item-sub {
  font-size: 0.85rem;
  color: var(--brown);
  opacity: 0.8;
}

footer {
  text-align: center;
  margin-top: 24px;
}

.reset-btn {
  background: none;
  border: none;
  color: var(--brown);
  opacity: 0.5;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.reset-btn:hover {
  opacity: 0.9;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--brown-dark);
  color: var(--cream);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  max-width: 90vw;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.end-overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 50, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.end-card {
  width: 100%;
  max-width: 360px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--cream);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.end-card h2 {
  margin: 0 0 8px;
}

.end-score {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--egg-dark);
  margin-bottom: 4px;
}

.end-best {
  font-size: 0.9rem;
  color: var(--brown);
  opacity: 0.85;
  margin-bottom: 18px;
}

.end-waiting {
  font-size: 0.95rem;
  color: var(--brown);
  opacity: 0.85;
  margin-bottom: 18px;
}

.end-result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 4px;
  border-bottom: 1px solid var(--straw);
  font-weight: 700;
}

.end-result-name {
  font-size: 1rem;
}

.end-result-score {
  font-size: 1.3rem;
  color: var(--brown);
  font-variant-numeric: tabular-nums;
}

#endMeRow .end-result-score {
  color: var(--egg-dark);
}

.end-bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--straw);
  margin: 14px 0 8px;
}

.end-bar-me {
  background: var(--egg-dark);
}

.end-bar-opp {
  background: var(--brown);
  opacity: 0.5;
}

.end-delta {
  text-align: center;
  font-size: 0.85rem;
  color: var(--brown);
  opacity: 0.85;
}

.end-verdict {
  margin: 14px 0 4px;
  font-weight: 700;
  font-size: 1.05rem;
}

.play-again {
  background: none;
  border: 2px solid var(--brown);
  color: var(--brown-dark);
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  cursor: pointer;
}

.debug-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--brown-dark);
  color: var(--cream);
  opacity: 0.35;
  cursor: pointer;
  font-size: 1rem;
  transition: opacity 0.15s ease;
  z-index: 50;
}

.debug-toggle:hover {
  opacity: 0.9;
}

.debug-panel {
  position: fixed;
  right: 14px;
  bottom: 58px;
  width: 240px;
  max-width: calc(100vw - 28px);
  background: #2a1c10;
  color: #f3e6cf;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
  z-index: 50;
  font-size: 0.8rem;
}

.debug-panel h3 {
  margin: 0 0 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.debug-note {
  margin: 0 0 10px;
  opacity: 0.6;
  font-size: 0.72rem;
  line-height: 1.3;
}

.debug-group {
  margin-bottom: 10px;
}

.debug-label {
  display: block;
  opacity: 0.6;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.debug-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.debug-row button {
  flex: 1 1 auto;
  background: #4a3220;
  color: #f3e6cf;
  border: 1px solid #6b4a2f;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}

.debug-row button:hover {
  background: #5c4128;
}

.debug-close {
  width: 100%;
  margin-top: 4px;
  background: transparent;
  border: 1px solid #6b4a2f;
  color: #f3e6cf;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.7;
}

.debug-close:hover {
  opacity: 1;
}

.menu-screen {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  max-width: 320px;
  margin: 15vh auto 0;
  text-align: center;
}

.menu-title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 700;
}

.menu-tagline {
  margin: 0 0 8px;
  color: var(--brown);
  opacity: 0.8;
  font-size: 0.95rem;
}

.menu-btn {
  border: 2px solid var(--brown);
  background: none;
  color: var(--brown-dark);
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.menu-btn.primary {
  background: var(--egg-dark);
  border-color: var(--egg-dark);
}

.menu-btn.small {
  padding: 10px 14px;
  flex: 0 0 auto;
}

.menu-btn.link {
  border: none;
  opacity: 0.6;
  font-weight: 600;
}

.menu-btn.link:hover {
  opacity: 1;
}

.menu-input {
  border: 2px solid var(--straw);
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  background: #fffaf0;
  color: var(--brown-dark);
  text-align: center;
}

.lobby-link {
  margin-bottom: 8px;
}

.lobby-link-row {
  display: flex;
  gap: 8px;
}

.lobby-link-row .menu-input {
  flex: 1 1 auto;
  min-width: 0;
}

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
  text-align: left;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fffaf0;
  border: 2px solid var(--straw);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
}

.lobby-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--straw);
  flex: 0 0 auto;
}

.lobby-dot.ready {
  background: var(--green);
}
