/* ===== 가족 보드게임 스타일: 색은 여기에서만 정한다 =====
   톤: 가을 저녁 거실의 카드 게임. 짙은 호두나무 탁자 + 말차색 펠트 판 + 일본 전통색 포인트.
   (변수 이름은 역할 이름이다: coral=주요, sun=강조, sky=도움말, leaf=성공, purple=분석) */
:root {
  --wood-a: #94643f;
  --wood-b: #6b4227;
  --board-a: #d3e4b6;
  --board-b: #a3c486;
  --duel-a: #fbcbab;
  --duel-b: #ee9c78;
  --cream: #fffaf0;
  --paper: #fff3df;
  --line: #5a3e2b;
  --ink: #4a3426;
  --muted: #8a7462;
  --on-board: #3a5531;
  --coral: #ef6a4b;
  --coral-d: #c34b2f;
  --sun: #f8bd3a;
  --sun-d: #d4920f;
  --sun-glow: rgb(248 189 58 / 80%);
  --sky: #5b93d3;
  --sky-d: #3c70b0;
  --leaf: #3fb39c;
  --leaf-d: #2a8a77;
  --purple: #9c86d0;
  --purple-d: #7660ad;
  --hl: #fff1c6;
  --blush: #f4a3a0;
  --base-shadow: #d9c4a0;
  --beige: #e3cca3;
  --card-red: #dc4a43;
  --card-navy: #2f3a56;
  --card-back: #46639e;
  --font-round: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-body: "Segoe UI", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --pop: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--ink);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* 나무 탁자: 널빤지 이음매 + 옅은 나뭇결 + 위→아래 그라데이션 */
  background:
    repeating-linear-gradient(180deg, transparent 0 116px, rgb(40 22 10 / 45%) 116px 118px),
    repeating-linear-gradient(90deg, rgb(40 22 10 / 0%) 0 7px, rgb(40 22 10 / 8%) 7px 9px, rgb(40 22 10 / 0%) 9px 23px, rgb(255 230 200 / 4%) 23px 24px),
    linear-gradient(180deg, var(--wood-a), var(--wood-b));
  background-attachment: fixed;
}
button { font: inherit; color: inherit; }

/* ===== 게임판 ===== */
.board {
  position: fixed;
  inset: 20px;
  z-index: 1;
  border-radius: 36px;
  border: 10px solid var(--cream);
  background:
    radial-gradient(circle, rgb(255 255 255 / 22%) 3px, transparent 3.5px) 0 0 / 34px 34px,
    radial-gradient(ellipse at center, var(--board-a), var(--board-b));
  box-shadow: 0 8px 0 var(--beige), 0 14px 26px rgb(90 62 43 / 35%);
}
.board::before, .board::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 26px;
  transition: opacity .6s ease;
}
/* 一騎打ち(홍시색 판)는 위에 겹쳐 두고 투명도만 바꾼다 */
.board::before {
  background:
    radial-gradient(circle, rgb(255 255 255 / 22%) 3px, transparent 3.5px) 0 0 / 34px 34px,
    radial-gradient(ellipse at center, var(--duel-a), var(--duel-b));
  opacity: 0;
}
.board.duel::before { opacity: 1; }
.board[hidden] { display: none; }
.board::after {
  inset: 12px;
  border: 4px dashed rgb(255 255 255 / 85%);
  border-radius: 20px;
}

#stage { position: fixed; inset: 0; z-index: 2; }
#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* 손가락으로 카드를 끌 때 화면이 같이 스크롤되지 않게 */
  touch-action: none;
}

/* ===== 공통 모양 ===== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--base-shadow);
  font-family: var(--font-round);
  font-weight: 700;
}
.pill.sun { background: var(--sun); box-shadow: 0 4px 0 var(--sun-d); }

/* ===== 사탕 버튼 ===== */
.btn {
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 16px;
  padding: 9px 22px;
  min-height: 42px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--base-shadow);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, opacity .15s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--base-shadow); }
