:root {
  --bg: #fff8ec;
  --ink: #2b2d42;
  --muted: #7a7f99;
  --line: #eadfca;
  --panel: #ffffff;
  --coral: #ff6b6b;
  --coral-d: #e8514f;
  --sun: #ffd93d;
  --mint: #3ecf8e;
  --sky: #4dabf7;
  --grape: #9775fa;
  --shadow: 0 3px 0 rgba(43, 45, 66, .12), 0 10px 30px rgba(43, 45, 66, .08);
  --radius: 18px;
  --display: 'Jua', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(#f1e4c9 1.2px, transparent 1.2px);
  background-size: 22px 22px;
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--coral-d); }

.btn {
  border: 2px solid var(--ink);
  background: #fff;
  border-radius: 14px;
  padding: 10px 16px;
  font-family: var(--display);
  font-size: 17px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
  white-space: nowrap;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--coral); color: #fff; }
.btn.yellow { background: var(--sun); }
.btn.huge { width: 100%; font-size: 22px; padding: 14px; }

/* ---------------- home ---------------- */
#home { max-width: 1120px; margin: 0 auto; padding: 12px 16px 24px; }
.home-top { display: flex; justify-content: flex-end; gap: 8px; }
.lang-btn { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 700; }
.logo { text-align: center; margin: 4px 0 18px; }
.logo h1 { font-family: var(--display); font-weight: 400; font-size: clamp(52px, 12vw, 88px); line-height: 1; margin: 0; letter-spacing: -2px; }
.logo .l1 { color: var(--coral); display: inline-block; transform: rotate(-4deg); text-shadow: 3px 3px 0 var(--ink); }
.logo .l2 { color: var(--sun); display: inline-block; transform: rotate(3deg); margin-left: 6px; text-shadow: 3px 3px 0 var(--ink); -webkit-text-stroke: 1px var(--ink); }
.logo .tag { margin: 12px 0 0; font-size: 17px; color: var(--muted); }

.home-grid { display: grid; grid-template-columns: 360px 1fr; grid-template-areas: "profile rooms" "how rooms"; gap: 16px; align-items: start; }
.panel { background: var(--panel); border: 2px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 0 0 10px; }
.profile { grid-area: profile; display: flex; flex-direction: column; gap: 12px; }
.rooms { grid-area: rooms; min-height: 300px; }
.how { grid-area: how; }

