:root {
  --ink: #4a3426;
  --ink-soft: #75594a;
  --cream: #fff8ec;
  --cream-2: #f6e7cf;
  --line: #ead6b5;
  --honey: #ffc145;
  --honey-dark: #d99a1e;
  --tomato: #c8402f;
  --tomato-dark: #9a2e22;
  --accent-text: #94530a;
  --felt: #4fae8c;
  --wood: #c98b5a;
  --wood-dark: #a86d40;
  /* 귀여운 글씨체는 제목과 핵심 게임 버튼에만 쓴다 */
  --body: 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --cute: 'Jua', 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #f1d9bb;
  color: var(--ink);
  font-family: var(--body);
  user-select: none;
}
/* 테이블: 나무 테두리 + 펠트. 카드는 그 위 캔버스에 그린다 */
#tableBg {
  position: fixed; inset: 8px; border-radius: 44px;
  background-color: var(--felt);
  background-image: radial-gradient(rgb(255 255 255 / 7%) 1.5px, transparent 1.6px);
  background-size: 18px 18px;
  border: 10px solid var(--wood);
  box-shadow: inset 0 0 0 3px var(--wood-dark), 0 4px 0 var(--wood-dark);
}
#gameCanvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

button {
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  border: none; border-radius: 12px; padding: 8px 14px;
  background: var(--cream-2); color: var(--ink);
  box-shadow: 0 3px 0 #d9c3a0;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.1s;
}
button:hover:not(:disabled) { filter: brightness(1.05); }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d9c3a0; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--honey); color: var(--ink); box-shadow: 0 3px 0 var(--honey-dark); }
button.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--honey-dark); }
button.danger { background: var(--tomato); color: #fff; box-shadow: 0 3px 0 var(--tomato-dark); }
button.danger:active:not(:disabled) { box-shadow: 0 1px 0 var(--tomato-dark); }
button.small { padding: 4px 10px; font-size: 13px; border-radius: 10px; box-shadow: 0 2px 0 #d9c3a0; }
button.small.primary { box-shadow: 0 2px 0 var(--honey-dark); }

.hud { position: fixed; z-index: 10; }
#topRight { top: 22px; right: 24px; display: flex; gap: 6px; }
#topRight button[hidden] { display: none; }

#topLeft {
  top: 22px; left: 24px; width: 280px;
  background: var(--cream); border: 2px solid var(--line); border-radius: 14px;
  padding: 8px 12px; font-size: 13px;
}
#roundInfo { font-family: var(--cute); font-size: 16px; margin-bottom: 4px; display: inline-block; margin-right: 8px; }
#logList { margin: 6px 0 0; padding-left: 0; list-style: none; max-height: 110px; overflow-y: auto; line-height: 1.55; }
#logList[hidden] { display: none; }
#logList li.round { color: var(--accent-text); font-weight: 700; margin-top: 4px; }

#actions {
  right: 24px; bottom: 24px; width: 290px;
  background: var(--cream); border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px 12px;
}
#hint { font-size: 15px; font-weight: 600; line-height: 1.5; margin-bottom: 9px; min-height: 21px; }
#actions .row { display: flex; gap: 8px; }
#actions .row button { flex: 1; padding: 10px; font-family: var(--cute); font-weight: 400; font-size: 18px; }
#actions .row button[hidden] { display: none; }

