:root {
  --bg: #0f1222;
  --panel: #1a1f36;
  --panel-2: #232a48;
  --line: #313a63;
  --text: #eef1ff;
  --muted: #9aa3c7;
  --accent: #ffb703;
  --accent-2: #fb8500;
  --good: #34d399;
  --bad: #f87171;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 20% 0%, #1d2450 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 15px;
}
h1, h2 { margin: 0 0 .6rem; }
h1 { font-size: 1.8rem; color: var(--accent); }
h2 { font-size: 1.3rem; }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.center { text-align: center; }

button, input {
  font: inherit;
  color: inherit;
}
input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65rem .8rem;
  min-width: 0;
  flex: 1;
  outline: none;
}
input:focus { border-color: var(--accent); }
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .05s, background .15s;
}
button:hover:not(:disabled) { background: #2d3560; }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1b1300; border: none; font-weight: 700; }
button.primary:hover:not(:disabled) { filter: brightness(1.07); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
button.ghost { background: transparent; }
button.small { padding: .35rem .7rem; font-size: .85rem; }
button.wide { width: 100%; margin-top: .6rem; }

/* 상단바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .6rem 1rem;
  background: rgba(15, 18, 34, .9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.1rem; }
.top-info { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .25rem .7rem; font-size: .85rem; }
.timer b { color: var(--accent); font-variant-numeric: tabular-nums; }
.timer.urgent { border-color: var(--bad); animation: pulse 1s infinite; }
.timer.urgent b { color: var(--bad); }
.conn.ok { color: var(--good); }
.conn.bad { color: var(--bad); }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(248, 113, 113, .25); } }

/* 레이아웃 */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  padding: 1rem;
  max-width: 1280px;
  margin: 0 auto;
  min-height: calc(100vh - 56px);
}
.layout:not(:has(.chat:not([hidden]))) { grid-template-columns: minmax(0, 1fr); }
.stage { min-width: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.narrow { max-width: 520px; margin: 0 auto; }
.row { display: flex; gap: .5rem; margin-top: .6rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin: 1rem 0 .4rem; color: var(--muted); font-size: .9rem; }
.field input { color: var(--text); }
.divider { text-align: center; margin: 1.2rem 0 .4rem; color: var(--muted); font-size: .85rem; position: relative; }
.divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--line); }
.divider span { background: var(--panel); padding: 0 .6rem; position: relative; }
.rules { margin-top: 1.2rem; color: var(--muted); }
.rules summary { cursor: pointer; color: var(--text); }
.rules ol { padding-left: 1.2rem; line-height: 1.7; }

/* 대기실 */
.code-box { display: flex; justify-content: space-between; align-items: center; gap: .5rem; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem; }
.code { font-size: 1.5rem; letter-spacing: .2em; color: var(--accent); }
.player-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.player-list li { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; display: flex; align-items: center; gap: .4rem; overflow: hidden; }
.player-list li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.player-list li.me { border-color: var(--accent); }
.player-list li.off { opacity: .45; }
.player-list .num { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.player-list.compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

/* 주제어 선택 */
.choices { display: grid; gap: .6rem; margin: 1rem 0; }
.choices button { font-size: 1.15rem; padding: 1rem; text-align: center; }

/* 그리기 */
.prompt-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: .7rem; display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.prompt-label { color: var(--muted); font-size: .9rem; }
.prompt-text { font-size: 1.5rem; color: var(--accent); word-break: break-all; }
.canvas-wrap { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); line-height: 0; }
#canvas { width: 100%; height: auto; aspect-ratio: 4 / 3; touch-action: none; cursor: crosshair; display: block; }
.tools { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: .7rem; }
.tools #submitDrawBtn { margin-left: auto; padding: .7rem 1.4rem; }
.palette { display: flex; flex-wrap: wrap; gap: .3rem; }
.swatch { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 2px solid var(--line); }
.swatch.active { outline: 3px solid var(--accent); outline-offset: 1px; }
.tool-group { display: flex; gap: .3rem; }
.size-btn { width: 42px; padding: .4rem 0; }
.size-btn.active, #eraserBtn.active { border-color: var(--accent); color: var(--accent); }
.draw-locked #canvas { opacity: .6; cursor: not-allowed; }

