/* ---------- room layout: players · stage · chat ---------- */
#room {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "players stage chat";
  gap: 14px 18px;
  padding: 10px 18px 18px;
}
.topbar { grid-area: top; }
.players { grid-area: players; }
.stage { grid-area: stage; }
.chat { grid-area: chat; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; min-height: 56px; }
.brand { font-family: var(--font-logo); font-size: 1.55rem; white-space: nowrap; transform: rotate(-2deg); }
.round { font-size: 1.2rem; color: var(--ink-soft); white-space: nowrap; }
.hint {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 1.75rem;
  letter-spacing: 0.22em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hint small { display: block; font-size: 0.95rem; letter-spacing: 0.02em; color: var(--muted); line-height: 1; }
.hint .known { letter-spacing: 0.06em; }
/* Letter slots: one underline per letter, bigger gaps between words, words wrap as units */
.slots {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 6px 18px;
  padding-top: 4px;
  letter-spacing: 0;
  white-space: normal;
  line-height: 1;
}
.slot-word { display: inline-flex; align-items: flex-end; gap: 5px; }
.slot {
  display: inline-block;
  width: 0.78em;
  height: 1.05em;
  text-align: center;
  border-bottom: 3px solid currentColor;
  border-radius: 1px;
}
.slot.shown { color: var(--ink); border-bottom-color: var(--accent); }
.sym { display: inline-block; min-width: 0.4em; text-align: center; }
.timer { position: relative; width: 54px; height: 54px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-track { fill: var(--panel); stroke: var(--ink); stroke-width: 2.5; }
.timer-bar {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: calc(100 - var(--p, 1) * 100);
  transform: scale(0.8);
  transform-origin: center;
}
#timerText { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.3rem; }
.timer.low { animation: wiggle 0.6s ease-in-out infinite; }
.timer.low .timer-bar { stroke: #ff6b6b; }
.top-actions { display: flex; gap: 6px; }
.narrow-only { display: none; }

/* ---------- players ---------- */
.players { overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.players-title { margin: 0 4px 6px; font-size: 1.25rem; font-weight: 400; }
.player {
  position: relative;
  display: grid;
  grid-template-columns: 22px 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--r-btn);
  border: 2px solid transparent;
}
.player .rank { color: var(--muted); font-size: 0.95rem; text-align: right; }
.player .who { min-width: 0; line-height: 1.1; }
.player .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.1rem; }
.player .pts { font-size: 0.95rem; color: var(--ink-soft); white-space: nowrap; }
.player .badge { font-size: 1.1rem; color: var(--ink-soft); }
.player.guessed .badge { color: var(--good); }
.player.me .name { text-decoration: underline wavy var(--accent); text-underline-offset: 4px; }
.player.guessed { background: var(--good-bg); border-color: var(--good); }
.player.drawing { background: var(--panel-2); border: 2px dashed var(--ink); }
.player.offline { opacity: 0.45; }
.player .kick {
  position: absolute; right: -4px; top: -4px; width: 20px; height: 20px; padding: 0;
  font-size: 0.75rem; line-height: 1; border-radius: 50%; border: 1.5px solid var(--ink);
  background: var(--danger-bg); cursor: pointer; display: none;
}
.player:hover .kick { display: block; }
.gain { color: var(--good); font-size: 0.95rem; animation: pop-in 0.3s ease-out; }

/* ---------- stage ---------- */
.stage { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.play { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.board-wrap { position: relative; width: var(--board-w, 100%); aspect-ratio: 4 / 3; flex: none; }
.board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--board-bg, #fff);
  border: 3px solid var(--ink);
  border-radius: 8px 14px 10px 16px / 16px 8px 14px 10px;
  box-shadow: 4px 5px 0 var(--shadow);
  transition: background-color 0.25s;
}
.board.drawing { touch-action: none; cursor: crosshair; }
.board .layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.brush-cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.65); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
}
/* Tape holding the paper down */
.board-wrap::before, .board-wrap::after {
  content: '';
  position: absolute;
  z-index: 3;
  width: 84px;
  height: 24px;
  background: var(--tape);
  pointer-events: none;
}
.board-wrap::before { top: -8px; left: -24px; transform: rotate(-38deg); }
.board-wrap::after { top: -8px; right: -24px; transform: rotate(38deg); }

/* ---------- overlays on the board ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  padding: 16px;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(2px);
  border-radius: 8px 14px 10px 16px / 16px 8px 14px 10px;
  overflow: auto;
}
/* margin:auto centers the card but, unlike place-items, never clips it when it's taller than the board */
.ov-card { margin: auto; max-width: 100%; padding: 20px 22px; text-align: center; animation: pop-in 0.25s ease-out; }
.ov-card h2 { margin: 0 0 6px; font-weight: 400; font-size: 1.7rem; }
.ov-card p { margin: 4px 0; }
.word-choices { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 14px 0 6px; }
.word-choices .btn:nth-child(2n) { transform: rotate(1.5deg); }
.word-choices .btn:nth-child(3n) { transform: rotate(-1.5deg); }
.big-word { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.1; margin: 4px 0 12px; }
/* Reveal scores as a small table: points (right-aligned) | avatar | name; the table itself is centered */
.gains {
  list-style: none;
  margin: 8px auto 0;
  padding: 0;
  display: inline-grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: 4px 8px;
  max-height: 40vh;
  overflow: auto;
  text-align: left;
}
.gains li { display: contents; font-size: 1.15rem; }
.gains .plus { color: var(--good); text-align: right; }
.gains .zero { color: var(--muted); }
.gains .who { white-space: nowrap; }
.waiting-avatar { display: inline-block; }
/* "Ana draws it with you" on the word picker, in pairs mode */
.pair-note { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 1.1rem; color: var(--ink-soft); }

/* ---------- podium ---------- */
.podium {
  display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 14px 0 8px;
  border-bottom: 3px solid var(--ink);
}
.step { display: flex; flex-direction: column; align-items: center; width: 112px; }
.step .name { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.15rem; }
.step .block {
  width: 100%;
  margin-top: 4px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  border: 2.5px solid var(--ink);
  border-bottom: 0;
  border-radius: 10px 14px 0 0 / 14px 10px 0 0;
}
.step.p1 .block { height: 118px; background: var(--accent); color: var(--accent-ink); }
.step.p2 .block { height: 92px; background: #dee2e6; color: #2b2533; }
.step.p3 .block { height: 76px; background: #f4c095; color: #2b2533; padding-bottom: 6px; }
.step.p1 svg.avatar { animation: wiggle 1.4s ease-in-out infinite; }
.rest { list-style: none; padding: 0; margin: 6px 0 0; color: var(--ink-soft); }
.rest.cols { columns: 2; column-gap: 28px; }
.podium-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- reactions ---------- */
.reactions-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.float-emoji {
  position: absolute;
  bottom: 8%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ink);
  animation: float-up 2.4s ease-out forwards;
}
.float-emoji .ic {
  padding: 8px;
  font-size: 1.7rem;
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: 50% 46% 52% 48%;
  box-shadow: 2px 3px 0 var(--shadow);
}
.float-emoji > span:last-child { font-size: 0.85rem; background: var(--panel); border: 1.5px solid var(--ink); border-radius: 8px; padding: 0 5px; }
/* Chat lines for a phone drawer (whose chat is hidden), shown in .drawer-feed */
.ticker {
  padding: 2px 10px;
  font-size: 0.98rem;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: var(--r-btn);
  box-shadow: 2px 2px 0 var(--shadow);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: pop-in 0.2s ease-out;
}
.ticker.good, .ticker.you { color: var(--good); background: var(--good-bg); border-color: var(--good); }
@keyframes float-up {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  12% { transform: translateY(-20px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-260px) rotate(12deg); opacity: 0; }
}
.react-bar {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 4px 6px;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: var(--r-btn);
  box-shadow: 2px 2px 0 var(--shadow);
}
.react-bar button { border: 0; background: none; color: var(--ink); font-size: 1.3rem; cursor: pointer; padding: 2px 3px; transition: transform 0.1s; }
.react-bar button:hover { transform: scale(1.3) rotate(-8deg); }

/* ---------- toolbar ---------- */
.toolbar { position: relative; width: var(--board-w, 100%); flex: none; }
/* Wraps rather than scrolls, so Undo/Redo/Clear are never hidden off to the side on laptop widths */
.tb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 4px 6px 2px; }
.tb-btn {
  flex: none;
  height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  font-size: 1.1rem;
  white-space: nowrap;
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: var(--r-btn);
  box-shadow: 2px 2px 0 var(--shadow);
  cursor: pointer;
}
.tb-btn:active { transform: translate(1px, 1px); box-shadow: none; }
.tb-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: 2px 2px 0 var(--shadow); }
.tb-btn.danger:hover { background: var(--danger-bg); }
.tb-btn .ic { font-size: 1.15rem; }
.tb-color .chip, .bg-chip {
  width: 24px; height: 24px; flex: none; background: var(--c);
  border: 2px solid var(--ink); border-radius: 50% 45% 55% 48%;
}
.bg-chip { border-radius: 4px 6px 5px 7px; }
.tb-spacer { flex: 1; }
.quick-colors { display: flex; gap: 5px; flex: none; }
.tb-size { display: flex; align-items: center; gap: 8px; flex: none; }
.size-dot { width: var(--s, 8px); height: var(--s, 8px); background: var(--c, #000); border: 1.5px solid var(--ink); border-radius: 50%; flex: none; }
.size-range { width: 110px; accent-color: var(--ink); }
.swatch {
  width: 28px; height: 28px; flex: none; padding: 0; cursor: pointer; background: var(--c);
  border: 2px solid var(--ink); border-radius: 50% 45% 52% 48%; transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.12) rotate(-6deg); }
.swatch.sel { outline: 3px solid var(--accent); outline-offset: 2px; transform: scale(1.08); }
.pop {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 20;
  display: none;
  width: min(380px, 100%);
  padding: 12px 14px 14px;
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: var(--r-card);
  box-shadow: 3px 4px 0 var(--shadow);
}
.pop.open { display: block; animation: pop-in 0.15s ease-out; }
.pop-title { font-size: 1.05rem; color: var(--ink-soft); margin: 2px 0 6px; }
.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.tool-pick {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px;
  font-size: 0.95rem; background: var(--panel-2); border: 2px solid transparent;
  border-radius: var(--r-btn); cursor: pointer;
}
.tool-pick .ic { font-size: 1.35rem; }
.tool-pick.sel { border-color: var(--ink); background: var(--accent); color: var(--accent-ink); }
/* Inline tools + colors: only for a phone drawer (see drawer-mode below) */
.tb-inline { display: none; }
.tb-inline-tools { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; padding: 2px 0 6px; }
.tb-inline-tools .tool-pick { min-width: 0; font-size: 0.68rem; padding: 5px 0 3px; gap: 0; white-space: nowrap; overflow: hidden; }
.tb-inline-tools .tool-pick .ic { font-size: 1.3rem; }
/* Latest chat lines for a phone drawer, in the space under the tools */
.drawer-feed { display: none; width: var(--board-w, 100%); flex-direction: column; gap: 4px; }
.drawer-feed .ticker { max-width: 100%; }
.tb-inline-colors { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; padding: 2px 0 4px; justify-items: center; }
.tb-inline-colors .swatch { width: 100%; max-width: 28px; height: auto; aspect-ratio: 1; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; justify-items: center; }
.custom-color, .check { display: flex; align-items: center; gap: 8px; margin-top: 10px; cursor: pointer; }
.custom-color input { width: 40px; height: 32px; padding: 0; border: 2px solid var(--ink); border-radius: 6px; background: none; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}
.msg { line-height: 1.25; }
.msg b { font-weight: 400; color: var(--ink-soft); }
.msg b::after { content: ':'; }
.msg.system, .msg.join, .msg.leave, .msg.start, .msg.drawing { color: var(--muted); }
.msg.win { font-size: 1.15rem; }
.msg.good, .msg.you { color: var(--good); background: var(--good-bg); padding: 2px 8px; border-radius: var(--r-btn); }
.msg.you { font-size: 1.15rem; }
.msg.close { color: var(--warn); background: var(--warn-bg); padding: 2px 8px; border-radius: var(--r-btn); }
.msg.warn { color: var(--warn); }
.msg.guessed { color: var(--good); }
.msg.reveal { padding: 2px 8px; background: var(--panel-2); border: 1.5px dashed var(--ink); border-radius: var(--r-btn); }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 2px dashed color-mix(in srgb, var(--ink) 35%, transparent); }
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 0.3em 0.7em;
  font-size: 1.15rem;
  background: var(--panel-2);
  border: 2px solid var(--ink);
  border-radius: var(--r-btn);
  outline: none;
}
.chat-form input:focus { box-shadow: 0 0 0 3px var(--accent); }
.chat-form input:disabled { opacity: 0.6; }

