:root {
  --line: #1c1530;          /* thick comic outline */
  --card: #ffffff;
  --ink: #241a3a;
  --muted: #7b6f93;
  --primary: #7c3aed;
  --primary-d: #6d28d9;
  --accent: #ec4899;
  --yellow: #fbbf24;
  --green: #22c55e;
  --blue: #3b82f6;
  --ok: #22c55e;
  --warn: #ef4444;
  --radius: 26px;
  --display: "Comfortaa", ui-rounded, system-ui, sans-serif;
  --hard: 6px 6px 0 var(--line);
  --hard-sm: 4px 4px 0 var(--line);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(150deg, #a855f7 0%, #ec4899 48%, #fb923c 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 14px;
  overflow-x: hidden; overflow-y: auto;
}
/* Flexible spacers: grow to center the content when it fits, shrink to a fixed
   minimum when it's tall — and because they're real boxes (not padding) the
   top/bottom gaps are always preserved, even while scrolling. */
body::before, body::after { content: ""; display: block; flex: 1 1 auto; width: 1px; }
body::before { min-height: calc(env(safe-area-inset-top) + 34px); }
body::after { min-height: calc(env(safe-area-inset-bottom) + 52px); }

/* polka-dot overlay */
#bg-dots {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.22) 2.5px, transparent 2.6px);
  background-size: 28px 28px;
  mask-image: radial-gradient(120% 100% at 50% 40%, #000 60%, transparent 100%);
}

/* floating doodle stickers */
#doodles { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.dd { position: absolute; font-size: 30px; opacity: .55; filter: drop-shadow(0 3px 0 rgba(0,0,0,.15)); animation: wobble 7s ease-in-out infinite; }
.d1 { top: 8%; left: 7%; --rot: -12deg; }
.d2 { top: 16%; right: 9%; --rot: 14deg; animation-delay: -1.5s; font-size: 34px; }
.d3 { top: 44%; left: 4%; --rot: 8deg; animation-delay: -3s; }
.d4 { bottom: 12%; left: 10%; --rot: -8deg; animation-delay: -2s; font-size: 36px; }
.d5 { bottom: 18%; right: 7%; --rot: 10deg; animation-delay: -4s; }
.d6 { top: 60%; right: 5%; --rot: -14deg; animation-delay: -2.5s; font-size: 34px; }
.d7 { top: 30%; right: 16%; --rot: 18deg; animation-delay: -5s; }
.d8 { bottom: 34%; left: 6%; --rot: -10deg; animation-delay: -1s; }
@keyframes wobble {
  0%,100% { transform: rotate(var(--rot)) translateY(0); }
  50% { transform: rotate(calc(var(--rot) * -1)) translateY(-12px); }
}

#app { position: relative; z-index: 1; width: 100%; max-width: 540px; display: flex; flex-direction: column; flex: 0 0 auto; }

/* ---- card ---- */
.card {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--hard);
  padding: 22px;
  display: flex; flex-direction: column; gap: 13px;
  animation: pop .32s cubic-bezier(.2,.9,.3,1.5);
}
@keyframes pop { from { transform: scale(.93) translateY(10px) rotate(-1deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.logo-img { display: block; width: auto; }
.logo-img.big { width: min(82%, 340px); animation: logoIn .55s cubic-bezier(.2,.9,.3,1.6); }
.logo-img.small { width: 150px; }

/* Home: logo poses like a sticker at the top of the white box — half of it
   sits outside the card, with breathing room above and below. */
.card.home { overflow: visible; margin-top: 104px; }
.home .brand { margin-bottom: 8px; }
.home .logo-img.big {
  width: min(86%, 330px);
  margin: -116px auto 20px;   /* pull up so ~half is outside + gap below */
}
@keyframes logoIn { from { transform: scale(.5) rotate(-8deg); opacity: 0; } 70% { transform: scale(1.06) rotate(3deg); } to { transform: scale(1) rotate(0); opacity: 1; } }
.tagline { color: var(--ink); font-weight: 700; font-size: 15px; margin: 2px 0 4px; font-family: var(--display); }

.screen-title { margin: 4px 0; font-size: 22px; text-align: center; font-family: var(--display); font-weight: 700; }
.section { margin: 6px 0 0; font-size: 15px; color: var(--muted); font-family: var(--display); font-weight: 700; }
.muted { color: var(--muted); }
.center { text-align: center; }
.tiny { font-size: 12px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 2px; font-family: var(--display); }
.lobby-head { display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* ---- inputs ---- */
.input {
  width: 100%; padding: 14px 15px; font-size: 16px; font-weight: 600;
  border: 3px solid var(--line); border-radius: 16px; outline: none;
  background: #fff; color: var(--ink); transition: box-shadow .12s, transform .12s;
  box-shadow: var(--hard-sm);
}
.input:focus { box-shadow: 6px 6px 0 var(--primary); }
.input.small { padding: 8px 10px; font-size: 14px; box-shadow: 2px 2px 0 var(--line); }
.textarea { min-height: 120px; resize: vertical; font-family: inherit; }

/* ---- buttons (sticker) ---- */
.btn {
  appearance: none; cursor: pointer;
  padding: 13px 16px; font-size: 16px; font-weight: 700; border-radius: 16px;
  font-family: var(--display);
  background: #fff; color: var(--ink);
  border: 3px solid var(--line); box-shadow: var(--hard-sm);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:active { transform: translate(4px,4px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:disabled { background: #b9b2cc; color: #fff; }
.btn.big { padding: 16px; font-size: 18px; border-radius: 18px; box-shadow: var(--hard); }
.btn.big:active { box-shadow: 0 0 0 var(--line); }
.btn.small { padding: 8px 12px; font-size: 13px; box-shadow: 3px 3px 0 var(--line); }
.btn.ghost { background: transparent; color: var(--ink); border-style: dashed; box-shadow: none; }
.btn.ghost:active { transform: scale(.96); }
.btn:disabled { opacity: .75; cursor: not-allowed; }

.row { display: flex; gap: 8px; }
.row .input { flex: 1; }
.divider { height: 3px; background: repeating-linear-gradient(90deg, var(--line) 0 10px, transparent 10px 18px); opacity: .25; margin: 6px 0; border-radius: 2px; }
.or { text-align: center; color: #fff; font-size: 13px; font-weight: 700; font-family: var(--display); }

/* ---- swatches ---- */
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 3px solid var(--line); cursor: pointer; transition: transform .1s; box-shadow: 2px 2px 0 var(--line); }
.swatch.sel { transform: scale(1.18) rotate(-6deg); }

/* ---- avatars / players ---- */
.avatar { border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; border: 3px solid var(--line); box-shadow: 2px 2px 0 var(--line); font-family: var(--display); }
.player-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.player-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #fdf7ff; border: 3px solid var(--line); border-radius: 16px; position: relative; box-shadow: 3px 3px 0 var(--line); animation: pop .25s ease; }
.player-chip:nth-child(even) { transform: rotate(.6deg); }
.player-chip:nth-child(odd) { transform: rotate(-.6deg); }
.player-chip.offline { opacity: .5; }
.p-meta { display: flex; flex-direction: column; min-width: 0; }
.p-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--display); }
.p-tags { display: flex; gap: 4px; }
.tag { font-size: 9px; font-weight: 800; padding: 1px 6px; border-radius: 7px; border: 2px solid var(--line); font-family: var(--display); }
.tag.host { background: var(--yellow); color: var(--line); }
.tag.off { background: #e5e1ee; color: var(--muted); }
.kick { position: absolute; top: 3px; right: 4px; border: none; background: transparent; color: #c0392b; cursor: pointer; font-size: 13px; font-weight: 800; }

/* ---- code box ---- */
.code-box { text-align: center; background: var(--yellow); border: 3px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: var(--hard-sm); transform: rotate(-1deg); }
.code { font-size: 42px; font-weight: 700; letter-spacing: 8px; color: var(--line); font-family: var(--display); }

/* ---- settings ---- */
.settings { background: #fdf7ff; border: 3px solid var(--line); border-radius: 16px; padding: 8px 12px; box-shadow: 3px 3px 0 var(--line); }
.settings summary { cursor: pointer; font-weight: 700; font-size: 14px; font-family: var(--display); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.setting { display: flex; flex-direction: column; gap: 3px; }

/* ---- round ---- */
.round-badge { align-self: center; background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; padding: 8px 18px; border-radius: 999px; border: 3px solid var(--line); box-shadow: var(--hard-sm); transform: rotate(-2deg); font-family: var(--display); }
.prompt-instr { text-align: center; font-weight: 700; font-size: 17px; margin: 2px; font-family: var(--display); }
.prompt-chip { background: #fff3d6; border: 3px solid var(--line); border-radius: 16px; padding: 11px 14px; text-align: center; box-shadow: var(--hard-sm); }
.prompt-text { display: block; font-size: 21px; font-weight: 700; color: #9a3412; font-family: var(--display); }

.timer { position: relative; height: 26px; background: #efe9f7; border: 3px solid var(--line); border-radius: 999px; overflow: hidden; box-shadow: 2px 2px 0 var(--line); }
.timer-fill { position: absolute; inset: 0; right: auto; background: var(--green); transition: width .25s linear, background .3s; }
.timer.low .timer-fill { background: var(--warn); }
.timer-text { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 800; line-height: 20px; color: var(--line); font-family: var(--display); }

.drawing-view { width: 100%; border-radius: 16px; border: 3px solid var(--line); background: #fff; box-shadow: var(--hard-sm); }

/* ---- canvas + toolbar ---- */
.draw-canvas { width: 100%; background: #fff; border: 3px solid var(--line); border-radius: 16px; touch-action: none; cursor: crosshair; display: block; box-shadow: var(--hard-sm); }
.toolbar { display: flex; flex-direction: column; gap: 8px; }
.tool-colors { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.tool-color { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); cursor: pointer; transition: transform .1s; box-shadow: 2px 2px 0 var(--line); }
.tool-color.sel { transform: scale(1.2) rotate(-6deg); }
.tool-row { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }
.tool-btn { min-width: 44px; height: 42px; border-radius: 13px; border: 3px solid var(--line); background: #fff; font-size: 18px; cursor: pointer; box-shadow: 2px 2px 0 var(--line); transition: transform .08s, box-shadow .08s; }
.tool-btn:active { transform: translate(2px,2px); box-shadow: 0 0 0 var(--line); }
.tool-btn.sel { background: var(--primary); color: #fff; }
.size-slider { flex: 1; min-width: 90px; max-width: 160px; accent-color: var(--primary); }

/* ---- waiting ---- */
.waiting { text-align: center; align-items: center; }
.spinner { width: 52px; height: 52px; border-radius: 50%; border: 6px solid #efe9f7; border-top-color: var(--primary); border-right-color: var(--accent); animation: spin 1s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 100%; height: 18px; background: #efe9f7; border: 3px solid var(--line); border-radius: 999px; overflow: hidden; box-shadow: 2px 2px 0 var(--line); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .35s; }
.big-count { font-size: 23px; font-weight: 700; font-family: var(--display); }

/* =====================  REVEAL — cinematic show  ===================== */
.reveal.show { min-height: 72dvh; justify-content: space-between; }
.show-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 10px 0 4px; text-align: center; }

.chain-num { font-size: 32px; font-weight: 700; color: var(--primary); font-family: var(--display); text-shadow: 3px 3px 0 rgba(28,21,48,.12); }
.title-author { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.title-author .avatar { box-shadow: 4px 4px 0 var(--line); }
.author-name { margin: 0; font-size: 26px; font-family: var(--display); font-weight: 700; }

.show-lead { font-weight: 700; color: var(--muted); margin: 0; font-family: var(--display); }
.show-author { display: flex; align-items: center; gap: 8px; }
.show-name { font-weight: 700; font-size: 18px; font-family: var(--display); }
.verb-chip { background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; padding: 4px 11px; border-radius: 999px; border: 2px solid var(--line); font-family: var(--display); }

.show-bubble {
  position: relative; max-width: 100%; background: #fff3d6; border: 3px solid var(--line);
  border-radius: 20px; padding: 18px 22px; font-size: 23px; font-weight: 700; color: #9a3412;
  box-shadow: var(--hard); font-family: var(--display);
}
.show-bubble::after { content: ""; position: absolute; left: 28px; bottom: -14px; width: 18px; height: 18px; background: #fff3d6; border-right: 3px solid var(--line); border-bottom: 3px solid var(--line); transform: rotate(45deg); }
.show-drawing-frame { background: #fff; border: 3px solid var(--line); border-radius: 18px; padding: 7px; box-shadow: var(--hard); max-width: 100%; transform: rotate(-1deg); }
.show-drawing { display: block; width: 100%; max-height: 46dvh; object-fit: contain; border-radius: 12px; }

.show-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; padding-top: 12px; margin-top: 4px; border-top: 3px dashed rgba(28,21,48,.18); }
.ctrl { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--line); background: #fff; font-size: 18px; cursor: pointer; box-shadow: 3px 3px 0 var(--line); transition: transform .08s, box-shadow .08s; flex: none; }
.ctrl:active { transform: translate(3px,3px); box-shadow: 0 0 0 var(--line); }
.big-ctrl { width: 56px; height: 56px; font-size: 22px; background: var(--primary); color: #fff; }
.show-transport { display: flex; align-items: center; gap: 10px; }
.host-drives { font-size: 13px; font-weight: 700; color: var(--muted); font-family: var(--display); background: #fdf7ff; border: 2px dashed var(--line); padding: 6px 12px; border-radius: 999px; }
.show-count { flex-basis: 100%; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); font-family: var(--display); order: 3; }
.gallery-btn { order: 4; }

/* connection status pill — top-right corner so it never covers the logo */
.status-pill {
  position: fixed; top: calc(env(safe-area-inset-top) + 6px); right: 8px; left: auto;
  z-index: 90; font-size: 11px; font-weight: 700; font-family: var(--display);
  background: #fff; color: var(--ink); border: 2px solid var(--line); border-radius: 999px;
  padding: 4px 10px; box-shadow: 2px 2px 0 var(--line); white-space: nowrap;
}
.status-pill.warn { background: #fff7d6; }
.status-pill.bad { background: #ffe1e1; animation: nudge .6s ease infinite; }
@keyframes nudge { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }

/* end card */
.end-card { text-align: center; align-items: center; }
.end-emoji { font-size: 66px; }
.bounce { animation: bounce 1s ease infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-16px) rotate(4deg); } }

/* entrance animations */
.pop-in { animation: popIn .45s cubic-bezier(.2,.9,.3,1.6) both; }
.fade-in { animation: fadeIn .5s ease both; }
.slide-in { animation: slideIn .45s cubic-bezier(.2,.9,.3,1.4) both; }
.delay1 { animation-delay: .35s; }
@keyframes popIn { from { transform: scale(.6) rotate(-3deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- gallery (browse) ---- */
.reveal-nav { display: flex; justify-content: space-between; align-items: center; }
.reveal-entries { display: flex; flex-direction: column; gap: 14px; max-height: 58dvh; overflow-y: auto; padding: 4px; }
.reveal-entry { background: #fdf7ff; border: 3px solid var(--line); border-radius: 18px; padding: 12px; box-shadow: var(--hard-sm); animation: pop .3s ease; }
.reveal-entry:nth-child(even) { transform: rotate(.5deg); }
.reveal-entry:nth-child(odd) { transform: rotate(-.5deg); }
.reveal-who { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); }
.reveal-img { width: 100%; border-radius: 12px; border: 3px solid var(--line); background: #fff; }
.reveal-text { font-size: 19px; font-weight: 700; padding: 8px 4px; font-family: var(--display); }
.react-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.react-btn { background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 5px 10px; font-size: 16px; cursor: pointer; transition: transform .1s; box-shadow: 2px 2px 0 var(--line); }
.react-btn:active { transform: translate(2px,2px); box-shadow: 0 0 0 var(--line); }
.react-count { font-size: 12px; font-weight: 800; margin-left: 3px; color: var(--primary); }
.reveal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.reveal-actions .btn { flex: 1 1 calc(50% - 8px); min-width: 0; }

/* ---- misc ---- */
.error-banner { background: #fff0f0; color: #b91c1c; border: 3px solid var(--line); border-radius: 14px; padding: 10px; font-size: 14px; text-align: center; font-weight: 700; box-shadow: var(--hard-sm); }
.toast { position: fixed; bottom: 30px; left: 50%; transform: translate(-50%, 20px); background: var(--line); color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 700; z-index: 100; opacity: 0; transition: all .3s; pointer-events: none; border: 3px solid #fff; font-family: var(--display); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti-canvas { position: fixed; inset: 0; width: 100vw; height: 100dvh; z-index: 200; pointer-events: none; }

@media (min-width: 600px) {
  .player-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .dd, .bounce, #bg-dots { animation: none !important; }
}
