@font-face {
  font-family: 'Galmuri11';
  src: url('/lib/galmuri/Galmuri11.woff2') format('woff2');
}
@font-face {
  font-family: 'Galmuri11';
  font-weight: bold;
  src: url('/lib/galmuri/Galmuri11-Bold.woff2') format('woff2');
}

:root {
  --bg: #1b1626;
  --panel: #2b2240;
  --panel-2: #3a2f57;
  --ink: #fff7e8;
  --muted: #b9acd6;
  --accent: #ffcf4a;
  --accent-ink: #3a2400;
  --danger: #ff6b7a;
  --line: #120e1b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Galmuri11', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game { position: fixed; inset: 0; }
#game canvas { image-rendering: pixelated; }

button, input { font: inherit; color: inherit; }
input { user-select: text; -webkit-user-select: text; }

/* ---------- 메뉴 ---------- */
.screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 50% 30%, #3b2c63 0, transparent 60%),
    repeating-linear-gradient(0deg, #1b1626 0 8px, #1e1829 8px 16px);
  z-index: 20;
}
.panel {
  width: min(340px, 100%);
  background: var(--panel);
  border: 4px solid var(--line);
  box-shadow: 0 0 0 4px var(--panel-2), 8px 8px 0 4px #0008;
  padding: 20px 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.logo {
  margin: 0; text-align: center; line-height: 1;
  font-size: 34px; letter-spacing: 2px;
  color: #7fd4ff; text-shadow: 3px 3px 0 var(--line);
}
.logo span { color: var(--accent); font-size: 40px; }
.sub { margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

input {
  width: 100%;
  background: #1a1428;
  border: 3px solid var(--line);
  padding: 10px;
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  background: var(--panel-2);
  border: 3px solid var(--line);
  box-shadow: inset 0 -4px 0 #0004;
  padding: 10px 12px;
  font-size: 15px;
  cursor: pointer;
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 #0004; }
.btn-main { background: var(--accent); color: var(--accent-ink); font-weight: bold; font-size: 17px; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.join-row .btn { flex: 0 0 80px; }
.error { margin: 0; min-height: 1em; color: var(--danger); font-size: 12px; text-align: center; }

/* ---------- 캐릭터 생성 ---------- */
#creator { z-index: 21; overflow-y: auto; }
#creator[hidden] { display: none; }
.cc-panel { width: min(560px, 100%); }
.cc-title { margin: 0; text-align: center; font-size: 20px; color: var(--accent); }
.cc-body { display: grid; grid-template-columns: 160px 1fr; gap: 16px; }
.cc-stage { display: flex; flex-direction: column; gap: 8px; align-items: center; }
#cc-canvas {
  width: 144px; height: 144px; image-rendering: pixelated;
  background: #1a1428; border: 3px solid var(--line);
}
.cc-turn { display: flex; gap: 8px; }
.cc-turn .btn { padding: 6px 16px; }
#cc-random { width: 150px; padding: 6px; font-size: 13px; }
.cc-options { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cc-group { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.cc-chips, .cc-swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.cc-chips button {
  flex: 1 1 40%; padding: 6px 4px; font-size: 12px; cursor: pointer;
  background: var(--panel-2); border: 3px solid var(--line);
}
.cc-swatches button { width: 28px; height: 28px; padding: 0; cursor: pointer; background: var(--c); border: 3px solid var(--line); }
.cc-chips button.on { background: var(--accent); color: var(--accent-ink); font-weight: bold; }
.cc-swatches button.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.me-row { display: flex; align-items: center; gap: 10px; }
#me-look { width: 64px; height: 64px; image-rendering: pixelated; background: #1a1428; border: 3px solid var(--line); }
.me-row .btn { flex: 1; font-size: 13px; }
@media (max-width: 500px) {
  .cc-body { grid-template-columns: 1fr; }
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#hud[hidden] { display: none; }

.room-badge {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left));
  display: flex; align-items: stretch;
  background: var(--panel); border: 3px solid var(--line);
  font-size: 12px;
}
.room-badge > * { padding: 6px 10px; display: flex; align-items: center; }
.room-type { color: var(--muted); border-right: 3px solid var(--line); }
.room-code { background: none; border: 0; border-right: 3px solid var(--line); gap: 6px; cursor: pointer; }
.room-code small { color: var(--muted); font-size: 10px; }
.room-code b { color: var(--accent); font-size: 16px; letter-spacing: 3px; }

/* 채팅은 왼쪽 아래 입력창 바로 위. 글은 잠깐 떴다 사라지고, 입력창을 누르면 지난 글이 다시 보인다 */
#chat-log {
  position: absolute; left: max(8px, env(safe-area-inset-left)); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 44px);
  width: min(380px, calc(100% - 16px)); max-height: 45vh; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 3px;
  pointer-events: none !important;
  font-size: 12px;
}
#chat-log .log-line:nth-last-child(n+7) { display: none; }
body.chatting #chat-log .log-line { display: block; animation: none; opacity: 1; }
.log-line {
  background: #120e1bcc; padding: 4px 8px; border-left: 3px solid var(--c, #fff);
  word-break: break-all;
  animation: fade 10s forwards;
}
.log-line b { color: var(--c); margin-right: 4px; }
.log-line.sys { color: var(--muted); border-left-color: var(--muted); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

.bottom-bar {
  position: absolute; left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(380px, calc(100% - 16px));
  display: flex; flex-direction: column; gap: 6px;
}
.quick { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip {
  background: var(--panel); border: 3px solid var(--line);
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  box-shadow: inset 0 -3px 0 #0004;
}
.chip:active { transform: translateY(2px); }
.chip.emo { padding: 2px 8px; font-size: 14px; }
.chat-row { display: flex; gap: 6px; }
.chat-row input { padding: 8px 10px; font-size: 14px; background: #1a1428e6; }
.btn-send { flex: 0 0 auto; padding: 6px 14px; font-size: 14px; }

#toast {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); border: 3px solid var(--line);
  padding: 6px 12px; font-size: 13px; opacity: 0; transition: opacity .2s;
  pointer-events: none !important;
}
#toast.show { opacity: 1; }

/* ---------- 모바일 조이스틱 ---------- */
#joy-zone {
  position: absolute; left: 0; top: 60px; bottom: 90px; width: 45%;
  display: none;
}
body.touch #joy-zone { display: block; }
#joy-base {
  position: absolute; width: 96px; height: 96px; margin: -48px 0 0 -48px;
  border: 3px solid #fff5; border-radius: 50%; background: #0003;
  left: 90px; top: 65%;
  opacity: .5;
}
#joy-base.active { opacity: 1; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%; background: #fffc; border: 3px solid var(--line);
}

/* 모바일 가로 화면은 높이가 낮으므로 메뉴는 2단, HUD는 압축 */
@media (max-height: 420px) {
  .screen { overflow-y: auto; padding: 8px; }
  #menu .panel {
    width: min(620px, 100%);
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; row-gap: 8px;
    padding: 14px;
  }
  .logo { grid-column: 1; grid-row: 1 / span 3; align-self: center; font-size: 30px; }
  .logo span { font-size: 36px; }
  .sub { grid-column: 1; grid-row: 4 / span 2; margin: 0; }
  #menu .field, #menu .panel > .btn, #menu .join-row, #menu .error { grid-column: 2; }
  .field input, .join-row input { padding: 7px; }
  #menu .panel .btn { padding: 7px 10px; }

  .room-badge { font-size: 10px; }
  .room-badge > * { padding: 4px 8px; }
  .room-code b { font-size: 13px; }
  .chip { padding: 2px 8px; font-size: 11px; }
  .chat-row input { padding: 5px 8px; font-size: 13px; }
  .btn-send { padding: 4px 10px; font-size: 13px; }
  .bottom-bar { width: min(440px, 55%); left: auto; right: max(8px, env(safe-area-inset-right)); }
  #joy-zone { bottom: 8px; top: 48px; }
}

#rotate {
  position: fixed; inset: 0; z-index: 50;
  display: none; place-content: center; text-align: center;
  background: var(--bg); font-size: 18px; line-height: 2;
}
@media (orientation: portrait) and (pointer: coarse) {
  body.in-game #rotate { display: grid; }
}

