:root {
  --gold: #f6c544;
  --gold-deep: #e0a92e;
  --sand: #fdf4dd;
  --ink: #2b2440;
  --grape: #6c4ad6;
  --grape-deep: #5739bd;
  --sky: #56c3e8;
  --rose: #ff6f91;
  --green: #3fc785;
  --green-deep: #2fa86c;
  --card: #ffffff;
  --muted-ink: #6b6385; /* 4.8:1 on white (WCAG AA) */
  --shadow: 0 8px 24px rgba(43, 36, 64, 0.15);
  --radius-s: 12px;
  --radius-m: 18px;
  --radius-l: 24px;
  --t-fast: 150ms;
  --t-med: 250ms;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Comic Neue", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: linear-gradient(160deg, #fff7e6 0%, #ffe9c7 40%, #ffd9e6 100%);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3, .brand, .btn, .navbtn, .buybtn, .title-big, .item-name, .pill, .ghost, .preset, .coins {
  font-family: "Baloo 2", "Comic Neue", "Trebuchet MS", system-ui, sans-serif;
}
.hidden { display: none !important; }

/* Keyboard accessibility: a clear, consistent focus ring everywhere */
:focus-visible {
  outline: 3px solid var(--grape);
  outline-offset: 2px;
  border-radius: 6px;
}
button { touch-action: manipulation; }

