/* Scrawl — notebook-paper, marker-pen look */
:root {
  --ink: #222;
  --paper: #fbf7ec;
  --line: #e4ddc8;
  --yellow: #ffd43b;
  --pink: #ff8fa3;
  --blue: #74c0fc;
  --green: #8ce99a;
  --wob: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wob2: 15px 225px 15px 255px / 255px 15px 225px 15px;
}

* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Patrick Hand', 'Comic Neue', 'Segoe Print', 'Bradley Hand', 'Marker Felt', 'Comic Sans MS', cursive;
  font-size: 19px;
  color: var(--ink);
  background-color: var(--paper);
  /* ruled notebook paper with a red margin line */
  background-image:
    linear-gradient(90deg, transparent 58px, rgba(255, 107, 107, .35) 58px, rgba(255, 107, 107, .35) 60px, transparent 60px),
    repeating-linear-gradient(transparent 0 31px, var(--line) 31px 32px);
}
h1, h2, h3, h4 { margin: 0; font-weight: normal; }
button, input, select { font: inherit; color: inherit; }
.av { filter: url(#wobble); flex: none; }

/* ---------- hand-drawn border: a wobbly outline drawn on ::before ---------- */
.sk { position: relative; background: #fff; border-radius: 14px; }
.sk::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--ink);
  border-radius: var(--wob);
  box-shadow: 4px 5px 0 var(--ink);
  filter: url(#wobble);
  pointer-events: none;
  z-index: 2;
}

/* ---------- buttons & inputs ---------- */
.btn {
  position: relative;
  border: 0;
  background: var(--yellow);
  padding: 6px 18px 7px;
  font-size: 20px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .08s;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--ink);
  border-radius: var(--wob);
  box-shadow: 3px 3px 0 var(--ink);
  filter: url(#wobble);
  pointer-events: none;
}
.btn:hover { transform: rotate(-1.2deg) translateY(-1px); }
.btn:active { transform: translate(2px, 2px); }
.btn:active::before { box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px dashed var(--blue); outline-offset: 4px; }
.btn.alt { background: #fff; }
.btn.big { font-size: 26px; padding: 10px 24px; }
.btn.x { padding: 2px 10px; font-size: 18px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

input, select {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px 4px 14px 5px / 5px 14px 4px 12px;
  padding: 6px 10px;
  min-width: 0;
}
input:focus, select:focus { outline: 3px dashed var(--blue); outline-offset: 2px; }

/* sound controls */
.vol { display: flex; align-items: center; gap: 8px; }
.vol .btn { padding: 4px 12px; }
.vol input[type=range] { width: 84px; padding: 0; border: 0; background: none; accent-color: var(--ink); cursor: pointer; }
.vol.muted input[type=range] { opacity: .35; }

/* ---------- logo ---------- */
.logo {
  font-family: 'Caveat Brush', 'Patrick Hand', 'Segoe Print', cursive;
  font-size: 40px;
  letter-spacing: 1px;
  transform: rotate(-3deg);
  filter: url(#wobble);
}
.logo span { color: #e8590c; }
.logo.big { font-size: 78px; text-align: center; margin-bottom: 0; }

/* ---------- auth ---------- */
#auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); padding: 28px 28px 30px; }
.tagline { text-align: center; margin: 0 0 14px; color: #555; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  background: none;
  border: 0;
  padding: 4px 12px;
  cursor: pointer;
  border-radius: 10px;
  font-size: 21px;
}
.tab.on { background: var(--yellow); transform: rotate(-1deg); }
#authForm { display: grid; gap: 12px; }
#authForm label, .row label { display: grid; gap: 4px; }
.error { color: #c92a2a; min-height: 1.2em; margin: 0; }

/* ---------- app shell ---------- */
.top { display: flex; align-items: center; gap: 14px; padding: 12px 22px 8px; max-width: 1400px; margin: 0 auto; }
.spacer { flex: 1; }
.me-chip { display: inline-flex; align-items: center; gap: 8px; padding: 2px 16px 2px 8px; }
.me-chip .av { margin-top: -2px; }

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 290px;
  gap: 22px;
  padding: 8px 22px 28px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
.panel { padding: 12px; }
.center { display: grid; gap: 16px; min-width: 0; }

/* players */
#players { max-height: 78vh; overflow: auto; }
#players h3, .chat h3 { font-size: 24px; margin-bottom: 6px; }
.pl { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 12px; }
.pl.me { background: #fff3bf; }
.pl.drawer { background: #d0ebff; }
.pl.guessed { background: #d3f9d8; }
.pl.away { opacity: .45; }
.pl .rank { width: 24px; color: #888; font-size: 16px; text-align: right; }
.pl .pi { flex: 1; min-width: 0; line-height: 1.1; }
.pl .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .sc { font-size: 16px; color: #555; }
.pl .plus { color: #2b8a3e; font-weight: bold; }
.pl .badge { font-size: 20px; }

/* word bar */
.wordbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; min-height: 76px; }
.timer {
  width: 54px; height: 54px; flex: none;
  display: grid; place-items: center;
  font-size: 26px;
  background: #fff;
  border-radius: 50%;
}
.timer::before { border-radius: 50%; box-shadow: 2px 3px 0 var(--ink); }
.timer.low { background: #ffe3e3; animation: jiggle .4s infinite alternate; }
@keyframes jiggle { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
.hint { flex: 1; text-align: center; min-width: 0; }
.hint small { display: block; font-size: 15px; color: #777; letter-spacing: 1px; text-transform: uppercase; }
.hint .ch {
  display: inline-block;
  min-width: 24px;
  margin: 0 3px;
  font-size: 32px;
  line-height: 36px;
  border-bottom: 4px solid var(--ink);
  border-radius: 2px;
}
.hint .gap { display: inline-block; width: 22px; }
.hint .msg { font-size: 26px; }
.roundlabel { font-size: 19px; color: #555; white-space: nowrap; }

/* canvas */
.canvas-wrap { padding: 6px; }
.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  background: #fff;
  border-radius: 10px;
  touch-action: none;
  cursor: default;
}
.canvas-wrap canvas.can-draw { cursor: crosshair; }
.overlay {
  position: absolute;
  inset: 6px;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
  background: rgba(251, 247, 236, .94);
  border-radius: 10px;
  overflow: auto;
}
.overlay h2 { font-family: 'Caveat Brush', 'Patrick Hand', cursive; font-size: 44px; }
.overlay p { margin: 0; }
.overlay .row { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.choices { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.choices .btn.big { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.choices .btn small { font-size: 14px; letter-spacing: 1.5px; text-transform: uppercase; opacity: .65; }
.btn.lvl-easy { background: #b2f2bb; }
.btn.lvl-medium { background: var(--yellow); }
.btn.lvl-hard { background: #ffa8a8; }
.bigword { font-family: 'Caveat Brush', 'Patrick Hand', cursive; font-size: 64px; color: #e8590c; transform: rotate(-2deg); }
.gains { display: grid; gap: 4px; min-width: 220px; text-align: left; }
.gains div { display: flex; justify-content: space-between; gap: 24px; }
.gains b { color: #2b8a3e; }
.podium { display: grid; gap: 6px; min-width: 260px; }
.podium .prow { display: flex; align-items: center; gap: 10px; padding: 4px 10px; border-radius: 12px; background: #fff; }
.podium .prow:first-child { background: #fff3bf; font-size: 24px; }
.podium .prow span.grow { flex: 1; text-align: left; }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding: 10px 14px; transition: opacity .2s; }
.toolbar.off { opacity: .35; pointer-events: none; }
.colors { display: grid; grid-template-columns: repeat(9, 28px); gap: 5px; }
.swatch {
  width: 28px; height: 28px; padding: 0; cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: 40% 60% 55% 45% / 55% 45% 60% 40%;
}
.swatch.sel, .size.sel, .tool.sel { outline: 3px solid var(--blue); outline-offset: 2px; }
.sizes, .tools { display: flex; gap: 8px; align-items: center; }
.size, .tool {
  background: #fff; border: 3px solid var(--ink); cursor: pointer;
  border-radius: 12px 6px 12px 6px; height: 40px; min-width: 40px; padding: 0 8px; font-size: 20px;
}
.size i { display: block; margin: auto; background: var(--ink); border-radius: 50%; }
.tool:hover, .size:hover { background: #fff3bf; }

/* chat */
.chat { display: flex; flex-direction: column; height: min(78vh, 760px); gap: 8px; }
.chatlog { flex: 1; overflow-y: auto; padding: 2px 4px; font-size: 18px; line-height: 1.25; }
.cm { padding: 2px 0; word-break: break-word; }
.cm b { font-weight: normal; color: #1971c2; }
.cm.sys { color: #868e96; font-style: italic; }
.cm.correct { color: #2b8a3e; font-weight: bold; background: #ebfbee; border-radius: 6px; padding: 2px 6px; }
.cm.close { color: #e8590c; }
.cm.team { color: #1971c2; background: #e7f5ff; border-radius: 6px; padding: 2px 6px; }
#chatForm { display: flex; gap: 8px; }
#chatForm input { flex: 1; }
#chatForm .btn { padding: 4px 12px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(34, 34, 34, .45); padding: 16px; }
.modal-card { width: min(620px, 100%); padding: 18px 20px; background: var(--paper); display: flex; flex-direction: column; max-height: 92vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { font-family: 'Caveat Brush', 'Patrick Hand', cursive; font-size: 40px; }
.modal-body { overflow: auto; padding: 4px 6px 8px; min-height: 120px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 12px; padding-top: 10px; }
.modal-foot:empty { display: none; }

/* leaderboard */
.lbrow { display: flex; align-items: center; gap: 12px; padding: 4px 8px; border-radius: 12px; }
.lbrow:nth-child(odd) { background: rgba(255, 255, 255, .7); }
.lbrow.me { background: #fff3bf; }
.lbrow .rk { width: 40px; text-align: center; font-size: 24px; }
.lbrow .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 22px; }
.lbrow .pts { font-size: 24px; min-width: 70px; text-align: right; }
.lbrow .sub { font-size: 15px; color: #666; min-width: 74px; text-align: right; line-height: 1.1; }
.lbhead { color: #666; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; }
.lbnote { color: #666; margin: 0 0 8px; }
.empty { text-align: center; padding: 30px 10px; color: #666; }

/* avatar editor */
.av-preview { display: grid; place-items: center; padding: 4px 0 10px; }
.arow { margin-bottom: 8px; }
.arow h4 { font-size: 20px; margin-bottom: 2px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { width: 62px; height: 62px; padding: 2px; background: #fff; border: 3px solid transparent; border-radius: 14px; cursor: pointer; }
.opt:hover { border-color: #ced4da; }
.opt.sel { border-color: var(--ink); background: #fff3bf; }
.sw { width: 34px; height: 34px; padding: 0; cursor: pointer; border: 3px solid var(--ink); border-radius: 50%; }
.sw.sel { outline: 3px solid var(--blue); outline-offset: 2px; }

/* connection banner */
.conn { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 30; background: #fff3bf; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 18px; box-shadow: 3px 3px 0 var(--ink); }

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  body { font-size: 18px; background-image: repeating-linear-gradient(transparent 0 31px, var(--line) 31px 32px); }
  .layout { grid-template-columns: 1fr; gap: 18px; padding: 8px 14px 28px; }
  .center { order: 1; }
  .chat { order: 2; height: 320px; }
  #players { order: 3; max-height: none; }
  .top { padding: 10px 14px 4px; flex-wrap: wrap; }
  .wordbar { flex-wrap: wrap; justify-content: center; }
  .colors { grid-template-columns: repeat(9, 26px); }
  .swatch { width: 26px; height: 26px; }
  .logo.big { font-size: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  .timer.low { animation: none; }
  .btn { transition: none; }
}
