:root {
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --text: #2b2420;
  --muted: #7a6d60;
  --accent: #b5482d;
  --border: #e4d9c7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  line-height: 1.5;
}

header { text-align: center; padding: 24px 16px 8px; }

/* 위쪽 게임 바꾸기 링크 */
.games { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.games a {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.games a.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.playing .games { display: none; }
h1 { margin: 0; font-size: 1.8rem; }
.sub { margin: 4px 0 0; color: var(--muted); }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}

button {
  font: inherit;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

#lobbyButtons { display: flex; flex-wrap: wrap; gap: 8px; }
#lobbyButtons button { flex: 1 1 200px; }

.row { display: flex; gap: 8px; }
.row-end { justify-content: flex-end; margin-top: 8px; }
.row-center { justify-content: center; flex-wrap: wrap; }

.match-msg { text-align: center; font-weight: 700; font-size: 1.15rem; margin: 4px 0; }
.match-hint { text-align: center; color: var(--muted); margin: 0 0 12px; min-height: 1.5em; }
.row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.hint { color: var(--muted); }
.msg { color: var(--accent); margin: 8px 0 0; min-height: 1.5em; }

.players { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.player {
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  transition: all 0.2s;
}
.player.active {
  border-color: var(--accent);
  color: var(--text);
  background: #fff3c4;
  box-shadow: 0 0 0 3px rgba(181, 72, 45, 0.15);
}

.status { text-align: center; font-weight: 600; font-size: 1.1rem; margin: 16px 0 8px; min-height: 1.6em; }

/* 게임 중에는 머리말을 줄여 판과 버튼이 한 화면에 들어오게 한다 */
.playing header { padding: 12px 16px 0; }
.playing header h1 { font-size: 1.3rem; }
.playing header .sub { display: none; }
.playing .players { margin-top: 10px; }

/* 판 위: 주사위 숫자 + 확률 */
.dice-row {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.dice-row .odds { margin-bottom: 0; }

/* 판 아래: 주사위 굴리기(가운데, 크게) → 다시 하기·나가기·소리 */
.roll-row { display: flex; justify-content: center; margin: 14px 0 10px; }
button.roll {
  min-width: min(260px, 100%);
  padding: 14px 32px;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(181, 72, 45, 0.35);
}
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.dice {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--text);
  border-radius: 10px;
}
.dice.rolling { animation: roll 0.4s ease-out; }
@keyframes roll {
  0% { transform: rotate(0) scale(1); }
  50% { transform: rotate(200deg) scale(1.25); }
  100% { transform: rotate(360deg) scale(1); }
}

.dice[data-v="0"] { background: #e6e2dc; color: #8a8178; border-color: #8a8178; }
.dice[data-v="2"] {
  background: linear-gradient(135deg, #ffe680, #f5b700);
  border-color: #b8860b;
  box-shadow: 0 0 14px rgba(245, 183, 0, 0.8);
}

/* 확률 안내 */
.odds { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; font-size: 0.85rem; }
.odd { padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--muted); }
.odd b { color: var(--text); margin-right: 2px; }
.odd-0 { background: #eeeae4; }
.odd-2 { background: #fff3c4; border-color: #f0d36b; }

/* 주사위 결과 연출 */
#fx {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.95);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 10;
}
#fx.fx-2 { background: rgba(40, 24, 10, 0.92); }
#fx.fx-2 small { color: #f0d9a8; }
#fx small { display: block; font-size: 1rem; color: var(--muted); }
#fx b { display: block; font-size: clamp(1.6rem, 8vw, 2.6rem); }

/* 0: 비틀거리며 떨어지는 조롱 */
#fx.fx-0 { animation: fxZero 1.8s ease-out forwards; }
#fx.fx-0 b { color: #6b6b6b; }
@keyframes fxZero {
  0% { opacity: 0; transform: translate(-50%, -120%) rotate(0); }
  15% { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg); }
  30% { transform: translate(-50%, -50%) rotate(8deg); }
  45% { transform: translate(-50%, -50%) rotate(-5deg); }
  60% { opacity: 1; transform: translate(-50%, -50%) rotate(3deg); }
  100% { opacity: 0; transform: translate(-50%, 10%) rotate(12deg); }
}
#game.shake { animation: shake 0.45s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* 1: 살짝 떠올랐다 사라짐 */
#fx.fx-1 { animation: fxOne 0.9s ease-out forwards; }
#fx.fx-1 b { font-size: 1.4rem; color: var(--text); }
@keyframes fxOne {
  0% { opacity: 0; transform: translate(-50%, -30%); }
  25% { opacity: 1; transform: translate(-50%, -50%); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%); }
}

/* 2: 크게 터지는 금빛 연출 */
#fx.fx-2 { animation: fxTwo 1.8s cubic-bezier(0.2, 0.8, 0.3, 1.2) forwards; }
#fx.fx-2 b {
  background: linear-gradient(90deg, #f5b700, #ff5e3a, #f5b700);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 8px rgba(245, 183, 0, 0.9));
}
@keyframes fxTwo {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(-10deg); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.3) rotate(3deg); }
  35% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  background: radial-gradient(circle at 50% 50%, rgba(255, 220, 90, 0.55), transparent 60%);
  animation: flash 0.7s ease-out forwards;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.confetti {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 11;
  animation: burst 1.5s ease-out forwards;
}
@keyframes burst {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0); }
  55% { opacity: 1; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx) * 1.1), calc(-50% + var(--dy) + 160px)) rotate(var(--rot)); }
}

