:root {
  --cream: #fff7ec;
  --ink: #4a3b35;
  --ink-soft: #7a6a60;
  --card: rgba(255, 250, 240, 0.92);
  --shadow: 0 10px 30px rgba(90, 60, 40, 0.18);
  --radius: 18px;
  --coral: #ff9a76;
  --leaf: #7bbf6a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
  background: #cdeafd;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

/* Dreamy toy-diorama sky behind the floating planet */
#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 50% 18%, #fff2d8 0%, rgba(255, 242, 216, 0) 42%),
    radial-gradient(140% 120% at 50% 120%, #ffd9b8 0%, rgba(255, 217, 184, 0) 55%),
    linear-gradient(180deg, #b7e4ff 0%, #cdeafd 40%, #ffe7cf 100%);
}
/* soft glow halo behind the planet */
#sky::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 54%;
  width: 78vmin;
  height: 78vmin;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 62%);
  filter: blur(4px);
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
#ui > * { pointer-events: auto; }

.hidden { display: none !important; }

/* Intro title */
.intro {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 1.1s ease;
  pointer-events: none;
}
.intro-mark {
  font-size: clamp(46px, 9vmin, 92px);
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 6px 0 rgba(255, 154, 118, 0.55), 0 12px 26px rgba(90, 60, 40, 0.25);
}
.intro-sub {
  margin-top: 2px;
  font-size: clamp(15px, 2.4vmin, 20px);
  font-weight: 500;
  color: #fffefb;
  text-shadow: 0 2px 8px rgba(90, 60, 40, 0.28);
}
.intro-hint {
  margin-top: 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  background: var(--card);
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.intro-hint b { color: var(--coral); }
.hint-touch { display: none; }
.touch-ui .hint-kb { display: none; }
.touch-ui .hint-touch { display: inline; }
.touch-only { display: none; }
.touch-ui .kb-only { display: none; }
.touch-ui .touch-only { display: inline; }

/* Interaction prompt pill */
.prompt {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px 9px 10px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 500;
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.prompt:not(.hidden) { opacity: 1; transform: translateX(-50%) translateY(0); }
.key {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 9px;
  background: linear-gradient(180deg, #fff, #ffe6d3);
  box-shadow: 0 2px 0 rgba(255, 154, 118, 0.5), inset 0 1px 0 #fff;
  font-weight: 700;
  color: var(--coral);
  font-size: 14px;
}

/* Panels (plant selection) */
.panel {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 92vw);
  padding: 18px 18px 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.24s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateX(-50%) translateY(14px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.panel-title { font-weight: 600; font-size: 18px; margin-bottom: 12px; }
.panel-foot, .fact-foot { margin-top: 12px; font-size: 12px; color: var(--ink-soft); }
.panel-foot b, .fact-foot b { color: var(--coral); }

.cards { display: flex; gap: 12px; justify-content: center; }
.card {
  flex: 1 1 0;
  cursor: pointer;
  padding: 14px 8px 12px;
  border-radius: 14px;
  background: #fffdf8;
  box-shadow: 0 3px 0 rgba(90, 60, 40, 0.08);
  border: 2px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--leaf);
  box-shadow: 0 10px 20px rgba(90, 60, 40, 0.14);
}
.card-emoji { font-size: 34px; line-height: 1; }
.card-name { margin-top: 8px; font-weight: 600; font-size: 15px; }
.card-hint { margin-top: 2px; font-size: 12px; color: var(--ink-soft); }

/* Fact card */
.fact {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, 90vw);
  padding: 20px 22px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.24s ease;
}
.fact-emoji { font-size: 42px; }
.fact-name { font-weight: 700; font-size: 20px; margin-top: 4px; }
.fact-text { margin-top: 8px; font-size: 15px; line-height: 1.45; color: var(--ink); }

/* Collection */
.collection-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 24px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.collection-btn:hover { transform: translateY(-2px) rotate(-4deg); }
.collection {
  position: absolute;
  top: 74px;
  right: 18px;
  width: min(260px, 80vw);
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}
.collection-title { font-weight: 600; font-size: 15px; margin-bottom: 10px; }
.collection-list { display: flex; flex-direction: column; gap: 8px; }
.collection-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}
.collection-row .dot { font-size: 20px; }
.collection-empty { font-size: 13px; color: var(--ink-soft); }

/* Toast */
.toast {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 12px 20px;
  background: rgba(74, 59, 53, 0.92);
  color: #fff7ec;
  font-weight: 500;
  font-size: 15px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mobile virtual joystick + interact */
#ui .mobile-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}
#ui .joystick,
#ui .action-btn { pointer-events: auto; }
.joystick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 132px;
  height: 132px;
  touch-action: none;
  display: grid;
  place-items: center;
}
.joystick-base {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 253, 248, 0.95) 0%, rgba(255, 247, 236, 0.72) 58%, rgba(255, 230, 211, 0.55) 100%);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -6px 12px rgba(90, 60, 40, 0.08);
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.55);
}
.joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff8ef 0%, #ffd7bf 100%);
  box-shadow:
    0 4px 0 rgba(255, 154, 118, 0.45),
    0 8px 16px rgba(90, 60, 40, 0.16),
    inset 0 2px 0 #fff;
  border: 2px solid rgba(255, 154, 118, 0.35);
  transform: translate(0, 0);
  will-change: transform;
}
.joystick.active .joystick-knob {
  background: linear-gradient(180deg, #fff 0%, #ffc9a8 100%);
}
.action-btn {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(36px, calc(env(safe-area-inset-bottom) + 18px));
  width: 68px;
  height: 68px;
  pointer-events: auto;
  border: none;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff, #ffe6d3);
  box-shadow:
    0 4px 0 rgba(255, 154, 118, 0.5),
    var(--shadow),
    inset 0 1px 0 #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 22px;
  color: var(--coral);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, opacity 0.18s ease;
}
.action-btn:active { transform: translateY(2px) scale(0.96); }
.action-btn.ready {
  animation: action-pulse 1.4s ease-in-out infinite;
}
.action-btn.close-mode { font-size: 18px; }
@keyframes action-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Keep HUD above thumbs on touch */
.touch-ui .prompt {
  bottom: max(28%, calc(env(safe-area-inset-bottom) + 168px));
  cursor: pointer;
}
.touch-ui .panel { bottom: max(26%, calc(env(safe-area-inset-bottom) + 156px)); }
.touch-ui .fact { bottom: max(26%, calc(env(safe-area-inset-bottom) + 156px)); }
.touch-ui .toast { bottom: max(32%, calc(env(safe-area-inset-bottom) + 180px)); }
.touch-ui .collection-btn {
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
}
.touch-ui .collection {
  top: max(74px, calc(env(safe-area-inset-top) + 56px));
  right: max(18px, env(safe-area-inset-right));
}

@media (max-width: 520px) {
  .cards { flex-direction: column; }
  .panel { width: min(360px, 92vw); }
}
