/* 동물 박스 — 하얀 바탕 · 파스텔 UI */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #ffffff;
  --panel: #fbf8f4;   /* 크림 패널 */
  --panel-2: #f4efe8;
  --line: #eae2d7;
  --text: #6b5d52;    /* 부드러운 브라운 그레이 */
  --text-dim: #b5aa9f;

  --mint: #9ed9cd;   --mint-hi: #c3ebe4;   --mint-ink: #2a625a;
  --pink: #f7b7c5;   --pink-hi: #fdd5de;   --pink-ink: #8e4155;
  --sky: #a6c9ee;    --sky-hi: #cae1f9;    --sky-ink: #305c88;
  --lilac: #cbbfe6;  --lilac-hi: #e2d8f6;  --lilac-ink: #57457f;
  --butter: #f8dda2; --butter-hi: #fdeecb; --butter-ink: #8b6420;
  --gray: #ded8cf;   --gray-hi: #eee9e2;   --gray-ink: #7b7269;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none; /* iOS 길게 누르기 메뉴 방지 */
}

/* iOS Safari 더블탭 확대 방지 — 버튼/입력엔 manipulation, 보드엔 none */
button, input { touch-action: manipulation; }
canvas { touch-action: none; }

.hidden { display: none !important; }

/* 화면 전환 — 두 화면이 겹친 채 서로 페이드되는 디졸브 */
.screen { transition: opacity 0.28s ease; }
.screen.dissolve { opacity: 0; pointer-events: none; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 50% -8%, rgba(158, 217, 205, 0.22), transparent 62%),
    radial-gradient(760px 420px at 100% 8%, rgba(247, 183, 197, 0.16), transparent 60%),
    var(--bg);
}

/* ---------- 브랜드 ---------- */
/* 하단 배너 자리만큼 로비 내용을 위로 올린다 (배너 높이 + 여백) */
#screen-lobby { padding-bottom: 135px; }
#screen-ranking, #screen-config { padding-bottom: 95px; }

.brand { text-align: center; margin-bottom: 48px; }
.brand.small { margin-bottom: 28px; }
.brand-logo {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--mint-ink);
  text-shadow: 0 2px 0 #fff, 0 6px 20px rgba(158, 217, 205, 0.5);
}
.brand.small .brand-logo { font-size: 32px; }
.brand-logo span { color: var(--pink-ink); }
.brand-sub {
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--text-dim);
}
.lobby-welcome {
  margin-top: 10px;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--text-dim);
}
.lobby-welcome b { color: var(--mint-ink); }
.signoff-link {
  margin-left: 10px;
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}
.signoff-link:active { color: var(--text); border-color: var(--text-dim); }

/* Sign Off 팝업 */
.signoff-box { max-width: 340px; }
.signoff-msg {
  white-space: pre-line;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  letter-spacing: 0.5px;
}
.signoff-btns {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 1행: Sign Off · Sign Up */
  gap: 8px;
  margin-top: 22px;
}
#signoff-cancel { grid-column: 1 / -1; } /* 2행: Cancel */
.signoff-nick { color: var(--mint-ink); }

.btn-small {
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
}
.btn-small:active { filter: brightness(0.96); transform: scale(0.98); }
.btn-small-pink { background: linear-gradient(180deg, var(--pink-hi), var(--pink)); color: var(--pink-ink); }
.btn-small-gray { background: linear-gradient(180deg, var(--gray-hi), var(--gray)); color: var(--gray-ink); }
.btn-small-sky  { background: linear-gradient(180deg, var(--sky-hi), var(--sky));   color: var(--sky-ink); }
.btn-small-mint { background: linear-gradient(180deg, var(--mint-hi), var(--mint)); color: var(--mint-ink); }

/* ---------- 게임 방법 팝업 ---------- */
.match-box.guide-box { max-width: 360px; text-align: left; padding: 26px 26px 22px; }
.guide-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--mint-ink);
  text-align: center;
  margin-bottom: 16px;
}
.guide-list { margin: 0 0 4px 18px; text-align: left; }
.guide-list li {
  font-size: 13.5px;
  line-height: 1.75;
  margin-bottom: 8px;
  color: var(--text);
}
.guide-list b { color: var(--pink-ink); }
.guide-close { width: 100%; margin-top: 14px; }

