:root {
  --bg: #0e1422; --panel: #172033; --line: #27354d; --ink: #e9eef6; --muted: #93a4bb;
  --felt: #0b4f4a; --felt-2: #0a3b38;
  --r: #d7263d; --y: #f3c623; --g: #2e9e5b; --b: #1f6fd6;
  --accent: #f3c623; --danger: #ff6b5e;
  --cw: clamp(56px, 11vw, 92px); --ch: calc(var(--cw) * 1.45);
  --radius: 14px;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; }
button { font: inherit; color: inherit; }

.app { max-width: 1040px; margin: 0 auto; padding: 12px 14px 24px; min-height: 100dvh; display: flex; flex-direction: column; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.top p { margin: 0; font-size: 12px; letter-spacing: .18em; color: var(--muted); }
.top h1 { margin: 0; font-size: clamp(22px, 4vw, 30px); letter-spacing: .04em; }
.top-actions { display: flex; align-items: center; gap: 10px; }

button {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 10px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: transform .08s, background .15s, opacity .15s;
}
button:hover:not(:disabled) { background: #1f2b44; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #1a1400; border-color: transparent; }
button.primary:hover:not(:disabled) { background: #ffd84a; }
button.ghost { background: transparent; }
button.big { padding: 13px 30px; font-size: 17px; }
input {
  font: inherit; color: var(--ink); background: #0c1322; border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#nickname { width: 12em; }
#roomCode { width: 13em; text-transform: uppercase; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
label { color: var(--muted); }

.row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.wrap { justify-content: center; }
.grow { flex: 1 1 auto; }
.or { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.status { color: var(--muted); font-size: 14px; text-align: center; flex: 1 1 auto; }
.badge { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.lobby, .intro, .seats { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.lobby { margin-bottom: 12px; }
#roomStatus { text-align: center; margin: 12px 0 0; min-height: 1.5em; }
#roomActive { margin-top: 12px; }
.seats { list-style: none; margin: 0 0 12px; padding: 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.seats li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; background: #0c1322; border: 1px dashed var(--line); }
.seats li.on { border-style: solid; border-color: var(--accent); }
.seats li small { color: var(--muted); }
.seats li b { font-weight: 600; }

.intro { text-align: center; padding: 28px 18px; flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.intro h2 { margin: 10px 0 0; font-size: clamp(22px, 4vw, 30px); }
.intro > p { margin: 0; color: var(--muted); max-width: 520px; }
.rules { text-align: left; max-width: 560px; margin: 6px 0 10px; padding-left: 20px; color: var(--muted); display: grid; gap: 6px; }
.rules b { color: var(--ink); }
.fan { --cw: clamp(54px, 10vw, 84px); display: flex; justify-content: center; height: calc(var(--ch) + 24px); align-items: flex-start; }
.fan .card:nth-child(1) { transform: rotate(-18deg) translateY(16px); }
.fan .card:nth-child(2) { transform: rotate(-9deg) translateY(4px); }
.fan .card:nth-child(3) { transform: rotate(0deg); }
.fan .card:nth-child(4) { transform: rotate(9deg) translateY(4px); }
.fan .card:nth-child(5) { transform: rotate(18deg) translateY(16px); }

/* ---------- 牌面 ---------- */
.card {
  position: relative; width: var(--cw); height: var(--ch); border-radius: var(--radius); border: 0; padding: 0;
  background: #fff; color: #16181d; font-weight: 900; display: grid; place-items: center; flex: 0 0 auto;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .4), inset 0 0 0 5px #fff, inset 0 0 0 7px rgba(0, 0, 0, .08);
}
.card::before { content: ''; position: absolute; inset: 7px; border-radius: calc(var(--radius) - 6px); border: 3px solid #fff; pointer-events: none; }
.card b { font-size: calc(var(--cw) * .62); line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, .25); z-index: 1; font-variant-numeric: tabular-nums; }
.card .corner { position: absolute; font-size: calc(var(--cw) * .22); line-height: 1; text-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.card .tl { top: 9px; left: 11px; }
.card .br { bottom: 9px; right: 11px; transform: rotate(180deg); }
.card.c-r { background: var(--r); color: #fff; }
.card.c-g { background: var(--g); color: #fff; }
.card.c-b { background: var(--b); color: #fff; }
.card.c-y { background: var(--y); color: #2a2000; }
.card.c-w { background: #1c2230; color: #fff; }
.card.c-w .pip {
  position: absolute; width: 54%; height: 66%; border-radius: 50%; overflow: hidden; z-index: 0;
  display: grid; grid-template: 1fr 1fr / 1fr 1fr; transform: rotate(-28deg); opacity: .95;
}
.card.c-w .pip i:nth-child(1) { background: var(--r); }
.card.c-w .pip i:nth-child(2) { background: var(--b); }
.card.c-w .pip i:nth-child(3) { background: var(--y); }
.card.c-w .pip i:nth-child(4) { background: var(--g); }
.card.c-w b, .card.c-w .corner { text-shadow: 0 0 6px #000, 0 0 2px #000; }
.card.back { background: #1c2230; box-shadow: 0 3px 0 rgba(0, 0, 0, .4), inset 0 0 0 3px #fff, inset 0 0 0 5px #1c2230; }
.card.back::before { border: 0; background: radial-gradient(circle at 50% 50%, var(--accent) 0 26%, var(--r) 27% 42%, var(--b) 43% 58%, var(--g) 59% 74%, var(--y) 75% 90%, transparent 91%); }
.card.back b { font-size: calc(var(--cw) * .3); }

/* ---------- 牌桌 ---------- */
.table {
  flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px;
  background: radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt-2) 70%);
  border: 1px solid #0d5f58; border-radius: 22px; padding: 10px; min-height: calc(100dvh - 90px);
}
.opponents { --cw: clamp(38px, 6.5vw, 58px); display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start; min-height: calc(var(--ch) * .9 + 54px); }
.opp {
  list-style: none; position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 16px;
  background: rgba(0, 0, 0, .22); border: 1px solid transparent; min-width: 0;
}
.opp.p-top { grid-column: 2; flex-direction: column; gap: 6px; }
.opp.p-left { grid-column: 1; justify-self: start; }
.opp.p-right { grid-column: 3; justify-self: end; flex-direction: row-reverse; }
.opp.turn { border-color: var(--accent); background: rgba(0, 0, 0, .38); box-shadow: 0 0 0 3px rgba(243, 198, 35, .18); }
.opp.gone { opacity: .45; }
.opp .backs { display: flex; height: calc(var(--ch) * .9); overflow: hidden; }
.opp .backs i { margin-left: calc(var(--cw) * -.58); transform: translateY(0); }
.opp .backs i:first-child { margin-left: 0; }
.opp .backs .card { width: calc(var(--cw) * .9); height: calc(var(--ch) * .9); --radius: 9px; }
.opp .who { min-width: 0; text-align: center; }
.opp .who b { display: block; font-weight: 700; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .who small { color: var(--muted); font-variant-numeric: tabular-nums; }
.flags { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }
.flag { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 999px; background: #223; color: var(--muted); letter-spacing: .04em; }
.flag.host { background: #3a4a66; color: #fff; }
.flag.uno { background: var(--accent); color: #1a1400; }
.flag.off { background: var(--danger); color: #2a0904; }
.flag.away { background: #445; }
.opp .timer { position: absolute; left: 10px; right: 10px; bottom: 4px; }
.opp.p-top .timer { left: 14px; right: 14px; }

.center { display: grid; grid-template-columns: auto auto minmax(120px, 1fr); align-items: center; justify-content: center; gap: clamp(12px, 4vw, 40px); padding: 6px 4px; }
.pilebox { text-align: center; }
.pilebox small { color: var(--muted); font-variant-numeric: tabular-nums; }
.deck { --cw: clamp(70px, 13vw, 104px); --ch: calc(var(--cw) * 1.45); position: relative; width: var(--cw); height: var(--ch); margin: 0 auto 6px; }
.deck .card { position: absolute; inset: 0; }
.deck .card:nth-child(1) { transform: translate(-6px, 5px) rotate(-6deg); }
.deck .card:nth-child(2) { transform: translate(4px, 2px) rotate(4deg); }
.deck.empty .card { opacity: .25; }
.discard { --cw: clamp(84px, 15vw, 120px); --ch: calc(var(--cw) * 1.45); position: relative; padding: 7px; border-radius: 22px; }
.discard .card { box-shadow: 0 7px 0 rgba(0, 0, 0, .4), inset 0 0 0 5px #fff, inset 0 0 0 7px rgba(0, 0, 0, .08); animation: drop .22s ease-out; }
@keyframes drop { from { transform: translateY(-18px) scale(1.08); opacity: .4; } to { transform: none; opacity: 1; } }
.discard.tint-r { box-shadow: 0 0 0 5px var(--r), 0 0 26px var(--r); }
.discard.tint-y { box-shadow: 0 0 0 5px var(--y), 0 0 26px var(--y); }
.discard.tint-g { box-shadow: 0 0 0 5px var(--g), 0 0 26px var(--g); }
.discard.tint-b { box-shadow: 0 0 0 5px var(--b), 0 0 26px var(--b); }
.meta { text-align: left; }
.meta p { margin: 0 0 6px; }
#turnHint { font-size: clamp(15px, 2.6vw, 19px); font-weight: 800; }
#direction { color: var(--muted); font-variant-numeric: tabular-nums; }

.log { list-style: none; margin: 0; padding: 0 10px; max-height: 4.9em; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; color: #d6e9e6; font-size: 13px; }
.log li { line-height: 1.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log li:last-child { color: #fff; }

.me { margin-top: auto; }
.actions { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.actions.foot { padding-top: 2px; }
button.shout { background: var(--accent); color: #1a1400; border-color: transparent; font-weight: 900; letter-spacing: .06em; padding: 10px 18px; animation: pulse 1s ease-in-out infinite; }
button.shout.warn { background: var(--danger); color: #2a0904; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.timer { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .12); margin: 0 10px; overflow: hidden; }
.timer i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.opp .timer i { background: var(--accent); }
.hand { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 8px; padding: 12px 8px; min-height: calc(var(--ch) + 24px); }
.hand.dense { --cw: clamp(42px, 7vw, 64px); gap: 6px; }
.hand .card { transition: transform .12s, box-shadow .12s, opacity .12s; }
.hand .card.dim { filter: saturate(.35) brightness(.6); cursor: not-allowed; }
.hand .card.ok { cursor: pointer; }
.hand .card.ok:hover { transform: translateY(-14px); box-shadow: 0 14px 0 rgba(0, 0, 0, .4), inset 0 0 0 5px #fff, inset 0 0 0 7px rgba(0, 0, 0, .08); }
.hand .card.drawn { outline: 3px solid var(--accent); outline-offset: 3px; animation: pulse .9s ease-in-out infinite; }

/* ---------- 弹层 ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(4, 8, 16, .72); padding: 16px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 22px; width: min(440px, 100%); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.sheet h2 { margin: 0; font-size: 24px; }
.sheet p { margin: 0; color: var(--muted); }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.swatches button { height: 76px; border: 0; border-radius: 16px; }
.swatches button:hover { filter: brightness(1.15); }
.s-r { background: var(--r); } .s-y { background: var(--y); } .s-g { background: var(--g); } .s-b { background: var(--b); }
.end-hands { --cw: clamp(34px, 6vw, 50px); width: 100%; display: flex; flex-direction: column; gap: 8px; }
.end-hands .eh { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.end-hands .eh b { width: 6.5em; text-align: left; font-weight: 600; }
.end-hands .card { --radius: 7px; pointer-events: none; }
.end-hands .eh .card b { font-size: calc(var(--cw) * .5); }
.end-hands .empty { color: var(--accent); font-weight: 800; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 40; margin: 0; background: #0c1322; border: 1px solid var(--line); color: var(--ink); padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); font-weight: 600; max-width: min(90vw, 460px); text-align: center; }

/* 较矮的窗口：缩小手牌并精简日志，让底部操作栏留在首屏 */
@media (max-height: 850px) and (min-width: 641px) {
  :root { --cw: clamp(50px, 9vw, 76px); }
  .log { max-height: 3.2em; }
  .opponents { min-height: calc(var(--ch) * .9 + 44px); }
  .center { padding: 0 4px; }
}

@media (max-width: 640px) {
  .app { padding: 10px 8px 16px; }
  button { padding: 10px 12px; }
  .actions.foot button { padding: 9px 10px; }
  .opp.p-left, .opp.p-right { flex-direction: column; gap: 4px; }
  .opp.p-right { flex-direction: column; }
  .opp .backs i:nth-child(n+5) { display: none; }
  .center { grid-template-columns: auto auto; }
  .meta { grid-column: 1 / -1; text-align: center; }
  .log { max-height: 3.2em; }
  .actions.foot .status { font-size: 12px; }
}
