:root {
  --paper: #fff7ec;
  --card: #ffffff;
  --ink: #2b2622;
  --muted: #7a6f66;
  --line: #eadfce;
  --accent: #ff5d8f;
  --accent2: #3a86ff;
  --sun: #ffbe0b;
  --ok: #06d6a0;
  --shadow: 0 6px 20px rgba(80, 50, 20, 0.12);
  --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h2, h3, .logo { font-family: 'Fredoka', 'Nunito', sans-serif; }

/* ---------- buttons ---------- */
.btn {
  background: var(--accent); color: #fff; font-weight: 800;
  padding: 14px 20px; border-radius: 999px; box-shadow: 0 4px 0 #d63f6f;
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d63f6f; }
.btn.alt { background: var(--accent2); box-shadow: 0 4px 0 #2563c9; }
.btn.alt:active { box-shadow: 0 1px 0 #2563c9; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; border: 2px solid var(--line); }
.btn.small { padding: 9px 14px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 10px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--card);
  box-shadow: var(--shadow); font-size: 20px; display: grid; place-items: center; flex: none;
}
.icon-btn.small { width: 38px; height: 38px; font-size: 17px; }

/* ---------- home ---------- */
#home { max-width: 980px; margin: 0 auto; padding: 18px 16px 60px; }
.hero { text-align: center; padding: 14px 0 6px; }
.logo { font-size: clamp(34px, 9vw, 54px); font-weight: 700; letter-spacing: -0.5px; }
.logo .c1 { color: var(--accent); }
.logo .c2 {
  background: linear-gradient(90deg, #3a86ff, #06d6a0, #ffbe0b, #fb5607);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag { color: var(--muted); margin: 6px 0 0; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
@media (max-width: 560px) { .card-row { grid-template-columns: 1fr; } }
.field {
  display: flex; flex-direction: column; gap: 6px; background: var(--card);
  border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow);
}
.field > span { font-size: 13px; color: var(--muted); font-weight: 700; }
.field input {
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; background: #fffdf9;
  min-width: 0;
}
.field input:focus { border-color: var(--accent2); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 2px; font-weight: 800; }
h2 { font-size: 22px; margin: 22px 0 10px; }
.gallery-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 7px 12px; border-radius: 999px; background: var(--card); border: 2px solid var(--line); font-weight: 700; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tile {
  background: var(--card); border-radius: var(--r); padding: 8px; box-shadow: var(--shadow);
  text-align: left; transition: transform .12s; position: relative;
}
.tile:active { transform: scale(.97); }
.tile canvas { width: 100%; aspect-ratio: 1; border-radius: 12px; display: block; }
.tile .t-name { font-weight: 800; margin: 8px 4px 2px; }
.tile .t-meta { font-size: 12px; color: var(--muted); margin: 0 4px 4px; display: flex; gap: 6px; align-items: center; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.Easy { background: #06d6a0; }
.badge.Medium { background: #3a86ff; }
.badge.Hard { background: #fb5607; }
.badge.Expert { background: #8338ec; }
.recent-list { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.recent-item { flex: none; width: 120px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.recent-item img, .recent-item .ph {
  width: 120px; height: 120px; border-radius: 14px; box-shadow: var(--shadow); display: block; background: #fff; object-fit: cover;
}
.recent-item .done { color: var(--ok); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(43, 38, 34, 0.45); display: grid; place-items: end center;
  z-index: 50; animation: fade .15s;
}
.overlay.light { background: rgba(255, 247, 236, 0.85); place-items: center; align-content: center; text-align: center; }
@media (min-width: 640px) { .overlay { place-items: center; } }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative; background: var(--card); width: min(480px, 100%); border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow: auto;
  animation: up .22s ease-out;
}
@media (min-width: 640px) { .sheet { border-radius: 26px; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet h3 { margin: 4px 0 4px; font-size: 24px; }
.close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; background: var(--paper); z-index: 2; }
.sheet-preview canvas { width: 100%; aspect-ratio: 1; border-radius: 16px; display: block; }
.sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
.muted { color: var(--muted); margin: 4px 0; }
.tiny { font-size: 12px; }
.code-big {
  font-family: 'Fredoka', sans-serif; font-size: 40px; letter-spacing: 8px; text-align: center; font-weight: 700;
  margin: 10px 0; color: var(--accent2);
}
.qr { display: grid; place-items: center; margin: 6px 0 12px; }
.qr img, .qr canvas { width: 170px; height: 170px; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 12px; padding: 9px 10px; font-size: 13px; }
.finish-img { width: 100%; border-radius: 16px; box-shadow: var(--shadow); display: block; margin-top: 8px; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-weight: 700; z-index: 80; max-width: calc(100% - 32px); text-align: center;
  font-size: 14px;
}
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: inherit; }
.confetti i {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall 1.6s ease-in forwards;
}
@keyframes fall { to { transform: translateY(560px) rotate(540deg); opacity: 0; } }

/* ---------- game ---------- */
#game { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}
.title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.title b { font-family: 'Fredoka', sans-serif; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title small { color: var(--muted); font-size: 12px; font-weight: 700; }
.members { display: flex; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 800; font-size: 13px; border: 3px solid var(--paper); margin-left: -8px; position: relative;
}
.avatar.off { opacity: .35; }
.avatar.me::after {
  content: ''; position: absolute; bottom: -2px; right: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--paper);
}
.progress { height: 5px; background: var(--line); margin: 0 12px; border-radius: 9px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: linear-gradient(90deg, #ff5d8f, #ffbe0b, #06d6a0); transition: width .5s; }
.viewport { flex: 1; position: relative; overflow: hidden; touch-action: none; min-height: 0; }
.stage {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff;
  box-shadow: 0 10px 30px rgba(80, 50, 20, .18); border-radius: 6px; overflow: hidden;
}
.stage canvas, .outline-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.outline-host { position: absolute; inset: 0; pointer-events: none; }
#cursors { position: absolute; inset: 0; pointer-events: none; }
.rcursor {
  position: absolute; left: 0; top: 0; transition: transform .09s linear, opacity .4s; will-change: transform;
}
.rcursor .dot { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); margin: -9px 0 0 -9px; }
.rcursor .nm {
  position: absolute; left: 10px; top: 6px; white-space: nowrap; color: #fff; font-size: 12px; font-weight: 800;
  padding: 2px 7px; border-radius: 999px;
}
.hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 9px 14px; border-radius: 999px; font-weight: 700; font-size: 14px; pointer-events: none; white-space: nowrap;
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translate(-50%, -5px); } }
.net {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #fff3cd; color: #7a5d00;
  padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 13px; box-shadow: var(--shadow);
}
.view-tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 8px; }
/* cheers: fixed reactions instead of chat (list in app.js CHEERS) */
.cheer-bar {
  position: absolute; right: 58px; top: 10px; max-width: calc(100% - 78px); display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px; border-radius: 20px; background: var(--card); box-shadow: var(--shadow); z-index: 6;
}
.cheer-bar button {
  display: inline-flex; align-items: center; gap: 4px; border: 0; cursor: pointer; padding: 6px 10px; border-radius: 999px;
  background: var(--paper); color: var(--ink); font: inherit; font-weight: 800; font-size: 14px;
}
.cheer-bar button:hover, .cheer-bar button:focus-visible { background: var(--line); }
.cheer-bar .e, .cheer-bubble .e { font-size: 20px; line-height: 1; }
#cheerBtn[aria-expanded="true"] { background: var(--accent); }
.cheer-stack {
  position: absolute; left: 0; right: 0; top: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 5;
}
.cheer-bubble {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; border: 2.5px solid var(--accent);
  background: var(--card); color: var(--ink); font-weight: 800; font-size: 14px; box-shadow: var(--shadow);
  animation: cheer-in .25s ease-out;
}
.cheer-bubble .who { font-size: 13px; }
@keyframes cheer-in { from { transform: translateY(-8px) scale(.9); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cheer-bubble { animation: none; } }
.dock {
  background: var(--card); border-radius: 22px 22px 0 0; box-shadow: 0 -6px 20px rgba(80, 50, 20, .08);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}
.tools { display: flex; gap: 4px; justify-content: space-between; }
.tool {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 14px;
  font-size: 11px; font-weight: 800; color: var(--muted); min-width: 0;
}
.tool i { font-style: normal; font-size: 22px; line-height: 1.1; }
.tool.on { background: #ffe4ee; color: var(--accent); }
.tool:disabled { opacity: .35; }
.sep { width: 2px; background: var(--line); margin: 6px 2px; border-radius: 2px; flex: none; }
.palette-row { margin-top: 6px; }
.palette { display: flex; gap: 7px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: none; }
.palette::-webkit-scrollbar { display: none; }
.sw {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line);
  position: relative; display: grid; place-items: center; font-size: 15px;
}
.sw.on { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.08); }
.sw.magic { background: conic-gradient(#ff5d8f, #ffbe0b, #06d6a0, #3a86ff, #8338ec, #ff5d8f); }
.sw.custom { background: #fff; color: var(--muted); font-weight: 800; overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.opts { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.size { display: flex; align-items: center; gap: 8px; flex: 1; font-size: 12px; font-weight: 800; color: var(--muted); min-width: 0; }
.size input { flex: 1; accent-color: var(--accent); min-width: 0; }
.toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.toggle input { accent-color: var(--accent2); width: 18px; height: 18px; }
.pct { font-weight: 800; font-size: 13px; color: var(--muted); min-width: 36px; text-align: right; }
@media (min-width: 900px) {
  #game { flex-direction: column; }
  .dock { max-width: 760px; margin: 0 auto; width: 100%; }
}

/* ---------- icons ---------- */
.ic {
  width: 22px; height: 22px; flex: none; display: block;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ic.sm { width: 18px; height: 18px; }
.ic .dot { fill: currentColor; stroke: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn .ic { width: 20px; height: 20px; }
.btn.small .ic { width: 17px; height: 17px; }
.icon-btn { color: var(--ink); }
.close { display: grid; place-items: center; color: var(--muted); }
.close .ic { width: 18px; height: 18px; }
.hint { display: flex; align-items: center; gap: 8px; }
.hint .ic { width: 18px; height: 18px; color: var(--sun); }
#inviteBtn { padding: 9px 13px; }
@media (max-width: 380px) { #inviteBtn .lbl { display: none; } }

/* tools: each tool has its own color; the active one becomes a filled tile */
.tool { --tc: var(--ink); }
.tool i {
  width: 44px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  color: var(--tc); transition: background .15s, color .15s, transform .1s;
}
.tool.plain i { color: var(--ink); }
.tool:active i { transform: scale(.92); }
.tool.on { background: none; color: var(--ink); }
.tool.on i { background: var(--tc); color: #fff; box-shadow: 0 4px 10px color-mix(in srgb, var(--tc) 40%, transparent); }
.tool span { margin-top: 2px; }

/* palette */
.sw.magic { color: #fff; }
.sw.magic .ic { width: 18px; height: 18px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.sw.custom { color: var(--muted); }
.sw.custom .ic { width: 18px; height: 18px; pointer-events: none; }
.size .ic { color: var(--muted); }
.net { display: flex; align-items: center; gap: 6px; }
.net .ic { width: 16px; height: 16px; }

/* ---------- Google account ---------- */
.account { display: flex; justify-content: center; margin-top: 12px; }
.gbtn { display: inline-flex; align-items: center; gap: 10px; padding: 10px 18px; border-radius: 999px; border: 1.5px solid #e2d8c8; background: #fff; color: #3c3a36; font: 600 15px/1 'Nunito', system-ui, sans-serif; cursor: pointer; box-shadow: 0 2px 6px rgba(80,60,30,.08); }
.gbtn:active { transform: translateY(1px); }
.guser { display: inline-flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; background: #fff; border: 1.5px solid #e2d8c8; font: 600 15px 'Nunito', system-ui, sans-serif; color: #3c3a36; }
.guser img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.linkbtn { background: none; border: 0; color: #b0563c; font: 700 13px 'Nunito', system-ui, sans-serif; cursor: pointer; padding: 4px; }

/* generated player name + shuffle */
.name-row { display: flex; align-items: center; gap: 10px; }
.name-show { flex: 1; min-width: 0; font-size: 18px; padding: 10px 14px; border-radius: 14px; background: #fffcf7; border: 1.5px solid var(--line, #eadfcd); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shuffle { flex: none; border: 0; border-radius: 14px; padding: 11px 14px; font: inherit; font-weight: 800; color: #fff; background: var(--accent2, #4a90e2); cursor: pointer; }
.shuffle:active { transform: scale(0.96); }
