/* 뭐 그렸게? — 채팅·입력이 있는 DOM 게임이라 공통 스타일 일부를 덮어쓴다 */
[hidden] { display: none !important; }

html, body {
  /* 공통은 none 이지만 여기선 채팅 목록을 손가락으로 스크롤해야 한다. 막는 건 캔버스만 */
  touch-action: manipulation;
}
input {
  font: inherit;
  user-select: text;
  -webkit-user-select: text;
}

/* 화상 키보드가 올라오면 game.js 가 --vh 를 보이는 높이로 줄인다 */
#app {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--vh, 100%);
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}

button.small { font-size: 15px; letter-spacing: 1px; padding: 9px 16px; }
button.tiny { font-size: 12px; letter-spacing: 0; padding: 3px 8px; box-shadow: none; }
button.ghost.tiny { box-shadow: inset 0 0 0 1px var(--muted); }
button.icon {
  padding: 4px 6px;
  font-size: 18px;
  letter-spacing: 0;
  background: transparent;
  box-shadow: none;
}
button:disabled { opacity: 0.45; cursor: default; }

/* ── 첫 화면 ─────────────────────────────────────────────── */
.home {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: max(24px, 8vh) 16px 24px;
  text-align: center;
}
.home h1 { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 2px; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(320px, 100%); }
.stack > button { width: 100%; }
.row { display: flex; gap: 8px; width: 100%; }
.row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; width: min(320px, 100%); font-size: 13px; color: var(--muted); text-align: left; }
.home input, .chat-form input {
  padding: 10px 12px;
  font-size: 16px;   /* 16px 미만이면 iOS 가 입력할 때 화면을 확대한다 */
  color: var(--fg);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  outline: none;
}
.home input:focus, .chat-form input:focus { border-color: var(--accent-2); }
.join-to { margin: 0; color: var(--muted); }
.join-to b { color: var(--accent); font-family: ui-monospace, Menlo, monospace; font-size: 20px; letter-spacing: 3px; }
.err { margin: 0; min-height: 1.4em; color: #ff5d73; font-size: 14px; }

/* ── 방 화면 ─────────────────────────────────────────────── */
.room {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.round { min-width: 3.2em; font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--muted); }
.word-box { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.word {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 3px;
  color: var(--accent);
}
.word.status { font-size: 14px; font-weight: normal; letter-spacing: 0; color: var(--muted); }
.time { min-width: 2.4em; text-align: right; font-family: ui-monospace, Menlo, monospace; font-size: 20px; font-weight: bold; color: var(--accent-2); }
.time.hurry { color: #ff5d73; }

.board-col { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding-top: 6px; }
.board-wrap {
  position: relative;
  width: var(--board, 300px);
  height: var(--board, 300px);
}
#board {
  width: 100%;
  height: 100%;
  background: #fff;
  image-rendering: auto;
  border-radius: 4px;
  touch-action: none;   /* 그리는 동안 페이지가 스크롤·확대되지 않게 */
  cursor: crosshair;
}

.board-ov {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;   /* 판이 작아 넘치면 위가 잘리지 않고 스크롤되게 */
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  text-align: center;
  border-radius: 4px;
  background: rgba(5, 6, 15, 0.9);
}
.board-ov.dim { background: rgba(5, 6, 15, 0.62); }
.board-ov p { margin: 0; }
.board-ov button:not(.tiny):not(.small) { font-size: 17px; letter-spacing: 2px; padding: 10px 30px; }
.board-ov h2 { margin: 0; color: var(--accent); font-size: 20px; letter-spacing: 2px; }
.label { color: var(--muted); font-size: 13px; }
.big-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: min(72px, calc(var(--board, 300px) * 0.2));
  font-weight: bold;
  line-height: 1;
  letter-spacing: 10px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #d6336c;
  user-select: text;
  -webkit-user-select: text;
}
.reveal-word { font-size: min(44px, calc(var(--board, 300px) * 0.12)); font-weight: bold; color: var(--accent); text-shadow: 2px 2px 0 #d6336c; }
.gains, .ranking { list-style: none; margin: 0; padding: 0; width: min(280px, 100%); font-size: 14px; }
.gains li, .ranking li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 4px; }
.gains li span:last-child { color: var(--accent-2); }
.ranking li { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 15px; }
.ranking li.me { color: var(--accent); }
.ranking .medal { display: inline-block; width: 1.8em; }

/* 도구: 높이를 고정해 그리는 사람이 바뀌어도 판 크기가 그대로다 */
.tools {
  /* 판이 아주 작아도 버튼이 손가락 크기 아래로 줄지 않게 최소 폭을 둔다 */
  width: max(var(--board, 300px), min(100vw - 16px, 360px));
  height: 44px;
  display: flex;
  align-items: center;
}
.tool-set { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.swatches, .sizes { display: flex; align-items: center; gap: 3px; }
.swatch, .size, .tool {
  width: clamp(24px, 6.6vw, 30px);
  height: clamp(24px, 6.6vw, 30px);
  padding: 0;
  border-radius: 50%;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.swatch:active, .size:active, .tool:active { transform: none; }
.swatch.on, .size.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.swatch.eraser { background: #fff; font-size: 13px; }
.size { display: grid; place-items: center; background: rgba(255, 255, 255, 0.08); }
.size i { display: block; border-radius: 50%; background: var(--fg); }
.tool { border-radius: 6px; font-size: 16px; color: var(--fg); background: rgba(255, 255, 255, 0.1); }
.tool-note { margin: 0; width: 100%; text-align: center; font-size: 13px; color: var(--muted); }

/* ── 참가자 · 채팅 ───────────────────────────────────────── */
.side { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 0 8px 8px; }
.players {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
.players li {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 13px;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}
.players li.me { box-shadow: inset 0 0 0 1px var(--accent); }
.players li.drawer { background: rgba(255, 210, 63, 0.18); }
.players li.guessed { background: rgba(76, 242, 255, 0.16); }
.players li.off { opacity: 0.45; }
.players .score { color: var(--accent-2); font-family: ui-monospace, Menlo, monospace; }
.players .kick {
  padding: 0 4px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  box-shadow: none;
  letter-spacing: 0;
}

.chat {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 4px 2px;
  list-style: none;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.chat li { padding: 1px 0; overflow-wrap: anywhere; }
.chat .who { margin-right: 6px; color: var(--accent-2); }
.chat .sys { color: var(--muted); font-size: 13px; }
.chat .good { color: #7dffa1; font-weight: bold; }
.chat .warn { color: #ff5d73; font-size: 13px; }
.chat .secret { color: #b9f3c8; }
.chat .secret .who::after { content: " (정답자끼리)"; font-size: 11px; color: var(--muted); }

.chat-form { flex: 0 0 auto; display: flex; gap: 6px; padding-top: 6px; }
.chat-form input { flex: 1; min-width: 0; padding: 8px 10px; }

.conn {
  position: absolute;
  left: 50%;
  top: 52px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
  background: #3a1420;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  z-index: 5;
}

/* 넓은 화면: 판은 왼쪽, 참가자·채팅은 오른쪽 */
.wide .room {
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: auto 1fr;
}
.wide .bar { grid-column: 1 / -1; }
.wide .board-col { padding: 10px 0; }
.wide .side { padding: 10px 10px 10px 0; }
.wide .players { flex-direction: column; overflow-x: visible; overflow-y: auto; max-height: 40%; touch-action: pan-y; }
.wide .players li { border-radius: 6px; padding: 5px 8px; }
.wide .players .name { flex: 1; }