/* 모바일 가로: 채팅 로그는 최근 3줄만, 반투명하게 */
@media (max-height: 420px) {
  #chat-log { width: min(440px, 55%); left: auto; right: max(8px, env(safe-area-inset-right)); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 36px); max-height: 60vh; font-size: 10px; gap: 2px; }
  #chat-log .log-line { background: #120e1b99; padding: 2px 6px; }
  #chat-log .log-line:nth-last-child(n+4) { display: none; }
}

/* 휴대폰: 채팅은 오른쪽 위에 작게. 입력창 밑에 최근 3줄만 보이고, 입력 중이면 지난 글도 보인다 */
body.touch .bottom-bar {
  top: calc(max(8px, env(safe-area-inset-top)) + 38px); bottom: auto; left: auto; right: max(8px, env(safe-area-inset-right));
  width: min(200px, 32%);
}
body.touch .chat-row input { padding: 3px 6px; font-size: 11px; }
body.touch .btn-send { display: none; }
body.touch #chat-log {
  top: calc(max(8px, env(safe-area-inset-top)) + 66px); bottom: auto !important; left: auto; right: max(8px, env(safe-area-inset-right));
  width: min(200px, 32%); max-height: 55vh; font-size: 9px; gap: 1px;
}
body.touch #chat-log .log-line { background: #120e1b99; padding: 1px 4px; border-left-width: 2px; }
body.touch #chat-log .log-line:nth-last-child(n+4) { display: none; }
body.touch.chatting #chat-log .log-line { display: block; }
body.touch:has(#market-board.fish:not([hidden])) #chat-log { display: none; }

/* ---------- 누적 점수판 ---------- */
#score-board {
  position: absolute; left: max(8px, env(safe-area-inset-left)); top: calc(max(8px, env(safe-area-inset-top)) + 40px);
  background: #120e1bcc; border: 3px solid var(--line); padding: 6px 10px;
  font-size: 11px; display: flex; flex-direction: column; gap: 2px; min-width: 120px;
  pointer-events: none !important;
}
#score-board h3 { margin: 0 0 2px; font-size: 11px; color: var(--accent); }
#score-board .row { display: flex; gap: 6px; }
#score-board .row b { color: var(--c); flex: 1; }

