/* 캐치마인드 — "책상 위 스케치북" 컨셉
 *
 * 바탕은 어두운 책상(따뜻한 잉크 보라), 가운데는 도화지, 강조색은 형광펜 노랑.
 * 참가자마다 크레용 색이 배정되어 점수판과 채팅 이름에 그대로 쓰인다.
 */

:root {
  --ink: #16111f;
  --ink-2: #1f1830;
  --ink-3: #2b2140;
  --line: #3a2f52;
  --chalk: #f5efe4;
  --dust: #a294bd;
  --marker: #ffcb47;
  --hot: #ff5d8f;
  --cool: #5ee7d5;
  --paper: #fdfbf5;
  --radius: 16px;

  --font-display: 'Gaegu', 'Gothic A1', 'Malgun Gothic', sans-serif;
  --font-body: 'Gothic A1', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo',
               'Segoe UI', 'Malgun Gothic', 'Noto Sans KR', 'Noto Sans CJK KR', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--chalk);
  font: 15px/1.55 var(--font-body);
  overflow: hidden;
  background-color: var(--ink);
  /* 모눈종이 책상. 아주 옅게만 깔아 존재를 눈치채지 못하게 한다. */
  background-image: radial-gradient(circle, rgba(245, 239, 228, .045) 1px, transparent 1px);
  background-size: 24px 24px;
}

:focus-visible { outline: 2px solid var(--marker); outline-offset: 2px; }

button {
  font: 600 14px/1.2 var(--font-body);
  color: var(--chalk);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--ink-3);
  border-radius: 10px;
  padding: 10px 16px;
  transition: transform .14s, filter .14s, box-shadow .14s;
}
button:hover:not(:disabled) { filter: brightness(1.3); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .38; cursor: not-allowed; }
button.ghost { background: transparent; padding: 6px 11px; font-size: 12.5px; color: var(--dust); }
button.ghost:hover { color: var(--chalk); }
button.danger { border-color: #6b2340; }

/* 형광펜으로 칠한 듯한 주요 버튼 */
button.primary {
  background: var(--marker);
  border-color: var(--marker);
  color: #2a1e05;
  font-weight: 800;
  font-size: 15px;
  padding: 13px 26px;
  box-shadow: 0 4px 0 #c99418;
}
button.primary:hover:not(:disabled) { filter: brightness(1.06); }
button.primary:active:not(:disabled) { box-shadow: 0 1px 0 #c99418; }

input[type=text] {
  font: 15px/1.4 var(--font-body);
  color: var(--chalk);
  background: #120e1a;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  outline: none;
  width: 100%;
}
input[type=text]::placeholder { color: #6f6288; }
input[type=text]:focus { border-color: var(--marker); }

.hidden { display: none !important; }

/* ------------------------------------------------------------------ 레이아웃 */

.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 10px 22px;
  background: linear-gradient(180deg, var(--ink-2), rgba(31, 24, 48, .6));
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: .01em;
}
/* 아래를 향한 크레용 한 자루 */
.brand-mark {
  width: 11px;
  height: 27px;
  background: linear-gradient(180deg, var(--marker) 62%, #f0a52a 62%);
  clip-path: polygon(0 0, 100% 0, 100% 76%, 50% 100%, 0 76%);
}

.round {
  color: var(--dust);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 지금 들어가 있는 방 이름 */
.room-chip { display: flex; align-items: center; gap: 8px; }
.room-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--dust);
}

/* --------------------------------------------------- 제시어: 밑줄 글자칸 */

.word-slots {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
}
.slot {
  min-width: 36px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: var(--chalk);
  /* 빈 칸이 "채워질 자리"로 읽혀야 글자 수를 셀 수 있다. 밑줄만으로는 너무 약하다. */
  background: rgba(245, 239, 228, .06);
  border-radius: 7px 7px 3px 3px;
  border-bottom: 4px solid rgba(162, 148, 189, .6);
  animation: slotIn .3s ease-out backwards;
}
.slot.filled {
  color: var(--marker);
  background: rgba(255, 203, 71, .15);
  border-bottom-color: var(--marker);
}
.slot.gap { min-width: 14px; background: none; border-bottom-color: transparent; }
/* 출제자에게는 전부 보이므로, 비밀이라는 뜻으로 색을 달리한다. */
.word-slots.secret .slot.filled {
  color: var(--cool);
  background: rgba(94, 231, 213, .14);
  border-bottom-color: var(--cool);
}

@keyframes slotIn { from { opacity: 0; transform: translateY(7px); } }

/* --------------------------------------------------- 타이머: 닳는 크레용 */

.timer { display: flex; align-items: center; gap: 11px; width: 190px; }
.timer-num {
  font-size: 23px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}
.crayon {
  flex: 1;
  height: 15px;
  border-radius: 4px;
  background: var(--ink-3);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.crayon i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, var(--marker) 60%, #e5a91f 60%);
  /* 오른쪽 끝을 뾰족하게 깎아 크레용 심처럼 보이게 한다. */
  clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%);
  transition: width .12s linear, background .4s;
}
.timer.urgent .timer-num { color: var(--hot); }
.timer.urgent .crayon i { background: linear-gradient(180deg, var(--hot) 60%, #d94371 60%); }

/* --------------------------------------------------------------- 패널 공통 */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr) 306px;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  animation: riseIn .45s ease-out backwards;
}
.panel:nth-of-type(2) { animation-delay: .06s; }
@keyframes riseIn { from { opacity: 0; transform: translateY(10px); } }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--chalk);
}