/* ---------- Top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--grape); color: #fff;
  box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-size: 1.25rem; font-weight: 800; line-height: 1.2; }
#topbar nav {
  display: flex; gap: 8px; margin-left: 4px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  max-width: 100%; padding: 2px;
}
#topbar nav::-webkit-scrollbar { display: none; }
.navbtn {
  background: rgba(255,255,255,0.16); color: #fff; border: none;
  min-height: 44px; padding: 10px 16px; border-radius: 999px; font-size: 1rem; cursor: pointer;
  font-weight: 700; transition: transform var(--t-fast), background var(--t-med);
  white-space: nowrap; flex: none;
}
.navbtn:hover { background: rgba(255,255,255,0.3); transform: translateY(-1px); }
.navbtn:active { transform: scale(0.96); }
.navbtn.active { background: var(--gold); color: var(--ink); }
.coins {
  margin-left: auto; background: var(--gold); color: var(--ink);
  min-height: 44px; display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 1.1rem;
}
.ghost {
  background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.45);
  min-height: 44px; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 700;
  transition: background var(--t-med), transform var(--t-fast); font-size: 1rem;
}
.ghost:hover { background: rgba(255,255,255,.15); }
.ghost:active { transform: scale(0.96); }

/* ---------- Layout ---------- */
main { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }
h1 { font-size: 2rem; margin-bottom: 4px; line-height: 1.25; }
h2 { font-size: 1.4rem; margin: 18px 0 12px; line-height: 1.3; }
.muted { color: var(--muted-ink); }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 420px; margin: 6vh auto; padding: 0 4px; }
.auth-card {
  background: var(--card); border-radius: var(--radius-l); padding: 28px; box-shadow: var(--shadow);
}
.logo-big { font-size: 3rem; text-align: center; }
.title-big { text-align: center; font-size: 1.8rem; font-weight: 800; margin-bottom: 2px; }
.sub { text-align: center; color: var(--muted-ink); margin-bottom: 20px; }
label { display: block; font-weight: 700; margin: 12px 0 4px; font-size: .95rem; }
input, select {
  width: 100%; min-height: 48px; padding: 12px 14px; border: 2px solid #ece6f7; border-radius: var(--radius-s);
  font-size: 1rem; font-family: inherit; background: #faf8ff;
  transition: border-color var(--t-med), box-shadow var(--t-med);
}
input:focus, select:focus {
  outline: none; border-color: var(--grape);
  box-shadow: 0 0 0 3px rgba(108, 74, 214, 0.18);
}
.btn {
  width: 100%; margin-top: 18px; min-height: 48px; padding: 13px; border: none; border-radius: 14px;
  background: var(--grape); color: #fff; font-size: 1.1rem; font-weight: 800;
  cursor: pointer; transition: transform var(--t-fast), background var(--t-med), box-shadow var(--t-med);
  box-shadow: var(--shadow);
}
.btn:hover { background: var(--grape-deep); transform: translateY(-2px); }
.btn:active { transform: scale(0.97); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: var(--gold-deep); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.switch { text-align: center; margin-top: 16px; }
.switch a {
  color: var(--grape); font-weight: 800; cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px; padding: 6px; display: inline-block;
}

/* ---------- Cards / grids ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border-radius: var(--radius-m); padding: 16px; box-shadow: var(--shadow);
  transition: transform var(--t-fast), box-shadow var(--t-med);
}
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(43, 36, 64, 0.2); }
.world-card:active { transform: scale(0.98); }
.tile-emoji { font-size: 2.4rem; line-height: 1.2; }
.item-name { font-weight: 800; margin: 6px 0 2px; }
.item-cat { font-size: .8rem; color: var(--muted-ink); text-transform: capitalize; }
.price-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 8px; }
.price { font-weight: 800; color: var(--gold-deep); font-variant-numeric: tabular-nums; }
.buybtn {
  background: var(--green); color: #fff; border: none; min-height: 40px; padding: 8px 16px;
  border-radius: 999px; font-weight: 800; cursor: pointer; font-size: .95rem;
  transition: filter var(--t-med), transform var(--t-fast);
}
.buybtn:hover { filter: brightness(1.07); }
.buybtn:active { transform: scale(0.95); }
.buybtn:disabled { opacity: .55; cursor: wait; transform: none; }
.buybtn.owned { background: #cfc8e0; color: #564f6e; cursor: default; }

/* ---------- Home ---------- */
.hero {
  display: flex; gap: 20px; align-items: center; background: var(--card);
  border-radius: 22px; padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px;
  flex-wrap: wrap;
}
.avatar-bubble {
  width: 92px; height: 92px; border-radius: 50%; background: linear-gradient(150deg,var(--sky),var(--grape));
  display: grid; place-items: center; font-size: 3rem; flex: none; box-shadow: var(--shadow);
  overflow: hidden;
}
.daily { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pill { background: var(--sand); border-radius: 999px; padding: 8px 14px; font-weight: 700; }

.world-card { cursor: pointer; }
.world-banner { height: 90px; border-radius: 14px; display: grid; place-items: center; font-size: 2.6rem; margin-bottom: 10px; }
.b1 { background: linear-gradient(135deg,#ffd86b,#ff9f43); }
.b2 { background: linear-gradient(135deg,#56c3e8,#3fc785); }
.b3 { background: linear-gradient(135deg,#ff6f91,#6c4ad6); }
.b4 { background: linear-gradient(135deg,#a8e063,#56ab2f); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow); z-index: 1000; animation: pop .2s ease;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.good { background: var(--green-deep); }
.toast.bad { background: #e0476e; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

/* in-world chat */
.preset {
  background: var(--sand); border: none; border-radius: 999px; min-height: 40px; padding: 8px 14px;
  font-weight: 700; cursor: pointer; font-family: inherit; font-size: .95rem;
  transition: background var(--t-med), transform var(--t-fast);
}
.preset:hover { background: var(--gold); }
.preset:active { transform: scale(0.95); }
#chatInput:focus { outline: none; border-color: var(--grape); }

.center { text-align: center; padding: 40px; }
.spinner { width: 38px; height: 38px; border: 5px solid #eadcff; border-top-color: var(--grape);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile (375px+) ---------- */
@media (max-width: 600px) {
  main { padding: 16px 12px 48px; }
  h1 { font-size: 1.65rem; }
  .hero { padding: 16px; gap: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  #topbar { gap: 8px; padding: 8px 10px; }
  .brand { font-size: 1.05rem; }
  .coins { font-size: 1rem; padding: 6px 12px; }
}

/* ---------- Accessibility: respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