/* ---------- 오락기 시작 버튼 ---------- */
/* 왼쪽 아래 채팅과 겹치지 않게 그 오른쪽에 둔다 */
#actions {
  position: absolute; left: min(396px, 45%); right: 8px;
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px);
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  animation: bob 0.8s ease-in-out infinite alternate;
}
#actions[hidden] { display: none; }
#actions { z-index: 5; } /* 모바일 조이스틱 터치 영역보다 위에 있어야 눌린다 */
#actions .btn { font-size: 14px; }
@keyframes bob { from { margin-bottom: 0; } to { margin-bottom: 4px; } }

/* 레이스 중에는 대기실 조작 UI를 숨김 */
body.racing .bottom-bar, body.racing #joy-zone, body.racing #actions { display: none !important; }

/* ---------- 레이스 HUD ---------- */
#race-hud { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
#race-hud[hidden] { display: none; }
.race-top {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px;
}
.race-box {
  background: var(--panel); border: 3px solid var(--line); padding: 4px 10px;
  display: flex; flex-direction: column; align-items: center; min-width: 64px;
  font-variant-numeric: tabular-nums;
}
.race-box small { font-size: 9px; color: var(--muted); }
.race-box b { font-size: 16px; }
.race-pos { flex-direction: row; align-items: baseline; gap: 2px; background: var(--accent); color: var(--accent-ink); }
.race-pos b { font-size: 24px; }
.race-pos small { color: var(--accent-ink); font-size: 12px; }
#race-count {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-size: 72px; font-weight: bold; color: var(--accent); text-shadow: 5px 5px 0 var(--line);
}
#race-intro {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: #ffffff8c;
}
#race-intro[hidden] { display: none; }
.ri-box {
  width: min(360px, calc(100vw - 32px)); padding: 10px 12px;
  background: var(--panel); border: 3px solid var(--line); text-align: center;
}
.ri-title { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ri-row { padding: 4px 8px; font-size: 15px; color: var(--muted); border: 2px solid transparent; }
.ri-row.on { background: var(--accent); color: var(--accent-ink); border-color: var(--line); font-weight: bold; }
.ri-row.won { animation: ri-blink 0.25s steps(2) 4; }
@keyframes ri-blink { 50% { background: var(--ink); } }
.ri-result { visibility: hidden; margin-top: 8px; padding-top: 8px; border-top: 3px solid var(--line); }
.ri-result.show { visibility: visible; }
.ri-mode { font-size: 28px; font-weight: bold; color: var(--accent); text-shadow: 3px 3px 0 var(--line); }
.ri-sub { font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
#win-show {
  position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center;
  pointer-events: none; overflow: hidden;
}
#win-show[hidden] { display: none; }
.lw-sparks { position: absolute; left: 50%; top: 50%; }
.lw-sparks i {
  position: absolute; width: 8px; height: 8px; background: var(--c); opacity: 0;
  animation: lw-burst 1.8s ease-out both;
}
@keyframes lw-burst {
  0% { transform: translate(0, 0); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--x), calc(var(--y) + 120px)); opacity: 0; }
}
.lw-card {
  position: relative; display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center;
  max-width: calc(100vw - 32px);
  -webkit-text-stroke: 6px var(--line); paint-order: stroke fill;
  animation: lw-pop 0.35s steps(4) both;
}
@keyframes lw-pop { from { transform: scale(0.4); } to { transform: scale(1); } }
.lw-card small { color: var(--ink); font-size: clamp(16px, 3.5vw, 24px); -webkit-text-stroke-width: 6px; }
.lw-card b { font-size: clamp(26px, 7vw, 48px); color: var(--ink); }
.lw-card strong { font-size: clamp(36px, 10vw, 72px); color: var(--accent); -webkit-text-stroke-width: 8px; }
#race-help {
  position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 12px; background: #120e1bcc; padding: 4px 10px; white-space: nowrap;
}
body.touch #race-help { display: none; }
.race-pad {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom));
  display: none; gap: 12px; pointer-events: auto;
}
body.touch .race-pad { display: flex; }
.pad-left { left: max(14px, env(safe-area-inset-left)); }
.pad-right { right: max(14px, env(safe-area-inset-right)); }
.pad-btn {
  width: 76px; height: 76px; display: grid; place-items: center;
  background: #120e1b88; border: 3px solid #fff6; color: #fffc; font-size: 30px;
  touch-action: none;
}
.pad-btn.brake { width: 96px; font-size: 15px; background: #8a1f2a99; }
.pad-btn.on { background: #ffcf4acc; color: var(--accent-ink); border-color: var(--line); }
body.racing #score-board, body.racing .room-badge { display: none !important; }

/* ---------- 결과 ---------- */
#results { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: #0008; padding: 16px; }
#results[hidden] { display: none; }
.results-panel { width: min(420px, 100%); }
.results-title { margin: 0; text-align: center; color: var(--accent); font-size: 22px; text-shadow: 2px 2px 0 var(--line); }
#results-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#results-list li {
  display: grid; grid-template-columns: 28px 10px 1fr auto 44px 54px; gap: 8px; align-items: center;
  background: #1a1428; border: 3px solid var(--line); padding: 5px 8px; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#results-list li.me { border-color: var(--accent); }
#results-list .rk { font-weight: bold; font-size: 16px; text-align: center; }
#results-list li:nth-child(1) .rk { color: #ffd84a; }
#results-list li:nth-child(2) .rk { color: #d9d4e8; }
#results-list li:nth-child(3) .rk { color: #e0a070; }
#results-list .dot { width: 10px; height: 10px; background: var(--c); border: 2px solid var(--line); }
#results-list .tm { color: var(--muted); font-size: 11px; }
#results-list .pt { color: #7be08f; text-align: right; }
#results-list .tt { text-align: right; font-size: 11px; color: var(--muted); }
@media (max-height: 420px) {
  .results-panel { padding: 10px 14px; gap: 6px; width: min(520px, 100%); max-height: calc(100% - 4px); overflow-y: auto; }
  #results { padding: 8px; }
  #results-list { gap: 3px; }
  #results-list li { padding: 2px 8px; font-size: 12px; }
  .results-title { font-size: 18px; }
  #race-count { font-size: 56px; }
  #score-board { display: none !important; }
}
#score-board[hidden] { display: none; }

/* ---------- 지갑 ---------- */
.room-gold { border-left: 3px solid var(--line); color: var(--accent); font-variant-numeric: tabular-nums; }

/* ---------- 광산 HUD ---------- */
#mine-hud { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
#mine-hud[hidden] { display: none; }
#mine-hud .race-top { top: max(48px, env(safe-area-inset-top)); }
.mine-pick { font-size: 13px !important; }
.pad-btn.drift { background: #4f8fe899; margin-right: 8px; }
.pad-btn.dig { width: 96px; font-size: 15px; background: #4f8fe899; }
#mine-help {
  position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 12px; background: #120e1bcc; padding: 4px 10px; white-space: nowrap;
}
body.touch #mine-help { display: none; }
body.mining #score-board { display: none !important; }
body.mining .bottom-bar { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 26px); }
body.mining #chat-log { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 70px); }
body.mining.touch .bottom-bar { display: none; }
@media (max-height: 420px) {
  #mine-hud .race-top { top: max(40px, env(safe-area-inset-top)); }
  .room-gold { padding: 4px 8px; }
}
body.mining #toast { top: calc(max(48px, env(safe-area-inset-top)) + 54px); }

/* ---------- 그림 릴레이 ---------- */
#quiz {
  position: fixed; inset: 0; z-index: 25;
  background: #1b1626f2;
  display: flex; flex-direction: column; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
#quiz[hidden] { display: none; }
.quiz-top { display: flex; gap: 8px; align-items: stretch; }
.quiz-prompt {
  flex: 1; min-width: 0; background: var(--panel); border: 3px solid var(--line);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 16px; padding: 4px 10px; line-height: 1.3;
}
.quiz-prompt b { color: var(--accent); font-size: 22px; margin: 0 4px; }
.quiz-timer b { font-variant-numeric: tabular-nums; }
.quiz-timer.hurry b { color: var(--danger); }
.quiz-main { flex: 1; min-height: 0; display: flex; gap: 10px; }
.quiz-board { flex: 1; min-width: 0; min-height: 0; display: grid; place-items: center; position: relative; }
#quiz-canvas {
  image-rendering: pixelated; background: #fff; border: 4px solid var(--line);
  box-shadow: 0 0 0 3px var(--panel-2);
  width: min(100%, calc((100vh - 120px) * 1.6)); max-height: 100%; aspect-ratio: 64 / 40;
  touch-action: none; cursor: crosshair;
}
.quiz-note {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  font-size: 18px; color: var(--muted); padding: 16px;
}
.quiz-side {
  width: 220px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; justify-content: center;
}
.quiz-side[hidden] { display: none; }
.quiz-row { display: flex; gap: 6px; }
.quiz-row .chip { flex: 1; padding: 6px 4px; }
.quiz-row .chip.on, .quiz-palette button.on { outline: 3px solid var(--accent); outline-offset: -3px; }
.quiz-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.quiz-palette button { aspect-ratio: 1; border: 3px solid var(--line); background: var(--c); cursor: pointer; padding: 0; }
.quiz-ask { margin: 0; color: var(--muted); }
#quiz-answer { font-size: 18px; text-align: center; }
#quiz-status { color: var(--muted); font-size: 13px; line-height: 1.7; }
#quiz-status b { color: var(--ink); }
#quiz-status .done { color: #7be08f; }
#quiz-reveal { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
#quiz-reveal[hidden] { display: none; }
.reveal-head { display: flex; align-items: center; gap: 8px; }
#rv-title { flex: 1; text-align: center; font-size: 16px; }
#rv-title b { color: var(--accent); }
.reveal-strip { flex: 1; min-height: 0; display: flex; gap: 10px; align-items: center; overflow-x: auto; padding: 4px; }
.rv-card {
  flex: 0 0 auto; background: var(--panel); border: 3px solid var(--line); padding: 6px;
  display: flex; flex-direction: column; gap: 4px; align-items: center; font-size: 12px;
  animation: pop .35s ease-out;
}
.rv-card canvas { width: 192px; aspect-ratio: 64 / 40; image-rendering: pixelated; background: #fff; border: 2px solid var(--line); }
.rv-card .say { font-size: 18px; padding: 10px 14px; background: #fff; color: #2b2033; border: 3px solid var(--line); }
.rv-card .who { color: var(--muted); }
.rv-card.word .say { background: var(--accent); }
.rv-arrow { color: var(--muted); font-size: 18px; flex: 0 0 auto; }
.rv-result { font-size: 22px; flex: 0 0 auto; animation: pop .35s ease-out; }
.reveal-scores { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; font-size: 12px; }
.reveal-scores span { background: #120e1bcc; padding: 3px 8px; border-left: 3px solid var(--c); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
body.quiz-step .bottom-bar, body.quizzing #actions, body.quizzing #joy-zone { display: none !important; }
@media (max-height: 420px) {
  .quiz-side { width: 170px; gap: 5px; }
  .quiz-prompt { font-size: 13px; }
  .quiz-prompt b { font-size: 17px; }
  .quiz-row .chip { font-size: 11px; padding: 4px 2px; }
  .quiz-side .btn { padding: 6px; font-size: 13px; }
  #quiz-canvas { width: min(100%, calc((100vh - 76px) * 1.6)); }
  .rv-card canvas { width: 132px; }
  .rv-card .say { font-size: 14px; padding: 6px 10px; }
}
#quiz [hidden] { display: none !important; } /* 그림 릴레이 안에서 숨긴 요소가 그림판을 가리지 않게 */

/* ---------- 땅따먹기 ---------- */
#paint-hud { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
#paint-hud[hidden] { display: none; }
.paint-bar {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 52px);
  width: min(360px, 60vw); height: 12px; display: flex; border: 3px solid var(--line); background: #e7dec9;
}
.paint-bar span { display: block; min-width: 0; transition: flex .25s; }
#paint-count {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-size: 64px; font-weight: bold; color: var(--accent); text-shadow: 5px 5px 0 var(--line);
}
#paint-help {
  position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 12px; background: #120e1bcc; padding: 4px 10px; white-space: nowrap;
}
body.touch #paint-help { display: none; }
body.painting #score-board, body.painting #actions, body.painting .room-badge { display: none !important; }
body.painting .bottom-bar { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 26px); }
body.painting.touch .bottom-bar { display: none; }
@media (max-height: 420px) {
  .paint-bar { top: calc(max(8px, env(safe-area-inset-top)) + 44px); }
  #paint-count { font-size: 48px; }
}

