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

/* ─── Sueca ────────────────────────────────────────────────────────────
   Top to bottom: info row (trump · match games · rival level) · felt table with the three other
   seats around the trick · deal points bar · status line · your hand (two rows of five). */
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(40px, min(16vw, 7.6dvh), 64px);     /* table card width */
  --ch: calc(var(--cw) * 1.38);
}

/* info row */
.sq-info { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.sq-trumpbox {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f4efe2; color: #1b1d24; border-radius: 10px; padding: 3px 10px 3px 8px;
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 2px 6px rgba(0,0,0,.4);
}
.sq-trumpbox em { font-style: normal; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #4a4d57; }
.sq-trumpbox b { font-size: 22px; line-height: 1; }
.sq-trumpbox.flash { animation: sq-flash 1.1s ease-out; }
@keyframes sq-flash { 0%,40% { transform: scale(1.25); box-shadow: 0 0 0 4px #ffcf4a, 0 2px 6px rgba(0,0,0,.4); } 100% { transform: none; } }
.sq-match { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 5px; }
.sq-g { display: inline-flex; gap: 3px; align-items: center; }
.sq-g i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; opacity: .55; }
.sq-g i.on { background: currentColor; opacity: 1; }
.sq-g small { font-size: 12px; font-weight: 800; margin-left: 2px; }
.sq-g.us { color: #6fd3a2; }
.sq-g.them { color: #ff8f8f; }
.sq-vs { color: #8b8f99; font-weight: 800; }
.sq-x2 { font-size: 12px; font-weight: 900; color: #1b1d24; background: #ffcf4a; border-radius: 6px; padding: 1px 5px; }
.sq-lv { font-size: 12px; font-weight: 700; color: #c9cbd3; background: #1b1d24; border: 1px solid #2c3040; border-radius: 999px; padding: 4px 9px; white-space: nowrap; }

/* felt table */
.sq-table {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 22px;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255,255,255,.07), transparent 62%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.035) 0 2px, transparent 2px 5px),
    #155c43;
  border: 5px solid #5b3a22;
  box-shadow: inset 0 0 0 2px #7a5233, inset 0 6px 22px rgba(0,0,0,.45), 0 4px 14px rgba(0,0,0,.45);
  overflow: hidden;
}

.sq-mark {
  position: absolute; left: 50%; top: 53%; transform: translate(-50%, -50%);
  font-size: calc(var(--ch) * 2.3); line-height: 1; color: rgba(255,255,255,.06); pointer-events: none;
}
.sq-seat {
  position: absolute; z-index: 3;
  display: flex; align-items: center; gap: 5px;
  pointer-events: none;
}
.sq-seat.n { top: 6px; left: 50%; transform: translateX(-50%); }
.sq-seat.s { bottom: 7px; left: 8px; }
.sq-seat.s .sq-name { display: none; }
.sq-seat.w { left: 5px; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: flex-start; gap: 4px; }
.sq-seat.e { right: 5px; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: flex-end; gap: 4px; }
.sq-seat.w .sq-tc, .sq-seat.e .sq-tc { flex-direction: column; gap: 2px; }
.sq-seat.e .sq-tc { align-items: flex-end; }
.sq-seat.w .sq-tc { align-items: flex-start; }
.sq-name {
  font-size: 12px; font-weight: 800; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 999px; white-space: nowrap;
  background: rgba(0,0,0,.42); color: #ffd3d3; border: 2px solid rgba(255,143,143,.55);
  transition: background .2s, color .2s, box-shadow .2s;
}
.sq-seat.mate .sq-name { color: #d4f7e6; border-color: rgba(111,211,162,.6); }
.sq-seat.turn .sq-name {
  background: #ffcf4a; color: #1b1d24; border-color: #ffcf4a;
  box-shadow: 0 0 0 3px rgba(255,207,74,.35), 0 0 14px rgba(255,207,74,.7);
  animation: sq-pulse 1s ease-in-out infinite alternate;
}
@keyframes sq-pulse { to { box-shadow: 0 0 0 6px rgba(255,207,74,.12), 0 0 18px rgba(255,207,74,.9); } }
.sq-cnt { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; color: #e3efe9; }
.sq-back {
  display: inline-block; width: 13px; height: 18px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, #8f2f3a 0 2px, #6e1f2a 2px 4px);
  border: 1.5px solid #f4efe2;
}
.sq-tc { display: inline-flex; align-items: center; gap: 4px; }
.sq-dchip { font-size: 9px; font-weight: 800; color: #1b1d24; background: #e9e2cf; border-radius: 6px; padding: 2px 5px; text-transform: uppercase; letter-spacing: .04em; }

/* cards */
.sq-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(#fffdf6, #f1ead8);
  color: #1b1d24;
  border: 1px solid #cbbf9f;
  border-radius: 8px;
  font-weight: 800; line-height: 1;
  box-shadow: 0 2px 5px rgba(0,0,0,.45);
  font-family: inherit;
  padding: 0;
}
.sq-card b { font-size: calc(var(--fs, 22px)); letter-spacing: -0.03em; }
.sq-card i { font-style: normal; font-size: calc(var(--fs, 22px) * 0.95); margin-top: 2px; }
.sq-card u {
  position: absolute; top: 3px; right: 4px; text-decoration: none;
  font-size: 10px; font-weight: 900; color: #5f5640;
}
/* four-colour suits so neighbouring suits never look alike */
.sq-card.s0, .s0 .sq-trumpsuit { color: #1b1d24; }
.sq-card.s1, .sq-trumpbox.s1 b { color: #c62b40; }
.sq-card.s2, .sq-trumpbox.s2 b { color: #1d5fb8; }
.sq-card.s3, .sq-trumpbox.s3 b { color: #17713d; }
.sq-card.mini { width: 26px; height: 36px; --fs: 12px; border-radius: 5px; box-shadow: 0 0 0 2px #ffcf4a, 0 2px 4px rgba(0,0,0,.5); }
.sq-card.mini u { display: none; }

/* trick */
.sq-trick { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.sq-slot { position: absolute; left: 50%; top: 53%; width: var(--cw); height: var(--ch); margin: calc(var(--ch) / -2) 0 0 calc(var(--cw) / -2); }
.sq-slot[data-seat="0"] { transform: translate(0, calc(var(--ch) * 0.6)); }
.sq-slot[data-seat="2"] { transform: translate(0, calc(var(--ch) * -0.6)); }
.sq-slot[data-seat="1"] { transform: translate(calc(var(--cw) * 1.02), 0); }
.sq-slot[data-seat="3"] { transform: translate(calc(var(--cw) * -1.02), 0); }
.sq-card.tbl {
  width: 100%; height: 100%; --fs: calc(var(--cw) * 0.36);
  transition: transform .32s cubic-bezier(.2,.8,.25,1), opacity .25s;
}
.sq-card.tbl.sweep { transition: transform .36s ease-in, opacity .36s ease-in; }
.sq-slot.win { z-index: 5; }
.sq-slot.win .sq-card { box-shadow: 0 0 0 3px #ffcf4a, 0 0 18px rgba(255,207,74,.8); }
.sq-slot.win::after {
  content: attr(data-pts);
  position: absolute; left: 50%; top: -12px; transform: translateX(-50%);
  font-size: 13px; font-weight: 900; color: #1b1d24; background: #ffcf4a; border-radius: 999px;
  padding: 1px 7px; white-space: nowrap;
}
.sq-slot.win[data-seat="2"]::after { top: auto; bottom: -12px; }
.sq-slot.win[data-pts=""]::after, .sq-slot.win:not([data-pts])::after { display: none; }

/* deal-end panel */
.sq-deal { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: rgba(6,24,17,.55); padding: 10px; }
.sq-deal[hidden] { display: none; }
.sq-deal-card { background: #f4efe2; color: #1b1d24; border-radius: 16px; padding: 12px 16px; text-align: center; width: min(270px, 100%); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.sq-deal-score { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
.sq-deal-score .us { color: #11734a; } .sq-deal-score .them { color: #b4283b; } .sq-deal-score .dash { color: #8b8f99; margin: 0 8px; }
.sq-deal-line { margin: 4px 0 2px; font-size: 14px; font-weight: 800; }
.sq-deal-line.ok { color: #11734a; } .sq-deal-line.bad { color: #b4283b; }
.sq-deal-sub { margin: 0 0 8px; font-size: 12px; color: #4a4d57; }
.sq-next { font: inherit; font-weight: 800; font-size: 15px; width: 100%; min-height: 44px; border: none; border-radius: 999px; background: #1b1d24; color: #fff; cursor: pointer; }
.sq-next:active { filter: brightness(1.3); }

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

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

/* hand: up to five per row */
.sq-hand {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  min-height: calc(var(--hh) * 2 + 6px);
  align-content: flex-end;
  --hh: clamp(52px, min(11.2dvh, calc((min(100vw, 480px) - 56px) / 5 * 1.36)), 88px);
}
.sq-hand .sq-card {
  width: calc((100% - 24px) / 5); height: var(--hh);
  --fs: clamp(17px, calc(var(--hh) * 0.3), 24px);
  cursor: pointer;
  transition: transform .15s, filter .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.sq-hand .sq-card.tr { background: linear-gradient(#fffaf0, #f3e3b8); }
.sq-hand .sq-card.up::before {
  content: '★'; position: absolute; left: 4px; top: 3px; font-size: 10px; color: #b88a12;
}
.sq-hand.my-turn .sq-card.ok { transform: translateY(-4px); box-shadow: 0 0 0 2px #ffcf4a, 0 4px 10px rgba(0,0,0,.5); }
.sq-hand.my-turn .sq-card.ok:active { transform: translateY(-1px) scale(.97); }
.sq-hand .sq-card.no { filter: brightness(.55) saturate(.6); }
.sq-hand .sq-card.idle { filter: brightness(.88); }
.sq-hand .sq-card.dealt { animation: sq-deal .35s backwards; animation-delay: calc(var(--i) * 40ms); }
@keyframes sq-deal { from { transform: translateY(-40px) scale(.6); opacity: 0; } }
.sq-hand .sq-card.shake { animation: sq-shake .3s; }
@keyframes sq-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* start + result cards */
.sq-intro h2 { font-size: 26px; }
.sq-rules { margin: 0; padding: 0 0 0 18px; text-align: left; font-size: 14px; line-height: 1.45; color: #d5d7de; display: flex; flex-direction: column; gap: 6px; }
.sq-rules b { color: #6fd3a2; }
.sq-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; }
.sq-line { font-size: 12px; color: #a9adb8; }
.sq-result.won h2 { color: #6fd3a2; } .sq-result.lost h2 { color: #ff8f8f; }

@media (max-height: 620px) {
  .sq-info { min-height: 30px; }
  .sq-trumpbox b { font-size: 19px; }
  .sq-rules { font-size: 13px; }
  .sq-name { padding: 3px 7px; font-size: 11px; }
}
@media (max-width: 370px) {
  .sq-lvw { display: none; }
  .sq-trumpbox em { font-size: 10px; }
  .sq-name { padding: 3px 7px; font-size: 11px; }
}
.sq-cap { margin: -6px 0 0; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #a9adb8; }
