:root {
  --ink: #34343a;
  --paper: #fffdf6;
  --paper-see: rgba(255, 253, 246, 0.88);
  --shadow: 2px 3px 0 rgba(40, 40, 50, 0.28);
  --hand: "Chalkboard SE", "Chalkboard", "Comic Sans MS", "Comic Neue", "Marker Felt", cursive;
  --p1: #5f9cff; --p2: #ff6fb5; --p3: #4fcf7d; --p4: #ff9f3d;
  --pink: #ff5fb0;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #cfe8ff; color: var(--ink);
  font-family: var(--hand);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ------------------------------------------------ pencil bubbles ------ */
.bubble {
  background: var(--paper-see);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  font-size: 20px; line-height: 1;
  padding: 8px 18px;
  touch-action: none;
  transition: transform 0.08s;
}
.bubble:active, .bubble.down { transform: scale(0.92) rotate(-2deg); }
.bubble.oval { border-radius: 50% / 50%; min-height: 52px; }
.bubble.circle { border-radius: 50%; width: 58px; height: 58px; padding: 0; display: grid; place-items: center; }
.bubble.circle.small { width: 44px; height: 44px; font-size: 22px; }
.bubble.big { font-size: 30px; padding: 14px 30px; }
.bubble:nth-of-type(odd) { border-radius: 52% 48% 50% 50% / 48% 52% 48% 52%; }

.paper {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px 22px 16px 24px;
  box-shadow: 4px 6px 0 rgba(40, 40, 50, 0.22);
}

/* --------------------------------------------------------- HUD -------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud #dpad { pointer-events: auto; }

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border: 2.5px solid rgba(40, 40, 50, 0.75); border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}
#crosshair::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; margin: -2.5px;
  background: var(--pink); border-radius: 50%;
}
#crosshair.lock { border-color: var(--pink); transform: scale(1.25); }

#hurt-flash {
  position: absolute; inset: 0; opacity: 0; transition: opacity 0.35s;
  box-shadow: inset 0 0 90px 30px rgba(255, 90, 140, 0.7);
}
#hurt-flash.on { opacity: 1; transition: none; }

#top-left {
  position: absolute; left: calc(12px + var(--safe-l)); top: calc(10px + var(--safe-t));
  display: flex; flex-direction: column; gap: 8px;
}
#top-left .row { display: flex; align-items: center; gap: 10px; }
#btn-home svg { width: 34px; height: 34px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
#btn-up { font-size: 17px; line-height: 0.95; padding: 6px 18px; }
#btn-up .inf { font-size: 22px; }
#btn-block { font-size: 22px; padding: 8px 22px; }

#me-panel { display: grid; grid-template-columns: auto; justify-items: center; gap: 1px; }
#me-slot { font-size: 22px; font-weight: bold; }
#me-label { font-size: 18px; margin-top: -2px; }
.bar {
  width: 150px; height: 20px; border: 3px solid var(--ink); border-radius: 12px 6px 12px 6px;
  background: var(--paper-see); overflow: hidden; box-shadow: var(--shadow);
}
.bar .fill { height: 100%; width: 100%; background: var(--p1); transition: width 0.25s; border-right: 2px solid var(--ink); }

#top-right {
  position: absolute; right: calc(12px + var(--safe-r)); top: calc(10px + var(--safe-t));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#timer { font-size: 26px; font-weight: bold; background: var(--paper-see); border: 3px solid var(--ink); border-radius: 14px; padding: 2px 14px; box-shadow: var(--shadow); }
#timer.hurry { color: #e0306f; }
#room-tag {
  font-size: 16px; background: var(--paper-see); border: 2px dashed var(--ink); border-radius: 10px;
  padding: 4px 10px; pointer-events: auto;
}
#scores { display: flex; flex-direction: column; gap: 4px; }
.score {
  display: flex; align-items: center; gap: 6px; font-size: 16px; padding: 2px 8px 2px 4px;
  background: var(--paper-see); border: 2px solid var(--ink); border-radius: 12px;
  min-width: 150px;
}
.score .tag { font-weight: bold; color: #fff; border-radius: 8px; padding: 1px 6px; border: 2px solid var(--ink); font-size: 14px; }
.score .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 96px; }
.score .st { font-weight: bold; }
.score.me { outline: 3px solid var(--pink); }
.score.dead { opacity: 0.5; }

#btn-fire {
  position: absolute; left: calc(18px + var(--safe-l)); bottom: calc(196px + var(--safe-b));
  font-size: 30px; padding: 16px 32px; background: #ffe3f1;
}

#dpad {
  position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(14px + var(--safe-b));
  width: 172px; height: 172px; touch-action: none;
}
#dpad .tri {
  position: absolute; width: 0; height: 0; pointer-events: none;
  border-style: solid; filter: drop-shadow(2px 3px 0 rgba(40, 40, 50, 0.28));
}
/* drawn as outlined triangles: a dark triangle with a paper one inside */
#dpad .tri::after { content: ""; position: absolute; width: 0; height: 0; border-style: solid; }
#dpad .up    { left: 58px; top: 0;   border-width: 0 28px 48px 28px; border-color: transparent transparent var(--ink) transparent; }
#dpad .up::after    { left: -21px; top: 7px; border-width: 0 21px 36px 21px; border-color: transparent transparent var(--paper) transparent; }
#dpad .down  { left: 58px; bottom: 0; border-width: 48px 28px 0 28px; border-color: var(--ink) transparent transparent transparent; }
#dpad .down::after  { left: -21px; top: -43px; border-width: 36px 21px 0 21px; border-color: var(--paper) transparent transparent transparent; }
#dpad .left  { left: 0; top: 58px;  border-width: 28px 48px 28px 0; border-color: transparent var(--ink) transparent transparent; }
#dpad .left::after  { left: 7px; top: -21px; border-width: 21px 36px 21px 0; border-color: transparent var(--paper) transparent transparent; }
#dpad .right { right: 0; top: 58px; border-width: 28px 0 28px 48px; border-color: transparent transparent transparent var(--ink); }
#dpad .right::after { left: -43px; top: -21px; border-width: 21px 0 21px 36px; border-color: transparent transparent transparent var(--paper); }
#dpad .tri.on { filter: drop-shadow(0 0 6px var(--pink)); }
#dpad .jump {
  position: absolute; left: 56px; top: 56px; width: 60px; height: 60px; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--paper); box-shadow: var(--shadow); padding: 0;
}
#dpad .jump.down { transform: scale(0.9); background: #ffe3f1; }

