/* 반디도 - 홍차넷 오락실 */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: #241a12;
  color: #f2e8d8;
}

.bd-app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 헤더 ---------- */
.bd-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #1b130c;
  border-bottom: 1px solid #3d2e1e;
}

.bd-back {
  color: #b59d7c;
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
}
.bd-back:active { background: rgba(255,255,255,0.1); }

.bd-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
}

.bd-hud {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
  color: #b59d7c;
  white-space: nowrap;
}
.bd-hud-item b { color: #ffcf7d; }

.bd-timer {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffcf7d;
  min-width: 76px;
  text-align: right;
}

/* ---------- 보드 ---------- */
.bd-scroll {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 200, 120, 0.05), transparent 50%),
    repeating-linear-gradient(45deg, #241a12 0px, #241a12 14px, #221810 14px, #221810 28px);
}

.bd-board {
  position: relative;
  margin: auto;
}

.bd-cell {
  position: absolute;
  width: 64px;
  height: 64px;
}

.bd-dirt { fill: #4a3826; stroke: #5d4930; stroke-width: 1.5; }
.bd-dirt--start { fill: #5a3030; stroke: #7d4444; }

/* 시작 타일 위 감옥 그림 (실물 슈퍼카드) */
.bd-jail {
  position: absolute;
  width: 78px;
  height: 52px;
  border-radius: 4px;
  border: 2px solid #2b1f13;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 2;
}
.bd-tunnel-outer { fill: none; stroke: #2b1f13; stroke-width: 22; stroke-linecap: round; }
.bd-tunnel { fill: none; stroke: #c9a86a; stroke-width: 16; stroke-linecap: round; }
.bd-chamber { fill: #c9a86a; stroke: #2b1f13; stroke-width: 3; }
.bd-cap { fill: #2b1f13; stroke: #c9a86a; stroke-width: 3; }

/* 열린 출구 마커 */
.bd-end {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #ff5a5a;
  box-shadow: 0 0 8px rgba(255, 90, 90, 0.8);
  animation: bd-pulse 1.1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes bd-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}

/* 배치 고스트 */
.bd-ghost {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: rgba(110, 220, 130, 0.18);
  border: 2px dashed rgba(110, 220, 130, 0.85);
  cursor: pointer;
  z-index: 5;
}
.bd-ghost:hover { background: rgba(110, 220, 130, 0.4); }

/* 배치 프리뷰: 실제 놓일 카드 모습을 반투명으로 (호버/첫 탭) */
.bd-prev {
  position: absolute;
  width: 64px;
  height: 64px;
  opacity: 0.62;
  pointer-events: none;
  z-index: 6;
  filter: drop-shadow(0 0 6px rgba(255, 207, 125, 0.5));
}

/* ---------- 손패 ---------- */
.bd-handbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #1b130c;
  border-top: 1px solid #3d2e1e;
}

.bd-hand {
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
}

.bd-hand-card {
  flex: 0 0 auto;
  min-width: 100px;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #3d2e1e;
  border-radius: 12px;
  background: #241a12;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.bd-hand-card.is-selected {
  border-color: #ffcf7d;
  background: #2f2214;
  box-shadow: 0 0 12px rgba(255, 207, 125, 0.25);
}
.bd-hand-card.is-empty { opacity: 0.25; cursor: default; }

/* 뽑기 연출: 카드가 도착할 때까지 슬롯 내용 숨김 → 도착 시 팝 */
.bd-hand-card.is-incoming .bd-hand-grid { visibility: hidden; }
.bd-hand-card.is-reveal .bd-hand-grid { animation: bd-reveal 0.18s ease-out; }
@keyframes bd-reveal {
  from { transform: scale(0.4); }
  to   { transform: scale(1); }
}

/* 더미(뽑을 카드 무더기) */
.bd-pile {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 72px;
}
.bd-pile-back {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: repeating-linear-gradient(135deg, #4a3826 0 7px, #3d2e1e 7px 14px);
  border: 2px solid #6b5335;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}
.bd-pile-back.l1 { transform: translate(2px, 2px); }
.bd-pile-back.l2 { transform: translate(4px, 4px); }
.bd-pile.is-empty .bd-pile-back { opacity: 0.25; border-style: dashed; }
.bd-pile-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  color: #ffcf7d;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

/* 날아가는 카드 뒷면 */
.bd-fly {
  position: fixed;
  z-index: 200;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: repeating-linear-gradient(135deg, #4a3826 0 7px, #3d2e1e 7px 14px);
  border: 2px solid #6b5335;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: transform 0.26s ease-in-out;
  will-change: transform;
}

.bd-hand-grid { position: relative; }
.bd-hand-cell {
  position: absolute;
  width: 46px;
  height: 46px;
}
.bd-hand-cell svg { width: 46px; height: 46px; }

.bd-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bd-act {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  background: #ffb84d;
  color: #3a2000;
  white-space: nowrap;
}
.bd-act:disabled { opacity: 0.35; cursor: default; }
.bd-act--sub { background: #4a3826; color: #d8c5a5; }
.bd-act:active:not(:disabled) { transform: scale(0.96); }

/* 효과음 토글 */
.bd-sound {
  border: none;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.bd-sound:active { transform: scale(0.92); }

/* 현재 회전 방향에 놓을 자리가 없을 때 안내 */
.bd-nofit {
  display: none;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.4;
  color: #ff9d8a;
  text-align: center;
}

/* 손패 3장 전부 막혔을 때만 켜지는 교환 버튼 강조 */
.bd-act.is-urgent {
  background: #ff5a5a;
  color: #fff;
  animation: bd-urgent 0.9s ease-in-out infinite;
}
@keyframes bd-urgent {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.7); }
  50% { box-shadow: 0 0 0 7px rgba(255, 90, 90, 0); }
}

/* ---------- 오버레이 ---------- */
.bd-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 10, 5, 0.88);
  z-index: 100;
  padding: 20px;
}
.bd-overlay.is-open { display: flex; }

.bd-panel {
  width: 100%;
  max-width: 400px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: linear-gradient(160deg, #332516 0%, #241a12 100%);
  border: 1px solid #4a3826;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.bd-logo {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 5px;
  color: #ffcf7d;
  text-shadow: 0 3px 0 #6b4423;
}
.bd-logo span {
  display: block;
  font-size: 12px;
  letter-spacing: 9px;
  margin-top: 2px;
  color: #8a745a;
  text-shadow: none;
}

.bd-desc {
  margin: 18px 0;
  font-size: 14px;
  line-height: 1.7;
  color: #d8c5a5;
}
.bd-desc b { color: #ffcf7d; }
.bd-tip { color: #8a745a; font-size: 12.5px; }

/* 시작 화면 규칙 목록 */
.bd-rules {
  text-align: left;
  margin: 12px auto 4px;
  padding-left: 20px;
  max-width: 340px;
  font-size: 13.5px;
  line-height: 1.8;
  color: #d8c5a5;
}
.bd-rules li { list-style: disc; }
.bd-rules b { color: #ff9d8a; }

.bd-mybest {
  min-height: 20px;
  font-size: 14px;
  font-weight: 700;
  color: #7ee2a8;
  margin-bottom: 10px;
}

.bd-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 10px;
  font-family: inherit;
}
.bd-btn--start {
  background: linear-gradient(90deg, #ffb84d, #ff8a5c);
  color: #3a2000;
  box-shadow: 0 6px 18px rgba(255, 150, 60, 0.3);
}
.bd-btn--start:active { transform: scale(0.97); }
.bd-btn--sub { background: #4a3826; color: #d8c5a5; }

/* 난이도 선택: 쉬움/어려움 두 버튼 나란히 */
.bd-mode-row {
  display: flex;
  gap: 10px;
}
.bd-mode-row .bd-btn { margin-top: 10px; }
.bd-btn--hard {
  background: linear-gradient(90deg, #ff7a5c, #e84d4d);
  color: #fff;
  box-shadow: 0 6px 18px rgba(230, 80, 60, 0.3);
}
.bd-btn-sub {
  display: block;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.75;
  margin-top: 3px;
}

.bd-ranks { margin-top: 22px; }
.bd-ranks-title {
  font-size: 12px;
  font-weight: 700;
  color: #8a745a;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.bd-ranks ol { list-style: none; counter-reset: rk; }
.bd-ranks li {
  counter-increment: rk;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.bd-ranks li:nth-child(odd) { background: rgba(255,255,255,0.05); }
.bd-ranks li::before {
  content: counter(rk);
  font-weight: 800;
  color: #8a745a;
  width: 18px;
  flex: 0 0 auto;
}
.bd-ranks li:nth-child(1)::before { content: "🥇"; width: 22px; }
.bd-ranks li:nth-child(2)::before { content: "🥈"; width: 22px; }
.bd-ranks li:nth-child(3)::before { content: "🥉"; width: 22px; }
.bd-rank-name {
  flex: 1 1 auto;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bd-rank-time {
  font-variant-numeric: tabular-nums;
  color: #ffcf7d;
  font-weight: 700;
}

.bd-login-note {
  margin-top: 14px;
  font-size: 12px;
  color: #8a745a;
}

.bd-end-title { font-size: 30px; font-weight: 900; }
.bd-end-title.is-win { color: #7ee2a8; }
.bd-end-title.is-lose { color: #ff8a99; }

.bd-end-time {
  font-size: 44px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #ffcf7d;
  margin: 10px 0 4px;
}

.bd-end-detail {
  font-size: 13px;
  color: #b59d7c;
  margin-bottom: 14px;
}

.bd-record-msg {
  min-height: 22px;
  font-size: 15px;
  font-weight: 700;
  color: #d8c5a5;
  margin-bottom: 12px;
}
.bd-record-msg.is-new { color: #7ee2a8; }
.bd-record-msg.is-err { color: #ff8a99; }

/* 좁은 화면 */
@media (max-width: 600px) {
  .bd-hud { gap: 8px; font-size: 12px; }
  .bd-timer { font-size: 17px; min-width: 62px; }
  .bd-title { letter-spacing: 0; }
  .bd-hand-card { min-width: 88px; min-height: 88px; }
  .bd-pile { width: 44px; height: 58px; }
  .bd-pile-count { font-size: 14px; }
}

/* 데스크탑: 손패를 맵 위 좌측 플로팅 패널로 */
@media (min-width: 901px) {
  .bd-handbar {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 40;
    flex-direction: column;
    align-items: stretch;
    width: auto;
    padding: 0;
    background: transparent;
    border: none;
    pointer-events: none;
  }
  .bd-handbar > * { pointer-events: auto; }
  .bd-hand {
    flex-direction: column;
    overflow: visible;
    gap: 10px;
  }
  .bd-hand-card {
    background: rgba(27, 19, 12, 0.88);
    border-color: #4a3826;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
  }
  .bd-hand-card.is-selected {
    background: rgba(47, 34, 20, 0.95);
    border-color: #ffcf7d;
  }
  .bd-actions {
    flex-direction: row;
    justify-content: center;
  }
  .bd-scroll { cursor: grab; }
  .bd-scroll.is-dragging { cursor: grabbing; }
}
