: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;
}

/* ─── Tute ─────────────────────────────────────────────────────────────
   Top to bottom: rival row (name · level · card backs · known cards) · felt table (stock with the
   face-up muestra, the trick, banners, declaration panel) · points bar · status line · your hand. */
main { gap: 8px; }
.score-bar .new-btn { min-height: 52px; }
.score-box { padding: 6px 10px; }

#game {
  flex: 1; min-height: 0;
  flex-direction: column; align-items: stretch; justify-content: flex-start;
  gap: 6px;
  --cw: clamp(44px, min(22vw, 9.6dvh), 92px);
  --ch: calc(var(--cw) * 1.45);
}

/* rival row */
.tu-opp { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.tu-name {
  font-size: 12px; font-weight: 800; white-space: nowrap;
  padding: 5px 10px; border-radius: 999px;
  background: #1b1d24; color: #ffd3d3; border: 2px solid rgba(255,143,143,.5);
  transition: background .2s, color .2s, box-shadow .2s;
}
.tu-name .tu-lv { color: #c9cbd3; font-weight: 700; }
.tu-name.turn { background: #ffcf4a; color: #1b1d24; border-color: #ffcf4a; box-shadow: 0 0 12px rgba(255,207,74,.7); }
.tu-name.turn .tu-lv { color: #4a3b0a; }
.tu-backs { display: inline-flex; flex: 1; min-width: 0; }
.tu-backs i {
  width: 18px; height: 26px; border-radius: 3px; margin-right: -7px; flex: 0 0 auto;
  background:
    radial-gradient(circle at 50% 50%, #f1c232 0 2.5px, transparent 3px),
    repeating-linear-gradient(45deg, #9d2f2a 0 2px, #7a1f1c 2px 4px);
  border: 1.5px solid #f4efe2; box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.tu-known { display: inline-flex; gap: 3px; }

/* cards */
.tu-card {
  position: relative; display: block;
  background: linear-gradient(#fffdf6, #efe7d2);
  border: 1px solid #c8b993; border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,.45);
  font-family: inherit; padding: 0; color: #1b1d24; overflow: hidden;
}
.tu-card::before { /* thin inner frame, like printed Spanish cards */
  content: ''; position: absolute; inset: 3px; border: 1px solid rgba(0,0,0,.12); border-radius: 5px; pointer-events: none;
}
.tu-card.s0 .tu-rank { color: #a26a00; }
.tu-card.s1 .tu-rank { color: #c1302a; }
.tu-card.s2 .tu-rank { color: #1f5aa8; }
.tu-card.s3 .tu-rank { color: #2c7a2c; }
.tu-rank {
  position: absolute; left: 5px; top: 4px; font-weight: 900; line-height: 1;
  font-size: calc(var(--w) * 0.3); letter-spacing: -0.04em;
}
.tu-card .tu-suit.big { position: absolute; left: 58%; top: 55%; width: 58%; height: 58%; transform: translate(-50%, -50%); }
.tu-court { position: absolute; left: 3px; top: calc(var(--w) * 0.34); width: calc(var(--w) * 0.3); height: calc(var(--w) * 0.3); }
.tu-card u {
  position: absolute; left: 4px; bottom: 4px; text-decoration: none;
  font-size: calc(var(--w) * 0.19); font-weight: 900; color: #fff;
  background: #3a3427; border-radius: 6px; padding: 1px 4px; line-height: 1.1;
}
.tu-card.mini { --w: 26px; width: 26px; height: 37px; border-radius: 5px; box-shadow: 0 0 0 2px #ffcf4a, 0 2px 4px rgba(0,0,0,.5); }
.tu-card.mini::before, .tu-card.mini u, .tu-card.mini .tu-court { display: none; }
.tu-card.mini .tu-rank { left: 3px; top: 2px; font-size: 11px; }
.tu-card.mini .tu-suit.big { top: 62%; width: 70%; height: 55%; }
svg.tu-suit { display: inline-block; }
svg.tu-suit.inl { width: 1.15em; height: 1.15em; vertical-align: -0.22em; }

/* felt table */
.tu-table {
  position: relative; flex: 1; min-height: 0;
  border-radius: 22px;
  background:
    radial-gradient(ellipse at 55% 45%, rgba(255,255,255,.08), transparent 62%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.035) 0 2px, transparent 2px 5px),
    #1d5a3c;
  border: 5px solid #6b3f22;
  box-shadow: inset 0 0 0 2px #8b5a32, inset 0 6px 22px rgba(0,0,0,.45), 0 4px 14px rgba(0,0,0,.45);
  overflow: hidden;
}
.tu-stock { position: absolute; left: 12px; top: 50%; transform: translateY(-46%); width: calc(var(--cw) * 1.75); height: calc(var(--ch) + 8px); }
.tu-mu { position: absolute; left: 0; top: 0; transform: rotate(-7deg); transform-origin: 50% 80%; }
.tu-stock.gone .tu-mu { left: 0; top: calc(var(--ch) / 2); transform: translateY(-50%); }
.tu-card.mu { --w: var(--cw); width: var(--cw); height: var(--ch); }
.tu-pile { position: absolute; left: calc(var(--cw) * 0.72); top: 4px; width: var(--cw); height: var(--ch); z-index: 2; }
.tu-pile[hidden] { display: none; }
.tu-pile i {
  position: absolute; inset: 0; border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, #f1c232 0 5px, #7a1f1c 5.5px 8px, transparent 8.5px),
    repeating-linear-gradient(45deg, #9d2f2a 0 3px, #7a1f1c 3px 6px);
  border: 2px solid #f4efe2; box-shadow: 0 2px 4px rgba(0,0,0,.5);
}
.tu-pile i:nth-child(2) { transform: translate(-2px, -2px); }
.tu-pile i:nth-child(3) { transform: translate(-4px, -4px); }
.tu-left {
  position: absolute; left: 50%; top: 50%; transform: translate(-60%, -60%); z-index: 4;
  font-size: 13px; font-weight: 900; color: #1b1d24; background: #f4efe2; border-radius: 999px; padding: 2px 7px;
}
.tu-arr {
  display: inline-block; font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase;
  color: #ffcf4a; background: rgba(0,0,0,.35); padding: 4px 8px; border-radius: 8px; white-space: nowrap;
}
.tu-trump {
  position: absolute; left: 10px; top: 10px; z-index: 3;
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0;
  background: #f4efe2; color: #1b1d24; border-radius: 10px; padding: 3px 8px 4px; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.tu-trump em { font-style: normal; font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #5a5d66; }
.tu-tsuit { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; }
.tu-tsuit svg { width: 18px; height: 18px; }
.tu-trump.flash { animation: tu-flash 1.2s ease-out; }
@keyframes tu-flash { 0%,40% { transform: scale(1.2); box-shadow: 0 0 0 4px #ffcf4a, 0 2px 6px rgba(0,0,0,.4); } 100% { transform: none; } }

.tu-mark { position: absolute; left: 60%; top: 50%; width: calc(var(--ch) * 1.7); height: calc(var(--ch) * 1.7); transform: translate(-50%, -50%); opacity: .06; filter: grayscale(1) brightness(2.2); pointer-events: none; }
.tu-mark svg { width: 100%; height: 100%; }
/* trick */
.tu-trick { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.tu-slot { position: absolute; left: calc(50% + var(--cw) * 0.6); top: 50%; width: var(--cw); height: var(--ch); margin: calc(var(--ch) / -2) 0 0 calc(var(--cw) / -2); }
.tu-slot.opp { transform: translate(calc(var(--cw) * -0.32), calc(var(--ch) * -0.36)) rotate(-6deg); }
.tu-slot.me { transform: translate(calc(var(--cw) * 0.32), calc(var(--ch) * 0.36)) rotate(5deg); }
.tu-card.tbl { --w: var(--cw); width: 100%; height: 100%; transition: transform .32s cubic-bezier(.2,.8,.25,1), opacity .25s; }
.tu-card.tbl.sweep { transition: transform .34s ease-in, opacity .34s ease-in; }
.tu-slot.win { z-index: 5; }
.tu-slot.win .tu-card { box-shadow: 0 0 0 3px #ffcf4a, 0 0 18px rgba(255,207,74,.8); }
.tu-slot.win::after {
  content: attr(data-pts); position: absolute; left: 50%; top: -13px; transform: translateX(-50%); z-index: 6;
  font-size: 13px; font-weight: 900; color: #1b1d24; background: #ffcf4a; border-radius: 999px; padding: 1px 7px; white-space: nowrap;
}
.tu-slot.win[data-pts=""]::after { display: none; }

/* banner (cantes, swaps, arrastre, last trick) */
.tu-banner {
  position: absolute; left: 50%; top: 12px; transform: translate(-50%, -8px); z-index: 7;
  max-width: calc(100% - 24px); text-align: center;
  font-size: 13px; font-weight: 800; line-height: 1.3;
  padding: 6px 12px; border-radius: 12px; background: #f4efe2; color: #1b1d24;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.tu-banner.show { opacity: 1; transform: translate(-50%, 0); }
.tu-banner.good { box-shadow: 0 0 0 3px #6fd3a2, 0 6px 18px rgba(0,0,0,.5); }
.tu-banner.bad { box-shadow: 0 0 0 3px #ff8f8f, 0 6px 18px rgba(0,0,0,.5); }
.tu-banner.info { box-shadow: 0 0 0 3px #ffcf4a, 0 6px 18px rgba(0,0,0,.5); }
.tu-banner b { font-size: 18px; letter-spacing: -0.01em; }
.tu-banner.big.show { animation: tu-pop .5s ease-out; }
@keyframes tu-pop { 0% { transform: translate(-50%, 0) scale(.6); } 60% { transform: translate(-50%, 0) scale(1.12); } 100% { transform: translate(-50%, 0) scale(1); } }

/* declaration panel */
.tu-decl {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 8;
  background: rgba(14, 28, 20, .93); border: 2px solid #ffcf4a; border-radius: 14px;
  padding: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.55);
  animation: tu-rise .25s ease-out;
}
.tu-decl[hidden] { display: none; }
@keyframes tu-rise { from { transform: translateY(14px); opacity: 0; } }
.tu-decl-t { margin: 0 0 6px; font-size: 12px; font-weight: 800; color: #ffcf4a; text-align: center; }
.tu-decl-b { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tu-act {
  font: inherit; font-size: 13px; font-weight: 800; min-height: 40px; padding: 0 12px;
  border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.tu-act.sing { background: #f4efe2; color: #1b1d24; border-color: #f4efe2; animation: tu-glow 1s ease-in-out infinite alternate; }
.tu-act.forty, .tu-act.tute { background: #ffcf4a; border-color: #ffcf4a; }
@keyframes tu-glow { to { box-shadow: 0 0 0 4px rgba(255,207,74,.3), 0 0 14px rgba(255,207,74,.6); } }
.tu-act.swap { background: #2f6bc0; border-color: #2f6bc0; }
.tu-act.draw { background: #1b1d24; }
.tu-act:active { filter: brightness(1.2); }

/* points bar */
.tu-pts { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.tu-p { display: inline-flex; align-items: baseline; gap: 5px; font-variant-numeric: tabular-nums; transition: transform .2s; }
.tu-p em { font-style: normal; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: #a9adb8; }
.tu-p b { font-size: 18px; font-weight: 900; min-width: 2ch; }
.tu-p small { font-size: 11px; font-weight: 800; color: #ffcf4a; }
.tu-p.me b { color: #6fd3a2; } .tu-p.ai b { color: #ff8f8f; text-align: right; }
.tu-p.bump { transform: scale(1.22); }
.tu-bar { flex: 1; position: relative; height: 8px; border-radius: 4px; background: #23262f; overflow: hidden; }
.tu-bar::after { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: #f4efe2; opacity: .7; }
.tu-bar i { position: absolute; inset: 0; background:
  linear-gradient(90deg, #2fae74 0 var(--me, 0%), transparent var(--me, 0%) calc(100% - var(--ai, 0%)), #d9485b calc(100% - var(--ai, 0%)));
}

.tu-msg { margin: 0; min-height: 20px; text-align: center; font-size: 13px; font-weight: 700; color: #c9cbd3; line-height: 1.25; }
.tu-msg.me { color: #ffcf4a; }
.tu-msg.ok { color: #6fd3a2; } .tu-msg.bad { color: #ff8f8f; }
.tu-msg.nudge { animation: tu-nudge .35s; }
@keyframes tu-nudge { 30% { transform: translateX(-4px); } 60% { transform: translateX(4px); } }

/* hand: one fanned row, positions set by game.js */
.tu-hand {
  position: relative; flex: 0 0 auto;
  height: clamp(74px, 14.5dvh, 122px);
}
.tu-hand .tu-card {
  --w: var(--hw, 56px);
  position: absolute; bottom: 0; width: var(--hw, 56px); height: calc(var(--hw, 56px) * 1.42);
  cursor: pointer;
  transition: transform .15s, filter .15s, left .25s;
  -webkit-tap-highlight-color: transparent;
}
.tu-hand .tu-card.tr { background: linear-gradient(#fffaf0, #f3e2b2); }
.tu-hand.my-turn .tu-card.ok { transform: translateY(-6px); box-shadow: 0 0 0 2px #ffcf4a, 0 4px 10px rgba(0,0,0,.5); }
.tu-hand.my-turn .tu-card.must { box-shadow: 0 0 0 3px #ffcf4a, 0 4px 12px rgba(255,207,74,.5); }
.tu-hand.my-turn .tu-card.ok:active { transform: translateY(-2px) scale(.97); }
.tu-hand .tu-card.no { filter: brightness(.5) saturate(.6); }
.tu-hand .tu-card.idle { filter: brightness(.9); }
.tu-hand .tu-card.dealt { animation: tu-deal .4s backwards; animation-delay: calc(var(--i) * 45ms); }
.tu-hand .tu-card.drawn { animation: tu-drawn .45s backwards; }
@keyframes tu-deal { from { transform: translateY(-60px) scale(.6); opacity: 0; } }
@keyframes tu-drawn { from { transform: translate(-60px, -90px) scale(.5) rotate(-20deg); opacity: 0; } }
.tu-hand .tu-card.shake { animation: tu-shake .3s; }
@keyframes tu-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* start + result cards */
.tu-intro h2 { font-size: 26px; display: flex; align-items: center; gap: 8px; }
.tu-intro-suits { display: inline-flex; gap: 2px; font-size: 18px; }
.tu-rules { margin: 0; padding: 0 0 0 18px; text-align: left; font-size: 14px; line-height: 1.42; color: #d5d7de; display: flex; flex-direction: column; gap: 5px; }
.tu-note { margin: 0; font-size: 13px; color: #a9adb8; }
.overlay-card .start-btn { background: #ffcf4a; border-color: #ffcf4a; color: #1b1d24; font-weight: 800; font-size: 16px; }
.overlay-sub { margin: 0; font-size: 14px; color: #c9cbd3; }
.tu-line { font-size: 12px; color: #a9adb8; }
.tu-cap { margin: -6px 0 0; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #a9adb8; }
.tu-result.won h2 { color: #6fd3a2; } .tu-result.lost h2 { color: #ff8f8f; } .tu-result.drawn h2 { color: #ffcf4a; }
.tu-sum { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; width: 100%; }
.tu-sum th, .tu-sum td { padding: 3px 6px; text-align: right; }
.tu-sum th:first-child { text-align: left; color: #a9adb8; font-weight: 700; }
.tu-sum thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #a9adb8; }
.tu-sum tr.tot td, .tu-sum tr.tot th { border-top: 1px solid #2a2a2a; font-weight: 900; font-size: 15px; color: #fff; }

@media (max-height: 620px) {
  .tu-rules { font-size: 13px; gap: 3px; }
  .tu-opp { min-height: 30px; }
  .overlay { padding-top: 58px; padding-bottom: 10px; }
  .overlay-card { padding: 14px 16px; gap: 7px; }
  .overlay-card .overlay-score { font-size: 38px; }
  .tu-sum th, .tu-sum td { padding: 1px 6px; }
  .tu-sum tr.tot td, .tu-sum tr.tot th { font-size: 14px; }
  .overlay-card button { min-height: 40px; padding: 8px 16px; }
  .tu-act { min-height: 36px; }
}