/* ---------- 랭킹 화면 ---------- */
.rank-tabs {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin-bottom: 12px;
}
.rank-tab {
  flex: 1;
  padding: 12px 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 3px;
  cursor: pointer;
}
.rank-tab.active {
  background: linear-gradient(180deg, var(--sky-hi), var(--sky));
  border-color: transparent;
  color: var(--sky-ink);
}
.rank-info {
  width: 100%;
  max-width: 420px;
  min-height: 15px; /* 로딩 중 비어도 높이를 유지해 아래가 흔들리지 않게 */
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-align: center;
}
.rank-remain { color: #c08a4a; } /* 남은 시간 */

.rank-list {
  width: 100%;
  max-width: 420px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(107, 93, 82, 0.07);
  font-size: 14px;
  /* 1등부터 아래로 한 줄씩 펼쳐진다 (지연은 JS에서 0.2초 간격) */
  transform-origin: center center;
  animation: rank-flip 0.32s ease-out backwards;
}
@keyframes rank-flip {
  from { opacity: 0; transform: scaleY(0); }
  to   { opacity: 1; transform: scaleY(1); }
}
.rank-row .rk {
  width: 34px;
  text-align: right;
  font-weight: 800;
  color: var(--text-dim);
}
.rank-row:nth-child(1) .rk { color: #e0a93a; }
.rank-row:nth-child(2) .rk { color: #9fb0c0; }
.rank-row:nth-child(3) .rk { color: #cf9163; }
.rank-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .val { font-weight: 800; letter-spacing: 1px; }
.rank-row .sub { font-size: 11px; color: var(--text-dim); margin-left: 6px; }
.rank-row.me { background: rgba(158, 217, 205, 0.22); }
.rank-row.me .nm { color: var(--mint-ink); font-weight: 800; }

/* 상단 고정 — 내 순위 */
.rank-me {
  display: flex;
  align-items: center;
  gap: 12px;
  transform-origin: center center;
  animation: rank-flip 0.32s ease-out backwards;
  width: 100%;
  max-width: 420px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--mint-hi), var(--mint));
  color: var(--mint-ink);
  box-shadow: 0 4px 16px rgba(158, 217, 205, 0.45);
}
.rank-me .rk { width: 34px; text-align: right; font-weight: 800; }
.rank-me .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.rank-me .val { font-weight: 800; letter-spacing: 1px; }
.rank-me .sub { font-size: 11px; opacity: 0.75; margin-left: 6px; }
.rank-empty {
  padding: 32px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
  line-height: 1.7;
}

/* ---------- 로비 하단 (배너 + 버전/저작권) ----------
   묶음 전체가 화면 맨 아래에서 15px 띄운 자리에 놓인다. */
.lobby-bottom {
  position: absolute;
  left: 50%;
  bottom: 15px;
  transform: translateX(-50%);
  width: calc(100% - 48px);
  max-width: 420px;
}

/* 게임 화면 배너 — 결과 오버레이(z-index 10)보다 위에 둔다 */
#game-banner { z-index: 16; }

/* 로비 외 화면(랭킹·설정·게임 결과)의 배너 — 화면 맨 아래에서 10px */
.app-banner {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: calc(100% - 48px);
  max-width: 420px;
}

/* 배너 본체 — 5초마다 다음 장이 아래에서 올라온다 */
.banner-track {
  position: relative;
  width: 100%;
  aspect-ratio: 1024 / 163; /* 원본 비율 그대로 */
  overflow: hidden;
  border-radius: 12px;
  background: var(--panel-2);
}
.banner-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: translateY(100%); /* 대기 위치 — 아래에 숨어 있다 */
  transition: transform 0.3s ease-out;
}
.banner-slide.current { transform: translateY(0); }
.banner-slide.leaving { transform: translateY(-100%); }

/* 버전 + 저작권 — 배너 바로 아래 */
.copyright {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  margin-top: 10px;
  text-align: center;
  font-size: 11px;
  line-height: 1.35;
  color: rgba(107, 93, 82, 0.38);
  letter-spacing: 0.02em;
}

/* ---------- 광고 화면 ---------- */
#screen-ad { padding: 0; background: #f7f4ef; }
.ad-text {
  font-size: 30pt;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--text-dim);
}
.ad-top {
  position: absolute;
  top: 30px;
  left: 0;
  height: 38px;
  display: flex;
  align-items: center;
}
.ad-count {
  padding: 0 14px;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--text-dim);
}
#ad-back { position: static; transform: none; }