#weapons {
  position: absolute; right: calc(12px + var(--safe-r)); top: 50%; transform: translateY(-40%);
  display: flex; flex-direction: column; gap: 10px;
}
.weapon {
  display: flex; align-items: center; gap: 8px; border-radius: 40px; padding: 6px 12px 6px 8px;
  font-size: 16px; line-height: 0.95; min-width: 128px; text-align: left;
}
.weapon span { flex: 1; }
.weapon b { font-size: 18px; }
.weapon .dot { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.dot.pink { background: var(--pink); }
.dot.blast { background: radial-gradient(circle at 35% 35%, #ffb347 0 25%, #4a4a52 30%); }
.dot.rainbow { background: conic-gradient(#ff5f5f, #ffd84a, #5fe07a, #5fb0ff, #c07aff, #ff5f5f); }
.weapon.sel { background: #ffe3f1; outline: 4px solid var(--pink); }
.weapon.empty { opacity: 0.45; }

#you-are {
  position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(12px + var(--safe-b));
  font-size: 22px; background: var(--paper-see); border: 3px solid var(--ink);
  border-radius: 6px 16px 6px 16px; padding: 6px 14px; box-shadow: var(--shadow);
}
#hint {
  position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  font-size: 24px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  padding: 8px 18px; animation: bob 1.2s ease-in-out infinite;
}
#banner {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%) rotate(-2deg);
  font-size: 34px; font-weight: bold; text-align: center; white-space: nowrap;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; padding: 10px 26px;
  box-shadow: 4px 6px 0 rgba(40, 40, 50, 0.22);
}
#banner small { display: block; font-size: 20px; font-weight: normal; margin-top: 4px; }
#toast {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%);
  font-size: 22px; background: #fff7c2; border: 3px solid var(--ink); border-radius: 16px; padding: 6px 16px;
  animation: pop 0.25s ease-out;
}
@keyframes bob { 50% { transform: translateX(-50%) translateY(-8px); } }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); } to { transform: translateX(-50%) scale(1); } }