.btn.primary { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-d); }
.btn.primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--coral-d); }
.btn.sky { background: var(--sky); color: #fff; box-shadow: 0 4px 0 var(--sky-d); }
.btn.sky:active:not(:disabled) { box-shadow: 0 2px 0 var(--sky-d); }
.btn.leaf { background: var(--leaf); color: #fff; box-shadow: 0 4px 0 var(--leaf-d); }
.btn.leaf:active:not(:disabled) { box-shadow: 0 2px 0 var(--leaf-d); }
.btn[hidden] { display: none; }
.btn:disabled { opacity: .4; cursor: default; }

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--base-shadow);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
}
.icon-btn svg { width: 24px; height: 24px; transition: transform .25s var(--pop); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--base-shadow); }
.icon-btn.gear:hover svg { transform: rotate(45deg); }

/* ===== 오른쪽 위 버튼 줄 ===== */
.topbar {
  position: fixed;
  top: 34px;
  right: 40px;
  z-index: 13; /* 타이틀 상자(12) 위에 있어야 타이틀에서도 눌린다 */
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar .btn { min-height: 42px; padding: 7px 18px; }
.topbar .round { cursor: default; }
.topbar .in-game[hidden] { display: none; }

/* ===== HUD ===== */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud button { pointer-events: auto; }
.hud[hidden] { display: none; }

.slot {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 4px dashed rgb(255 255 255 / 85%);
  border-radius: 22px;
  background: rgb(255 255 255 / 10%);
  transition: opacity .2s;
}
.slot.faded { opacity: .25; }
.slot-label {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -60%);
  padding: 3px 14px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 3px 0 var(--base-shadow);
  font-family: var(--font-round);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* 이름표 */
.plate {
  position: absolute;
  width: var(--plate-w, 188px);
  height: var(--plate-h, 58px);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 0 6px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--base-shadow);
  transition: transform .2s var(--pop), background .2s, box-shadow .2s, opacity .2s;
}
.plate .avatar { width: 44px; height: 44px; flex: none; }
.pinfo { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.pname { font-family: var(--font-round); font-size: 17px; font-weight: 700; white-space: nowrap; }
.pcount { font-size: 13px; color: var(--muted); white-space: nowrap; }
.plate.is-turn {
  background: var(--hl);
  box-shadow: 0 4px 0 var(--sun-d), 0 0 0 4px var(--sun-glow);
  transform: translate(-50%, -50%) scale(1.07);
}
.plate.is-turn .avatar { animation: hop .6s ease-in-out infinite; }
.plate.is-out .pcount { color: var(--leaf-d); }
.turn-arrow {
  position: absolute;
  left: 50%;
  top: -26px;
  width: 24px;
  height: 18px;
  margin-left: -12px;
  opacity: 0;
  transition: opacity .15s;
}
.plate.is-turn .turn-arrow { opacity: 1; animation: bounce .6s ease-in-out infinite; }
.badge {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 55%);
  padding: 1px 11px;
  border-radius: 999px;
  border: 2px solid var(--line);
  font-family: var(--font-round);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  animation: pop .22s var(--pop);
}
.badge[hidden] { display: none; }
.badge.gold { background: var(--sun); color: var(--ink); box-shadow: 0 2px 0 var(--sun-d); }
.badge.leaf { background: var(--leaf); box-shadow: 0 2px 0 var(--leaf-d); }
.badge.coral { background: var(--coral); box-shadow: 0 2px 0 var(--coral-d); }
.badge.sky { background: var(--sky); box-shadow: 0 2px 0 var(--sky-d); }

.avatar {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  overflow: hidden;
}
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.small { width: 34px; height: 34px; }

/* 진행 기록 */
.log {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: max-content;
  max-width: var(--log-max, 60vw);
}
.log-line {
  padding: 2px 14px;
  border-radius: 999px;
  background: rgb(255 250 240 / 55%);
  color: var(--on-board);
  font-size: 12px;
}
.log-line.latest {
  font-size: 15px;
  padding: 4px 16px;
  background: rgb(255 250 240 / 90%);
  border: 2px solid var(--line);
  color: var(--ink);
  animation: pop .22s var(--pop);
}