/* ---------- 광물 시세판 ---------- */
#market-board {
  position: absolute; right: max(8px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
  background: var(--panel); border: 3px solid var(--line); padding: 8px 10px; width: 190px;
  display: flex; flex-direction: column; gap: 4px; font-size: 13px; pointer-events: none !important;
  font-variant-numeric: tabular-nums;
}
#market-board[hidden] { display: none; }
#market-board h3 { white-space: nowrap; margin: 0 0 2px; font-size: 13px; color: var(--accent); display: flex; justify-content: space-between; gap: 6px; }
#market-board h3 small { color: var(--muted); font-weight: normal; font-size: 10px; align-self: center; }
#market-board h4 { margin: 4px 0 0; font-size: 11px; font-weight: normal; color: var(--muted); }
#market-board .row i.rank { width: auto; height: auto; border: 0; font-style: normal; color: var(--accent); }
#market-board.rank .row { grid-template-columns: 12px 1fr auto; }
#market-board p { margin: 0 0 4px; }
#market-board p small { color: var(--muted); font-size: 10px; }
#market-board .row { display: grid; grid-template-columns: 10px 1fr auto 14px; gap: 6px; align-items: center; }
#market-board .row i { width: 10px; height: 10px; border: 2px solid var(--line); }
#market-board .row b { text-align: right; }
#market-board em { font-style: normal; text-align: center; color: var(--muted); }
#market-board em.up { color: #7be08f; }
#market-board em.down { color: var(--danger); }
/* 낚시 가게 앞에서는 물고기 통 판 옆에 작게 놓는다 */
#market-board.fish { right: calc(max(8px, env(safe-area-inset-right)) + 200px); font-size: 11px; gap: 1px; padding: 6px 8px; }
/* 모바일(터치 기기): 오른쪽은 채팅 로그와 상점이 있어서 왼쪽 위 빈 곳으로 */
body.touch #market-board h3 { flex-direction: column; gap: 0; }
body.touch #market-board {
  width: 160px; font-size: 11px; padding: 6px 8px; gap: 2px;
  left: max(8px, env(safe-area-inset-left)); right: auto; top: 48px; transform: none;
}

