/* Paper Doodle look. Every color the game uses is defined here; the canvas reads these too. */
:root {
  --paper: #fbf3e2;
  --paper-2: #f6e8cb;
  --card: #fffaf0;
  --table: #f9dca4;
  --ink: #3b2a1e;
  --ink-soft: #7a5c45;
  --orange: #f68b3c;
  --orange-deep: #d0661d;
  --yellow: #ffd84d;
  --yellow-soft: #fff0a6;
  --mint: #bfe9c8;
  --rose: #f7b6aa;
  --sky: #bcdcf6;
  --lilac: #d9cdf5;
  --danger: #d2483a;
  --back: #9db8de;
  --back-deep: #5f7fb3;
  --focus: #2f78d8;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --radius: 15px 11px 14px 10px / 11px 14px 10px 15px;
  --radius-sm: 10px 7px 9px 6px / 7px 10px 6px 9px;
  --font-title: 'Fredoka', 'Nunito', 'Trebuchet MS', sans-serif;
  --font-body: 'Nunito', 'Segoe UI', sans-serif;
  --topbar-h: 58px;
  --panel-w: 340px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
#app { display: grid; grid-template-rows: var(--topbar-h) 1fr; grid-template-columns: minmax(0, 1fr); height: 100dvh; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 14px; border-bottom: 3px solid var(--ink); background: var(--paper-2);
}
.title {
  margin: 0; display: flex; align-items: center; gap: 8px;
  font-family: var(--font-title); font-weight: 700; font-size: 24px; letter-spacing: .3px;
  white-space: nowrap; overflow: hidden;
}
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }
#main { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); min-height: 0; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
/* The table scrolls inside the stage when many players need more room than the window has */
#scroller { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
#board { position: relative; width: 100%; height: 100%; }
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
#spots { position: absolute; inset: 0; pointer-events: none; }
#panel {
  border-left: 3px solid var(--ink); background: var(--paper-2);
  overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px;
}

@media (max-width: 920px) {
  :root { --topbar-h: 52px; }
  #app { height: auto; min-height: 100dvh; }
  #main { grid-template-columns: minmax(0, 1fr); }
  /* Small screens: the whole page scrolls, and the table is as tall as it needs to be */
  #stage { height: auto; overflow: visible; }
  #scroller { position: static; overflow: visible; }
  #toast { position: fixed; bottom: 16px; }
  #panel { border-left: 0; border-top: 3px solid var(--ink); overflow: visible; }
  .title { font-size: 19px; }
}
@media (max-width: 520px) {
  .title span:last-child { font-size: 17px; }
  .btn.small { padding: 5px 9px; font-size: 13px; }
}

/* ---------- Crown motif ---------- */
.crown {
  display: inline-block; width: 30px; height: 24px; flex-shrink: 0;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 32'%3E%3Cpath d='M4 26 L3 8 L12 16 L20 4 L28 16 L37 8 L36 26 Z' fill='%23ffd84d' stroke='%233b2a1e' stroke-width='3' stroke-linejoin='round'/%3E%3Crect x='4' y='25' width='32' height='5' rx='2' fill='%23f68b3c' stroke='%233b2a1e' stroke-width='3'/%3E%3C/svg%3E");
}
.crown.big { width: 64px; height: 50px; margin: 0 auto 4px; }
.crown.tiny { width: 20px; height: 16px; vertical-align: -2px; }