.panel-foot { padding: 11px 13px; border-top: 1px solid var(--line); }
.panel-foot button { width: 100%; }

/* --------------------------------------------- 점수판: 참가자 = 크레용 한 자루 */

.players { list-style: none; margin: 0; padding: 9px; overflow-y: auto; flex: 1; }
.players li {
  --crayon: var(--dust);
  position: relative;
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 11px 12px 11px 15px;
  border-radius: 11px;
  margin-bottom: 5px;
  background: var(--ink-3);
  overflow: hidden;
}
/* 왼쪽 끝 크레용 심 */
.players li::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  background: var(--crayon);
}
.players li.me { box-shadow: inset 0 0 0 1px var(--marker); }
.players li.drawing {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--crayon) 26%, var(--ink-3)), var(--ink-3));
}
.rank { color: var(--dust); font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: center; }
.rank.brush { font-size: 14px; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pname .tag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--dust);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: 1.5px;
}
.pscore { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- 그림판: 도화지 */

.stage { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  overflow: hidden;
  background: #120e1a;
  border: 1px solid var(--line);
}
/* 종횡비를 고정해야 모든 참가자 화면에서 그림 비율이 똑같이 보인다. */
#board {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 1000 / 700;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  touch-action: none;
}
#board.drawable { cursor: crosshair; }

/* -------------------------------------------------------------- 오버레이 */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 30px;
  text-align: center;
  background: rgba(18, 13, 26, .93);
  backdrop-filter: blur(4px);
  animation: fadeIn .22s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }

