: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;
  min-height: 0;   /* 작은 폰에서 아래 조작 요소가 화면 밖으로 밀리지 않게 */
}

/* 좌상단 ← 홈, 우상단 🏆 명예의 전당 — 모든 게임 공통 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;
}

/* ─── Cuarenta ─────────────────────────────────────────────────────
   Green felt, light cards with classic red/black French suits.
   Sizes are tuned for 320×568 (everything inside 100dvh) up to 480px wide. */
main { gap: 10px; }

#game {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 7px;
  position: relative;
  --cw: min(64px, calc((min(100vw, 480px) - 64px) / 5));   /* hand card width: (content width - 4 gaps) / 5 */
}

/* side rows: rival on top, you above your hand */
.cu-side {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  border-radius: 12px;
  background: #141414;
  border: 1px solid #262626;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 42px;
}
.cu-side.turn { border-color: #e0b84a; box-shadow: 0 0 0 1px #e0b84a inset; }
.cu-side.bump .cu-pts { animation: cu-bump 0.6s ease; }
@keyframes cu-bump { 30% { transform: scale(1.45); color: #ffd45e; } }

.cu-backs { display: flex; flex: 0 0 auto; width: 70px; height: 32px; }
.cu-backs i {
  width: 23px; height: 32px; border-radius: 4px; margin-right: -11px; flex: 0 0 auto;
  border: 1px solid #0c3b33;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.13) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.13) 0 2px, transparent 2px 6px),
    #146b5a;
  box-shadow: 0 1px 2px rgba(0,0,0,0.6), inset 0 0 0 2px #e9e2cf;
}
.cu-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cu-who { display: flex; gap: 8px; align-items: baseline; font-size: 12px; font-weight: 700; color: #d6d6d6; }
.cu-lv { font-style: normal; font-size: 11px; color: #e0b84a; font-weight: 700; }
.cu-marks { display: flex; gap: 4px; }
.cu-grp { display: flex; gap: 2px; flex: 1; }
.cu-grp i { flex: 1; height: 7px; border-radius: 2px; background: #2c2c2c; }
.cu-me .cu-grp i.on { background: #4ade80; }
.cu-ai .cu-grp i.on { background: #ff8a7a; }
.cu-num { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; min-width: 52px; }
.cu-pts { font-size: 22px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.cu-pile { font-size: 11px; color: #a8a8a8; font-variant-numeric: tabular-nums; margin-top: 2px; }
.cu-pile.at20 { color: #ffd45e; font-weight: 700; }

/* felt */
.cu-felt {
  position: relative;
  flex: 1 1 auto;
  min-height: 150px;
  border-radius: 16px;
  background: radial-gradient(120% 90% at 50% 40%, #1d6b45 0%, #134a31 70%, #0e3925 100%);
  border: 1px solid #2c6b4a;
  box-shadow: inset 0 0 0 3px rgba(0,0,0,0.18), inset 0 6px 18px rgba(0,0,0,0.35);
  padding: 24px 8px 8px;
  overflow: hidden;
}
.cu-info {
  position: absolute; top: 5px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; gap: 8px; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: #bfe6cf;
}
.cu-table {
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  gap: 6px; min-height: 100%;
}

.cu-last { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; color: #fff; font-weight: 700; }
.cu-last.ai { color: #ffd0c8; }
.cu-last.me { color: #b6ffd0; }

/* roomier table cards on taller screens */
@media (min-height: 700px) and (min-width: 360px) {
  .cu-table .cu-card { width: 54px; height: 76px; border-radius: 7px; }
  .cu-table .cu-ix b { font-size: 18px; }
  .cu-table .cu-ix i { font-size: 13px; }
  .cu-table .cu-pips i { font-size: 12px; }
  .cu-table .cu-pips.ace i { font-size: 28px; }
  .cu-table { gap: 8px; }
}

/* message line */
.cu-msg {
  margin: 0; min-height: 32px; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 13px; font-weight: 600; color: #d0d0d0; line-height: 1.25;
  padding: 0 4px;
}
.cu-msg.ok { color: #9ff0bd; }
.cu-msg.warn { color: #fbd36b; }
.cu-msg.dim { color: #9a9a9a; }

/* hand */
.cu-hand { display: flex; justify-content: center; gap: 8px; min-height: calc(var(--cw) * 1.4); flex: 0 0 auto; }

/* ─── cards ─────────────────────────────────────────────────────── */
.cu-card {
  position: relative;
  font: inherit; margin: 0; padding: 0;
  width: 44px; height: 62px; flex: 0 0 auto;
  border-radius: 6px;
  border: 1px solid #c9c2ae;
  background: linear-gradient(180deg, #fffdf6, #f1ead8);
  color: #1c1c1c;
  cursor: pointer;
  box-shadow: 0 2px 3px rgba(0,0,0,0.45);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.3s ease;
}
.cu-card.red { color: #c0262d; }
.cu-card.blk { color: #1b1b1f; }
.cu-ix { position: absolute; top: 3px; left: 4px; display: flex; flex-direction: column; align-items: center; line-height: 0.95; }
.cu-ix b { font-size: 15px; font-weight: 800; font-family: Georgia, "Times New Roman", serif; }
.cu-ix i { font-style: normal; font-size: 11px; }
.cu-pips { position: absolute; left: 34%; right: 7%; top: 11%; bottom: 9%; }
.cu-pips.ace { left: 20%; right: 4%; top: 20%; }
.cu-pips i { position: absolute; transform: translate(-50%, -50%); font-style: normal; font-size: 10px; line-height: 1; }
.cu-pips.ace i { font-size: 24px; }
.cu-face { position: absolute; right: 3px; bottom: 4px; width: 66%; height: 66%; }
.cu-face .f1 { fill: currentColor; opacity: 0.2; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.cu-face .f2 { fill: currentColor; }
.cu-face .f3 { fill: #d9a520; stroke: currentColor; stroke-width: 0.8; }

.cu-hand .cu-card { width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: 8px; }
.cu-hand .cu-ix { top: 4px; left: 5px; }
.cu-hand .cu-ix b { font-size: 20px; }
.cu-hand .cu-ix i { font-size: 14px; }
.cu-hand .cu-pips i { font-size: 13px; }
.cu-hand .cu-pips.ace i { font-size: 32px; }
.cu-hand:not(.mine) .cu-card { filter: saturate(0.6) brightness(0.78); }

.cu-card.sel { transform: translateY(-10px); box-shadow: 0 0 0 3px #ffd45e, 0 8px 14px rgba(0,0,0,0.55); }
.cu-card.will { box-shadow: 0 0 0 3px #4ade80, 0 0 14px rgba(74,222,128,0.6); transform: translateY(-3px); }
.cu-card.will.fall { box-shadow: 0 0 0 3px #ffd45e, 0 0 16px rgba(255,212,94,0.75); }
.cu-card.alt { outline: 2px dashed #e9f5ee; outline-offset: 2px; }
.cu-card.taken, .cu-card.taker { box-shadow: 0 0 0 3px #ffd45e, 0 0 16px rgba(255,212,94,0.7); animation: cu-glow 0.6s ease infinite alternate; }
@keyframes cu-glow { to { box-shadow: 0 0 0 3px #fff3c4, 0 0 22px rgba(255,212,94,0.95); } }
.cu-card.sweep-me { transform: translateY(160px) scale(0.5) !important; opacity: 0; transition: transform 0.3s ease-in, opacity 0.3s ease-in; }
.cu-card.sweep-ai { transform: translateY(-160px) scale(0.5) !important; opacity: 0; transition: transform 0.3s ease-in, opacity 0.3s ease-in; }
.cu-card.incoming.from-ai { animation: cu-in-ai 0.32s ease-out; }
.cu-card.incoming.from-me { animation: cu-in-me 0.28s ease-out; }
@keyframes cu-in-ai { from { transform: translateY(-120px) rotate(-8deg); opacity: 0.2; } }
@keyframes cu-in-me { from { transform: translateY(120px) rotate(6deg); opacity: 0.2; } }
.cu-card.dealt { animation: cu-deal 0.34s ease-out backwards; }
@keyframes cu-deal { from { transform: translateY(-60px) scale(0.6); opacity: 0; } }
.cu-card.shake { animation: cu-shake 0.32s ease; }
@keyframes cu-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* hand hints on your turn: green bar = this card captures, gold = it makes a caída */
.cu-hand.mine .cu-card.can::before, .cu-hand.mine .cu-card.fall::before {
  content: ''; position: absolute; left: 22%; right: 22%; bottom: 4px; height: 4px; border-radius: 2px; background: #22a95a;
}
.cu-hand.mine .cu-card.fall::before { background: #e0a91a; }

/* the card your rival just dropped — a caída target */
.cu-card.tagged::after {
  content: attr(data-tag);
  position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  font-size: 9px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  color: #2a1d00; background: #ffd45e; border-radius: 6px; padding: 1px 5px; white-space: nowrap;
}

/* score badges */
.cu-pop { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.cu-badge {
  font-size: 22px; font-weight: 900; letter-spacing: 0.02em; padding: 6px 16px; border-radius: 999px;
  background: rgba(10,10,10,0.82); color: #fff; border: 2px solid #fff;
  animation: cu-pop 1.5s ease forwards;
}
.cu-badge.good { color: #b6ffd0; border-color: #4ade80; }
.cu-badge.bad { color: #ffd0c8; border-color: #ff8a7a; }
@keyframes cu-pop { 0% { transform: scale(0.4); opacity: 0; } 15% { transform: scale(1.12); opacity: 1; } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* end-of-hand count panel (inside the felt) */
.cu-panel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 8px; background: rgba(6,20,13,0.72); border-radius: 16px; z-index: 3; }
.cu-panel[hidden] { display: none; }
.cu-count { width: 100%; max-width: 300px; background: #161616; border: 1px solid #2f2f2f; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.cu-count h3 { margin: 0; font-size: 16px; text-align: center; }
.cu-count table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.cu-count th, .cu-count td { padding: 3px 4px; text-align: right; }
.cu-count tbody th { text-align: left; color: #c8c8c8; font-weight: 600; }
.cu-count thead th { font-size: 11px; color: #9a9a9a; text-transform: uppercase; letter-spacing: 0.05em; }
.cu-aw td { color: #ffd45e; font-weight: 800; }
.cu-tot td { border-top: 1px solid #333; font-size: 17px; }
.cu-bar { display: block; height: 4px; margin-top: 3px; background: #2c2c2c; border-radius: 2px; overflow: hidden; }
.cu-bar i { display: block; height: 100%; background: #6b6b6b; }
.cu-bar.full i { background: #e0b84a; }
.cu-note { margin: 0; font-size: 12px; color: #a8a8a8; line-height: 1.35; text-align: center; }
.cu-next {
  font: inherit; font-weight: 700; font-size: 15px; color: #fff; background: #2563eb; border: none;
  border-radius: 999px; min-height: 44px; margin-top: 4px; cursor: pointer;
}
.cu-next:active { background: #1d4fc4; }

/* start / result cards */
.cu-rules { margin: 0; padding-left: 18px; text-align: left; font-size: 13.5px; line-height: 1.4; color: #dedede; display: flex; flex-direction: column; gap: 6px; }
.cu-rules b { color: #ffd45e; }
.cu-intro .cu-note b { color: #ffd45e; }
.cu-final { margin: 0; display: flex; gap: 10px; align-items: baseline; font-size: 14px; color: #c8c8c8; }
.cu-final b { font-size: 22px; color: #fff; }
.cu-cap { margin: -6px 0 0; font-size: 12px; color: #9a9a9a; }
.cu-line { margin: 0; font-size: 12px; color: #b8b8b8; }
.cu-result.won h2 { color: #4ade80; }
.cu-result.lost h2 { color: #ff8a7a; }

@media (max-height: 600px) {
  main { gap: 8px; }
  .cu-count { padding: 10px 12px; gap: 4px; }
  .cu-count table { font-size: 13px; }
  .cu-intro { padding: 16px 16px; gap: 8px; }
  .cu-intro h2 { font-size: 19px; }
  .cu-rules { font-size: 12.5px; line-height: 1.3; gap: 4px; }
  .cu-intro .cu-note { font-size: 11.5px; }
  #game { gap: 5px; }
  .cu-side { min-height: 38px; padding: 4px 10px; }
  .cu-felt { padding-top: 22px; }
  .cu-msg { min-height: 30px; font-size: 12.5px; }
}