/* ---------- Buttons ---------- */
.btn {
  font: 700 15px var(--font-title); color: var(--ink);
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 16px; cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  touch-action: manipulation;
}
.btn:hover { background: #fff3d6; }
.btn:active:not(:disabled), .btn.pressed { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--orange); }
.btn.primary:hover { background: #ff9d55; }
.btn.act { background: var(--yellow); }
.btn.act:hover { background: #ffe370; }
.btn.small { padding: 5px 12px; font-size: 14px; box-shadow: var(--shadow-sm); }
.btn.small:active:not(:disabled) { transform: translate(3px, 3px); }
.btn:disabled {
  cursor: not-allowed; color: var(--ink-soft); background: var(--paper);
  border-style: dashed; box-shadow: none; transform: translate(4px, 4px);
}
.btn.block { width: 100%; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* ---------- Panel ---------- */
.box {
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 10px 12px;
}
.box h3 {
  margin: 0 0 6px; font: 600 16px var(--font-title);
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.status-line { display: flex; align-items: center; gap: 8px; font: 700 18px var(--font-title); }
.status-meta { color: var(--ink-soft); font-size: 13px; font-weight: 700; margin-top: 2px; }
.instr { font-weight: 800; font-size: 16px; }
.instr.act { background: var(--yellow); }
.instr.wait { background: var(--paper); }
.instr .sub { display: block; font-weight: 600; font-size: 13.5px; margin-top: 4px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choices:empty { display: none; }
.choices .btn { font-size: 14px; padding: 6px 11px; box-shadow: var(--shadow-sm); }
.choices .btn:active { transform: translate(3px, 3px); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
.tracker { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.tracker li {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 4px 8px; border: 2px dashed var(--ink-soft); border-radius: var(--radius-sm); font-size: 14px;
}
.tracker li.done { border-style: solid; border-color: var(--ink); background: var(--yellow-soft); }
.tracker li b { font-weight: 800; }
.pill {
  display: inline-block; padding: 1px 8px; border: 2px solid var(--ink); border-radius: 999px;
  font-size: 12px; font-weight: 800; white-space: nowrap; background: var(--paper);
}
.pill.good { background: var(--mint); }
.pill.bad { background: var(--rose); }
.pill.blue { background: var(--sky); }
.pill.white { background: var(--card); }
.mission { padding: 7px 0; border-top: 2px dashed var(--paper-2); display: grid; gap: 4px; }
.mission:first-of-type { border-top: 0; padding-top: 0; }
.mission .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores td { padding: 3px 2px; }
.scores td:last-child { text-align: right; font-weight: 800; }
.muted { color: var(--ink-soft); font-size: 13px; }
.log { margin: 0; padding-left: 18px; font-size: 13.5px; max-height: 190px; overflow-y: auto; }
.log li { margin: 2px 0; }
details > summary { cursor: pointer; font: 600 16px var(--font-title); list-style-position: inside; }
.tip { background: var(--lilac); }
.tip p { margin: 0 0 8px; }
.tip .row { justify-content: flex-end; }

/* ---------- Hotspots over the table ---------- */
.spot {
  position: absolute; pointer-events: auto; margin: 0; padding: 0;
  background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  font: 800 12px var(--font-body); color: var(--ink);
  display: flex; align-items: flex-start; justify-content: center;
}
.spot.hand { border-radius: 12px; }
.spot.hand:hover { box-shadow: 0 0 0 3px var(--ink); }
.spot.hand.selected { box-shadow: 0 0 0 5px var(--yellow), 0 0 0 8px var(--ink); }
.spot.zone {
  border: 3px dashed var(--ink); background: rgb(255 216 77 / 34%);
  animation: glow 1.1s ease-in-out infinite alternate;
}
.spot.zone:hover { background: rgb(255 216 77 / 60%); }
.spot.zone span {
  margin-top: 4px; padding: 1px 8px; border: 2px solid var(--ink); border-radius: 999px; background: var(--yellow);
  white-space: nowrap; max-width: 96%; overflow: hidden; text-overflow: ellipsis;
}
.spot.zone.lower { align-items: flex-end; }
.spot.zone.lower span { margin: 0 0 4px; }
.spot.kill { border: 3px solid var(--danger); background: rgb(210 72 58 / 18%); border-radius: 6px; }
.spot.kill:hover { background: rgb(210 72 58 / 40%); }
.spot.pending { border: 3px dashed var(--orange-deep); border-radius: 6px; }
.spot.pending:hover { background: rgb(246 139 60 / 22%); }
.spot.draggable { touch-action: none; cursor: grab; }
.spot.zone.drop { border-style: solid; border-width: 4px; background: rgb(255 216 77 / 72%); animation: none; }
body.dragging, body.dragging .spot { cursor: grabbing; }
body.dragging { user-select: none; -webkit-user-select: none; }
body.dragging #tooltip { display: none; }
#btnSound[aria-pressed='false'] { background: var(--paper-2); }
@keyframes glow { from { background-color: rgb(255 216 77 / 22%); } to { background-color: rgb(255 216 77 / 48%); } }

#tooltip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 230px;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); padding: 6px 9px; font-size: 13px;
}
#tooltip b { font-family: var(--font-title); font-weight: 600; font-size: 14px; }
#toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 6;
  max-width: min(92%, 420px); pointer-events: none; text-align: center;
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 14px; font-weight: 800;
  opacity: 0; transition: opacity .18s;
}
#toast.show { opacity: 1; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgb(59 42 30 / 55%);
}
.panel-card {
  width: min(480px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--paper); border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: 6px 6px 0 var(--ink); padding: 20px 24px;
}
.panel-card.wide { width: min(720px, 100%); }
.panel-card h2 { margin: 0 0 10px; font: 700 26px var(--font-title); }
.panel-card h3 { margin: 16px 0 4px; font: 600 18px var(--font-title); }
.panel-card.start { text-align: center; }
.lead { font-size: 16px; font-weight: 700; }
.steps { text-align: left; padding-left: 22px; margin: 10px 0; }
.steps li { margin: 4px 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.row.end { justify-content: flex-end; }
.lobby-title { text-align: left; }
.seats { list-style: none; margin: 4px 0 6px; padding: 0; display: grid; gap: 7px; text-align: left; }
.seat {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 10px;
  background: var(--card); border: 3px solid var(--ink); border-radius: var(--radius-sm);
}
.seat.you { background: var(--yellow-soft); }
.seat.empty { background: transparent; border-style: dashed; }
.seat-no {
  flex-shrink: 0; width: 28px; height: 28px; display: grid; place-items: center;
  border: 2px solid var(--ink); border-radius: 50%; background: var(--paper-2); font: 700 14px var(--font-title);
}
.seat-who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.seat-who b { font: 600 16px var(--font-title); }
.seat-who small { color: var(--ink-soft); font-weight: 700; }
.seat .btn { flex-shrink: 0; }
.settings label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-weight: 700; cursor: pointer; }
.settings label small { display: block; font-weight: 600; color: var(--ink-soft); }
.settings input { width: 20px; height: 20px; accent-color: var(--orange); flex-shrink: 0; margin-top: 2px; }
.rules-note { background: var(--yellow-soft); border: 2px dashed var(--ink); border-radius: var(--radius-sm); padding: 8px 10px; }
.results { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 14px; }
.results th, .results td { border-bottom: 2px dashed var(--paper-2); padding: 5px 4px; text-align: left; vertical-align: top; }
.results th { font: 600 15px var(--font-title); }
.results td.num, .results th.num { text-align: right; white-space: nowrap; }
.results tr.winner td { background: var(--yellow-soft); }
.results tr.total td { font-weight: 800; border-bottom: 0; }
.winner-line { font: 700 20px var(--font-title); }

/* Online: name, invite link, connection status */
.online-box {
  display: grid; gap: 8px; margin: 10px 0 4px; padding: 10px 12px; text-align: left;
  background: var(--paper-2); border: 2px dashed var(--ink); border-radius: var(--radius-sm);
}
.field { display: grid; gap: 4px; font-weight: 800; font-size: 14px; }
.field[hidden] { display: none; }
.field input {
  min-width: 0; width: 100%; font: 700 15px var(--font-body); color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius-sm); padding: 6px 9px;
}
.field input[readonly] { font-size: 13px; color: var(--ink-soft); }
.field input:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.invite-row { display: flex; gap: 8px; align-items: center; }
.invite-row input { flex: 1; }
.net-status { margin: 0; font-weight: 800; font-size: 14px; }
.small-note { margin: 4px 0 0; text-align: left; }
.small-note[hidden] { display: none; }
.wait-note { align-self: center; font-weight: 700; }
.status-meta.net { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .spot.zone { animation: none; }
  .btn, #toast { transition: none; }
}
body.reduce-motion .spot.zone { animation: none; }
body.reduce-motion .btn, body.reduce-motion #toast { transition: none; }