#badges { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.badge {
  position: absolute; transform: translate(-50%, -100%);
  display: flex; align-items: center; gap: 6px;
  background: var(--cream); color: var(--ink); border: 2px solid var(--line);
  border-radius: 14px; padding: 3px 10px 3px 4px;
  font-size: 13px; white-space: nowrap; line-height: 1.3;
}
.badge.below { transform: translate(-50%, 0); }
.badge img { display: block; flex: none; }
.badge .name { font-family: var(--cute); font-size: 15px; }
.badge .sub { font-size: 12px; color: var(--ink-soft); }
.badge.turn { border-color: var(--honey); }
.badge.turn img { animation: bob 0.9s ease-in-out infinite; }
.badge.dead { opacity: 0.6; }
.badge.dead .name { text-decoration: line-through; }
.badge .tagTurn {
  margin-left: 5px; padding: 0 6px; border-radius: 8px;
  background: var(--honey); color: var(--ink); font-family: var(--body); font-weight: 700; font-size: 12px; vertical-align: 1px;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.tag {
  position: fixed; z-index: 5; transform: translate(-50%, -100%); pointer-events: none;
  font-family: var(--cute); font-size: 14px; color: var(--ink);
  background: rgb(255 248 236 / 92%); padding: 2px 10px; border-radius: 10px; white-space: nowrap;
}
.tag:empty { display: none; }

#banner {
  position: fixed; z-index: 6; transform: translate(-50%, -50%); pointer-events: none;
  background: var(--cream); color: var(--ink); border: 3px solid var(--line);
  padding: 10px 22px; border-radius: 16px; box-shadow: 0 4px 0 rgb(0 0 0 / 15%);
  font-family: var(--cute); font-size: 20px; text-align: center; line-height: 1.45; white-space: nowrap;
  animation: pop 0.25s ease-out;
}
#banner.bad { border-color: var(--tomato); }
#banner.good { border-color: var(--felt); }
#banner[hidden] { display: none; }
@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgb(58 38 24 / 55%);
}
/* 위의 display: grid가 hidden 속성을 이기므로 따로 숨긴다 */
.overlay[hidden] { display: none; }
.panel {
  max-width: 520px; max-height: 86vh; overflow-y: auto;
  padding: 22px 26px; border-radius: 20px;
  background: var(--cream); color: var(--ink); line-height: 1.7;
  border: 3px solid var(--line); box-shadow: 0 8px 0 rgb(0 0 0 / 14%);
}
.panel.center { text-align: center; min-width: 300px; }
.panel h1 { margin: 0 0 2px; font-family: var(--cute); font-weight: 400; font-size: 30px; }
.panel h2 { margin: 0 0 12px; font-family: var(--cute); font-weight: 400; font-size: 24px; }
.panel .row { display: flex; gap: 10px; justify-content: center; margin: 14px 0 0; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--honey-dark); width: 16px; height: 16px; }
.muted { color: var(--ink-soft); font-size: 13px; margin: 8px 0 0; }
#rulesList { padding-left: 22px; margin: 0 0 16px; }
#rulesList li { margin-bottom: 4px; }
#rulesList li::marker { font-weight: 700; color: var(--accent-text); }