/* 행동 바 */
.actionbar {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 22px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--base-shadow);
  white-space: nowrap;
  transition: background .2s, box-shadow .2s;
}
.actionbar.has-btns { padding-right: 6px; }
.actionbar.mine { background: var(--hl); box-shadow: 0 4px 0 var(--sun-d), 0 0 0 4px var(--sun-glow); }
.actionbar .hint { font-family: var(--font-round); font-size: 16px; font-weight: 700; }
.actionbar .hint.good { color: var(--leaf-d); }
.actionbar .hint.warn { color: var(--coral-d); }
.bar-btns { display: flex; gap: 8px; }
.bar-btns:empty { display: none; }

/* 내밀어진 손패의 주인 이름표 */
.present-label {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 16px 3px 4px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--base-shadow);
  font-family: var(--font-round);
  font-size: 15px;
  white-space: nowrap;
  animation: pop .22s var(--pop);
}
.present-label[hidden] { display: none; }
.present-label .avatar.small { width: 30px; height: 30px; }
/* ===== 큰 이벤트 배너(스티커 글자) ===== */
.banner-layer { position: absolute; inset: 0; display: grid; place-items: center; }
.banner { animation: banner 1.5s var(--pop) forwards; }
.sticker {
  position: relative;
  display: inline-block;
  isolation: isolate;
  font-family: var(--font-round);
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  --shadow-c: var(--coral-d);
}
.banner .sticker { font-size: 64px; }
/* 갈색 외곽선과 색 그림자는 같은 글자를 뒤에 두 겹 더 깔아서 만든다 */
.sticker::before, .sticker::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  -webkit-text-stroke: 6px var(--line);
}
.sticker::before { z-index: -1; color: var(--line); }
.sticker::after { z-index: -2; color: var(--shadow-c); transform: translateY(6px); -webkit-text-stroke-color: var(--shadow-c); }

