/* 简川综合漫研社 · 斗地主
   配色沿用聊天室的粉调，牌桌用一点绒布绿做区分，整体还是浅色系。 */

:root {
    --accent: #ec4899;
    --accent-2: #f472b6;
    --accent-soft: rgba(236, 72, 153, 0.12);
    --accent-glow: rgba(236, 72, 153, 0.35);

    --bg: #fdf6f9;
    --panel: #ffffff;
    --panel-2: #faf7f9;
    --text: #1e293b;
    --text-dim: #64748b;
    --text-faint: #94a3b8;
    --border: #f0e4ec;

    --felt: #3f7d63;
    --felt-2: #356a54;
    --card-red: #e11d48;

    --radius: 16px;
    --shadow-sm: 0 2px 8px rgba(30, 41, 59, 0.06);
    --shadow-md: 0 8px 24px rgba(30, 41, 59, 0.08);
    --shadow-lg: 0 20px 50px -12px rgba(30, 41, 59, 0.22);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.ddz-app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 16px 14px;
}

/* ---------------- 顶栏 ---------------- */

.ddz-head {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.ddz-head .back {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 10px;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.ddz-head .back:hover { background: var(--accent-soft); color: var(--accent); }

.ddz-head .title h1 { margin: 0; font-size: 17px; letter-spacing: .5px; }
.ddz-head .title .sub { margin: 2px 0 0; font-size: 12px; color: var(--text-faint); }

.head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
    display: flex; align-items: baseline; gap: 5px;
    padding: 5px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px; color: var(--text-dim);
}
.chip b { font-size: 14px; color: var(--text); }
.chip b.hl { color: var(--accent); }
.chip-stats { cursor: pointer; transition: background .15s; }
.chip-stats:hover { background: var(--accent-soft); }

.btn {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font-size: 13px;
    padding: 7px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .12s, box-shadow .15s, background .15s, border-color .15s;
    font-family: inherit;
}
.btn:hover:not(:disabled) { border-color: var(--accent-2); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 6px 16px -6px var(--accent-glow);
}
.btn-ghost { background: var(--panel); color: var(--text-dim); font-size: 12px; padding: 6px 11px; }
.btn-danger:hover:not(:disabled) { border-color: #fca5a5; color: #dc2626; }

/* ---------------- 牌桌布局 ---------------- */

.table {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 196px minmax(0, 1fr) 196px;
    grid-template-rows: minmax(180px, auto) auto auto;
    grid-template-areas:
        "left board right"
        "hist hist  hist"
        "mine mine  mine";
    gap: 12px;
}

.seat-left  { grid-area: left; }
.seat-right { grid-area: right; }
.board      { grid-area: board; }
.history    { grid-area: hist; }
.mine       { grid-area: mine; }

/* ---------------- 两位社娘的座位 ---------------- */

.seat {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 168px;
    position: relative;
    transition: border-color .2s, box-shadow .2s;
}
.seat.turn {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.seat-top { display: flex; align-items: center; gap: 9px; }

.seat-avatar {
    width: 46px; height: 46px; flex: 0 0 46px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--panel-2);
    border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; color: var(--text-faint);
}
.seat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.seat.turn .seat-avatar { border-color: var(--accent-2); }

.seat-meta { min-width: 0; }
.seat-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.seat-count { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.seat-count b { color: var(--accent); font-size: 15px; }

.badge {
    font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
    background: #fef3c7; color: #b45309; border: 1px solid #fde68a;
}
.badge-farmer { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }

/* 台词气泡 */
.seat-bubble {
    font-size: 12px; line-height: 1.5;
    color: var(--text);
    background: var(--accent-soft);
    border-radius: 10px;
    padding: 6px 9px;
    animation: bubbleIn .3s ease both;
}
.seat-bubble.hidden { visibility: hidden; animation: none; }

/* 该座位这一轮出的牌 */
.seat-last { margin-top: auto; min-height: 54px; }
.seat-last .pass,
.mine-last .pass {
    font-size: 12px; color: var(--text-faint);
    border: 1px dashed var(--border); border-radius: 8px;
    padding: 3px 8px; display: inline-block;
}
.seat-last .new,
.mine-last .new { animation: popIn .26s ease both; }

.mine-last { display: flex; align-items: center; gap: 3px; min-height: 54px; }

/* ---------------- 中央牌桌 ---------------- */

.board {
    background: linear-gradient(160deg, var(--felt), var(--felt-2));
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: var(--radius);
    box-shadow: inset 0 0 60px rgba(0, 0, 0, .18), var(--shadow-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #eaf6f0;
    min-height: 180px;
    position: relative;
    overflow: hidden;
}

.bottom-row { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: .95; }
.bottom-label { color: rgba(255, 255, 255, .7); }
.mini-cards { display: flex; gap: 4px; }
.mini-cards .back {
    width: 26px; height: 36px; border-radius: 4px;
    background: repeating-linear-gradient(45deg, #8d5a9e, #8d5a9e 4px, #7c4d8c 4px, #7c4d8c 8px);
    border: 1px solid rgba(255, 255, 255, .35);
}

.board-msg { font-size: 15px; font-weight: 600; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.board-flags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; min-height: 20px; }
.flag {
    font-size: 11px; padding: 2px 9px; border-radius: 999px;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .3);
    color: #fff;
}
.flag.hot { background: #f59e0b; border-color: #fbbf24; color: #422006; font-weight: 600; }

/* 炸弹特效：整桌抖一下 + 闪一下 */
body.boom .board { animation: shake .42s cubic-bezier(.36, .07, .19, .97) both; }
body.boom .ddz-app::after {
    content: '';
    position: fixed; inset: 0; pointer-events: none; z-index: 60;
    background: radial-gradient(circle at 50% 45%, rgba(255, 196, 0, .5), rgba(255, 60, 0, 0) 60%);
    animation: flash .45s ease-out both;
}

/* ---------------- 出牌历史 ---------------- */

.history {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 10px 12px;
}
.history-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 12px; color: var(--text-dim); margin-bottom: 7px;
}
.history-tip { color: var(--text-faint); font-size: 11px; }
.history-list { display: flex; flex-direction: column; gap: 4px; height: 96px; overflow-y: auto; }

/* 历史里的牌再小一号。
   原来直接用「小牌」(54px 高)，一行就 58px，历史区一有记录就长高，
   把底部手牌顶出首屏；缩小后每行约 44px，历史区高度也就固定住了。
   选择器必须写成 .card.sm：只写 .card 和后面的 .card.sm 优先级相同，
   靠后的规则会赢，小牌尺寸就白设了。 */
.hist-row .card.sm { width: 28px; height: 40px; border-radius: 4px; }
.hist-row .card.sm .r { font-size: 12px; }
.hist-row .card.sm .s { font-size: 9px; }
.hist-row .card.sm.joker .r { font-size: 10px; }
.hist-row .card.sm.joker .s { font-size: 11px; }

.hist-row {
    flex: 0 0 auto;         /* 别被 flex 容器压扁 */
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; padding: 2px 0;
    animation: rowIn .22s ease both;
}
.hist-who { width: 52px; flex: 0 0 52px; color: var(--text-dim); }
.hist-cards { display: flex; gap: 2px; flex-wrap: wrap; }
.hist-pass { color: var(--text-faint); }
.hist-label { color: var(--text-faint); font-size: 11px; }
.hist-empty { font-size: 12px; color: var(--text-faint); }

/* ---------------- 我的手牌 ---------------- */

.mine {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 12px;
}

.mine-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.mine-info { display: flex; align-items: center; gap: 9px; }
.mine-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; overflow: hidden;
    border: 2px solid var(--border);
}
.mine-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mine-name b { font-size: 14px; display: block; }
.mine-name .tag { font-size: 11px; color: var(--text-faint); }

.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions .hint-text { font-size: 12px; color: var(--text-faint); margin-right: 4px; }

.hand {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    min-height: 96px;
    padding: 16px 0 4px;
}

/* 手牌之间用负边距叠起来（斗地主的经典排法）：
   20 张也能排成一行，牌多的时候不会顶到屏幕外面去。 */
.hand .card { margin-right: -14px; }
.hand .card:last-child { margin-right: 0; }

/* ---------------- 扑克牌 ---------------- */

/* 一组牌的容器（手牌、历史、座位上打出的牌都用它）。
   这条必须是全局的：之前只写在 .seat-last 下面，
   结果出牌历史里的牌没有 flex，竖着堆成了一列。 */
.cards { display: flex; flex-wrap: wrap; gap: 2px; }
.cards.sm { gap: 1px; }

.card {
    width: 58px; height: 82px;
    background: #fff;
    border: 1px solid #d8dee9;
    border-radius: 7px;
    box-shadow: 0 2px 5px rgba(30, 41, 59, .12);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1px;
    color: #1e293b;
    user-select: none;
    position: relative;
    transition: transform .13s ease, box-shadow .13s ease, border-color .13s;
    flex: 0 0 auto;
}
.card .r { font-size: 20px; font-weight: 700; line-height: 1; }
.card .s { font-size: 16px; line-height: 1; }
.card.red { color: var(--card-red); }
.card.joker .r { font-size: 15px; }
.card.joker .s { font-size: 19px; }

.card.selectable { cursor: pointer; }
.card.selectable:hover { transform: translateY(-7px); box-shadow: 0 8px 16px rgba(30, 41, 59, .2); z-index: 4; }
.card.selected {
    transform: translateY(-15px);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft), 0 10px 18px rgba(236, 72, 153, .28);
    z-index: 3;
}
/* 入场动画只在刚拿到牌时播一次。
   注意结束帧不能一直挂着——animation 的优先级高于普通声明，
   带着 forwards/both 的动画会永远盖住 .selected 的 transform，
   表现就是「点了提示，牌被选中了却不会抬起来」。 */
.card.mine-in { animation: cardIn .3s ease; }

.card.sm { width: 38px; height: 54px; border-radius: 5px; }
.card.sm .r { font-size: 14px; }
.card.sm .s { font-size: 11px; }
.card.sm.joker .r { font-size: 11px; }
.card.sm.joker .s { font-size: 13px; }

.card.glow { box-shadow: 0 0 0 2px var(--accent), 0 6px 14px rgba(236, 72, 153, .3); }

/* ---------------- 提示条 / 弹层 ---------------- */

.toast {
    position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 12px);
    background: rgba(30, 41, 59, .93); color: #fff;
    font-size: 13px; padding: 9px 16px; border-radius: 10px;
    opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
    z-index: 80; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(30, 41, 59, .38);
    display: none; align-items: center; justify-content: center;
    padding: 20px;
}
.modal.show { display: flex; animation: fadeIn .18s ease both; }
.modal-card {
    background: var(--panel); border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 22px; width: 100%; max-width: 420px;
    animation: popIn .24s cubic-bezier(.2, .9, .3, 1.2) both;
}
.modal-card h3 { margin: 0 0 12px; font-size: 17px; }
.modal-body { font-size: 13px; color: var(--text-dim); line-height: 1.7; }
.modal-foot { margin-top: 18px; display: flex; gap: 9px; justify-content: flex-end; }

.result-line { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.result-line:last-child { border-bottom: none; }
.result-line b { color: var(--text); }
.result-line .win { color: #059669; font-weight: 700; }
.result-line .lose { color: #dc2626; font-weight: 700; }
.result-big { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.result-big.win { color: #059669; }
.result-big.lose { color: #dc2626; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.stat-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.stat-box .k { font-size: 11px; color: var(--text-faint); }
.stat-box .v { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ---------------- 动画 ---------------- */

@keyframes cardIn {
    from { opacity: 0; transform: translateY(18px) scale(.9); }
    to   { opacity: 1; transform: none; }
}
@keyframes popIn {
    from { opacity: 0; transform: scale(.7); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes rowIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: none; }
}
@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-8px); }
    40%, 60% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------- 窄屏 ---------------- */

@media (max-width: 860px) {
    .table {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "board board"
            "left  right"
            "hist  hist"
            "mine  mine";
    }
    .seat { min-height: 0; }
    .seat-last { min-height: 44px; }
    .card { width: 46px; height: 66px; }
    .card .r { font-size: 16px; }
    .card .s { font-size: 13px; }
    .hand .card { margin-right: -12px; }
    .ddz-head .title .sub { display: none; }
    .head-right { width: 100%; margin-left: 0; }
}
