: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); } }

#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; }

@media (max-width: 720px) {
  #hud { flex-direction: column; }
  .right { justify-content: flex-start; }
  .stats { gap: 10px; }
  .search input { width: 140px; }
  #minimap { width: 130px; height: 91px; }
  #help .desk { display: none; }
  #toasts { max-width: calc(100vw - 170px); }
}
