:root {
  --paper: #fffdf7;
  --ink: #302c23;
  --ink-soft: #756c58;
  --line: #ddd2b7;
  --red: #b23a30;
  --blue: #2f5285;
  --gold: #a97a2e;
  --green: #1f5c41;
  --felt: #256c4c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh; color: var(--ink); background-color: #e2dfd3;
  background-image:
    linear-gradient(rgba(90,80,55,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(90,80,55,.035) 1px, transparent 1px);
  background-size: 28px 28px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px; -webkit-font-smoothing: antialiased;
}
button, select { font-family: inherit; }
button { cursor: pointer; }

/* ---------- A4 横式纸张 ---------- */
.desk { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.sheet-wrap { width: 1220px; height: 863px; }
.sheet {
  position: relative; width: 1220px; height: 863px; transform-origin: top left;
  display: flex; flex-direction: column; padding: 18px 30px 14px;
  background: var(--paper);
  background-image: linear-gradient(90deg, rgba(169,122,46,.04) 0 1px, transparent 1px 38px);
  border: 1px solid #d9cdb0; border-radius: 3px;
  box-shadow: 0 20px 55px rgba(60,50,30,.22), 0 2px 6px rgba(60,50,30,.1);
}
.sheet::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--red) 0 46%, #c9b78d 46% 54%, var(--green) 54% 100%); opacity: .6;
}
.sheet-head { height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 6px; display: grid; place-items: center;
  font-size: 22px; color: #ffe9a8; background: linear-gradient(145deg, #b23a30, #7c1f19);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: 3px; font-weight: 700; font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif; }
.brand-text h1 em { color: var(--gold); font-style: normal; }
.brand-text p { margin: 2px 0 0; font-size: 10.5px; color: var(--ink-soft); letter-spacing: 1.5px; }
.head-center { text-align: center; display: flex; flex-direction: column; gap: 3px; }
.doc-label { font-size: 12px; letter-spacing: 5px; color: #8a774e; font-family: "Songti SC", "SimSun", serif; }
.doc-sub { font-size: 10px; letter-spacing: 2px; color: #a99c7f; }
.top-actions { display: flex; gap: 7px; }
.ghost { border: 1px solid var(--line); background: #fffdf7; color: var(--ink); padding: 7px 12px; border-radius: 5px; font-size: 12px; transition: .15s; }
.ghost:hover { border-color: var(--gold); color: var(--gold); }
.head-rule { height: 5px; border-top: 1.5px solid var(--gold); border-bottom: 1px solid var(--line); margin: 2px 0 13px; }

.sheet-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 20px; min-height: 0; }

/* ---------- 左侧：牌桌 ---------- */
.table-area { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.status-bar {
  height: 32px; display: flex; align-items: center; gap: 0;
  border: 1px solid var(--line); border-radius: 5px; background: #faf6ea; overflow: hidden; flex: none;
}
.sb-item { flex: 1; text-align: center; font-size: 10.5px; color: var(--ink-soft); border-right: 1px solid var(--line); white-space: nowrap; }
.sb-item:last-child { border-right: none; }
.sb-item b { color: var(--ink); font-size: 12px; margin-left: 4px; }
.sb-item b.trump-red { color: var(--red); }
.sb-item b.trump-black { color: #2d2a22; }

.felt {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  border-radius: 46% / 42%; border: 3px solid #c9b78d;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255,255,255,.09), transparent 62%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.018) 0 2px, transparent 2px 5px),
    radial-gradient(ellipse at 50% 50%, #2d7553, #174630 78%);
  box-shadow: inset 0 0 40px rgba(0,0,0,.28), 0 4px 12px rgba(30,60,40,.2);
}
.felt-ring {
  position: absolute; inset: 14px; border-radius: 46% / 42%;
  border: 1px dashed rgba(255,255,255,.22); pointer-events: none;
}
.felt-mark {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.28); font-size: 17px; letter-spacing: 9px;
  font-family: "Songti SC", "SimSun", serif; pointer-events: none;
}
.seat {
  position: absolute; min-width: 92px; padding: 5px 9px; border-radius: 7px;
  background: rgba(255,253,247,.92); border: 1px solid rgba(255,255,255,.7);
  box-shadow: 0 2px 8px rgba(0,0,0,.18); text-align: center; font-size: 10.5px;
}
.seat .s-name { font-weight: 700; font-size: 11.5px; display: block; }
.seat .s-meta { color: var(--ink-soft); font-size: 10px; }
.seat .s-role { display: inline-block; margin-left: 3px; padding: 0 4px; border-radius: 3px; font-size: 9.5px; font-weight: 700; }
.s-role.banker { background: #f6dedb; color: var(--red); }
.s-role.friend { background: #f7efd8; color: #8a6214; }
.s-role.def { background: #dde6f5; color: var(--blue); }
.seat.active { border-color: #f0c04a; box-shadow: 0 0 0 2px #f0c04a, 0 2px 8px rgba(0,0,0,.2); }
.seat.winner .s-name::after { content: ' ★'; color: var(--gold); }
#seat-1 { left: 3%; top: 52%; }
#seat-2 { left: 15%; top: 8%; }
#seat-3 { right: 15%; top: 8%; }
#seat-4 { right: 3%; top: 52%; }

.trick-zone {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -46%);
  width: 66%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; align-items: start;
}
.trick-col {
  background: rgba(255,253,247,.9); border: 1px solid rgba(255,255,255,.65);
  border-radius: 6px; padding: 4px 3px 5px; min-height: 68px; text-align: center;
}
.trick-col.best { border-color: #f0c04a; box-shadow: 0 0 0 2px rgba(240,192,74,.85); }
.trick-col .t-name { font-size: 9.5px; color: var(--ink-soft); white-space: nowrap; }
.trick-col .t-name b { color: var(--ink); }
.trick-col .t-cards { display: flex; justify-content: center; margin-top: 3px; }
.trick-col .t-empty { font-size: 10px; color: #b0a488; margin-top: 12px; }

/* ---------- 扑克牌 ---------- */
.card {
  position: relative; width: 54px; height: 76px; flex: none;
  border-radius: 5px; border: 1px solid #cfc6b2;
  background: linear-gradient(160deg, #fffefb, #f4efe3);
  box-shadow: 0 2px 4px rgba(30,25,12,.22);
  color: #26241f; user-select: none;
}
.card.red { color: #b4261f; }
.card .c-top { position: absolute; top: 3px; left: 5px; line-height: 1; text-align: center; }
.card .c-top b { display: block; font-size: 13px; font-weight: 800; }
.card .c-top i { font-style: normal; font-size: 11px; }
.card .c-mid {
  position: absolute; top: 26px; left: 0; right: 0; text-align: center;
  font-size: 27px; line-height: 1; opacity: .9;
}
.card.joker .c-mid { font-size: 15px; font-weight: 800; letter-spacing: 1px; top: 28px; }
.card.joker.big { color: #b4261f; }
.card.joker.small { color: #2f5285; }
.card.mini { width: 30px; height: 42px; border-radius: 3px; margin-left: -8px; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.card.mini:first-child { margin-left: 0; }
.card.mini .c-top { top: 2px; left: 3px; }
.card.mini .c-top b { font-size: 9px; }
.card.mini .c-top i { font-size: 7px; }
.card.mini .c-mid { font-size: 14px; top: 17px; }
.card.mini.joker .c-mid { font-size: 8px; top: 16px; }

/* ---------- 手牌 ---------- */
.hand-area { flex: none; }
.hand-label { display: flex; align-items: center; justify-content: space-between; font-size: 10.5px; color: var(--ink-soft); height: 17px; }
.hand-label b { color: var(--ink); }
.hand-tip { color: #8a6214; }
.swipe-hand { display: none; }
.hand { display: flex; justify-content: center; align-items: flex-end; height: 88px; padding-top: 6px; }
.hand .card { margin-left: -22px; cursor: pointer; transition: transform .14s ease, box-shadow .14s ease; }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-7px); z-index: 5; }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 2px #e0a83a, 0 5px 10px rgba(30,25,12,.3); z-index: 6; }
.hand .card.hint { box-shadow: 0 0 0 2px #4f7c4a, 0 3px 8px rgba(30,25,12,.25); }
.hand.disabled .card { cursor: default; }

.action-bar { flex: none; min-height: 38px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.act-btn {
  padding: 7px 14px; border-radius: 5px; font-size: 11.5px;
  border: 1px solid var(--line); background: #fffdf7; color: var(--ink); transition: .14s;
}
.act-btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.act-btn:disabled { opacity: .45; cursor: not-allowed; }
.act-btn.primary {
  border: none; background: linear-gradient(135deg, #9d2f26, #711d17); color: #fff3e4;
  font-weight: 700; letter-spacing: 2px; padding: 8px 20px;
}
.act-btn.primary:hover:not(:disabled) { filter: brightness(1.12); color: #fff3e4; }
.act-btn.green { border: none; background: linear-gradient(135deg, #3d7a55, #265c3e); color: #f2faef; font-weight: 700; }
.act-btn.green:hover:not(:disabled) { filter: brightness(1.12); color: #f2faef; }
.act-btn.pick {
  border-color: #e0cfa2; background: #fbf4e2; font-size: 12px; font-weight: 700; padding: 7px 12px;
}
.act-btn.pick.red { color: var(--red); }
.act-btn.pick.black { color: #2d2a22; }
.act-label { font-size: 10.5px; color: var(--ink-soft); margin-right: 3px; }
.tip-line { flex: none; min-height: 17px; font-size: 11px; color: #6c5327; text-align: center; }
.tip-line.error { color: var(--red); font-weight: 700; }

/* ---------- 右侧 ---------- */
.side { display: flex; flex-direction: column; gap: 9px; min-height: 0; }
.side::-webkit-scrollbar, .log::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-thumb, .log::-webkit-scrollbar-thumb { background: #d8ccae; border-radius: 3px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.panel h2 { margin: 0 0 8px; font-size: 12px; letter-spacing: 1.5px; font-weight: 700; display: flex; align-items: center; }
.panel h2::before { content: ''; width: 3px; height: 12px; background: var(--gold); margin-right: 7px; border-radius: 2px; }
.panel h2 .mini { margin-left: auto; }
.mini { border: none; background: none; color: var(--ink-soft); font-size: 10.5px; padding: 2px 4px; }
.mini:hover { color: var(--gold); }
.phase-line { display: flex; align-items: center; gap: 9px; }
.phase-tag { background: var(--gold); color: #fff; border-radius: 4px; font-size: 10.5px; padding: 3px 8px; letter-spacing: 2px; font-weight: 700; }
.phase-tag.play { background: var(--green); }
.phase-tag.over { background: #6c6555; }
.turn-text { font-size: 12.5px; font-weight: 700; }
.phase-desc { margin-top: 6px; font-size: 10.5px; color: var(--ink-soft); line-height: 1.6; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.info-grid > div:first-child { grid-column: 1 / -1; }
.info-grid span { display: block; font-size: 10px; color: var(--ink-soft); }
.info-grid b { font-size: 11.5px; font-weight: 700; }
.rank-chain { font-size: 10.5px; line-height: 1.7; color: #6c5327; background: #faf6ea; border: 1px solid #eee2c4; border-radius: 4px; padding: 6px 8px; }
.hint { margin: 7px 0 0; font-size: 10.5px; line-height: 1.65; color: var(--ink-soft); }
.log-panel { flex: 1; display: flex; flex-direction: column; min-height: 130px; }
.log { flex: 1; min-height: 0; overflow-y: auto; font-size: 10.5px; line-height: 1.6; }
.log-line { padding: 3px 5px; border-bottom: 1px dashed #eee6d2; display: flex; gap: 6px; }
.log-line:last-child { border-bottom: none; }
.log-no { color: #b0a488; flex: 0 0 19px; font-variant-numeric: tabular-nums; }
.log-line.red { color: #8d3229; }
.log-line.blue { color: #2b4b7c; }
.log-line.big { background: #f7efd8; font-weight: 700; border-radius: 4px; }
.log-line.info { color: var(--ink-soft); }

.sheet-foot { height: 34px; margin-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; font-size: 10px; color: #9b8f74; letter-spacing: 1px; }

/* ---------- 弹窗 ---------- */
.modal-layer { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(38,33,22,.48); backdrop-filter: blur(3px); padding: 20px; }
.modal-layer[hidden] { display: none; }
.modal-card { position: relative; width: min(620px, 100%); max-height: 86vh; overflow-y: auto; background: var(--paper); border: 1px solid #e0d3b3; border-radius: 10px; padding: 24px 30px 26px; box-shadow: 0 20px 60px rgba(30,25,12,.35); animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-close { position: absolute; top: 10px; right: 14px; border: none; background: none; font-size: 24px; line-height: 1; color: #9b8f74; }
.modal-close:hover { color: var(--red); }
.modal-card h2 { margin: 0 0 12px; font-size: 20px; letter-spacing: 3px; font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif; }
.modal-card h3 { margin: 15px 0 6px; font-size: 12.5px; color: #6c5327; letter-spacing: 1px; }
.modal-card p, .modal-card li { font-size: 12px; line-height: 1.8; color: #4d4637; }
.modal-card ul { padding-left: 20px; margin: 5px 0; }
.result-banner { text-align: center; padding: 6px 0 14px; font-size: 26px; font-weight: 700; letter-spacing: 6px; font-family: "Songti SC", "SimSun", serif; }
.result-banner.win { color: var(--red); }
.result-banner.lose { color: var(--blue); }
.result-stats { display: flex; justify-content: center; gap: 22px; margin: 4px 0 16px; font-size: 11.5px; color: var(--ink-soft); }
.result-stats b { display: block; font-size: 18px; color: var(--ink); text-align: center; }

@media (max-width: 900px) {
  .desk { display: block; padding: 10px; }
  .sheet-wrap { width: 100% !important; height: auto !important; }
  .sheet { width: 100%; height: auto; transform: none !important; padding: 12px 14px 10px; }
  .sheet-head { height: auto; flex-wrap: wrap; gap: 8px; }
  .head-center { display: none; }
  .brand-text p { display: none; }
  .ghost { padding: 6px 9px; font-size: 11px; }
  .sheet-body { grid-template-columns: 1fr; gap: 14px; }
  .status-bar { flex-wrap: wrap; height: auto; }
  .sb-item { flex: 0 0 33.333%; padding: 5px 0; }
  .felt { flex: none; height: 340px; border-radius: 26px; }
  .felt-ring { border-radius: 20px; }
  .seat { display: none; }
  .trick-zone { width: 94%; top: 50%; }
  .swipe-hand { display: inline; color: var(--red); font-weight: 700; }
  .hand { overflow-x: auto; justify-content: flex-start; padding: 6px 4px 2px; }
  .hand .card { margin-left: -30px; }
  .hand .card:first-child { margin-left: 0; }
  .action-bar { gap: 5px; }
  .side { max-height: none; }
  .log-panel { min-height: 180px; }
  .log { max-height: 220px; }
  .sheet-foot { height: auto; flex-wrap: wrap; gap: 5px; padding-top: 8px; }
}
