:root {
  --ink: #2c2420;
  --card: rgba(255, 250, 242, 0.96);
  --accent: #f0a431;
  --accent-dark: #c47a12;
  --green: #5ed35a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9e3da;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
canvas { display: block; }
.hidden { display: none !important; }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: #f6efe4;
}
.loader-hamster { font-size: 64px; animation: hop 0.6s ease-in-out infinite alternate; }
@keyframes hop { to { transform: translateY(-12px); } }
.bar { width: 220px; height: 10px; border-radius: 6px; background: #e4d7c3; overflow: hidden; }
#loading-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
}
#hud-left { position: absolute; left: 14px; top: 12px; }
#level {
  display: inline-block; font-weight: 800; font-size: 15px; letter-spacing: 0.5px;
  background: var(--card); padding: 5px 12px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#seeds {
  margin-top: 8px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; max-width: 44vw;
  background: var(--card); padding: 6px 10px; border-radius: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.seed-icon {
  width: 11px; height: 18px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: repeating-linear-gradient(90deg, #2a2724 0 3px, #e7e2d6 3px 5px);
  opacity: 0.25;
  transform: rotate(20deg);
}
.seed-icon.found { opacity: 1; }
#power {
  margin-top: 6px; display: inline-flex; gap: 2px;
  background: var(--card); padding: 3px 8px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.power-pip { font-size: 16px; filter: grayscale(1); opacity: 0.3; transition: opacity 0.2s, transform 0.2s; }
.power-pip.full { filter: none; opacity: 1; transform: scale(1.1); }
.seed-count { margin-left: 4px; font-weight: 800; font-size: 14px; }
#timer {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  font-weight: 900; font-size: 30px; font-variant-numeric: tabular-nums;
  background: var(--card); padding: 4px 16px; border-radius: 14px; box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
#timer.warn { color: #d8352a; animation: pulse 0.5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: translateX(-50%) scale(1.08); } }
#hud-right { position: absolute; right: 14px; top: 12px; display: flex; gap: 8px; pointer-events: auto; }
#hud-right button {
  width: 40px; height: 40px; border: 0; border-radius: 12px; font-size: 17px; cursor: pointer;
  background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,0.15); color: var(--ink);
}

#wheel {
  position: fixed; left: 0; top: 0; width: 60px; height: 60px; z-index: 9;
  pointer-events: none; opacity: 0;
}

#toast {
  position: fixed; left: 50%; bottom: 18%; transform: translate(-50%, 20px); z-index: 12;
  background: rgba(44, 36, 32, 0.88); color: #fff; font-weight: 700; font-size: 16px;
  padding: 10px 18px; border-radius: 14px; max-width: min(90vw, 520px); text-align: center;
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlay screens ---------- */
#screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(40, 30, 20, 0.35); backdrop-filter: blur(3px);
}
.card {
  background: var(--card); border-radius: 22px; padding: 26px 28px; width: min(460px, 100%);
  max-height: 100%; overflow: auto; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.card h1 { margin: 0 0 6px; font-size: 32px; }
.card h2 { margin: 0 0 8px; font-size: 26px; }
.card p { margin: 8px 0; line-height: 1.45; }
.card .big-emoji { font-size: 52px; line-height: 1; }
.card .stats { font-size: 18px; font-weight: 700; }
.controls {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; text-align: left;
  font-size: 14px; margin: 14px auto 0; max-width: 340px;
}
.controls b {
  display: inline-block; min-width: 26px; padding: 1px 6px; border-radius: 6px; text-align: center;
  background: #efe3d1; border-bottom: 2px solid #d9c6a9; font-size: 13px;
}
.buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.buttons button {
  font: inherit; font-weight: 800; font-size: 17px; padding: 11px 22px; border-radius: 14px; cursor: pointer;
  border: 2px solid #d9c6a9; background: #fff; color: var(--ink);
}
.buttons button.primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.buttons button:focus-visible { outline: 3px solid #4a90e2; outline-offset: 2px; }

/* ---------- touch controls ---------- */
#touch-ui { display: none; }
@media (pointer: coarse) {
  #touch-ui { display: block; }
}
#joy {
  position: fixed; width: 120px; height: 120px; border-radius: 50%; display: none; z-index: 11;
  background: rgba(255, 255, 255, 0.25); border: 2px solid rgba(255, 255, 255, 0.6); pointer-events: none;
}
#joy-knob {
  position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#touch-buttons {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 11;
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 10px; align-items: end;
}
#touch-buttons button {
  border: 0; border-radius: 50%; background: rgba(255, 250, 242, 0.85); box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  font-size: 22px; color: var(--ink); touch-action: none;
}
#touch-buttons .small { width: 50px; height: 50px; }
#touch-buttons .mid { width: 62px; height: 62px; }
#touch-buttons .big { width: 80px; height: 80px; font-size: 32px; background: rgba(240, 164, 49, 0.92); color: #fff; }