/* ===== 특별한 순간 효과 ===== */
.shake { animation: shake .36s linear; }
.fx-flash { position: fixed; inset: 0; z-index: 15; background: #fff; pointer-events: none; animation: flash .45s ease-out forwards; }
/* 칼로 베는 듯한 흰 빛줄기: 한 번 가로질러 지나간다 */
.fx-slash {
  position: fixed;
  left: -30vw;
  top: 50%;
  width: 160vw;
  height: 14px;
  z-index: 14;
  pointer-events: none;
  border-radius: 999px;
  background: linear-gradient(90deg, rgb(255 255 255 / 0%), #fff 45%, var(--hl) 55%, rgb(255 255 255 / 0%));
  transform-origin: center;
  animation: slash .34s ease-out forwards;
}
@keyframes slash {
  from { transform: translateY(-50%) rotate(-14deg) translateX(-70vw) scaleY(.4); opacity: 1; }
  60% { opacity: 1; }
  to { transform: translateY(-50%) rotate(-14deg) translateX(40vw) scaleY(1); opacity: 0; }
}

/* ===== 패널(HTML 오버레이) ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(60 35 15 / 45%);
  animation: fade .15s ease-out;
}
.overlay[hidden] { display: none; }
.panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  padding: 24px 28px;
  border-radius: 24px;
  border: 3px solid var(--line);
  background: var(--cream);
  box-shadow: 0 8px 0 var(--base-shadow), 0 18px 36px rgb(60 35 15 / 30%);
  line-height: 1.75;
  animation: pop .22s var(--pop);
}
.panel h2 {
  margin: 0 0 10px;
  font-family: var(--font-round);
  font-size: 26px;
  color: var(--coral-d);
  text-align: center;
}
.panel h3 {
  margin: 16px 0 2px;
  font-family: var(--font-round);
  font-size: 17px;
  color: var(--sky-d);
}
.panel ul { margin: 0; padding-left: 1.2em; }
.panel li { margin: 2px 0; }
.panel-btns { display: flex; justify-content: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

.result-lead { text-align: center; font-family: var(--font-round); font-size: 17px; margin: 0 0 14px; }
.result-lead.good { color: var(--leaf-d); }
.result-lead.warn { color: var(--coral-d); }
.result-rows { border: 2px solid var(--line); border-radius: 16px; overflow: hidden; }
.result-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
}
.result-row:nth-child(even) { background: rgb(227 204 163 / 35%); }
/* 내 줄: 줄무늬 안에서 노란 알약처럼 떠 보이게 */
.result-row.me {
  margin: 3px;
  padding: 5px 13px;
  border-radius: 12px;
  background: var(--hl);
  box-shadow: inset 0 0 0 3px var(--sun);
}
.result-rank {
  min-width: 64px;
  text-align: center;
  padding: 0 10px;
  border-radius: 999px;
  border: 2px solid var(--line);
  font-family: var(--font-round);
  font-size: 14px;
  color: #fff;
}
.result-rank.gold { background: var(--sun); color: var(--ink); }
.result-rank.leaf { background: var(--leaf); }
.result-rank.coral { background: var(--coral); }
.result-rank.plain { background: var(--cream); color: var(--ink); }
.result-who { display: flex; align-items: center; gap: 10px; font-family: var(--font-round); font-size: 17px; }
.host-mark {
  padding: 0 9px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font-family: var(--font-round);
  font-size: 12px;
}

/* みんなで遊ぶ: 招待リンク */
.lobby-share { display: flex; gap: 10px; align-items: center; margin: 0 0 14px; }
.lobby-share[hidden] { display: none; }
.lobby-link {
  flex: 1;
  min-width: 0;
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 2px dashed var(--beige);
}
.setting-row:last-child { border-bottom: 0; }
.setting-label { font-family: var(--font-round); font-weight: 700; }
.segmented {
  display: inline-flex;
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 4px 0 var(--base-shadow);
  background: var(--cream);
}
.segmented button {
  border: 0;
  border-left: 2px solid var(--line);
  background: transparent;
  padding: 7px 16px;
  min-height: 40px;
  font-family: var(--font-round);
  font-weight: 700;
  cursor: pointer;
}
.segmented button:first-child { border-left: 0; }
.segmented button.on { background: var(--sun); }

/* ===== 타이틀 화면 ===== */
.title {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
}
.title[hidden] { display: none; }
.lid {
  position: relative;
  width: min(520px, 100%);
  padding: 58px 36px 34px;
  border-radius: 36px;
  border: 10px solid var(--cream);
  background:
    radial-gradient(circle, rgb(255 255 255 / 22%) 3px, transparent 3.5px) 0 0 / 34px 34px,
    radial-gradient(ellipse at center, var(--board-a), var(--board-b));
  box-shadow: 0 10px 0 var(--beige), 0 20px 34px rgb(90 62 43 / 40%);
  text-align: center;
  animation: pop .3s var(--pop);
}
.lid::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 4px dashed rgb(255 255 255 / 85%);
  border-radius: 22px;
  pointer-events: none;
}
.lid-chars {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -55%);
  display: flex;
  gap: 12px;
}
.lid-chars .avatar {
  width: 62px;
  height: 62px;
  box-shadow: 0 4px 0 var(--base-shadow);
  animation: hop 1.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * .18s);
}
.dash-badge {
  display: inline-block;
  padding: 3px 14px;
  border: 2px dashed var(--on-board);
  border-radius: 999px;
  color: var(--on-board);
  font-family: var(--font-round);
  font-size: 12px;
  letter-spacing: .25em;
}
.title .sticker { font-size: 58px; margin: 10px 0 0; --shadow-c: var(--coral); }
.title-sub { margin: 6px 0 22px; color: var(--on-board); font-family: var(--font-round); font-size: 16px; }
.modes { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 14px; }
.mode-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 20px;
  border-radius: 26px;
  border: 2px solid var(--line);
  color: #fff;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, opacity .15s;
}
.mode-btn b { font-family: var(--font-round); font-size: 21px; }
.mode-btn small { font-size: 13px; opacity: .95; }
.mode-btn.sky { background: var(--sky); box-shadow: 0 4px 0 var(--sky-d); }
.mode-btn.coral { background: var(--coral); box-shadow: 0 4px 0 var(--coral-d); }
.mode-btn.leaf { background: var(--leaf); box-shadow: 0 4px 0 var(--leaf-d); }
.mode-btn.purple { background: var(--purple); box-shadow: 0 4px 0 var(--purple-d); }
.mode-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.mode-btn:disabled { opacity: .4; cursor: default; }
.mode-btn .tag {
  position: absolute;
  right: -8px;
  top: -10px;
  padding: 1px 10px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--sun);
  color: var(--ink);
  font-family: var(--font-round);
  font-size: 12px;
  transform: rotate(6deg);
}

