:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: #0a0a0a;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(60px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
  gap: 16px;
}

/* 점수바: SCORE | BEST | New 버튼 */
.score-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.score-box {
  flex: 1;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 0;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a0a0a0;
}

.score-val,
.best-val {
  display: block;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: #f5f5f5;
  margin-top: 2px;
  line-height: 1.1;
}

.new-btn {
  flex: 0 0 auto;
  font: inherit;
  color: #fff;
  background: #4f9eff;
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 56px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.new-btn:active { background: #3d8ae8; }

/* 게임 영역 — 보드/캠버스/그리드 등을 여기에 */
#game {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 chrome */
.home-link,
.hof-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  z-index: 10;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.home-link { left:  max(12px, env(safe-area-inset-left)); }
.hof-link  { right: max(12px, env(safe-area-inset-right)); }

@media (hover: hover) {
  .home-link:hover,
  .hof-link:hover {
    background: rgba(0, 0, 0, 0.55);
  }
}

/* 오버레이 (게임 종료 / 완료 시 점수 + 저장 버튼) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 18px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  text-align: center;
  min-width: 240px;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.overlay-score {
  margin: 0;
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.overlay-card button {
  font: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.overlay-card button:active {
  background: rgba(255, 255, 255, 0.18);
}

.overlay-card .save-btn {
  background: #4f9eff;
  border-color: #4f9eff;
}

.overlay-card .save-btn:active {
  background: #3d8ae8;
}

/* ─── 두락 ─────────────────────────────────────────────────
   위에서부터: 상대 손패(뒷면) · 덱+으뜸패와 테이블 · 안내문 · 버튼 · 내 손패. */
#game {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 10px;
  min-height: 0;
}

/* 카드 한 장 */
.dk-card {
  position: relative;
  width: 46px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 7px;
  background: #f2f2f2;
  color: #14161c;
  border: 1px solid #cfcfcf;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.dk-card.red { color: #d1344b; }
.dk-card b { font-size: 19px; }
.dk-card i { font-style: normal; font-size: 17px; margin-top: 2px; }

.dk-back {
  width: 22px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 5px;
  border: 1px solid #2f3a52;
  background: repeating-linear-gradient(45deg, #26314a 0 3px, #1b2333 3px 6px);
  margin-left: -8px;
}

.dk-back:first-child { margin-left: 0; }

/* 상대 손패 */
.dk-foe {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
}

.dk-fan { display: flex; }

.dk-count {
  font-size: 12px;
  font-weight: 700;
  color: #a0a0a0;
  font-variant-numeric: tabular-nums;
}

/* 덱 + 으뜸패, 그리고 테이블 */
/* 가운데는 '카드 테이블' 판. 배경을 깔아 빈 공간이 허전한 여백이 아니라
   판 위로 읽히게 한다. */
.dk-mid {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: #10151f;
  border: 1px solid #1e2636;
}

.dk-stock {
  position: relative;
  flex: 0 0 auto;
  width: 82px;
  height: 66px;
  align-self: flex-start;
}

/* 으뜸패는 덱 오른쪽으로 비스듬히 빼서 무늬가 항상 보이게 한다.
   (처음엔 덱 아래에 눕혔더니 덱 뒷면에 거의 가려져, 가장 중요한 정보가 안 보였다.) */
.dk-trump .dk-card {
  position: absolute;
  left: 30px;
  top: 2px;
  width: 44px;
  height: 62px;
  transform: rotate(11deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.dk-trump .dk-card b { font-size: 17px; }
.dk-trump .dk-card i { font-size: 15px; }

.dk-deck {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 62px;
  border-radius: 7px;
  border: 1px solid #2f3a52;
  background: repeating-linear-gradient(45deg, #26314a 0 3px, #1b2333 3px 6px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  z-index: 1;
}

.dk-deck.empty { display: none; }

/* 남은 덱 장수는 덱 뒷면 위에 겹쳐 쓴다. 덱이 마르면 으뜸 무늬만 남긴다. */
.dk-dnum {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  font-size: 16px;
  font-weight: 800;
  color: #e8e8e8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  font-variant-numeric: tabular-nums;
}

.dk-dnum.suit {
  font-size: 26px;
  color: #d0d0d0;
  border: 1px dashed #2f3a52;
  border-radius: 7px;
  text-shadow: none;
}

.dk-dnum.suit.red { color: #ff6b7f; }

/* 공격/방어 카드 쌍 — 방어 카드가 공격 카드 위에 비스듬히 겹친다 */
.dk-table {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 6px 14px;
  min-height: 82px;
}

.dk-pair { position: relative; width: 60px; height: 78px; }
.dk-pair .dk-card { position: absolute; left: 0; top: 0; }
.dk-pair .dk-card.def { left: 14px; top: 12px; transform: rotate(7deg); }
.dk-table.tight { gap: 4px 8px; }
.dk-table.tight .dk-pair { width: 54px; }

/* 안내문 */
.dk-msg {
  margin: 0;
  min-height: 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #b8b8b8;
}

.dk-msg.ok { color: #6ee787; }
.dk-msg.bad { color: #ff6b6b; }

/* 가져가기 / 넘기기 */
.dk-acts {
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: 46px;
}

.dk-btn {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: #f5f5f5;
  border-radius: 12px;
  min-height: 46px;
  padding: 0 26px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dk-btn[hidden] { display: none; }
.dk-btn.take { background: #2c1616; border: 1px solid #5a2a2a; color: #ffb3b3; }
.dk-btn.take:active { background: #3a1c1c; }
.dk-btn.pass { background: #16262c; border: 1px solid #2c4f55; color: #a8dfe9; }
.dk-btn.pass:active { background: #1c333a; }

/* 내 손패 — 낼 수 있는 카드만 또렷하게 */
.dk-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 5px;
  min-height: 70px;
}

.dk-hand .dk-card { cursor: pointer; transition: transform 0.12s ease, filter 0.12s ease; }
.dk-hand .dk-card.off { filter: brightness(0.45) saturate(0.5); cursor: default; }
.dk-hand .dk-card.on { outline: 2px solid rgba(110, 231, 135, 0.75); outline-offset: -2px; }
.dk-hand .dk-card.on:active { transform: translateY(-6px); }

.dk-hand.many .dk-card { width: 40px; height: 56px; }
.dk-hand.many .dk-card b { font-size: 16px; }
.dk-hand.many .dk-card i { font-size: 15px; }
.dk-hand.lots .dk-card { width: 33px; height: 47px; }
.dk-hand.lots .dk-card b { font-size: 13px; }
.dk-hand.lots .dk-card i { font-size: 12px; }

@media (max-height: 680px) {
  .dk-card { width: 40px; height: 56px; }
  .dk-card b { font-size: 16px; }
  .dk-card i { font-size: 15px; }
  .dk-pair { width: 54px; height: 70px; }
  .dk-stock { height: 70px; }
}
