/* 티츄 · 로컬 — tichu.be 스타일 테이블 */
:root {
  --felt-c: #4a5f22;
  --felt-m: #3a4c1a;
  --felt-e: #232d0c;
  --bar: #d6d8d6;
  --ink: #1b1d20;
  --panel: #121619;
  --panel-line: #262c31;
  --accent: #e8806a;
  --coral: #d0614f;
  --pink: #ec5ea6;
  --teal: #17879a;
  --team1: #2c3e9a;
  --team2: #a3245a;
  --turn: #c9a21a;
  --star: #b02a2a;
  --sword: #2b78c2;
  --pagoda: #9f9e1c;
  --jade: #2f9a2a;
  --cw: clamp(40px, calc((100vw - 500px) / 14), 72px);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  color: #e9ece6;
  background: radial-gradient(ellipse at 50% 45%, var(--felt-c) 0%, var(--felt-m) 48%, var(--felt-e) 100%) fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
input { font: inherit; }

.screen { position: fixed; inset: 0; }
.screen.scroll { overflow: auto; }

/* ───────── 공통 버튼 ───────── */
.btn-accent, .btn-dark, .btn-pink, .btn-light {
  border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700; font-size: 14px;
  transition: filter .15s, transform .15s, background .15s;
}
.btn-accent { background: var(--coral); color: #fff; }
.btn-dark { background: #1f2429; color: #dfe3e6; border: 1px solid #30373d; }
.btn-light { background: #e2ddd4; color: #2a2a2a; }
.btn-pink { background: var(--pink); color: #1a1030; border-bottom: 3px solid #23237d; }
.btn-accent:hover:not(:disabled), .btn-dark:hover:not(:disabled), .btn-pink:hover:not(:disabled), .btn-light:hover:not(:disabled) { filter: brightness(1.1); }
.btn-accent:disabled, .btn-pink:disabled, .btn-dark:disabled { opacity: .45; }
.wide { width: 100%; }

/* ───────── 첫 화면 ───────── */
.welcome-bar {
  position: sticky; top: 0; z-index: 2; height: 42px; display: flex; align-items: center; gap: 10px;
  padding: 0 14px; background: #1b2a30; border-bottom: 1px solid #2c3d44; font-size: 13px;
}
.welcome-bar b { color: #fff; font-size: 14px; }
.welcome-bar span { color: #a9b6bb; }
.welcome-bar .bar-btn {
  margin-left: auto; background: transparent; color: #fff; border: 1px solid #5c6a70; border-radius: 999px;
  padding: 5px 14px; font-weight: 700; font-size: 13px;
}
.welcome-bar .bar-btn:hover { background: rgba(255,255,255,.08); }
.welcome-center { min-height: calc(100% - 42px); display: grid; place-items: center; padding: 30px 16px; }
.welcome-card, .lobby-card, .solo {
  width: min(460px, 100%); border-radius: 16px; overflow: hidden; border: 1px solid #5a6440;
  background: linear-gradient(160deg, #3f4f20 0%, #27321a 100%);
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.stripe { display: flex; height: 6px; }
.stripe i { flex: 1; }
.stripe i:nth-child(1) { background: #c0281f; }
.stripe i:nth-child(2) { background: #1e86d0; }
.stripe i:nth-child(3) { background: #b2b01e; }
.stripe i:nth-child(4) { background: #24a81e; }
.welcome-body { padding: 26px 26px 24px; display: flex; flex-direction: column; gap: 18px; }
.wordmark { display: flex; align-items: center; gap: 14px; }
.wordmark h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; color: #fff; }
.wordmark p { margin: 2px 0 0; color: #b9c2a8; font-size: 13px; }
.logo-icon {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: #e0533d; color: #fff; font-weight: 800; font-size: 16px; flex: none;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18);
}
.logo-icon.big { width: 54px; height: 54px; font-size: 26px; border-radius: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #c9d1bb; font-weight: 600; }
.field input, .join-row input, .target-input {
  background: rgba(0,0,0,.28); border: 1px solid #5a6440; border-radius: 10px; color: #fff;
  padding: 11px 13px; font-size: 15px; outline: none;
}
.field input:focus, .join-row input:focus, .target-input:focus { border-color: var(--pink); }
.w-actions { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .15em; font-weight: 700; }
.w-or { display: flex; align-items: center; gap: 10px; color: #8d977b; font-size: 12px; }
.w-or::before, .w-or::after { content: ""; flex: 1; height: 1px; background: #4d5838; }
.resume { text-align: center; margin: 0; }

/* ───────── 모달 ───────── */
#modal-root:empty { display: none; }
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42);
  display: flex; flex-direction: column; align-items: center; overflow-y: auto; padding: 16px; animation: fade .18s ease-out;
}
.modal-back > * { margin: auto 0; flex: none; }   /* centred when it fits, scrollable from the top when taller */
.modal {
  width: min(390px, 100%); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px;
  padding: 22px 20px 18px; box-shadow: 0 24px 60px rgba(0,0,0,.5); animation: pop .2s ease-out;
}
.modal.wide { width: min(520px, 100%); }
.m-kicker { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.m-title { color: #fff; font-size: 22px; font-weight: 800; margin: 8px 0 6px; }
.m-desc { color: #b7bcc0; font-size: 13px; line-height: 1.6; margin: 0 0 12px; }
.m-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--panel-line); margin-top: 16px; padding-top: 14px; }
.m-foot .m-wait { color: #9aa1a6; font-size: 13px; }
.m-sec { border-top: 1px solid var(--panel-line); padding: 12px 0 2px; }
.m-sec h4 { margin: 0 0 8px; font-size: 12px; color: #8e959b; font-weight: 700; letter-spacing: .06em; }
.wish-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 4px; }
.wish-grid button {
  background: #1f2429; border: 1px solid #333b42; color: #fff; border-radius: 8px; padding: 10px 0;
  font-size: 18px; font-weight: 700;
}
.wish-grid button:hover { background: var(--coral); border-color: var(--coral); }
.dragon-opts { display: flex; gap: 10px; }
.dragon-opts button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px; }
.dragon-opts small { color: #9aa1a6; font-weight: 500; }
.team-rows { display: flex; flex-direction: column; gap: 8px; }
.team-row { display: grid; grid-template-columns: 54px 1fr auto auto; align-items: center; gap: 10px; background: #1a1f23; border-radius: 10px; padding: 10px 12px; }
.team-row.mine { box-shadow: inset 0 0 0 1px #3c4a8a; }
.team-row .t-name { font-weight: 800; }
.team-row .t-who { color: #9aa1a6; font-size: 12px; }
.team-row .t-round { font-weight: 800; font-size: 18px; }
.team-row .t-total { color: #9aa1a6; font-size: 12px; min-width: 64px; text-align: right; }
.t1c { color: #7f95ff; }
.t2c { color: #ff6fa8; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rchip { background: #1f2429; border: 1px solid #333b42; border-radius: 999px; padding: 4px 10px; font-size: 12px; color: #dfe3e6; }
.rchip.ok { border-color: #2c8a5a; color: #7be0a5; }
.rchip.fail { border-color: #8a2c3a; color: #ff8a9a; }
.rchip.gold { border-color: #9c7e1a; color: #ffd55a; }

/* 복기 */
.rv-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.rv-tab {
  background: #1f2429; border: 1px solid #333b42; color: #c9cfd4; border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.rv-tab.mate { border-color: #3d4c8a; }
.rv-tab.on { background: var(--accent); border-color: var(--accent); color: #1a1010; }
.rv-tab i { font-style: normal; background: rgba(0,0,0,.25); border-radius: 999px; padding: 0 6px; font-size: 11px; }
.rv-tab.on i { background: rgba(0,0,0,.18); }
.rv-note, .rv-sum { color: #aeb5ba; font-size: 13px; margin: 2px 0 8px; }
.rv-sum b { color: #fff; }
.rv-item { border: 1px solid var(--panel-line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: rgba(0,0,0,.14); }
.rv-head { font-size: 13px; color: #dfe3e6; margin-bottom: 4px; }
.rv-head b { color: #fff; }
.rv-head .ok { color: #7be0a5; }
.rv-head .fail { color: #ff8a9a; }
.rv-judge { color: var(--accent); font-weight: 700; }
.rv-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 12px; color: #c9cfd4; margin-top: 4px; }
.rv-row small { color: #8e959b; }
.rv-alt { display: inline-flex; align-items: center; gap: 5px; background: #1f2429; border: 1px solid #2f8a62; border-radius: 8px; padding: 3px 7px; color: #e6f3ea; }
.rv-alt.was { border-color: #8a2c3a; }
.rv-ex { display: inline-flex; align-items: center; gap: 4px; }
.rv-ex i { font-style: normal; color: #8e959b; font-size: 11px; margin-left: 4px; }
.rv-item.eg { border-color: #6b4a1a; }
.rv-eg-head { margin-top: 10px; color: #ffd55a; }
.rv-loss { margin-left: auto; color: #ff8a9a; font-weight: 800; }
.mini-cards { display: inline-flex; --cw: 26px; vertical-align: middle; }
.mini-cards .card + .card { margin-left: -7px; }
.mini-cards .card { box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.modal.wide .rv { max-height: none; }
.winner { font-size: 30px; }

/* 솔로 난이도 선택 (solo.png) */
.solo { width: min(720px, 100%); animation: pop .2s ease-out; }
.solo-head { display: flex; align-items: center; gap: 14px; padding: 16px 16px 14px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.solo-tag {
  background: #3a2f8f; color: #f07fc0; font-weight: 800; font-size: 12px; letter-spacing: .08em;
  padding: 7px 9px; border-radius: 6px; border-bottom: 2px solid #1e1a5a;
}
.solo-head h2 { margin: 0; font-size: 24px; color: #fff; }
.solo-cur { font-size: 12px; color: #c8ceb8; line-height: 1.45; }
.solo-cur b { color: var(--pink); font-size: 14px; }
.x-btn {
  margin-left: auto; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #b9b9b9;
  background: #e8e8e8; color: #333; font-size: 16px; line-height: 1;
}
.level-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px; }
.level-card {
  position: relative; display: flex; align-items: center; gap: 12px; text-align: left; padding: 16px 12px;
  border-radius: 10px; border: 1px solid #66704a; color: #fff;
  background: linear-gradient(140deg, rgba(90,105,50,.5), rgba(30,40,15,.5));
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.level-card:hover:not(:disabled) { border-color: #a6b07a; }
.level-card.on { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink), 0 0 18px rgba(236,94,166,.25); }
.level-card:disabled { cursor: default; }
.level-card:disabled:not(.on) { opacity: .55; }
.level-card .ln {
  position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; display: grid; place-items: center;
  background: #3a2f8f; color: #fff; font-size: 11px; font-weight: 800; border-radius: 4px;
}
.level-card.on .ln { background: var(--pink); }
.level-card .li {
  width: 56px; height: 56px; flex: none; display: grid; place-items: center; font-size: 28px;
  background: linear-gradient(#fff, #e9e2e6); border-radius: 10px; box-shadow: 0 3px 0 #b9b0b5, inset 0 0 0 2px #f1c7dc;
}
.level-card b { display: block; font-size: 15px; }
.level-card small { color: #c8ceb8; font-size: 12px; }
.solo-foot { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: #ece6dc; color: #2a2a2a; font-weight: 700; font-size: 13px; }
.solo-foot .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pink); flex: none; }
.solo-foot .sp { flex: 1; }
.solo-foot .btn-light { background: #e2ddd4; padding: 10px 26px; border-radius: 6px; }
.solo-foot .btn-pink { border-radius: 6px; padding: 10px 16px; }

/* ───────── 대기실 ───────── */
.lobby-wrap { min-height: calc(100% - 42px); display: grid; place-items: center; padding: 26px 16px; }
.lobby-card { width: min(720px, 100%); }
.lobby-head { display: flex; align-items: center; gap: 16px; padding: 18px 20px 4px; }
.lobby-head .room-code { font-size: 44px; font-weight: 900; letter-spacing: .22em; color: #fff; line-height: 1.1; }
.lobby-head .sp { flex: 1; }
.lobby-table {
  margin: 14px 20px; border-radius: 14px; padding: 14px;
  background: radial-gradient(ellipse at center, rgba(255,255,255,.07), rgba(0,0,0,.18));
  display: grid; grid-template-columns: 1fr 1.1fr 1fr; grid-template-rows: auto auto auto; gap: 10px;
  grid-template-areas: ". top ." "left mid right" ". bottom .";
}
.lobby-table .mid { grid-area: mid; display: grid; place-items: center; color: rgba(255,255,255,.35); font-size: 13px; font-weight: 700; letter-spacing: .1em; }
.lseat {
  border-radius: 10px; padding: 12px; min-height: 74px; display: flex; flex-direction: column; justify-content: center;
  align-items: center; gap: 4px; border: 1px dashed rgba(255,255,255,.25); background: rgba(0,0,0,.18); color: #c8ceb8;
  transition: border-color .15s, background .15s;
}
.lseat.l-top { grid-area: top; } .lseat.l-left { grid-area: left; } .lseat.l-right { grid-area: right; } .lseat.l-bottom { grid-area: bottom; }
.lseat.taken { border-style: solid; border-color: rgba(255,255,255,.18); background: rgba(0,0,0,.28); color: #fff; }
.lseat.mine { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink); }
button.lseat:hover { border-color: #fff; background: rgba(255,255,255,.06); }
.lseat .lname { font-weight: 800; font-size: 15px; }
.lseat .lsub { font-size: 12px; color: #aab394; }
.lseat .ltags { display: flex; gap: 4px; }
.ltag { font-size: 11px; font-weight: 800; border-radius: 4px; padding: 1px 6px; background: #d8d8d8; color: #222; }
.ltag.t1 { background: #2c3e9a; color: #fff; }
.ltag.t2 { background: #a3245a; color: #fff; }
.ltag.host { background: var(--turn); color: #1a1a1a; }
.ltag.off { background: #555; color: #ddd; }
.lobby-set { padding: 4px 20px 6px; }
.lobby-set h4 { margin: 8px 0; font-size: 12px; letter-spacing: .1em; color: #c8ceb8; }
.lobby-set .level-cards { padding: 0; }
.target-row { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; font-size: 13px; color: #c8ceb8; font-weight: 700; }
.target-input { width: 120px; padding: 8px 10px; }
.target-row .tv { color: #fff; font-size: 16px; }
.lobby-foot { margin-top: 10px; }

/* ───────── 게임 테이블 ───────── */
#progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; z-index: 6; }
#progress i { display: block; height: 100%; width: 0; background: #e2402e; transition: width .6s ease; }
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 34px; z-index: 4; background: var(--bar); color: var(--ink);
  display: flex; align-items: center; font-size: 12.5px; box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
#tb-info { margin-left: 196px; display: flex; gap: 22px; white-space: nowrap; }
#tb-info b { font-weight: 600; }
#tb-info .t1 { color: var(--team1); }
#tb-info .t2 { color: var(--team2); }
.tb-right { margin-left: auto; margin-right: 12px; display: flex; align-items: center; gap: 8px; }
.chip {
  border: 1px solid #a9adab; border-radius: 6px; padding: 2px 8px; font-weight: 700; font-size: 12px; background: #e6e8e6;
  white-space: nowrap;
}
#tb-code { cursor: pointer; letter-spacing: .06em; }
#tb-code:hover { background: #fff; }
.icon-btn { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: transparent; color: #333; border-radius: 6px; padding: 0; }
.icon-btn:hover { background: rgba(0,0,0,.08); }
.icon-btn svg { width: 18px; height: 18px; }
.logo {
  position: absolute; top: 12px; left: 12px; z-index: 7; display: flex; align-items: center; gap: 12px; text-align: left;
  background: #1c2026; border: 1px solid #2d333a; border-radius: 10px; padding: 4px 16px 4px 4px; color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.logo:hover { background: #242a31; }
.logo-text { display: flex; flex-direction: column; line-height: 1.25; }
.logo-text b { font-size: 14px; }
.logo-text small { font-size: 11.5px; color: #9ca3aa; }
#wish-call { position: absolute; top: 42px; right: 30px; z-index: 3; font-size: 32px; color: #eceee8; font-weight: 500; text-shadow: 0 2px 8px rgba(0,0,0,.3); }
#wish-call:empty { display: none; }

/* 상대 자리 */
.seat { position: absolute; z-index: 2; display: flex; align-items: center; }
.seat-top { top: 48px; left: 50%; transform: translateX(-50%); flex-direction: column; }
.seat-left { left: 13vw; top: 50%; transform: translateY(-62%); }
.seat-right { right: 13vw; top: 50%; transform: translateY(-62%); }
.who { display: flex; flex-direction: column; align-items: center; position: relative; z-index: 2; }
.avatar {
  width: 74px; height: 74px; border-radius: 50%; overflow: hidden; background: radial-gradient(circle at 50% 40%, rgba(255,255,255,.08), rgba(0,0,0,0) 70%);
  transition: box-shadow .2s;
}
.avatar svg { width: 100%; height: 100%; display: block; }
.seat.acting .avatar { box-shadow: 0 0 0 3px #f3c623, 0 0 18px rgba(243,198,35,.5); }
.seat.out .avatar { opacity: .55; }
.name-pill {
  margin-top: -6px; min-width: 96px; text-align: center; background: #d4d5d3; border-radius: 999px; padding: 2px 14px;
  font-size: 12px; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.3); white-space: nowrap;
}
.name-pill.mate { color: var(--team1); }
.name-pill.foe { color: var(--team2); }
.name-pill.off { opacity: .55; }
.name-pill i { font-style: normal; font-size: 10px; background: #a9acaa; color: #fff; border-radius: 4px; padding: 0 4px; margin-left: 5px; vertical-align: 1px; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 5px; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 13px; font-weight: 800; line-height: 1.45;
  background: #d8d8d8; color: #222; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.badge.turn { background: var(--turn); color: #1a1a1a; }
.badge.pass, .badge.recv { background: var(--teal); color: #fff; }
.badge.tichu { background: #e0445f; color: #fff; }
.badge.gave { background: #2b333b; color: #e0e4e7; }
.badge.out { background: #3b6fd8; color: #fff; }
.badge.dim { background: rgba(0,0,0,.35); color: #d0d4c4; }
.seat-left .badges, .seat-right .badges { flex-direction: column; align-items: center; }

/* 카드 뒷면 부채 */
.fan { position: relative; flex: none; }
.fan-top { width: 170px; height: 92px; margin-top: -14px; }
.fan-left, .fan-right { width: 100px; height: 170px; }
.fan-left { margin-left: -12px; }
.fan-right { margin-right: -12px; }
.fan-in { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.fan-top .fan-in { transform: translateY(-24px) rotate(180deg); }
.fan-left .fan-in { transform: translateX(-22px) rotate(90deg); }
.fan-right .fan-in { transform: translateX(22px) rotate(-90deg); }
.cback {
  position: absolute; left: -17px; top: -40px; width: 34px; height: 48px; border-radius: 3px;
  transform-origin: 50% 150%;
  border: 2px solid #f3f3f3; box-shadow: 0 0 0 1px rgba(0,0,0,.55), 1px 1px 3px rgba(0,0,0,.35);
  background:
    radial-gradient(circle at 50% 50%, #8fa4d8 0 2px, transparent 3px),
    radial-gradient(circle at 50% 50%, transparent 0 7px, rgba(143,164,216,.7) 7.5px 8.5px, transparent 9px),
    repeating-linear-gradient(45deg, rgba(160,180,230,.25) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(-45deg, rgba(160,180,230,.25) 0 1px, transparent 1px 5px),
    #17213f;
  transition: transform .3s ease;
}

/* 트릭 */
#trick { position: absolute; z-index: 1; left: 50%; top: 46%; transform: translate(-50%, -50%); width: min(600px, 52vw); height: 270px; pointer-events: none; }
.play { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.play.top { left: 50%; top: 50%; transform: translate(-50%, -50%); --cw: clamp(46px, 4.6vw, 64px); z-index: 2; }
.play.older { --cw: 32px; opacity: .78; z-index: 1; }
.play.older.p-top { left: 50%; top: 0; transform: translateX(-50%); }
.play.older.p-bottom { left: 50%; bottom: 0; transform: translateX(-50%); }
.play.older.p-left { left: 0; top: 50%; transform: translateY(-50%); }
.play.older.p-right { right: 0; top: 50%; transform: translateY(-50%); }
.play-cards { display: flex; }
.play-cards .card + .card { margin-left: calc(var(--cw) * -0.28); }
.play-label {
  background: rgba(0,0,0,.45); color: #f3f4ef; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.play.top .play-label { font-size: 13px; }
.play.fresh { animation: drop-in .32s ease-out; }
.play.fresh.top { animation: drop-in-c .32s ease-out; }
.trick-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: rgba(255,255,255,.45); font-size: 14px; font-weight: 600; white-space: nowrap; }

/* 내 자리 */
#me {
  position: absolute; z-index: 3; left: 50%; bottom: 0; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100vw;
  padding: 10px 14px 12px; border: 5px solid transparent; transition: border-color .2s, background .2s;
}
#me.my-turn { border-color: #24307f; background: rgba(40, 60, 55, .45); }
#me-extra:empty, #me-badges:empty { display: none; }
#me-controls { display: flex; align-items: center; gap: 8px; min-height: 34px; flex-wrap: wrap; justify-content: center; }
.tbtn {
  background: #dadbdc; color: #1a1a1a; border: 1px solid #b8babc; border-radius: 3px; padding: 6px 14px; font-size: 14px; font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: background .12s, transform .12s;
}
.tbtn:hover:not(:disabled) { background: #f2f2f2; }
.tbtn:active:not(:disabled) { transform: translateY(1px); }
.tbtn:disabled { background: rgba(255,255,255,.07); color: rgba(255,255,255,.3); border-color: rgba(255,255,255,.05); box-shadow: none; }
.tbtn.go { background: #fff2b8; border-color: #e3bd2b; font-weight: 700; }
.tbtn.go:hover { background: #fff7d3; }
.tbtn.big { background: #e9e9e9; font-weight: 700; }
.ctl-note { color: #e3e6dc; font-size: 14px; margin-right: 6px; }
.ctl-wait { color: #cfd4c4; font-size: 14px; background: rgba(0,0,0,.25); padding: 6px 14px; border-radius: 999px; }
.pill-pending { background: #e0445f; color: #fff; font-weight: 800; font-size: 13px; padding: 6px 12px; border-radius: 999px; box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.extra-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.wish-hint {background: rgba(0,0,0,.35); color: #ffe17a; font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; }

/* 교환 박스 */
.xboxes { display: flex; gap: 40px; align-items: flex-end; }
.xbox {
  min-width: 64px; min-height: 34px; padding: 6px 10px; border-radius: 3px; border: 1px solid transparent;
  background: rgba(0,0,0,.16); color: rgba(255,255,255,.5); font-size: 13px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; transition: background .15s, border-color .15s, box-shadow .15s;
}
.xbox.partner { background: #17917a; color: #fff; }
.xbox.armed { border-color: rgba(255,255,255,.75); box-shadow: 0 0 10px rgba(255,255,255,.25); }
.xbox.armed:hover { background: rgba(255,255,255,.18); }
.xbox.partner.armed:hover { background: #1fae93; }
.xbox .card { --cw: 34px; }
.xbox:disabled { cursor: default; }

/* 손패 */
#hand { display: flex; justify-content: center; padding-top: 16px; min-height: calc(var(--cw) * 1.38 + 16px); }
#hand .card { transition: transform .16s ease, box-shadow .16s ease; }
#hand .card.pick { cursor: pointer; }
#hand .card.pick:hover { transform: translateY(-5px); }
#hand .card.sel { transform: translateY(-16px); box-shadow: 0 0 0 2px #f3c623, 0 6px 14px rgba(0,0,0,.35); z-index: 1; }
#hand .card.xsel { transform: translateY(-16px); box-shadow: 0 0 0 2px #2fd6b4, 0 6px 14px rgba(0,0,0,.35); z-index: 1; }
#hand .card.recv { box-shadow: 0 0 0 2px #2fd6b4; }
#hand .card.recv.sel { box-shadow: 0 0 0 2px #f3c623, 0 0 0 4px #2fd6b4; }
.recv-tag {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%); background: #17917a; color: #fff;
  font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 3px; white-space: nowrap; max-width: 110%; overflow: hidden; text-overflow: ellipsis;
}
.hand-empty { color: rgba(255,255,255,.55); font-size: 14px; align-self: center; }

/* 카드 앞면 */
.card {
  position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.38);
  border-radius: calc(var(--cw) * .06); border: 1px solid #999;
  background: linear-gradient(180deg, #f2f2f2, #e3e3e3); user-select: none;
  display: flex; flex-direction: column; align-items: center; overflow: visible;
}
.card .suit { width: calc(var(--cw) * .34); height: calc(var(--cw) * .34); margin-top: calc(var(--cw) * .2); flex: none; }
.card .suit svg { width: 100%; height: 100%; display: block; fill: currentColor; }
.card .rank {
  flex: 1; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .66); line-height: 1;
  font-family: "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif; font-weight: 400; letter-spacing: -.04em; padding-bottom: calc(var(--cw) * .08);
}
.card.s3 { color: var(--star); border-color: var(--star); }
.card.s1 { color: var(--sword); border-color: var(--sword); }
.card.s2 { color: var(--pagoda); border-color: var(--pagoda); }
.card.s0 { color: var(--jade); border-color: var(--jade); }
.card.special { background: linear-gradient(180deg, #f6f1e3, #e7dfca); border-color: #b9ad8a; justify-content: center; }
.sp-art { font-size: calc(var(--cw) * .58); line-height: 1; display: flex; align-items: flex-end; justify-content: center; position: relative; }
.sp-name { font-size: calc(var(--cw) * .16); color: #6d6248; font-weight: 700; margin-top: calc(var(--cw) * .1); }
.sp-dragon { background: linear-gradient(180deg, #eef5e8, #d7e6cc); border-color: #3d8a3a; }
.sp-phoenix { background: linear-gradient(180deg, #fff3e3, #f6d9b6); border-color: #d7782a; }
.sp-phoenix .sp-art { font-size: calc(var(--cw) * .44); }
.sp-dog { background: linear-gradient(180deg, #f6f0e0, #e9ddc0); border-color: #3a5a8a; }
.sp-mahjong .mj-one { font-family: Georgia, "Times New Roman", serif; font-weight: 900; font-size: calc(var(--cw) * .8); color: #1b2a5a; }
.sp-mahjong .mj-bird { position: absolute; right: calc(var(--cw) * -.22); bottom: calc(var(--cw) * .02); font-size: calc(var(--cw) * .24); }

/* 기록 패널 */
#log { position: absolute; z-index: 5; left: 12px; bottom: 14px; width: 200px; display: flex; flex-direction: column-reverse; }
#log .log-head { align-self: flex-start; }
#log .log-list { margin: 0 0 6px; max-height: min(200px, 26vh); }
.log-head {
  display: flex; align-items: center; gap: 6px; background: rgba(15,20,12,.72); color: #dfe4d4; border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; font-weight: 700;
}
.log-head:hover { background: rgba(15,20,12,.88); }
.log-list {
  list-style: none; margin: 6px 0 0; padding: 8px 10px; max-height: 200px; overflow-y: auto;
  background: rgba(10,14,8,.72); border: 1px solid rgba(255,255,255,.08); border-radius: 8px; font-size: 12px; line-height: 1.55; color: #cfd5c4;
}
.log-list li:last-child { color: #fff; }

/* 토스트 */
#toast {
  position: fixed; left: 50%; top: 56px; transform: translate(-50%, -10px); z-index: 80; opacity: 0; pointer-events: none;
  background: #121619; color: #fff; border: 1px solid #2d343a; border-radius: 999px; padding: 8px 18px; font-size: 14px; font-weight: 600;
  transition: opacity .2s, transform .2s; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { border-color: #8a2c3a; color: #ffb3bd; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes drop-in { from { opacity: 0; } }
@keyframes drop-in-c { from { opacity: 0; transform: translate(-50%, -30%) scale(.9); } }

@media (max-width: 1180px) {
  .seat-left { left: 4vw; }
  .seat-right { right: 4vw; }
  #tb-info { gap: 12px; }
  .lobby-table { grid-template-columns: 1fr 1fr 1fr; }
}

/* ───────── 작은 화면 공통 (좁거나 낮은 화면: 휴대폰) ───────── */
@media (max-width: 720px), (max-height: 520px) {
  .logo { display: none; }                       /* 상단 바의 나가기 버튼으로 충분 */
  #topbar { height: auto; min-height: 34px; padding: 3px 0; }
  #tb-info { margin-left: 10px; gap: 4px 12px; flex-wrap: wrap; font-size: 12px; min-width: 0; }
  .tb-right { margin-right: 6px; gap: 6px; flex: none; }
  #tb-level { display: none; }
  #wish-call { top: 40px; right: 8px; font-size: 22px; }
  .avatar { width: 48px; height: 48px; }
  .name-pill { min-width: 72px; font-size: 11px; padding: 1px 10px; margin-top: -4px; }
  .badge { font-size: 11px; padding: 0 5px; }
  .badges { gap: 3px; margin-top: 3px; }
  .seat-left .badges, .seat-right .badges { flex-direction: row; max-width: 96px; }
  .fan-top { width: 120px; height: 62px; margin-top: -8px; }
  .fan-top .fan-in { transform: translateY(-16px) rotate(180deg) scale(.64); }
  .fan-left, .fan-right { width: 62px; height: 110px; }
  .fan-left { margin-left: -6px; }
  .fan-right { margin-right: -6px; }
  .fan-left .fan-in { transform: translateX(-14px) rotate(90deg) scale(.64); }
  .fan-right .fan-in { transform: translateX(14px) rotate(-90deg) scale(.64); }
  .play.top { --cw: 44px; }
  .play.older { --cw: 28px; }
  .play-label { font-size: 11px; padding: 1px 7px; }
  .play.top .play-label { font-size: 12px; }
  #me { padding: 6px 6px 8px; gap: 5px; border-width: 3px; width: 100vw; }
  #me-controls { gap: 6px; min-height: 30px; }
  .tbtn { padding: 5px 10px; font-size: 13px; }
  .ctl-note, .ctl-wait { font-size: 12px; }
  .xboxes { gap: 14px; }
  .xbox { min-width: 56px; font-size: 12px; padding: 4px 6px; }
  #hand { padding-top: 12px; }
  #hand .card.sel, #hand .card.xsel { transform: translateY(-10px); }
  #log { display: none; }                        /* 기록 패널은 큰 화면에서만 */
  #toast { top: 44px; max-width: 92vw; font-size: 13px; }
  .level-cards { gap: 8px; }
  .level-card { padding: 10px 10px; }
  .level-card .li { width: 44px; height: 44px; font-size: 22px; }
  .solo-head { padding: 12px 12px 10px 14px; gap: 10px; }
  .solo-head h2 { font-size: 19px; }
  .solo-foot { flex-wrap: wrap; }
  .solo-foot > span:nth-child(2) { flex-basis: 100%; }
  .modal { padding: 18px 16px 14px; }
  .m-title { font-size: 19px; }
}

/* ───────── 좁은 화면 (세로 휴대폰): 상대 자리를 위쪽으로, 손패는 겹쳐서 한 줄 ───────── */
@media (max-width: 720px) {
  :root { --cw: clamp(34px, calc((100vw - 16px) / 9.4), 60px); }
  .seat-top { top: 44px; }
  .seat-left { left: 2vw; top: 30%; transform: translateY(-50%); }
  .seat-right { right: 2vw; top: 30%; transform: translateY(-50%); }
  #trick { width: 94vw; height: 190px; top: 54%; }
  .trick-hint { font-size: 12px; white-space: normal; text-align: center; width: 70vw; }
  #hand .card + .card { margin-left: calc(var(--cw) * -0.36); }
  #hand .card.sel, #hand .card.xsel { z-index: 2; }
  .recv-tag { display: none; }                   /* 겹친 손패 위에서는 이름표가 서로 가림: 테두리 색으로만 표시 */
  .play.top { --cw: 50px; }
  .level-cards { grid-template-columns: 1fr; }
  .welcome-bar span { display: none; }
  .welcome-body { padding: 20px 18px 18px; gap: 14px; }
  .wordmark h1 { font-size: 24px; }
  .lobby-head { padding: 14px 14px 2px; gap: 10px; }
  .lobby-head .room-code { font-size: 32px; letter-spacing: .14em; }
  .lobby-table {
    margin: 10px 14px; padding: 10px; gap: 8px; grid-template-columns: 1fr 1fr;
    grid-template-areas: "top top" "left right" "bottom bottom";
  }
  .lobby-table .mid { display: none; }
  .lseat { min-height: 62px; padding: 8px; }
  .lseat .lname { font-size: 13px; }
  .lseat .lsub { font-size: 11px; }
  .lobby-set { padding: 4px 14px 6px; }
}

/* ───────── 낮은 화면 (가로 휴대폰): 세로 공간 절약 ───────── */
@media (max-height: 520px) {
  :root { --cw: clamp(34px, calc((100vw - 40px) / 14), 52px); }
  .seat-top { top: 34px; }
  .seat-top .fan-top { display: none; }          /* 위쪽 상대의 부채는 높이를 많이 먹음 */
  .seat-left { left: 2vw; top: 42%; transform: translateY(-50%); }
  .seat-right { right: 2vw; top: 42%; transform: translateY(-50%); }
  #trick { height: 140px; top: 47%; width: min(600px, 56vw); }
  .play.top { --cw: 40px; }
  .play.older { --cw: 24px; }
  #me { padding: 2px 6px 4px; gap: 3px; }
  #me-controls { min-height: 26px; }
  #hand { padding-top: 6px; }
  #hand .card.sel, #hand .card.xsel { transform: translateY(-6px); }
}