/* ===== 움직임 ===== */
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
@keyframes banner {
  0% { transform: scale(.6); opacity: 0; }
  14% { transform: scale(1.1); opacity: 1; }
  24% { transform: scale(1); }
  82% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.9); opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(5px, -2px); }
  60% { transform: translate(-4px, 1px); }
  80% { transform: translate(3px, 0); }
}

/* ===== 말풍선 ===== */
.bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.bubble { position: absolute; max-width: var(--bubble-max, 220px); }
.bubble[hidden] { display: none; }
.bubble.right { transform: translate(0, -50%); }
.bubble.left { transform: translate(-100%, -50%); }
.bubble.up { transform: translate(-50%, -100%); }
.bubble-in {
  position: relative;
  display: block;
  padding: 7px 14px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-family: var(--font-round);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: 0 4px 0 var(--base-shadow);
  animation: pop .22s var(--pop);
}
.bubble-in::before, .bubble-in::after { content: ''; position: absolute; width: 0; height: 0; border: solid transparent; }
.bubble.right .bubble-in { transform-origin: left center; }
.bubble.right .bubble-in::before { right: 100%; top: 50%; margin-top: -9px; border-width: 9px 11px 9px 0; border-right-color: var(--line); }
.bubble.right .bubble-in::after { right: calc(100% - 3px); top: 50%; margin-top: -6px; border-width: 6px 8px 6px 0; border-right-color: #fff; }
.bubble.left .bubble-in { transform-origin: right center; }
.bubble.left .bubble-in::before { left: 100%; top: 50%; margin-top: -9px; border-width: 9px 0 9px 11px; border-left-color: var(--line); }
.bubble.left .bubble-in::after { left: calc(100% - 3px); top: 50%; margin-top: -6px; border-width: 6px 0 6px 8px; border-left-color: #fff; }
.bubble.up .bubble-in { transform-origin: center bottom; }
.bubble.up .bubble-in::before { top: 100%; left: 50%; margin-left: -9px; border-width: 11px 9px 0; border-top-color: var(--line); }
.bubble.up .bubble-in::after { top: calc(100% - 3px); left: 50%; margin-left: -6px; border-width: 8px 6px 0; border-top-color: #fff; }

/* ===== 도움말 쪽지 ===== */
.tip-layer { position: fixed; inset: 0; z-index: 18; pointer-events: none; }
.tip { position: absolute; width: min(330px, calc(100vw - 24px)); pointer-events: auto; }
.tip.up { transform: translateY(calc(-100% - 14px)); }
.tip.down { transform: translateY(14px); }
.tip-in {
  position: relative;
  padding: 18px 14px 12px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: #fff;
  box-shadow: 0 4px 0 var(--base-shadow), 0 10px 20px rgb(60 35 15 / 20%);
  animation: pop .22s var(--pop);
}
.tip.up .tip-in { transform-origin: var(--tail) bottom; }
.tip.down .tip-in { transform-origin: var(--tail) top; }
.tip-in > p { margin: 0 0 10px; font-weight: 600; line-height: 1.6; color: var(--ink); }
/* 위 테두리에 걸쳐 붙인 하늘색 「ヒント」 꼬리표(스티커처럼 살짝 기울임) */
.tip-tag {
  position: absolute;
  left: 14px;
  top: 0;
  transform: translateY(-58%) rotate(-4deg);
  padding: 0 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--sky);
  color: #fff;
  box-shadow: 0 2px 0 var(--sky-d);
  font-family: var(--font-round);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.tip.tag-right .tip-tag { left: auto; right: 14px; transform: translateY(-58%) rotate(4deg); }
.tip-in::before, .tip-in::after { content: ''; position: absolute; width: 0; height: 0; border: solid transparent; }
.tip.up .tip-in::before { top: 100%; left: var(--tail); margin-left: -10px; border-width: 12px 10px 0; border-top-color: var(--line); }
.tip.up .tip-in::after { top: calc(100% - 3px); left: var(--tail); margin-left: -7px; border-width: 9px 7px 0; border-top-color: #fff; }
.tip.down .tip-in::before { bottom: 100%; left: var(--tail); margin-left: -10px; border-width: 0 10px 12px; border-bottom-color: var(--line); }
.tip.down .tip-in::after { bottom: calc(100% - 3px); left: var(--tail); margin-left: -7px; border-width: 0 7px 9px; border-bottom-color: #fff; }
.tip-btns { display: flex; justify-content: flex-end; gap: 8px; }
.btn.small { min-height: 36px; padding: 5px 14px; font-size: 14px; }
.btn.purple { background: var(--purple); color: #fff; box-shadow: 0 4px 0 var(--purple-d); }
.btn.purple:active:not(:disabled) { box-shadow: 0 2px 0 var(--purple-d); }

/* ===== 환영 패널 ===== */
.panel-lead { text-align: center; font-weight: 700; margin: 0 0 12px; }
.panel-note { margin: 12px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
.panel-note.warn { color: var(--coral-d); }
.panel-note[hidden] { display: none; }
.welcome-steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.welcome-steps li {
  counter-increment: step;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px 8px 8px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: #fff;
  box-shadow: 0 4px 0 var(--base-shadow);
  font-family: var(--font-round);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.4;
}
.welcome-steps li::before {
  content: counter(step);
  flex: none;
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--sky);
  color: #fff;
  box-shadow: 0 2px 0 var(--sky-d);
}

/* ===== 분석 패널 ===== */
.panel.wide { width: min(640px, 100%); }
.panel h2.purple-title { color: var(--purple-d); }
.ana-block { padding: 12px 0; border-top: 2px dashed var(--beige); }
.ana-block h3 { margin-top: 0; }
.ana-block > p { margin: 0 0 10px; }
.ana-runs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.ana-running { text-align: center; font-family: var(--font-round); font-weight: 700; color: var(--purple-d); }
.ana-table { border: 2px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; }
.ana-row {
  display: grid;
  grid-template-columns: 1.3fr 2fr .8fr .9fr;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 14px;
}
.ana-row:nth-child(even) { background: rgb(227 204 163 / 35%); }
.ana-row.head { background: var(--purple); color: #fff; font-family: var(--font-round); font-weight: 700; }
.ana-who { display: flex; align-items: center; gap: 8px; font-family: var(--font-round); font-size: 15px; }
.ana-trait { color: var(--muted); font-weight: 600; line-height: 1.4; }
.ana-num { font-family: var(--font-round); font-weight: 700; font-size: 16px; text-align: right; }
.ana-row.head span:nth-child(n+3) { text-align: right; }
.ana-num.worst { color: var(--coral-d); }
.ana-summary { margin: 10px 0 0; font-size: 14px; font-weight: 600; }

/* ===== 룰북 버튼(타이틀 오른쪽 위, 규칙 창 오른쪽 위) ===== */
.book-btn { display: inline-flex; align-items: center; gap: 6px; }
.topbar .book-btn { padding: 7px 16px 7px 10px; }
.book-btn svg { width: 24px; height: 24px; flex: none; }
.topbar .title-only[hidden] { display: none; }
.rules-panel { width: min(600px, 100%); }
.rules-panel h2 { padding: 0 130px; }
.rules-book { position: absolute; top: 20px; right: 22px; min-height: 36px; padding: 4px 14px 4px 8px; font-size: 14px; }