.menuPanel { width: min(380px, 92vw); padding: 18px 28px 26px; }
#menuArt { display: block; margin: 0 auto 4px; }
.menuPanel h1 { font-size: 44px; line-height: 1.2; }
.menuPanel .muted { margin-top: 2px; font-size: 14px; }
.menuBtns { display: flex; flex-direction: column; gap: 10px; margin: 20px auto 4px; width: 250px; }
.menuMinor { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.big { font-family: var(--cute); font-weight: 400; font-size: 24px; padding: 14px 16px; border-radius: 14px; }
.note { margin: 12px 0 0; font-size: 14px; color: var(--accent-text); }
.note[hidden] { display: none; }

.settingsPanel { width: min(440px, 92vw); }
.setRow { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; }
.setLabel { width: 100px; flex: none; font-weight: 700; font-size: 15px; }
.seg { display: flex; gap: 6px; flex: 1; }
.seg button { flex: 1; padding: 7px 0; font-weight: 600; }
/* 고른 값은 진한 색으로: 노란색은 '닫기' 같은 주요 행동에만 남긴다 */
.seg button.on { background: var(--ink); color: var(--cream); box-shadow: 0 3px 0 #2c1f16; }
.seg button.on:active { box-shadow: 0 1px 0 #2c1f16; }
.vol { display: flex; align-items: center; gap: 10px; flex: 1; }
.vol input { flex: 1; accent-color: var(--honey-dark); }
.vol input:disabled { opacity: 0.4; }
#volumeVal { width: 32px; text-align: right; font-size: 14px; }
.setNote { margin: 4px 0 0 112px; font-size: 12px; }
#langSel {
  flex: 1; font: inherit; padding: 7px 10px; border-radius: 10px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
}
.panel .row.end { justify-content: flex-end; margin: 20px 0 0; }

.roomPanel { width: min(440px, 92vw); }
.roomHead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.roomHead .muted { margin: 0; }
#seatList { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seat {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 8px;
  border-radius: 14px; background: #fbefdc; border: 2px solid transparent; min-height: 52px;
}
.seat img { display: block; flex: none; }
.seat.me { background: #fff1c9; border-color: var(--honey); }
.seat.human { background: #e4f4ec; }
.seat.empty { background: transparent; border: 2px dashed #dcc5a2; }
.seat.empty img { opacity: 0.35; filter: grayscale(1); }
.seatNo { width: 52px; flex: none; font-size: 13px; color: var(--ink-soft); }
.seatName { flex: 1; font-weight: 700; font-size: 16px; }
.seat.empty .seatName { color: var(--ink-soft); }
#setupNote[hidden] { display: none; }
.seatTag {
  margin-left: 6px; font-weight: 700; font-size: 12px; padding: 1px 8px; border-radius: 8px;
  background: var(--honey); color: var(--ink); vertical-align: 2px;
}
#inviteBox { margin: 14px 0 0; padding: 14px 0 0; border-top: 2px dashed var(--line); }
#linkRow { display: flex; gap: 8px; align-items: center; }
#linkRow[hidden], #inviteBtn[hidden], #startBtn[hidden], #inviteNote[hidden], #gameoverNote[hidden] { display: none; }
#linkInput {
  flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 10px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
}
#inviteNote { white-space: pre-line; }

.gameoverPanel { min-width: 320px; padding-top: 18px; }
#winnerArt { display: block; margin: 0 auto 2px; }
.exitPanel { width: min(360px, 92vw); }
.exitPanel h2 { font-size: 21px; line-height: 1.45; }

/* 튜토리얼 말풍선 */
#tutBubble {
  position: fixed; z-index: 15; width: max-content; max-width: min(320px, calc(100vw - 16px));
  padding: 10px 14px 10px 62px; border-radius: 16px;
  background: #fff7e6; color: var(--ink); font-size: 14px; line-height: 1.6;
  border: 3px solid var(--honey); box-shadow: 0 5px 0 rgb(0 0 0 / 18%);
}
#tutBubble[hidden] { display: none; }
#tutGuide { position: absolute; left: 8px; top: 10px; }
#tutBubble::after {
  content: ''; position: absolute; width: 14px; height: 14px; background: inherit;
  border: 3px solid var(--honey); transform: rotate(45deg);
}
#tutBubble[data-side='above']::after { bottom: -9px; left: calc(var(--ax) - 9px); border-top: none; border-left: none; }
#tutBubble[data-side='below']::after { top: -9px; left: calc(var(--ax) - 9px); border-bottom: none; border-right: none; }
#tutBubble[data-side='right']::after { left: -9px; top: calc(var(--ay) - 9px); border-top: none; border-right: none; }
#tutBubble[data-side='left']::after { right: -9px; top: calc(var(--ay) - 9px); border-bottom: none; border-left: none; }
#tutBubble[data-side='center']::after { display: none; }
#tutCount { font-size: 12px; color: var(--ink-soft); }
#tutText { margin: 2px 0 0; white-space: pre-line; position: relative; z-index: 1; }
#tutBtns { display: flex; gap: 8px; justify-content: flex-end; }
#tutBtns:has(button:not([hidden])) { margin-top: 8px; }
#tutBtns button { position: relative; z-index: 1; }
#tutBtns button[hidden] { display: none; }
#tutRing {
  position: fixed; z-index: 7; pointer-events: none;
  border: 3px solid var(--honey); border-radius: 12px;
  animation: tutPulse 1s ease-in-out infinite;
}
#tutRing[hidden] { display: none; }
button.tutPulse { outline: 3px solid var(--honey); outline-offset: 2px; animation: tutPulse 1s ease-in-out infinite; }
@keyframes tutPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgb(255 193 69 / 70%); }
  50% { box-shadow: 0 0 0 9px rgb(255 193 69 / 0%); }
}

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

/* 좁은 화면: 행동 칸을 아래 전체 폭으로 (layout.js의 NARROW_PX와 맞춤) */
@media (max-width: 899.98px) {
  #tableBg { inset: 4px; border-width: 7px; border-radius: 28px; }
  #actions { left: 14px; right: 14px; bottom: 14px; width: auto; }
  #topLeft { width: 220px; top: 16px; left: 16px; }
  #topRight { top: 16px; right: 16px; }
  #topRight button { padding: 6px 10px; font-size: 13px; }
}