/* ---------- 바 버튼 ---------- */
.btn-bar {
  display: flex;
  flex-direction: column;
  align-items: center; /* 기본은 중앙 정렬, 로비 메뉴만 좌측 정렬 */
  justify-content: center;
  width: 100%;
  max-width: 420px;
  min-height: 66px;
  padding: 12px 22px;
  margin: 8px 0;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn-bar:active { transform: scale(0.98); filter: brightness(0.97); }
.bar-title { font-size: 18px; font-weight: 800; letter-spacing: 3px; }
.bar-desc { font-size: 12px; margin-top: 4px; opacity: 0.72; letter-spacing: 0.5px; }

.btn-mint {
  background: linear-gradient(180deg, var(--mint-hi), var(--mint));
  box-shadow: 0 6px 18px rgba(158, 217, 205, 0.55);
  color: var(--mint-ink);
}
.btn-pink {
  background: linear-gradient(180deg, var(--pink-hi), var(--pink));
  box-shadow: 0 6px 18px rgba(247, 183, 197, 0.55);
  color: var(--pink-ink);
}
.btn-sky {
  background: linear-gradient(180deg, var(--sky-hi), var(--sky));
  box-shadow: 0 6px 18px rgba(166, 201, 238, 0.55);
  color: var(--sky-ink);
}
.btn-lilac {
  background: linear-gradient(180deg, var(--lilac-hi), var(--lilac));
  box-shadow: 0 6px 18px rgba(203, 191, 230, 0.55);
  color: var(--lilac-ink);
}
.btn-gray {
  background: linear-gradient(180deg, var(--gray-hi), var(--gray));
  box-shadow: 0 4px 14px rgba(107, 93, 82, 0.18);
  color: var(--gray-ink);
}

.lobby-menu {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lobby-menu .btn-bar { align-items: flex-start; }

/* ---------- 닉네임 ---------- */
.nick-box {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.nick-box label {
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-align: center;
}
.nick-box input {
  width: 100%;
  padding: 14px 16px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 2px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  font-family: inherit;
}
.nick-box input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(158, 217, 205, 0.25);
}
.nick-field { position: relative; width: 100%; }
.nick-ghost {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 16px;
  font-size: 18px;
  letter-spacing: 2px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--mint);
  border-radius: 14px;
  cursor: text;
}
.nick-ghost .suffix { color: var(--text-dim); }

/* 토스트 */
.toast {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translateX(-50%);
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(107, 93, 82, 0.16);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ---------- 설정 ---------- */
/* 페이지 제목 줄 — 제목은 가운데, 뒤로가기는 화면 왼쪽 끝 */
.screen-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 28px;
}
.btn-exit.page-back { left: -24px; } /* 화면 좌우 패딩(24px) 상쇄 */
.screen-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--text);
}
.config-list {
  width: 100%;
  max-width: 420px;
  margin-bottom: 28px;
}
.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.toggle {
  min-width: 72px;
  padding: 10px 0;
  border: none;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 2px;
  cursor: pointer;
  font-family: inherit;
  background: var(--gray);
  color: var(--gray-ink);
}
.toggle.on {
  background: linear-gradient(180deg, var(--mint-hi), var(--mint));
  color: var(--mint-ink);
}
/* 설정의 '보기'처럼 켜고 끄는 게 아닌 버튼 — 토글과 같은 크기, 검은 테두리만 있고 채움 없음 */
.toggle.outline {
  background: transparent;
  border: 2px solid #1a1a1a;
  color: #1a1a1a;
  padding: 8px 0; /* 테두리 2px만큼 줄여 토글과 높이를 맞춘다 */
}
.toggle.outline:active { background: rgba(0, 0, 0, 0.06); }

/* ---------- 게임 화면 ---------- */
#screen-game {
  padding: 0 10px;
  justify-content: flex-start;
  /* 노치/홈 인디케이터 회피 — env가 0인 환경에서도 최소 여백을 확보 */
  padding-top: max(env(safe-area-inset-top), 8px);
  padding-bottom: max(env(safe-area-inset-bottom), 10px);
}

