:root {
    --cols: 7;
    /* 宽度约束：一行 7 堆；高度约束：表头 + 两行牌堆（每堆最多 5 张）+ 行距 + 内边距 ≤ 100vh */
    --card-w: min(12vw, 180px, calc((100vh - 80px) / 7));
    --card-h: calc(var(--card-w) * 1.4);
    --step: calc(var(--card-h) * 0.28);   /* 堆内所有牌统一的错开间距，足以露出牌角 */
}
* { box-sizing: border-box; }
body {
    font-family: sans-serif;
    background-color: #f0f0f0;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #f0f0f0;
}
header h1 { font-size: 20px; margin: 0; color: #303030; }
#home-button { display: flex; width: 40px; height: 40px; align-items: center; justify-content: center; }
#home-button img { width: 90%; height: 90%; }
#status { flex: 1; color: #555; font-size: 14px; }
.actions { display: flex; gap: 8px; }
button {
    padding: 8px 14px;
    border-radius: 5px;
    border: none;
    background: #2a52be;
    color: white;
    cursor: pointer;
    font-size: 14px;
}
button:hover { background: #224299; }
button:disabled { background: #999; cursor: default; }
#auto-button.on { background: #ffc107; color: #212529; }

#board {
    user-select: none;
    -webkit-user-select: none;
    flex: 1;
    background: green;
    padding: calc(var(--card-w) * 0.45) 12px 16px;
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--card-w));
    justify-content: center;
    align-content: start;
    column-gap: calc(var(--card-w) * 0.18);
    row-gap: calc(var(--card-h) * 0.35);
    position: relative;
}
.pile {
    position: relative;
    width: var(--card-w);
    height: calc(var(--card-h) + var(--step) * 4);
}
.pile .label {
    position: absolute;
    top: calc(-1.6em);
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255,255,255,0.85);
    font-size: calc(var(--card-w) * 0.16);
}
.pile .slot {
    position: absolute; top: 0; left: 0;
    width: var(--card-w); height: var(--card-h);
    border: 2px dashed rgba(255,255,255,0.35);
    border-radius: 6%;
}
.pile.current .card.back { outline: 3px solid #ffae42; box-shadow: 0 0 12px #ffae42; }
.pile.current { cursor: pointer; }
.pile.exhausted .slot { border-color: rgba(255,0,0,0.5); }

.card {
    position: absolute;
    left: 0; top: 0;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 6%;
    background: white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    font-weight: bold;
    font-size: calc(var(--card-w) * 0.26);
    line-height: 1;
    transition: transform 0.35s ease;
}
.card.red { color: #e00; }
.card.black { color: #000; }
.card .corner { position: absolute; display: flex; flex-direction: row; align-items: baseline; gap: 0.15em; }
.card .corner.tl { top: 5%; left: 7%; }
.card .corner.br { bottom: 5%; right: 7%; transform: rotate(180deg); }
.card .corner .s { font-size: 0.85em; }
.card .pips-container { position: absolute; top: 20%; bottom: 20%; left: 18%; right: 18%; }
.card .pip { position: absolute; font-size: 0.95em; line-height: 1; }
.card .face-card-art { position: absolute; inset: 0; }
.card .face-card-art svg { width: 100%; height: 100%; fill: currentColor; }
.card.back {
    background-color: #2a52be;
    background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.2) 0, rgba(0,0,0,0.2) 6px, transparent 6px, transparent 12px);
}
.card.back > * { display: none; }
.card.leftover { opacity: 0.55; outline: 2px solid #ff4136; }
.card.leftover.matched { outline-color: #2ecc40; opacity: 0.85; }
.card.flying { z-index: 1000; }

.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.modal.hidden { display: none; }
.modal-content {
    background: white; padding: 20px 30px; border-radius: 10px;
    text-align: center; box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    max-width: 90vw;
}
.modal-buttons { display: flex; gap: 15px; margin-top: 20px; justify-content: center; flex-wrap: wrap; }
#result-close-button, #normal-button { background: #ffc107; color: #212529; }
#result-close-button:hover, #normal-button:hover { background: #e0a800; }

@media (max-width: 600px) {
    header { flex-wrap: wrap; }
    #status { order: 3; width: 100%; }
}