#end { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(207, 232, 255, 0.55); pointer-events: auto; }
#end .paper { padding: 18px 28px; text-align: center; max-width: 92vw; }
#end h2 { margin: 0 0 8px; font-size: 38px; }
#podium { display: flex; gap: 14px; justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 18px; }
.pod canvas { width: 86px; height: 86px; }
.pod .place { font-size: 26px; font-weight: bold; }
.pod.first canvas { width: 116px; height: 116px; }
#end-next { font-size: 18px; margin: 10px 0 0; }

/* --------------------------------------------------------- menu ------- */
#menu {
  position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  display: flex; justify-content: center; align-items: flex-start;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background:
    repeating-linear-gradient(transparent 0 31px, rgba(95, 156, 255, 0.12) 31px 33px),
    rgba(253, 251, 243, 0.25);
}
.menu-paper { position: relative; width: min(760px, 100%); padding: 14px 22px 22px; text-align: center; margin: auto 0; }
#title { font-size: clamp(48px, 11vw, 92px); margin: 0; line-height: 1; letter-spacing: 1px; transform: rotate(-2deg); }
#title span { color: var(--pink); -webkit-text-stroke: 2px var(--ink); }
.by { margin: 4px 0 8px; font-size: 20px; }
h3 { margin: 6px 0; font-size: 22px; }
#chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.char {
  background: #fff; border: 3px solid var(--ink); border-radius: 16px 12px 18px 12px; padding: 6px 4px 4px;
  font-size: 18px; box-shadow: var(--shadow);
}
.char canvas { width: 100%; aspect-ratio: 1; display: block; }
.char.sel { outline: 5px solid var(--pink); transform: rotate(-2deg) scale(1.03); background: #fff0f8; }
.name-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 4px; font-size: 20px; }
input {
  font-family: inherit; font-size: 22px; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 12px; padding: 6px 12px; background: #fff;
  width: 190px; -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
#code { width: 130px; text-transform: uppercase; text-align: center; letter-spacing: 4px; }
#main-buttons { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; margin-top: 12px; }
.go { background: #ffe3f1; }
#friends { margin-top: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.join-row { display: flex; gap: 8px; align-items: center; }
.or { font-size: 16px; opacity: 0.8; }
.check { font-size: 18px; display: flex; gap: 8px; align-items: center; }
.check input { width: 22px; height: 22px; }
#menu-msg { min-height: 1.2em; font-size: 18px; margin: 10px 0 0; color: #c2185b; }
#btn-sound { position: absolute; right: 12px; top: 12px; }
#btn-sound.off { opacity: 0.4; text-decoration: line-through; }

#loading, #rotate { position: fixed; inset: 0; display: grid; place-items: center; background: #fdfbf3; z-index: 10; }
#loading .paper, #rotate .paper { padding: 18px 28px; font-size: 26px; }

/* ------------------------------------------------ smaller screens ----- */
@media (max-height: 500px) {
  .bubble.circle { width: 48px; height: 48px; }
  #btn-home svg { width: 28px; height: 28px; }
  .bubble.oval { min-height: 44px; }
  #btn-up { font-size: 14px; padding: 4px 14px; }
  #btn-block { font-size: 18px; padding: 6px 16px; }
  .bar { width: 110px; height: 16px; }
  #me-slot { font-size: 17px; } #me-label { font-size: 15px; }
  #btn-fire { bottom: calc(150px + var(--safe-b)); font-size: 24px; padding: 12px 24px; }
  #dpad { transform: scale(0.78); transform-origin: left bottom; }
  .weapon { min-width: 104px; font-size: 13px; padding: 4px 10px 4px 6px; }
  .weapon .dot { width: 20px; height: 20px; }
  .score { font-size: 13px; min-width: 118px; }
  .score .nm { max-width: 70px; }
  #timer { font-size: 20px; }
  #you-are { font-size: 16px; padding: 4px 10px; }
  #banner { font-size: 24px; }
  #top-right { flex-direction: row-reverse; align-items: flex-start; }
  #scores { flex-direction: row; gap: 4px; }
  #scores .score .nm { display: none; }
  #scores .score { min-width: 0; padding: 2px 6px 2px 3px; }
  #room-tag { position: absolute; top: 40px; right: 0; white-space: nowrap; font-size: 13px; }
  #weapons { top: 54%; }
  #hint { font-size: 17px; }
}
@media (max-width: 560px) {
  #chars { grid-template-columns: repeat(2, 1fr); }
}
