/* ── 기본 / 변수 ─────────────────────────────────────────── */
:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232730;
  --line: #2e3340;
  --text: #e8eaed;
  --muted: #9aa0ac;
  --primary: #5b8cff;
  --primary-dark: #4574e6;
  --accent: #ffcb47;
  --correct: #38d39f;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ── 버튼 ────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
  color: #fff;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--panel-2); border: 1px solid var(--line); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ── 진입 화면 ───────────────────────────────────────────── */
#screen-entry { align-items: center; justify-content: center; padding: 20px; }
.entry-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.logo { font-size: 34px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 26px; font-size: 14px; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 20px 0; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 700; }
.join-row .btn { white-space: nowrap; }

.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 14px 0 0; }

/* ── 대기실 ──────────────────────────────────────────────── */
#screen-lobby { align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.lobby-card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.lobby-card h2 { margin: 0 0 16px; }
.room-code-box {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 18px; font-size: 16px;
}
.room-code-box strong { font-size: 28px; letter-spacing: 6px; color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0; line-height: 1.5; }

.lobby-players { margin: 20px 0; }
.lobby-players h3 { font-size: 15px; margin: 0 0 10px; }
#lobby-player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
#lobby-player-list li {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 7px 13px; border-radius: 20px; font-size: 14px;
}
#lobby-player-list li.host::after { content: " 👑"; }

.lobby-controls { margin-top: 8px; }
.rounds-field { max-width: 140px; }

/* ── 게임 화면 ───────────────────────────────────────────── */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  gap: 10px;
}
.hdr-left { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); flex: 1; }
.hdr-round { background: var(--panel-2); padding: 5px 10px; border-radius: 8px; color: var(--text); font-weight: 700; }
.hdr-center { flex: 2; display: flex; justify-content: center; }
.hdr-right { flex: 1; display: flex; justify-content: flex-end; }

.word-display {
  font-size: 22px; font-weight: 800; letter-spacing: 6px;
  color: var(--accent); text-align: center; white-space: nowrap;
}
.word-display small { font-size: 13px; color: var(--muted); letter-spacing: 0; font-weight: 500; }

.timer { font-size: 24px; font-weight: 800; color: var(--text); }
.timer-unit { font-size: 13px; color: var(--muted); }

.timer-bar-wrap { height: 4px; background: var(--panel-2); }
.timer-bar { height: 100%; width: 100%; background: var(--correct); transition: width 1s linear; }
.timer-bar.low { background: var(--danger); }

.game-body { flex: 1; display: flex; gap: 12px; padding: 12px; min-height: 0; }

/* 캔버스 */
.canvas-area { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.canvas-wrap {
  position: relative; flex: 1; display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; min-height: 0;
}
#board {
  background: #fff; border-radius: 8px;
  max-width: 100%; max-height: 100%;
  aspect-ratio: 4 / 3; width: auto; height: auto;
  touch-action: none; cursor: crosshair;
}
.canvas-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 17, 21, 0.7); font-size: 18px; font-weight: 700; text-align: center;
  padding: 20px; pointer-events: none;
}

/* 이모지 반응 — 떠오름 레이어 */
.emoji-float {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5;
}
.emoji-float .fx {
  position: absolute; bottom: 8px;
  animation: floatUp 2s ease-out forwards;
  will-change: transform, opacity;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}
@keyframes floatUp {
  0%   { transform: translateY(0) scale(0.5); opacity: 0; }
  15%  { transform: translateY(-16px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-230px) scale(1) rotate(8deg); opacity: 0; }
}

/* 이모지 반응 바 */
.emoji-bar {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px;
}
.emoji-bar button {
  font-size: 22px; line-height: 1; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px; cursor: pointer; transition: transform 0.05s ease, background 0.15s ease;
}
.emoji-bar button:hover { background: var(--line); }
.emoji-bar button:active { transform: scale(1.25); }

/* 그리기 도구 */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px;
}
.colors, .sizes { display: flex; gap: 6px; align-items: center; }
.color-swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--primary); }
.size-dot {
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.size-dot.active { border-color: var(--primary); }
.size-dot i { display: block; border-radius: 50%; background: var(--text); }
.tool-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tool-btn.active { border-color: var(--primary); background: var(--primary); }

/* 사이드바 */
.sidebar { width: 300px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.scoreboard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; max-height: 38%; overflow: auto;
}
.scoreboard h3 { margin: 0 0 10px; font-size: 14px; }
#score-list { list-style: none; padding: 0; margin: 0; }
#score-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px; border-radius: 8px; font-size: 14px;
}
#score-list li.is-drawer { background: rgba(255, 203, 71, 0.12); }
#score-list li.is-correct { color: var(--correct); }
#score-list li .sc-name { display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#score-list li .sc-score { font-weight: 700; }
.dot-on { width: 7px; height: 7px; border-radius: 50%; background: var(--correct); flex: none; }
.dot-off { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; opacity: 0.5; }

.chat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { font-size: 14px; line-height: 1.4; word-break: break-word; }
.chat-msg .nm { font-weight: 700; color: var(--primary); }
.chat-msg.system { color: var(--muted); font-style: italic; font-size: 13px; }
.chat-msg.correct { color: var(--correct); font-weight: 700; }
.chat-msg.only-correct { background: rgba(56, 211, 159, 0.1); border-radius: 6px; padding: 2px 6px; }
.chat-msg.only-correct .nm { color: var(--correct); }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }

/* ── 오버레이 (제시어 선택 / 종료 / 다시보기) ─────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 9, 12, 0.78);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; max-width: 560px; width: 100%; box-shadow: var(--shadow);
  text-align: center; max-height: 90vh; overflow: auto;
}
.overlay-card h2 { margin: 0 0 8px; }
.word-choices { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.word-choices .btn { font-size: 18px; padding: 16px; }

/* 결과 / 다시보기 */
.result-ranking { list-style: none; padding: 0; margin: 18px 0; text-align: left; }
.result-ranking li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 10px; background: var(--panel-2);
  margin-bottom: 8px; font-size: 16px;
}
.result-ranking li .rk { font-size: 20px; width: 32px; text-align: center; }
.result-ranking li .nm { flex: 1; font-weight: 600; }
.result-ranking li .sc { font-weight: 800; color: var(--accent); }
.result-ranking li:first-child { background: rgba(255, 203, 71, 0.15); border: 1px solid var(--accent); }

.replay-wrap { margin: 16px 0; }
.replay-canvas {
  background: #fff; border-radius: 10px; width: 100%; aspect-ratio: 4/3;
  display: block; border: 1px solid var(--line);
}
.replay-caption { margin: 10px 0; font-size: 15px; }
.replay-caption b { color: var(--accent); }
.replay-controls { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.replay-progress { color: var(--muted); font-size: 13px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

/* ── 모바일 ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  .game-body { flex-direction: column; padding: 8px; gap: 8px; }
  .sidebar { width: 100%; flex-direction: row; height: 200px; }
  .scoreboard { max-height: none; width: 40%; }
  .chat { width: 60%; }
  .word-display { font-size: 18px; letter-spacing: 4px; }
  .hdr-code { display: none; }
}