/* ---------- lobby ---------- */
.lobby {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 26px 22px;
  align-content: start;
  align-items: start;
  padding: 18px 8px 24px;
}
.lobby .card { padding: 22px 18px 18px; }
.lobby h3 { margin: 0 0 12px; font-weight: 400; font-size: 1.5rem; }
.lobby .wide { grid-column: 1 / -1; }
.lobby-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.invite-row { display: flex; gap: 8px; }
.invite-row .input { font-size: 1rem; }
/* The link gets the full card width (button underneath), so its start and its room code both show */
.invite-row { flex-direction: column; align-items: flex-start; }
.invite-link { width: 100%; display: flex; align-items: center; white-space: nowrap; overflow: hidden; cursor: pointer; }
.invite-link .link-start { flex: 0 1 auto; min-width: 4em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.invite-link .link-end { flex: none; }
/* Game mode: two radio cards (Classic / Pairs); the chosen one gets the highlighter */
.mode-picks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-bottom: 16px; }
.mode-pick {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  background: var(--panel-2);
  border: 2px dashed color-mix(in srgb, var(--ink) 40%, transparent);
  border-radius: var(--r-btn);
  transition: transform 0.12s ease;
}
.mode-pick input { position: absolute; opacity: 0; pointer-events: none; }
.mode-pick .mode-icon { font-size: 1.7rem; }
.mode-pick b { display: block; font-weight: 400; font-size: 1.25rem; line-height: 1.1; }
.mode-pick small { display: block; font-size: 0.98rem; line-height: 1.2; color: var(--ink-soft); }
.mode-pick:hover:not(.locked) { transform: rotate(-0.8deg); }
.mode-pick.sel { background: var(--accent); color: var(--accent-ink); border: 2.5px solid var(--ink); box-shadow: 2px 3px 0 var(--shadow); }
.mode-pick.sel small { color: var(--accent-ink); }
.mode-pick:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }
.mode-pick.locked { cursor: default; }
.mode-pick.locked:not(.sel) { opacity: 0.6; }
.pairs-note { display: block; margin-top: 2px; font-size: 0.98rem; color: var(--warn); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.settings-grid .select { padding: 0.3em 0.5em; font-size: 1.08rem; }
.setting > span { display: block; font-size: 1rem; color: var(--ink-soft); margin-bottom: 2px; }
.setting.full { grid-column: 1 / -1; }
.setting .check { margin-top: 4px; }
.start-area { text-align: center; display: grid; gap: 8px; justify-items: center; }
.start-area p { margin: 0; color: var(--ink-soft); }
.hall table { width: 100%; border-collapse: collapse; font-size: 1.08rem; }
.hall td, .hall th { padding: 4px 6px; text-align: left; border-bottom: 1.5px dashed color-mix(in srgb, var(--ink) 25%, transparent); }
.hall th { font-weight: 400; color: var(--ink-soft); }
.hall td.num, .hall th.num { text-align: right; }
.hall .who { display: flex; align-items: center; gap: 6px; }

/* ---------- end of game: voting gallery + results ---------- */
.panel {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 18px 8px 28px;
}
.panel h3 { margin: 0 0 12px; font-weight: 400; font-size: 1.45rem; }
.vote-head { padding: 20px 18px 16px; }
.vote-head p { margin: 0 0 10px; }
.vote-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.vote-status { margin: 0 auto 0 0; font-size: 1.15rem; }
.vote-status .ic { color: #e64980; }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.gallery-grid.small { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.gallery-card {
  position: relative;
  margin: 0;
  padding: 8px 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: var(--r-btn);
  box-shadow: 2px 3px 0 var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.gallery-card:nth-child(3n + 1) { transform: rotate(-0.8deg); }
.gallery-card:nth-child(3n + 2) { transform: rotate(0.6deg); }
.gallery-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  border: 1.5px solid color-mix(in srgb, var(--ink) 30%, transparent);
  border-radius: 4px;
  background: #fff;
}
.caption { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 1rem; line-height: 1.15; }
.caption .word { color: var(--ink-soft); }
.caption .hearts, .best-pic .hearts { margin-left: auto; color: #e64980; white-space: nowrap; }
.vote-card { cursor: pointer; }
.vote-card:hover:not(:disabled) { transform: rotate(-1.5deg) scale(1.02); box-shadow: 3px 5px 0 var(--shadow); }
.vote-card .heart {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  color: var(--ink-soft);
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 50% 46% 52% 48%;
}
.vote-card.voted { border-color: #e64980; box-shadow: 3px 4px 0 #e64980; }
.vote-card.voted .heart { color: #fff; background: #e64980; border-color: #e64980; animation: pop-in 0.2s ease-out; }
.vote-card.voted .heart path { fill: currentColor; }
.vote-card .yours {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 0 8px;
  font-size: 0.95rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid var(--ink);
  border-radius: var(--r-btn);
}
.vote-card.own { cursor: default; opacity: 0.75; }
.vote-card.own .yours { display: block; }
.vote-card.own .heart { display: none; }
/* The drawings you gave a heart to: the heart is filled in */
.hearts.mine path { fill: currentColor; }
/* Save button in the corner of every picture in "All drawings" */
.save-pic {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.2rem;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--ink);
  border-radius: 50% 46% 52% 48%;
  box-shadow: 1px 2px 0 var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.save-pic:hover { transform: rotate(-8deg) scale(1.08); background: var(--accent); color: var(--accent-ink); }
.save-pic:active { transform: translate(1px, 1px); box-shadow: none; }
.award-note { margin: -6px 0 14px; }
/* Two avatars for a pair of drawers, the second one tucked half behind the first */
.duo { display: inline-flex; align-items: center; flex: none; }
.duo > span { display: inline-flex; }
.duo > span + span { margin-left: -8px; }
.waiting-avatar.duo > span + span { margin-left: -18px; }

.results { align-items: stretch; }
.results-title { margin: 0; text-align: center; font-weight: 400; font-size: clamp(1.8rem, 4vw, 2.6rem); transform: rotate(-1deg); }
.award { padding: 22px 18px 18px; }
.award h3 .ic { vertical-align: -0.15em; }
.best-list { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; }
.best-pic { margin: 0; flex: 1 1 320px; max-width: 620px; display: flex; flex-direction: column; gap: 8px; }
.best-list.many { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.best-list.many .best-pic { max-width: none; }
.best-list.many figcaption { font-size: 1rem; gap: 6px; }
.best-pic img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 3px solid var(--ink);
  border-radius: 6px 10px 8px 12px / 12px 6px 10px 8px;
  box-shadow: 4px 5px 0 var(--shadow);
  background: #fff;
}
.best-pic figcaption { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 1.15rem; }
.best-pic .hearts { font-size: 1.3rem; }
.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.results .confetti { position: absolute; inset: 0; height: 100vh; }

/* Fun stats: sticky notes in pastel colors, slightly askew */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.stat-note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 12px 14px;
  color: #2b2533;
  background: #fff3a8;
  border-radius: 2px 2px 14px 2px;
  box-shadow: 2px 4px 0 rgba(0, 0, 0, 0.12);
  transform: rotate(-1.2deg);
}
.stat-note:nth-child(4n + 2) { background: #ffd6e0; transform: rotate(1deg); }
.stat-note:nth-child(4n + 3) { background: #cdeafe; transform: rotate(-0.6deg); }
.stat-note:nth-child(4n + 4) { background: #d3f9d8; transform: rotate(1.4deg); }
.stat-head { font-size: 1rem; color: #5f5a66; }
.stat-who { font-weight: 400; font-size: 1.4rem; line-height: 1.15; overflow-wrap: anywhere; }
.stat-detail { font-size: 1rem; color: #3d3846; }

/* ---------- character editor pop-up ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  background: rgba(20, 16, 28, 0.45);
  animation: fade-in 0.15s ease-out;
}
.modal-card { margin: auto; width: min(440px, 100%); animation: pop-in 0.2s ease-out; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade-in { from { opacity: 0; } }
.me-btn { padding: 0; overflow: hidden; }
.me-btn svg { width: 34px; height: 34px; }

/* ---------- medium screens: players strip above the board ---------- */
@media (max-width: 1199px) {
  #room {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "top top" "players chat" "stage chat";
  }
  .players { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 8px 10px; gap: 6px; }
  .players-title { display: none; }
  .player { grid-template-columns: 1fr; justify-items: center; text-align: center; min-width: 70px; padding: 4px; gap: 0; }
  .player .rank { display: none; }
  .player .name { font-size: 0.98rem; max-width: 76px; }
  /* Badge as a little chip on the avatar's corner, so it never tangles with the avatar's hat */
  .player .badge {
    position: absolute;
    top: 0;
    right: 2px;
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    font-size: 0.82rem;
    background: var(--panel);
    border: 1.5px solid var(--ink);
    border-radius: 50%;
    box-shadow: 1px 1px 0 var(--shadow);
  }
  .player.guessed .badge { border-color: var(--good); background: var(--good-bg); }
}

/* ---------- phones ---------- */
@media (max-width: 759px) {
  #room {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "top" "players" "stage" "chat";
    gap: 8px;
    padding: 6px 10px 10px;
  }
  /* Lobby, voting and results scroll as one page (not a little box between players and chat);
     the top bar stays pinned and the chat keeps its own fixed-height log at the bottom */
  #room.in-panel {
    grid-template-rows: auto max-content max-content 340px;
    align-content: start;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #room.in-panel .topbar {
    position: sticky;
    top: -6px; /* the room's top padding, so the bar sits flush with the screen edge */
    z-index: 10;
    margin: -6px -10px 0;
    padding: 6px 10px;
    background: var(--paper);
    border-bottom: 2px dashed color-mix(in srgb, var(--ink) 18%, transparent);
  }
  #room.in-panel .stage { min-height: auto; }
  /* "Lobby" / "Voting" / "Final scores" just repeat the headline next to them; give it the room */
  #room.in-panel .round { display: none; }
  #room.in-panel .hint { text-align: left; font-size: 1.2rem; letter-spacing: 0.04em; white-space: normal; }
  #room.in-panel .lobby, #room.in-panel .panel { flex: none; min-height: auto; overflow: visible; }
  #room.in-game .stage { height: var(--stage-h, auto); }
  /* Drawer mode: no chat, every brush and color within thumb reach */
  #room.drawer-mode { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "top" "stage"; }
  #room.drawer-mode .chat, #room.drawer-mode .players { display: none; }
  #room.drawer-mode .hint small { display: inline; margin-right: 8px; }
  /* Keyboard up while guessing: drop the players strip so the drawing and your guess both fit */
  #room.in-game.kb-open { grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top" "stage" "chat"; }
  #room.in-game.kb-open .players, #room.in-game.kb-open .hint small, #room.in-game.kb-open .react-bar { display: none; }
  #room.drawer-mode .tb-inline { display: block; }
  #room.drawer-mode .drawer-feed { display: flex; }
  #room.drawer-mode .tb-tool, #room.drawer-mode .tb-color { display: none; }
  .chat { min-height: 110px; }
  .brand { display: none; }
  .topbar { gap: 8px; min-height: 46px; }
  /* In the game the word hint is the most important line: give it its own full-width row */
  #room.in-game .topbar { flex-wrap: wrap; row-gap: 2px; }
  #room.in-game .timer { margin-left: auto; }
  #room.in-game .hint { order: 10; flex: 1 0 100%; white-space: normal; letter-spacing: 0.08em; }
  .slots { gap: 6px 14px; }
  .slot-word { gap: 4px; }
  .slot { width: 0.74em; }
  .round { font-size: 1rem; }
  .hint { font-size: 1.35rem; letter-spacing: 0.16em; }
  .timer { width: 46px; height: 46px; }
  .icon-btn { width: 34px; height: 34px; font-size: 1rem; }
  .player { min-width: 58px; }
  .player svg.avatar { width: 36px; height: 36px; }
  .board-wrap::before, .board-wrap::after { width: 56px; height: 18px; }
  .wide-only { display: none; }
  .narrow-only { display: inline; }
  .tb-label, .quick-colors { display: none; }
  .tb-row { gap: 6px; }
  .tb-btn { height: 38px; padding: 0 8px; }
  .tb-size { gap: 4px; }
  .size-range { width: 64px; }
  .word-choices { gap: 8px; margin: 8px 0 2px; }
  .word-choices .btn.big { font-size: 1.15rem; padding: 0.2em 0.8em 0.25em; }
  .ov-card .muted { font-size: 0.95rem; }
  .panel { padding: 12px 4px 20px; gap: 18px; }
  .vote-head { padding: 14px 14px 12px; }
  .vote-head h3 { margin-bottom: 6px; font-size: 1.25rem; }
  .vote-head p.muted { display: none; }
  .gallery-grid, .gallery-grid.small, .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .vote-card .heart { top: 12px; right: 12px; width: 34px; height: 34px; font-size: 1.15rem; }
  .save-pic { top: 12px; right: 12px; width: 34px; height: 34px; font-size: 1.05rem; }
  .caption { font-size: 0.92rem; }
  .stat-who { font-size: 1.2rem; }
  .react-bar { right: 6px; bottom: 6px; padding: 2px 4px; }
  .react-bar button { font-size: 1.15rem; }
  .lobby { padding: 14px 4px 18px; gap: 22px; }
  .settings-grid, .mode-picks { grid-template-columns: 1fr; }
  .mode-picks { gap: 8px; }
  .chat-log { padding: 8px 10px 4px; font-size: 1.02rem; }
  .chat-form { padding: 6px; }
  .ov-card { padding: 14px; }
  .ov-card h2 { font-size: 1.35rem; }
  .step { width: 84px; }
  .step svg.avatar { width: 44px; height: 44px; }
  .podium { margin: 4px 0 2px; }
  .podium-actions { margin-top: 6px; }
  .podium-actions .btn { font-size: 1.05rem; padding: 0.15em 0.8em 0.2em; }
  .step.p1 .block { height: 80px; }
  .step.p2 .block { height: 66px; }
  .step.p3 .block { height: 58px; }
  .step .block { font-size: 1.1rem; line-height: 1.05; align-content: center; padding-bottom: 6px; }
  .step .block small { font-size: 0.9rem; }
}

/* ---------- big screens: give the board more room ---------- */
@media (min-width: 1600px) {
  #room { grid-template-columns: 260px minmax(0, 1fr) 340px; }
}
