:root {
  color-scheme: only light; /* 폰 브라우저가 어두운 화면으로 멋대로 바꾸지 않게 */
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --text: #2b2420;
  --muted: #7a6d60;
  --accent: #b5482d;
  --border: #e4d9c7;
}

* { box-sizing: border-box; }
/* 휴대폰 브라우저가 글자를 멋대로 키우지 않게 */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, 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 {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  font: inherit;
  line-height: 1.25;
  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; }
/* 사파리의 안쪽 그림자 같은 기본 입력칸 모양을 지운다 (체크박스·라디오는 그대로) */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea {
  -webkit-appearance: none;
  appearance: none;
}
.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;
  width: max-content;
  max-width: 90vw; /* 긴 문구는 화면 밖으로 나가지 않고 줄바꿈 */
  word-break: keep-all;
  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; }

/* ---------- 랭킹 상자 (게임 끝 카드 안, rank.js) ---------- */
.rank-box { margin: 12px 0 4px; padding: 10px 12px; background: #fff6dc; border: 1px solid #f0d99a; border-radius: 12px; text-align: center; }
.rank-head { margin: 0 0 6px; font-weight: 700; }
.rank-head b { color: var(--accent); }
.rank-msg { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }
.rank-animals { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-bottom: 6px; }
.rank-animals button { padding: 2px 4px; font-size: 1.25rem; line-height: 1.2; border-radius: 8px; background: #fff; }
.rank-animals button.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.rank-form { display: flex; gap: 6px; justify-content: center; }
.rank-form input { flex: 1; min-width: 0; max-width: 180px; padding: 6px 10px; font: inherit; border: 1px solid var(--border); border-radius: 8px; }
.rank-form button { padding: 6px 14px; }
.rank-edit { margin-left: 4px; padding: 1px 8px; font-size: 0.8rem; color: var(--muted); }
.rank-link { display: inline-block; margin-top: 6px; font-weight: 700; color: var(--accent); text-decoration: none; }

/* 시작 화면 랭킹 한 줄 */
.rank-menu { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0 auto 10px; padding: 8px 12px; max-width: 360px; background: #fff6dc; border: 1px solid #f3dfa2; border-radius: 12px; font-size: 0.88rem; text-align: center; }
.rank-menu b { color: var(--accent); }
.rank-menu .rm-me { color: var(--muted); font-size: 0.82rem; }

/* 어떤 화면이든 게임이 한눈에 들어오게 (폴드 접음·펼침, 가로 화면, PC) */
.playing main { max-width: none; padding: 0 8px 8px; }
.playing .rules { max-width: 640px; margin-left: auto; margin-right: auto; }
.playing #game { margin-left: auto; margin-right: auto; max-width: 1400px; }
@media (max-height: 760px) {
  .playing header { display: none; } /* 낮은 화면에서는 제목 대신 판을 크게 */
  .playing .status { margin: 8px 0 4px; }
}
html:not(.embed) .board-game .board-wrap { margin: 0 auto; }
@media (min-aspect-ratio: 11/10) {
  html:not(.embed) .board-game {
    display: grid;
    grid-template-columns: auto minmax(240px, 380px);
    justify-content: center;
    align-content: start;
    column-gap: 20px;
  }
  html:not(.embed) .board-game[hidden] { display: none; }
  html:not(.embed) .board-game > * { grid-column: 2; }
  html:not(.embed) .board-game .board-wrap { grid-column: 1; grid-row: 1 / span 9; width: auto; }
}
.overlay { overflow-y: auto; }
@media (max-height: 480px) {
  .result-card { padding: 12px 16px; }
  .result-sub { margin: 4px 0 8px; }
}

/* 접속 중인 사람과 하기 */
.menu-online { margin: 4px 0 8px; text-align: center; font-size: 0.85rem; color: var(--muted); }
.menu-online:empty { display: none; }
.count-big { font-size: 3rem; font-weight: 900; color: var(--accent); line-height: 1.2; }
.seats .seat-ready { margin-left: auto; flex: none; }

/* 오목: 내 꽝·더블 횟수 */
.dice-count { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 12px; margin: 4px 0 6px; font-size: 0.82rem; color: var(--muted); text-align: center; }
.dice-count[hidden] { display: none; }
.dice-count b { color: var(--text, #2b2420); font-weight: 700; }
.lobby-dice { margin: 8px 0 0; text-align: center; font-size: 0.88rem; color: var(--muted); }
.lobby-dice:empty { display: none; }

/* 다시 하기 동의 */
.rm-overlay { z-index: 40; }
.rm-toast {
  position: fixed; left: 50%; bottom: 12%; transform: translateX(-50%); z-index: 45;
  padding: 10px 18px; border-radius: 999px; background: rgba(30, 20, 10, 0.88); color: #fff;
  font-weight: 700; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}

/* 나가기: 주사위 버튼에서 멀리, 게임 화면 맨 위 오른쪽에 작게 */
.leave-row { display: flex; justify-content: flex-end; margin: 2px 0 4px; }
.leave-btn { padding: 3px 10px; font-size: 0.8rem; }

/* 인형뽑기 코인 받았을 때 알림 (rank.js Coins.earn) */
.coin-toast {
  position: fixed; left: 50%; top: 14px; z-index: 9999; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; background: #ffd23f; color: #6b3a1e; font-weight: 800; font-size: 0.95rem;
  white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2); pointer-events: none;
  animation: coin-toast 3s ease-out forwards;
}
@keyframes coin-toast {
  0% { opacity: 0; transform: translate(-50%, -20px) scale(0.8); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  16% { transform: translate(-50%, 0) scale(1); }
  85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* 🎵 배경음악 · 🔊 효과음 버튼: 꺼지면 흐리게 + 빗금 (bgm.js) */
.snd-btn.snd-off { position: relative; opacity: 0.55; }
.snd-btn.snd-off::after {
  content: ''; position: absolute; left: 22%; right: 22%; top: 50%;
  border-top: 2px solid #e63946; transform: rotate(-35deg); pointer-events: none;
}