body.touch #market-board.fish { left: auto; right: max(8px, env(safe-area-inset-right)); top: 8px; }

/* ---------- 게임 참가 모집(Y/N) ---------- */
#recruits {
  position: absolute; top: 56px; left: 8px; z-index: 6;
  display: flex; flex-direction: column; gap: 6px; width: 230px; max-width: calc(100% - 16px);
}
body.racing #recruits, body.quizzing #recruits { top: auto; bottom: 8px; }
.recruit {
  background: var(--panel); border: 3px solid var(--line); padding: 6px 8px; font-size: 12px;
  box-shadow: 4px 4px 0 #0008;
}
.recruit .rt { display: flex; justify-content: space-between; gap: 6px; }
.recruit .rt b { color: var(--accent); }
.recruit .bar { height: 5px; background: #0006; margin: 4px 0; }
.recruit .bar i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
.recruit .who { color: #cfc6e6; font-size: 11px; margin-bottom: 4px; word-break: keep-all; }
.recruit .bt { display: flex; gap: 6px; }
.recruit .bt .btn { flex: 1; padding: 4px 6px; font-size: 12px; }
.recruit.in { border-color: var(--accent); }
.recruit .ok { color: var(--accent); font-weight: bold; }
body.touch #recruits { top: 46px; width: 190px; }
body.touch #recruits .recruit { padding: 4px 6px; }
body.touch #recruits .who { display: none; }

/* ---------- 집 창고판 ---------- */
#store-board {
  position: absolute; right: max(8px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
  background: var(--panel); border: 3px solid var(--line); padding: 8px 10px; width: 190px;
  display: flex; flex-direction: column; gap: 4px; font-size: 13px; pointer-events: none !important;
}
#store-board[hidden] { display: none; }
#store-board h3 { margin: 0 0 2px; font-size: 13px; color: var(--accent); display: flex; justify-content: space-between; }
#store-board h3 small { color: var(--muted); font-weight: normal; font-size: 11px; align-self: center; }
#store-board .row { display: grid; grid-template-columns: 10px 1fr auto; gap: 6px; align-items: center; }
#store-board .row i { width: 10px; height: 10px; border: 2px solid var(--line); }
#store-board .row b { text-align: right; }
#store-board em { font-style: normal; color: var(--muted); font-size: 11px; }
body.touch #store-board { width: 150px; font-size: 11px; padding: 6px 8px; gap: 2px; left: max(8px, env(safe-area-inset-left)); right: auto; top: 48px; transform: none; }

/* ---------- 도박장 ---------- */
#btn-demo, #btn-demo:visited { display: block; text-align: center; text-decoration: none; color: #ffcf4a; }
.room-clock { border-left: 3px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.room-job { border-left: 3px solid var(--line); color: #7be08f; white-space: nowrap; }
.room-needs { border-left: 3px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.room-needs .low { color: var(--danger); font-weight: bold; }
.cp-job { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 6px 0; border-top: 2px solid var(--line); }
.cp-job.on b { color: #7be08f; }
.cp-job small { color: var(--muted); font-size: 11px; grid-column: 1; }
.cp-job .btn { grid-column: 2; grid-row: 1 / 3; padding: 4px 8px; font-size: 12px; }
#job-bar {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%); max-width: calc(100% - 16px); width: max-content;
  background: var(--panel); border: 3px solid var(--line); padding: 5px 10px; font-size: 13px; text-align: center;
  font-variant-numeric: tabular-nums; pointer-events: none !important;
}
#job-bar[hidden] { display: none; }
#job-bar b { color: var(--accent); }
#job-bar small { display: block; color: var(--muted); font-size: 11px; }
#job-bar.late b { color: var(--danger); }
body.racing #job-bar, body.quizzing #job-bar, body.painting #job-bar { display: none; }
body.in-course #job-bar { top: 84px; }
.room-full { background: none; border: 0; cursor: pointer; font-size: 14px; }
/* 경기장 안: 응원석을 가리지 않게 버튼을 위로 */
body.in-course #actions { top: max(44px, env(safe-area-inset-top)); bottom: auto; }

#casino-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 7;
  width: min(380px, calc(100% - 16px)); max-height: calc(100% - 16px); overflow-y: auto;
  background: var(--panel); border: 3px solid var(--line); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-variant-numeric: tabular-nums;
}
#casino-panel[hidden] { display: none; }
#casino-panel h3 { margin: 0; font-size: 15px; color: var(--accent); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#casino-panel h3 small { color: var(--muted); font-weight: normal; font-size: 11px; }
#casino-panel p { margin: 0; color: var(--muted); font-size: 12px; }
#casino-panel .chips { display: flex; flex-wrap: wrap; gap: 4px; }
#casino-panel .chip.on { background: var(--accent); color: var(--line); }
.cp-horse { display: grid; grid-template-columns: 12px 1fr 48px auto; gap: 6px; align-items: center; }
.cp-horse i { width: 12px; height: 12px; border: 2px solid var(--line); background: var(--c); }
.cp-horse small { color: var(--accent); }
.cp-horse .btn { padding: 4px 8px; font-size: 12px; }
.cp-nums { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.cp-nums button { font: inherit; padding: 4px 0; background: var(--line); color: #fff; border: 2px solid var(--line); cursor: pointer; }
.cp-nums button.on { background: var(--accent); color: var(--line); }
.cp-balls { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.cp-balls b { min-width: 24px; line-height: 24px; text-align: center; border-radius: 50%; background: var(--accent); color: var(--line); font-size: 12px; }
.cp-ticket { color: var(--muted); font-size: 12px; }

/* ---------- 차 타기 버튼 ---------- */
#car-btn {
  position: absolute; right: max(8px, env(safe-area-inset-right)); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 56px);
  z-index: 5; font-size: 14px; padding: 6px 12px;
}
#car-btn[hidden] { display: none; }
#car-btn.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- 낚시 막대 ---------- */
#fish-bar {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 6;
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 150px);
  background: var(--panel); border: 3px solid var(--line); padding: 6px 10px; width: 280px; max-width: calc(100% - 32px);
  box-shadow: 4px 4px 0 #0008; cursor: pointer;
}
#fish-bar[hidden] { display: none; }
#fish-bar .fb-title { font-size: 12px; color: var(--accent); text-align: center; margin-bottom: 4px; }
#fish-bar .fb-track { position: relative; height: 16px; background: #1a1428; border: 2px solid var(--line); }
#fb-zone { position: absolute; top: 0; bottom: 0; background: #5cc47a; }
#fb-mark { position: absolute; top: -4px; bottom: -4px; width: 4px; margin-left: -2px; background: #ffcf4a; border: 1px solid var(--line); }
body.touch #fish-bar { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 160px); }


/* 이모티콘 대신 쓰는 픽셀 아이콘 */
.pxi { width: 1.2em; height: 1.2em; vertical-align: -0.2em; image-rendering: pixelated; }
@media (max-height: 420px) { #actions { left: 8px; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 100px); } }