.avatar-pick { display: flex; align-items: center; justify-content: center; gap: 14px; }
.arrow { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; font-size: 24px; line-height: 1; box-shadow: 0 2px 0 var(--ink); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 21px; border: 2px solid var(--ink); flex: none; background: var(--sun); }
.avatar.big { width: 88px; height: 88px; font-size: 52px; border-width: 3px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .code-join input, .chat-form input, .set textarea, .set select {
  border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px; background: #fff; font-size: 17px; width: 100%; min-width: 0;
}
.field input:focus, .code-join input:focus, .chat-form input:focus, .set textarea:focus { outline: 3px solid var(--sun); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.code-join { display: flex; gap: 8px; }
.code-join input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.invite-box { background: #fff3bf; border: 2px dashed var(--ink); border-radius: 12px; padding: 10px; text-align: center; font-size: 16px; }
.conn-note { margin: 0; font-size: 12px; color: var(--muted); min-height: 1em; text-align: center; }

.rooms-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.online { font-size: 13px; color: var(--muted); }
.online::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); margin-right: 6px; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.room-item { border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; background: #fffdf8; cursor: pointer; text-align: left; width: 100%; }
.room-item:hover { border-color: var(--ink); }
.room-item .ri-main { flex: 1; min-width: 0; }
.room-item .ri-host { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .ri-sub { font-size: 12px; color: var(--muted); }
.room-item .ri-count { font-family: var(--display); font-size: 20px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--mint); color: #fff; margin-left: 4px; vertical-align: 1px; }
.badge.play { background: var(--sky); }
.empty { color: var(--muted); text-align: center; margin: 30px 0; }
.how ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.how li { display: flex; gap: 10px; align-items: flex-start; }
.how li b { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--sky); color: #fff; display: grid; place-items: center; font-family: var(--display); font-weight: 400; }
.home-foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 20px; }

/* ---------------- room ---------------- */
#room { height: 100dvh; display: flex; flex-direction: column; max-width: 1400px; margin: 0 auto; padding: 8px 12px 10px; gap: 8px; }
.bar { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-mini { font-family: var(--display); font-size: 24px; border: none; background: none; color: var(--coral); padding: 0 4px; text-shadow: 2px 2px 0 var(--ink); }
.brand-mini b { color: var(--sun); font-weight: 400; margin-left: 2px; }
.chip { border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 4px 12px; font-size: 14px; white-space: nowrap; }
.code-chip b { letter-spacing: 2px; }
.code-chip i { font-style: normal; }
.spacer { flex: 1; }
.icon-btn { border: 2px solid var(--ink); background: #fff; border-radius: 50%; width: 38px; height: 38px; font-size: 17px; }
.timer { position: relative; width: 46px; height: 46px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: #fff; stroke-width: 4; }
.timer .track { stroke: var(--line); }
.timer .prog { fill: none; stroke: var(--mint); stroke-linecap: round; stroke-dasharray: 97.4; transition: stroke-dashoffset .25s linear, stroke .3s; }
.timer.low .prog { stroke: var(--coral); }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-size: 17px; }
.timer.low span { color: var(--coral-d); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.15); } }

.wordbar { flex: none; display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 52px; background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 6px 12px; box-shadow: 0 3px 0 rgba(43,45,66,.12); position: relative; }
.word { font-family: var(--display); font-size: 26px; letter-spacing: 1px; text-align: center; display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; justify-content: center; }
.word .slot { display: inline-grid; place-items: center; min-width: 30px; height: 36px; border-bottom: 3px solid var(--ink); padding: 0 2px; }
.word .slot.init { color: var(--grape); }
.word .slot.open { color: var(--coral-d); }
.word .gap { width: 14px; }
.word .len { font-size: 14px; color: var(--muted); font-family: inherit; margin-left: 6px; }
.word .label { font-size: 15px; color: var(--muted); }
.word .answer { color: var(--coral-d); }
.tier { font-size: 12px; padding: 2px 8px; border-radius: 999px; color: #fff; font-family: system-ui, sans-serif; font-weight: 700; }
.tier.easy { background: var(--mint); }
.tier.normal { background: var(--sky); }
.tier.hard { background: var(--grape); }
.tier.custom { background: #f59f00; }
.votes { position: absolute; right: 8px; display: flex; gap: 6px; }
.vote { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 9px; font-size: 14px; }
.vote.on { border-color: var(--ink); background: var(--sun); }

.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: 210px minmax(0, 1fr) 300px; gap: 10px; }
.players { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); overflow-y: auto; padding: 6px; }
.pl { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 12px; position: relative; }
.pl + .pl { margin-top: 2px; }
.pl.me { background: #fff8e1; }
.pl.guessed { background: #d3f9d8; }
.pl.drawer { background: #e7f5ff; }
.pl.off { opacity: .45; }
.pl .rank { width: 18px; font-size: 12px; color: var(--muted); text-align: center; flex: none; }
.pl .who { flex: 1; min-width: 0; }
.pl .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.pl .sc { font-size: 12px; color: var(--muted); }
.pl .ic { font-size: 16px; flex: none; }
.pl .kick { border: none; background: none; color: var(--muted); font-size: 14px; padding: 2px 4px; visibility: hidden; }
.pl:hover .kick { visibility: visible; }

.board { display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; align-items: center; }
.canvas-wrap { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 100%; border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow); flex: 0 1 auto; min-height: 0; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#canvas.can-draw { cursor: none; }
#canvas.can-draw.fill { cursor: crosshair; }
.brush-cursor { position: absolute; pointer-events: none; border: 1.5px solid rgba(0,0,0,.6); border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,.8); transform: translate(-50%, -50%); }
.overlay { position: absolute; inset: 0; background: rgba(255, 248, 236, .94); display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 16px; text-align: center; overflow-y: auto; gap: 12px; }
/* centred while it fits, scrollable from the top when it does not (a centred flex box cuts off its top) */
.overlay > :first-child { margin-top: auto; }
.overlay > :last-child { margin-bottom: auto; }
/* The results (20 s) get the whole board column, and a taller board on phones; the last drawing
   underneath is hidden rather than stretched. */
#room.ended .canvas-wrap { aspect-ratio: auto; height: 100%; }
#room.ended #canvas { visibility: hidden; }
.overlay h2 { font-family: var(--display); font-weight: 400; font-size: clamp(22px, 3.2vw, 34px); margin: 0; }
.overlay p { margin: 0; color: var(--muted); }
.overlay .big-word { font-family: var(--display); font-size: clamp(30px, 5vw, 52px); color: var(--coral-d); }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 130px; }
.choice .tier { font-size: 11px; }
.gains { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; min-width: min(320px, 90%); }
.gains li { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 4px 10px; border: 1.5px solid var(--line); }
.gains li .g-name { flex: 1; text-align: left; font-weight: 700; }
.gains li .g-pts { font-family: var(--display); color: var(--mint); }
.gains li .g-pts.zero { color: var(--muted); }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 6px 0; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pod .blk { width: 88px; border: 2px solid var(--ink); border-radius: 10px 10px 0 0; display: grid; place-items: center; font-family: var(--display); font-size: 26px; color: #fff; }
.pod.p1 .blk { height: 96px; background: #fab005; }
.pod.p2 .blk { height: 70px; background: #adb5bd; }
.pod.p3 .blk { height: 52px; background: #e8590c; }
.pod .nm { font-weight: 700; max-width: 96px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod .sc { font-size: 12px; color: var(--muted); }
.pod.me .nm { color: var(--coral-d); }
.gains.rest { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); width: min(560px, 100%); }
.gains.rest li.me { background: #fff8e1; border-color: var(--sun); }
.gains.rest .g-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.relay-pick { width: min(560px, 100%); }
.relay-pick h3 { font-family: var(--display); font-weight: 400; font-size: 18px; margin: 0 0 6px; }
.relay-games { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.relay-games .btn { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 8px; font-size: 16px; white-space: normal; }
.relay-games small { font: 12px/1.3 system-ui, sans-serif; color: var(--muted); }
.relay-note { font-size: 13px; }

/* "〈host〉 is moving everyone to 〈game〉": over everything, at the top */
.relay-banner { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; width: min(560px, calc(100vw - 24px));
  display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid var(--ink); border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 4px 0 var(--ink), 0 12px 30px rgba(43, 45, 66, .18); animation: relayIn .25s ease-out; }
.relay-banner p { margin: 0; flex: 1; font-family: var(--display); font-size: 18px; line-height: 1.35; }
.relay-btns { display: flex; gap: 8px; flex: none; }
.relay-btns .btn { padding: 6px 12px; font-size: 16px; }
@keyframes relayIn { from { transform: translate(-50%, -16px); opacity: 0; } }

.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; width: min(520px, 100%); text-align: left; }
.set { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.set select { padding: 7px 10px; font-size: 15px; }
.set.wide { grid-column: 1 / -1; }
.set textarea { resize: vertical; min-height: 58px; font-size: 14px; }
.set .check { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.set .check input { width: 18px; height: 18px; accent-color: var(--coral); }
.lobby-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lobby-note { font-size: 13px; }

.tools { width: 100%; background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 6px 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex: none; }
.colors { display: grid; grid-template-columns: repeat(10, 24px); gap: 3px; }
.sw { width: 24px; height: 24px; border-radius: 6px; border: 1.5px solid rgba(0,0,0,.25); padding: 0; }
.sw.on { outline: 3px solid var(--ink); outline-offset: 1px; }
.tool-row { display: flex; gap: 10px; align-items: center; flex: 1; justify-content: space-between; flex-wrap: wrap; }
.sizes { display: flex; gap: 4px; }
.size { width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: #fff; display: grid; place-items: center; }
.size i { display: block; background: var(--ink); border-radius: 50%; }
.size.on { border-color: var(--ink); background: #fff3bf; }
.tool-btns { display: flex; gap: 4px; }
.tool { width: 38px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-size: 17px; padding: 0; }
.tool.on { border-color: var(--ink); background: #fff3bf; }

.chat { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.messages { list-style: none; margin: 0; padding: 8px 10px; flex: 1; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.messages li { word-break: break-word; padding: 2px 6px; border-radius: 8px; }
.messages li b { margin-right: 4px; }
.messages li.sys { color: var(--muted); font-size: 13px; }
.messages li.correct { background: #d3f9d8; color: #2b8a3e; font-weight: 700; }
.messages li.close { background: #fff3bf; color: #946800; }
.messages li.hidden { background: #ebfbee; color: #2f9e44; }
.messages li.reveal { background: #e7f5ff; color: #1864ab; font-weight: 700; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 2px solid var(--line); }
.chat-form input { font-size: 16px; padding: 8px 10px; }
.chat-form .btn { padding: 6px 12px; font-size: 16px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 50; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }

.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* ---------------- narrow screens ---------------- */
@media (max-width: 1080px) {
  .stage { grid-template-columns: 170px minmax(0, 1fr) 250px; }
}
@media (max-width: 860px) {
  .home-grid { grid-template-columns: 1fr; grid-template-areas: "profile" "rooms" "how"; }
  .rooms { min-height: 0; }

  #room { padding: 6px 8px 8px; gap: 6px; }
  .bar { gap: 6px; }
  .brand-mini { font-size: 19px; }
  .chip { font-size: 12px; padding: 3px 8px; }
  .timer { width: 40px; height: 40px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .wordbar { min-height: 44px; padding: 4px 8px; flex-direction: column; gap: 4px; }
  .word { font-size: 21px; }
  .word .slot { min-width: 22px; height: 30px; }
  .votes { position: static; }
  .stage { display: grid; grid-template-columns: 38% minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "board board" "players chat"; gap: 6px; }
  .board { grid-area: board; gap: 6px; }
  .canvas-wrap { max-height: none; }
  .players { grid-area: players; padding: 4px; border-radius: 14px; }
  .pl { padding: 3px 4px; gap: 5px; }
  .pl .avatar { width: 28px; height: 28px; font-size: 16px; }
  .pl .rank { display: none; }
  .pl .nm { font-size: 13px; }
  .pl .kick { visibility: visible; }
  .chat { grid-area: chat; border-radius: 14px; }
  .messages { font-size: 13px; padding: 6px; }
  .chat-form { padding: 5px; }
  .tools { padding: 5px; gap: 6px; }
  .colors { grid-template-columns: repeat(10, minmax(0, 1fr)); width: 100%; }
  .sw { width: 100%; height: 22px; }
  .size { width: 30px; height: 30px; }
  .tool { width: 34px; height: 30px; font-size: 15px; }
  .settings { gap: 8px; }
  .overlay { gap: 8px; padding: 10px; }
  .pod .blk { width: 64px; font-size: 20px; }
  .pod.p1 .blk { height: 64px; } .pod.p2 .blk { height: 46px; } .pod.p3 .blk { height: 34px; }
  .choice { min-width: 100px; }
  #room.ended .canvas-wrap { height: min(64dvh, 560px); }
  .relay-games .btn { font-size: 15px; padding: 6px; }
}
@media (max-width: 480px) {
  .relay-banner { flex-direction: column; align-items: stretch; gap: 8px; }
  .relay-btns .btn { flex: 1; }
}