/* 맞히기 */
.guess-image { background: #fff; border-radius: var(--radius); overflow: hidden; margin: .6rem 0; line-height: 0; }
.guess-image img { width: 100%; height: auto; display: block; }
.empty { color: #666; padding: 4rem 1rem; text-align: center; line-height: 1.5; background: #fafafa; }

/* 공개 */
.reveal-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.reveal-pages { display: flex; flex-direction: column; gap: .8rem; max-height: calc(100vh - 230px); overflow-y: auto; padding-right: .3rem; }
.page-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; animation: flipIn .45s ease; }
.page-card.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 183, 3, .25); }
.page-card .ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; gap: .5rem; }
.page-card .ph .who { color: var(--muted); font-size: .9rem; }
.page-card .big-word { font-size: 1.8rem; font-weight: 800; color: var(--accent); text-align: center; padding: 1.2rem 0; word-break: break-all; }
.page-card .guess-text { font-size: 1.5rem; font-weight: 700; text-align: center; padding: 1rem 0; word-break: break-all; }
.page-card .guess-text.none { color: var(--muted); font-weight: 400; font-size: 1.1rem; }
.page-card .img-box { background: #fff; border-radius: 10px; overflow: hidden; line-height: 0; max-width: 640px; margin: 0 auto; }
.page-card .img-box img { width: 100%; height: auto; }
.like-btn { padding: .3rem .7rem; font-size: .9rem; }
.like-btn.liked { color: #ff6b8b; border-color: #ff6b8b; }
@keyframes flipIn { from { opacity: 0; transform: perspective(800px) rotateX(-18deg) translateY(-8px); } to { opacity: 1; transform: none; } }
.reveal-summary { margin-top: .8rem; padding: .8rem 1rem; border-radius: var(--radius); text-align: center; font-size: 1.1rem; background: var(--panel-2); border: 1px solid var(--line); }
.reveal-summary.ok { border-color: var(--good); }
.reveal-summary.ng { border-color: var(--bad); }
.reveal-controls { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: .8rem; }
.reveal-controls .muted { text-align: center; flex: 1; font-size: .9rem; }

/* 결과 */
.awards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .7rem; margin: .8rem 0 1.2rem; }
.award { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; text-align: center; }
.award .t { color: var(--muted); font-size: .9rem; }
.award .n { font-size: 1.2rem; font-weight: 800; color: var(--accent); margin-top: .3rem; word-break: break-all; }
table { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; font-size: .92rem; }
th, td { border-bottom: 1px solid var(--line); padding: .5rem .4rem; text-align: left; word-break: break-all; }
th { color: var(--muted); font-weight: 600; }

/* 채팅 */
.chat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  height: calc(100vh - 88px);
  position: sticky; top: 72px;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem .8rem; border-bottom: 1px solid var(--line); font-weight: 700; }
.chat-list { list-style: none; margin: 0; padding: .6rem .8rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.chat-list li { line-height: 1.4; word-break: break-word; font-size: .92rem; }
.chat-list li .n { font-weight: 700; color: var(--accent); margin-right: .35rem; }
.chat-list li.mine .n { color: var(--good); }
.chat-list li.sys { color: var(--muted); font-size: .85rem; text-align: center; }
.chat-form { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--line); }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: #000c; border: 1px solid var(--line); padding: .7rem 1.2rem; border-radius: 999px; z-index: 50;
  max-width: 90vw; text-align: center;
}

/* 모바일 */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: .6rem; }
  .chat { height: 300px; position: static; }
  .reveal-pages { max-height: none; }
  .card { padding: 1rem; }
  .tools #submitDrawBtn { width: 100%; margin-left: 0; }
  .brand { font-size: 1rem; }
}