@media (prefers-reduced-motion: reduce) {
  .confetti, .drop { display: none; }
  #game.shake { animation: none; }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(30, 20, 10, 0.55);
}
.overlay[hidden] { display: none; }

/* 승리 / 패배 */
.result-card {
  min-width: min(300px, 100%);
  background: var(--panel);
  border-radius: 18px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.result-title { margin: 0; font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 800; }
.result-sub { margin: 6px 0 18px; color: var(--muted); }
.result-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
button.kakao { background: #fee500; border-color: #fee500; color: #191919; font-weight: 600; }

.result-win {
  background: linear-gradient(160deg, #fff8dc, #ffe08a);
  border: 3px solid #f5b700;
  box-shadow: 0 0 40px rgba(245, 183, 0, 0.7);
  animation: winPop 0.6s cubic-bezier(0.2, 0.8, 0.3, 1.4);
}
.result-win .result-title { color: #b8590b; text-shadow: 0 2px 0 #fff; }
@keyframes winPop {
  0% { transform: scale(0.3) rotate(-8deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-lose {
  background: #e9e7e4;
  animation: loseDrop 0.9s ease-out;
}
.result-lose .result-title { color: #5d6670; }
@keyframes loseDrop {
  0% { transform: translateY(-40px); opacity: 0; }
  60% { transform: translateY(6px) rotate(-2deg); opacity: 1; }
  100% { transform: translateY(0) rotate(-2deg); }
}

.result-draw { animation: winPop 0.5s ease-out; }

#game { transition: filter 1s; }
#game.defeat { filter: grayscale(0.85) brightness(0.92); }

.drop {
  position: fixed;
  top: -30px;
  z-index: 15;
  font-style: normal;
  pointer-events: none;
  animation: fall 2s ease-in forwards;
}
@keyframes fall {
  0% { transform: translateY(0); opacity: 0; }
  10% { opacity: 0.9; }
  100% { transform: translateY(105vh); opacity: 0.6; }
}

/* 선공 룰렛 */
.roulette-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 20px 24px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.roulette-title { margin: 0 0 12px; font-weight: 700; font-size: 1.1rem; }
.wheel-wrap { position: relative; width: 180px; height: 180px; margin: 0 auto; }
.pointer {
  position: absolute;
  left: 50%;
  top: -6px;
  transform: translateX(-50%);
  z-index: 1;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 22px solid var(--accent);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}
#wheel {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 4px solid var(--text);
  background: repeating-conic-gradient(#ffd38a 0 60deg, #a8d8ea 60deg 120deg);
  transition: transform 2.6s cubic-bezier(0.15, 0.6, 0.2, 1);
}
#wheel span {
  position: absolute;
  left: 50%;
  top: 50%;
  font-weight: 700;
  white-space: nowrap;
}
#rouletteResult { margin: 14px 0 0; font-weight: 700; font-size: 1.15rem; min-height: 1.6em; }

.board-wrap { width: 100%; }

/* 블로그 글 안(iframe)에서는 머리말과 규칙을 숨긴다 */
.embed header, .embed .rules { display: none; }
.embed body { display: flow-root; } /* 자식 margin까지 높이에 포함되게 */
.embed main { padding-bottom: 16px; }
#board {
  display: block;
  margin: 0 auto;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  touch-action: manipulation;
  cursor: pointer;
}

.rules h2 { margin: 0 0 8px; font-size: 1.1rem; }
.rules ul { margin: 0; padding-left: 20px; }
.rules ul + h2 { margin-top: 16px; }