.overlay h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.15;
}
.overlay p { margin: 0; color: var(--dust); max-width: 440px; font-size: 14.5px; }
.overlay .label {
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--dust);
}
.overlay .big {
  font-family: var(--font-display);
  font-size: 62px;
  font-weight: 700;
  line-height: 1;
  color: var(--marker);
  animation: stamp .4s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes stamp { from { transform: scale(.6) rotate(-4deg); opacity: 0; } }

/* 제시어 후보를 카드처럼 늘어놓는다 */
.overlay .cands { display: flex; gap: 13px; flex-wrap: wrap; justify-content: center; }
.overlay .cands button {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  padding: 20px 28px;
  min-width: 116px;
  border-radius: 14px;
  border-color: var(--line);
  background: var(--ink-2);
  box-shadow: 0 4px 0 #17112a;
}
.overlay .cands button:hover {
  border-color: var(--marker);
  color: var(--marker);
  transform: translateY(-3px) rotate(-1.2deg);
}
/* 몇 판 할지 고르는 칩 */
.overlay .chips { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; justify-content: center; }
.overlay .chips .chip {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  padding: 9px 20px;
  border-radius: 999px;
}
.overlay .chips .chip.on {
  border-color: var(--marker);
  background: rgba(255, 203, 71, .16);
  color: var(--marker);
}

.overlay .custom { display: flex; gap: 9px; width: 100%; max-width: 400px; }
.overlay .custom input { flex: 1; min-width: 0; }

.overlay .rank-list { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 360px; }
.overlay .rank-list li {
  --crayon: var(--dust);
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 11px;
  margin-bottom: 7px;
  background: var(--ink-3);
  overflow: hidden;
}
.overlay .rank-list li::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  background: var(--crayon);
}
.overlay .rank-list li:first-child {
  background: linear-gradient(90deg, rgba(255, 203, 71, .26), var(--ink-3));
  box-shadow: inset 0 0 0 1px var(--marker);
}
.overlay .rank-list .who { font-weight: 700; }
.overlay .rank-list .pts { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- 알림 · 꽃가루 */

.toast {
  position: absolute;
  z-index: 5;
  top: 18px; left: 50%;
  transform: translateX(-50%);
  padding: 13px 26px;
  border-radius: 999px;
  background: var(--marker);
  color: #2a1e05;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
  animation: dropIn .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes dropIn { from { opacity: 0; transform: translate(-50%, -18px); } }

.confetti { position: absolute; inset: 0; z-index: 4; overflow: hidden; pointer-events: none; }
.confetti span {
  position: absolute;
  top: -18px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  animation: fall 2.1s cubic-bezier(.35, .6, .5, 1) forwards;
}
@keyframes fall {
  to { transform: translateY(112vh) rotate(var(--spin, 360deg)); opacity: 0; }
}

/* -------------------------------------------------------------- 도구 */

.toolbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 11px 16px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: opacity .2s;
}
/* 잠길 때 도구만 흐려지게 한다. 왜 잠겼는지 알려주는 안내 문구는 또렷해야 한다. */
.toolbar.locked .tool-group { opacity: .35; pointer-events: none; }
.tool-group { display: flex; gap: 7px; align-items: center; }

.swatch {
  width: 27px; height: 27px; padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform .14s;
}
.swatch.on { border-color: var(--chalk); transform: scale(1.2); }

.wbtn { width: 36px; height: 32px; padding: 0; display: grid; place-items: center; }
.wbtn.on { border-color: var(--marker); background: rgba(255, 203, 71, .16); }
.wbtn i { display: block; background: var(--chalk); border-radius: 999px; }

.tool { font-size: 13px; padding: 8px 13px; }
.tool.on { border-color: var(--cool); background: rgba(94, 231, 213, .16); color: var(--cool); }
.tool-hint {
  margin-left: auto;
  color: var(--dust);
  font-family: var(--font-display);
  font-size: 18px;
}

/* -------------------------------------------------------------- 채팅 */

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.msg { font-size: 14px; word-break: break-word; animation: slideIn .2s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-5px); } }
.msg .who { font-weight: 800; margin-right: 5px; color: var(--crayon, var(--chalk)); }
.msg.system { color: var(--dust); font-size: 12.5px; }
.msg.notice { color: var(--hot); font-size: 12.5px; }
.msg.whisper { color: var(--cool); font-size: 13px; }
.msg.correct {
  color: #2a1e05;
  background: var(--marker);
  font-weight: 800;
  border-radius: 8px;
  padding: 7px 10px;
}
.chat-form { display: flex; gap: 9px; padding: 12px 14px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }

/* -------------------------------------------------------------- 모달 */

.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(14, 10, 20, .93);
}
.modal-card {
  position: relative;
  width: min(410px, 90vw);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 32px 30px;
  display: flex; flex-direction: column; gap: 15px;
  text-align: center;
  overflow: hidden;
  animation: dropIn .4s cubic-bezier(.2, 1.3, .4, 1);
}
/* 스케치북 상단 제본 띠 */
.modal-edge {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 7px;
  background: linear-gradient(90deg, var(--marker), var(--hot), var(--cool));
}
.modal-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 700;
}
.modal-card p { margin: 0; color: var(--dust); font-size: 14px; }
.modal-actions { display: flex; gap: 9px; justify-content: center; margin-top: 4px; }
.modal-actions button[type=submit] { flex: 1; }
.modal-card.wide { width: min(520px, 92vw); }

/* ------------------------------------------------------------ 로비 */

.entry-step { display: flex; flex-direction: column; gap: 13px; }
.entry-step p { margin: 0; color: var(--dust); font-size: 14px; }
.entry-step p b { color: var(--chalk); }

.lobby-row { display: flex; gap: 8px; }
.lobby-row input { flex: 1; min-width: 0; }

.lobby-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--dust);
}

.lobby-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  text-align: left;
}
.lobby-list .empty { color: var(--dust); font-size: 13px; text-align: center; padding: 18px 0; }
.lobby-list li button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 11px;
}
.lobby-list li button:hover { border-color: var(--marker); }
.lobby-list .rname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.lobby-list .rmeta { font-size: 12px; color: var(--dust); font-weight: 500; }
.lobby-list .rgo { font-size: 12.5px; font-weight: 700; color: var(--marker); }
.lobby-error { color: var(--hot) !important; font-size: 13px; }

/* ------------------------------------------------------------ 좁은 화면 */

@media (max-width: 1120px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr) 250px; gap: 12px; padding: 12px; }
  .word-slots .slot { min-width: 26px; height: 36px; font-size: 26px; }
  .overlay h2 { font-size: 32px; }
  .overlay .big { font-size: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