/* 나가기 버튼 — HUD 행 안에서 화면 좌측 끝에 붙는다 */
.btn-exit {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 4px;
  font-family: inherit;
  font-size: 26px;
  line-height: 1;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 12px 12px 0;
  cursor: pointer;
  z-index: 15;
}
.btn-exit:active { background: var(--panel-2); }

/* HUD — SCORE · LEFT */
.game-hud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  padding: 4px 8px 4px 46px;
  flex: none;
}
.hud-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
}
.hud-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--mint-ink);
  line-height: 1.15;
}
.hud-left { flex: 1; min-width: 0; }
/* 힌트 버튼은 화면 정중앙에 — HUD의 왼쪽 여백(나가기 버튼 자리 46px)이 오른쪽(8px)보다 커서
   flex 가운데 정렬로는 19px 오른쪽으로 쏠린다. 절대 배치로 HUD 폭의 50% 지점에 둔다. */
.hud-mid {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
}
.hud-right { flex: 1; min-width: 0; text-align: right; }
.hud-right .hud-value { color: var(--text-dim); font-size: 18px; }

/* 남은 시간 막대 */
.time-bar {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 18px;
  margin: 4px 0 8px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  flex: none;
}
.time-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--mint), var(--sky));
  transition: transform 0.1s linear, background 0.4s ease;
}
.time-bar.warn .time-fill { background: linear-gradient(90deg, var(--butter), var(--pink)); }
.time-bar.danger .time-fill {
  background: linear-gradient(90deg, #f79bad, #f2748e);
  animation: time-pulse 0.7s ease-in-out infinite;
}
@keyframes time-pulse { 50% { opacity: 0.55; } }
.time-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(107, 93, 82, 0.45);
}

/* 보드 */
.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#board-canvas {
  display: block;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 6px 26px rgba(107, 93, 82, 0.12);
}

/* 힌트 버튼 — HUD 줄 가운데 */
.hint-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  cursor: pointer;
  background: linear-gradient(180deg, var(--butter-hi), var(--butter));
  color: var(--butter-ink);
  box-shadow: 0 3px 10px rgba(248, 221, 162, 0.7);
}
.hint-btn:active { transform: scale(0.97); }
.hint-btn:disabled { background: var(--gray-hi); color: var(--text-dim); box-shadow: none; }

/* 멀티 — 상단 3분할 상대 화면 */
.multi-view {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 480px;
  height: 14vh;
  min-height: 74px;
  max-height: 130px;
  flex: none;
  margin-bottom: 4px;
}
.rival {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  padding: 3px;
}
.rival canvas { flex: 1; min-height: 0; display: block; }
.rival-info {
  display: flex;
  align-items: baseline;
  gap: 3px;
  width: 100%;
  padding: 1px 2px 0;
}
.rival-name {
  flex: 1;
  min-width: 0;
  font-size: 8px;
  letter-spacing: 0;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rival-score { flex: none; font-size: 10px; font-weight: 800; color: var(--mint-ink); }
/* 끝난 상대 — 판은 회색으로 바래고 카드 전체가 가라앉는다. 진행 중인 화면은 손대지 않는다. */
.rival.dead { background: #f1eee9; border-color: #e3ddd4; }
.rival.dead canvas { filter: grayscale(1) brightness(1.15) opacity(0.45); }
.rival.dead .rival-name, .rival.dead .rival-score { color: var(--text-dim); }

/* 카운트다운 배너 */
.count-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 74px;
  font-weight: 800;
  color: var(--mint-ink);
  text-shadow: 0 4px 0 #fff, 0 10px 30px rgba(158, 217, 205, 0.6);
  pointer-events: none;
  z-index: 12;
}
.count-banner .pop { animation: count-pop 0.9s ease-out both; }
@keyframes count-pop {
  0%   { opacity: 0; transform: scale(1.7); }
  22%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.82); }
}

/* 결과 오버레이 — 보드 영역만 덮는다 */
.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 20px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(2px);
  z-index: 10;
  animation: popup-fade 0.25s ease-out both;
}
.overlay-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--pink-ink);
}
.overlay-sub {
  margin-top: 6px;
  margin-bottom: 14px;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}
