:root {
  --ink: #2b2140;
  --paper: rgba(255, 252, 245, 0.92);
  --accent: #ff4f7b;
  --accent2: #7b5cff;
  --muted: #6f6585;
  --shadow: 0 6px 18px rgba(30, 20, 50, 0.18);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3d6f35; font-family: 'Fredoka', system-ui, sans-serif; color: var(--ink); }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: grab; }
canvas#game.dragging { cursor: grabbing; }
.hidden { display: none !important; }

.panel { background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(6px); }
.btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer; background: #fff; color: var(--ink); box-shadow: var(--shadow); text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: linear-gradient(135deg, #feda75, #fa7e1e 30%, #d62976 60%, #962fbf 85%, #4f5bd5); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; box-shadow: none; background: #efe9ff; }

#hud { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; }
#hud > * { pointer-events: auto; }
.brand { padding: 12px 16px; }
.brand .title { font-size: 26px; font-weight: 700; line-height: 1; }
.brand .title span { color: var(--accent); }
.brand .page { color: var(--accent2); font-weight: 600; text-decoration: none; font-size: 14px; }
.stats { display: flex; gap: 14px; margin-top: 8px; }
.stats div { display: flex; flex-direction: column; align-items: flex-start; }
.stats b { font-size: 18px; }
.stats small { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.search { padding: 4px; }
.search input { font: inherit; border: 0; outline: 0; background: transparent; padding: 6px 10px; width: 190px; color: var(--ink); }
.me { padding: 8px 10px 8px 14px; display: flex; gap: 10px; align-items: center; font-size: 14px; }

#banner { position: fixed; top: 110px; left: 50%; transform: translateX(-50%); background: #2b2140; color: #fff; padding: 10px 18px; border-radius: 14px; box-shadow: var(--shadow); font-size: 14px; text-align: center; max-width: calc(100vw - 32px); }
#help { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); padding: 8px 14px; font-size: 13px; color: var(--muted); white-space: nowrap; }
kbd { background: #efe9ff; border-radius: 5px; padding: 1px 5px; font-family: inherit; font-size: 12px; color: var(--ink); }
#emoteBar { position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%); padding: 6px; display: flex; gap: 4px; }
#emoteBar button { font-size: 20px; background: transparent; border: 0; border-radius: 10px; padding: 4px 8px; cursor: pointer; }
#emoteBar button:hover { background: #efe9ff; }

#minimap { position: fixed; right: 12px; bottom: 12px; width: 200px; height: 140px; border-radius: 14px; box-shadow: var(--shadow); background: #2e5228; cursor: pointer; border: 3px solid var(--paper); }

#toasts { position: fixed; left: 12px; bottom: 12px; display: flex; flex-direction: column-reverse; gap: 8px; max-width: min(360px, calc(100vw - 240px)); }
.toast { background: var(--paper); border-radius: 12px; padding: 9px 14px; box-shadow: var(--shadow); font-size: 14px; cursor: pointer; animation: tin .35s ease-out; }
.toast.out { animation: tout .4s ease-in forwards; }
.toast.leave { border-left: 4px solid #6f6585; }
.toast.join { border-left: 4px solid #2ec27e; }
@keyframes tin { from { transform: translateX(-30px); opacity: 0; } }
@keyframes tout { to { transform: translateX(-30px); opacity: 0; } }

#card { position: fixed; padding: 14px 16px; min-width: 210px; transform: translate(-50%, calc(-100% - 20px)); }
.cardName { font-weight: 700; font-size: 18px; }
.cardSub { color: var(--muted); font-size: 13px; margin: 2px 0 10px; line-height: 1.4; }
.x { position: absolute; top: 6px; right: 8px; border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }

#modal { position: fixed; inset: 0; background: rgba(30, 20, 50, .45); display: grid; place-items: center; padding: 16px; }
.dialog { position: relative; padding: 24px; width: min(420px, 100%); text-align: center; }
.dialog h2 { margin: 0 0 12px; }
.dialog p { color: var(--muted); line-height: 1.45; margin: 8px 0; }
.code { font-size: 30px; font-weight: 700; letter-spacing: .08em; background: #efe9ff; border-radius: 12px; padding: 12px; margin: 12px 0; user-select: all; cursor: copy; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #c9bff0; border-top-color: var(--accent2); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

#welcome { position: fixed; inset: 0; background: rgba(30, 20, 50, .45); display: grid; place-items: center; padding: 16px; z-index: 5; overflow-y: auto; }
.dialog.welcome { width: min(480px, 100%); text-align: left; }
.welcome h2 { text-align: center; }
.welcome .lead { color: var(--ink); text-align: center; }
.welcome a.pg, .welcome .pg { color: var(--accent2); text-decoration: none; }
.steps { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; background: #f6f2ff; border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.4; color: var(--muted); }
.steps li b { color: var(--ink); }
.steps .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent2); color: #fff; display: grid; place-items: center; font-weight: 700; }
.welcome .note { font-size: 13.5px; line-height: 1.45; color: var(--muted); background: #f3f0f7; border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.welcome .note.idea { background: #fff6e0; }
.welcome .row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.welcome .legal { text-align: center; font-size: 12px; margin: 14px 0 0; color: var(--muted); }
.welcome .legal a { color: var(--muted); }

#loading { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: #3d6f35; color: #fff; transition: opacity .5s; z-index: 10; }
#loading .logo { font-size: 48px; font-weight: 700; }
#loading .sub { opacity: .8; }

#searchBtn, #helpBtn .ico { display: none; }
.iconBtn { width: 36px; height: 36px; padding: 0; border-radius: 50%; display: grid; place-items: center; }

/* ---------- phones: one compact row on top, one row at the bottom ---------- */
@media (max-width: 720px) {
  #hud { top: 8px; left: 8px; right: 8px; flex-direction: row; align-items: center; gap: 6px; }
  .brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 14px; }
  .brand .title { font-size: 16px; flex: none; }
  .brand .page { display: none; }
  .stats { margin: 0; gap: 8px; flex: 1; justify-content: space-around; }
  .stats div { align-items: center; }
  .stats b { font-size: 14px; line-height: 1.1; }
  .stats small { font-size: 9.5px; letter-spacing: 0; text-transform: none; }
  .right { flex-wrap: nowrap; gap: 6px; }

  /* search: magnifier icon that opens a field under the top bar */
  #searchBtn { display: grid; }
  #searchBox { display: none; position: fixed; top: 58px; left: 8px; right: 8px; padding: 2px; }
  #searchBox.open { display: block; }
  #searchBox input { width: 100%; font-size: 16px; }

  /* "How it works" becomes a round "!" button */
  #helpBtn { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 19px; font-weight: 700; display: grid; place-items: center; }
  #helpBtn .lbl { display: none; }
  #helpBtn .ico { display: inline; }

  /* bottom row: emotes on the left, me/login on the right */
  #minimap, #help { display: none; }
  #loginBtn { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); padding: 10px 22px; white-space: nowrap; }
  #emoteBar { left: 8px; bottom: 8px; transform: none; padding: 3px; gap: 0; }
  #emoteBar button { font-size: 18px; padding: 4px 5px; }
  #meBox { position: fixed; right: 8px; bottom: 8px; padding: 4px 4px 4px 10px; gap: 6px; font-size: 12px; max-width: calc(100vw - 236px); }
  .meLbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .meLbl b { font-weight: 600; }
  .meLbl .pa { display: none; }
  #logoutBtn { padding: 5px 8px; font-size: 12px; flex: none; }

  #banner { top: 60px; font-size: 13px; padding: 8px 14px; }
  #toasts { left: 8px; bottom: 58px; max-width: calc(100vw - 16px); }
  .toast { font-size: 12.5px; padding: 7px 11px; }
}
@media (max-width: 380px) {
  .brand { gap: 6px; padding: 6px 8px; }
  .brand .title { font-size: 14px; }
  .stats { gap: 5px; }
  .stats small { font-size: 9px; }
  #meBox .meLbl { display: none; }
  #meBox { max-width: none; padding: 4px; }
}