.overlay-sub b { color: var(--mint-ink); font-size: 20px; }
.overlay-rank {
  width: 100%;
  max-width: 300px;
  margin-bottom: 18px;
}
.overlay-rank:empty { display: none; }
.orank-row {
  /* 랭킹 페이지처럼 1등부터 한 줄씩 펼쳐진다 (지연은 JS에서 0.2초 간격) */
  transform-origin: center center;
  animation: rank-flip 0.32s ease-out backwards;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
  margin-bottom: 4px;
  background: var(--panel);
}
.orank-row.me { background: linear-gradient(180deg, var(--mint-hi), var(--mint)); color: var(--mint-ink); font-weight: 800; }
.orank-row .rk { width: 20px; font-weight: 800; color: var(--text-dim); }
.orank-row.me .rk { color: var(--mint-ink); }
.orank-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.orank-row .val { font-weight: 800; }
.orank-row .sub { font-size: 11px; color: var(--text-dim); margin-right: 8px; white-space: nowrap; }
.orank-row.me .sub { color: var(--mint-ink); opacity: 0.75; }
.orank-row.playing { opacity: 0.6; }
.game-overlay .btn-bar { min-height: 52px; max-width: 300px; }

/* ---------- 팝업 공통 ---------- */
.match-popup {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(107, 93, 82, 0.28);
  backdrop-filter: blur(3px);
  z-index: 20;
  animation: popup-fade 0.15s ease-out both;
}
@keyframes popup-fade { from { opacity: 0; } to { opacity: 1; } }

/* 70% 스케일·투명에서 시작해 110%로 튀었다가 100%로 안착 */
@keyframes popup-spring {
  0%     { opacity: 0; transform: scale(0.7); }
  66.67% { opacity: 1; transform: scale(1.1); }
  100%   { opacity: 1; transform: scale(1); }
}

.match-box {
  animation: popup-spring 0.2s ease-out both;
  min-width: 240px;
  padding: 28px 36px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(107, 93, 82, 0.22);
}
.match-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--mint-ink);
}
.match-title span {
  display: inline-block;
  width: 1.6em; /* 점 개수가 변해도 제목이 흔들리지 않게 */
  text-align: left;
}
.match-sub {
  margin-top: 10px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.match-cancel { width: 100%; margin-top: 20px; }

/* 화면이 아주 좁거나 낮을 때 */
@media (max-height: 700px) {
  .brand { margin-bottom: 32px; }
  .brand-logo { font-size: 38px; }
  .btn-bar { min-height: 58px; margin: 6px 0; }
}

/* ---------- 튜토리얼 ----------
   게임 화면 아래쪽에 떠 있는 카드. 안내 대상 동물은 판 위쪽에 두어 카드가 가리지 않는다. */
.tutorial {
  position: absolute;
  left: 50%;
  bottom: max(env(safe-area-inset-bottom), 14px);
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  z-index: 14;
  pointer-events: none; /* 카드 바깥은 판을 그대로 만질 수 있게 */
}
.tutorial-card {
  pointer-events: auto;
  padding: 14px 16px 12px;
  border-radius: 16px;
  /* 연한 버터색 — 힌트 노랑과 한 계열이라 안내 카드임이 드러나고, 흰 판 위에서도 또렷하다 */
  background: rgba(255, 246, 216, 0.97);
  border: 1px solid #f3dfa4;
  box-shadow: 0 10px 30px rgba(107, 93, 82, 0.18);
  animation: popup-spring 0.2s ease-out both;
}
.tutorial-step {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--mint-ink);
}
.tutorial-text {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.tutorial-text b { color: var(--pink-ink); }
.tutorial-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.tutorial-btns .btn-small { padding: 8px 14px; font-size: 12px; }

/* 튜토리얼 힌트 단계 — 힌트 버튼 둘레를 검은 테두리가 감싸고, 그 위를 노란 빛이 빙글빙글 돈다.
   ::before 에 원뿔 그라데이션을 깔고 마스크로 안쪽을 도려내 3px 고리만 남긴다. */
@property --hint-spin {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.hint-btn { position: relative; }
.hint-btn.attention::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  padding: 3px;
  background: conic-gradient(from var(--hint-spin),
    #fff1b8 0deg, #ffd45e 30deg, #f0b429 70deg, #141414 120deg, #141414 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  animation: hint-spin 1s linear infinite;
  pointer-events: none;
}
@keyframes hint-spin {
  from { --hint-spin: 0deg; }
  to   { --hint-spin: 360deg; }
}
