:root {
    --brown:   #d4a373;
    --brown-dk:#ab8361;
    --cream:   #FAFAFA;
    --accent:  #ccd5ae;
    --green:   #2a9a5a;
    --danger:  #f77b6e;
}
body { background: var(--cream); margin: 0; padding: 0; font-family: sans-serif; }

/* ── 遊戲主畫面 ── */
#game-screen { padding: 0 0 80px; }

.game-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px;
    background: white; border-bottom: 1px solid #f0e8df;
    position: sticky; top: 0; z-index: 10;
}
.game-title { font-size: 1.1rem; font-weight: 700; color: var(--brown-dk); }
.game-stat {
    display: flex; align-items: center; gap: 5px;
    font-weight: 800; font-size: 1rem; color: #888;
}

.icon-clock {
    align-self: flex-end;  /* 或 flex-start 試試看 */
    margin-bottom: 3px;    /* 微調 */
}

.stat-pairs { color: var(--brown-dk); }

/* ── 牌格：固定2欄 ── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 16px;
    max-width: 500px;
    margin: 0 auto;
}
.card-grid.pairs-4 .card { aspect-ratio: 5/3; }
.card-grid.pairs-5 .card { aspect-ratio: 6/3; }

.card {
    aspect-ratio: 6/3;
    border-radius: 16px;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.4s ease;
}
.card.flipped { transform: rotateY(180deg); }
.card.matched { transform: rotateY(180deg); pointer-events: none; }
.card.matched .card-back { background: #f2faf6; border-color: #76b491; }
.card.matched .card-back-text { color: #459467; }

.card-face {
    position: absolute; inset: 0;
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    padding: 12px; text-align: center;
}
.card-front {
    background: white;
    border: 2px solid var(--brown);
}
.card-front::after {
    content: '✦';
    font-size: 2.2rem;
    color: var(--brown);
    opacity: 0.35;
}
.card-back {
    background: white;
    border: 2px solid #e7e7e7;
    transform: rotateY(180deg);
    flex-direction: column;
    gap: 4px;
}
.card-back-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: #8f735a;
    line-height: 30px;
    word-break: break-word;
}
.card-back-sub {
    font-size: 0.8rem;
    color: #bbb;
}

/* ── 完成畫面 ── */
.finish-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    align-items: center; justify-content: center;
    z-index: 999;
}
.finish-box {
    background: white; border-radius: 24px;
    padding: 36px 28px; text-align: center;
    width: 85%; max-width: 320px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: popUp 0.3s ease-out;
}
@keyframes popUp {
    0%   { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}
.finish-emoji  { font-size: 3rem; margin-bottom: 12px; }
.finish-title  { font-size: 1.5rem; font-weight: 900; color: var(--brown-dk); margin-bottom: 20px; }
.finish-stats  { display: flex; gap: 20px; justify-content: center; margin-bottom: 24px; }
.finish-stat-num   { font-size: 2rem; font-weight: 900; color: var(--brown); }
.finish-stat-label { font-size: 0.85rem; color: #aaa; }
.finish-btn {
    width: 100%; padding: 16px; border-radius: 14px; border: none;
    background: var(--brown); color: white;
    font-size: 1.1rem; font-weight: 800; cursor: pointer; margin-bottom: 10px;
}
.finish-btn-outline {
    width: 100%; padding: 14px; border-radius: 14px;
    border: 2px solid #eee; background: white;
    color: #888; font-size: 1rem; font-weight: 700; cursor: pointer;
}

/* ── 底部按鈕 ── */
.fixed-buttons {
    position: fixed; bottom: 0; left: 0; right: 0;
    display: flex; gap: 8px; padding: 12px 10px;
    background: white; border-top: 1px solid #f0e8df; z-index: 10;
}
.fixed-buttons button {
    padding: 12px; border-radius: 36px; border: none;
    font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-back   { background: #dae0f4; color:#666; flex: 1; transition: border: 1px solid #afb4c4}
.btn-replay { background: var(--brown); color: white; flex: 1;}
.btn-back.is-active   { background: #bac7ef; transform: scale(0.99); }
.btn-replay.is-active { background: #b8864f; transform: scale(0.99); }

/* ── 震動效果 ── */
@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25%       { transform: rotateY(180deg) translateX(-6px); }
    75%       { transform: rotateY(180deg) translateX(6px); }
}
.card.wrong { animation: shake 0.4s ease; }

/* 9對：三欄格子 */
.card-grid-9 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px 10px;
    max-width: 500px;
    margin: 0 auto;
    margin-top: 4px;
}
.card-grid-9 .card { height: 72px; aspect-ratio: unset; }
.card-grid-9 .card-front::after { font-size: 1.4rem; }
.card-grid-9 .card-face { padding: 6px 5px; }  

/* 9對文字 */
.card-back-text-sm { font-weight: 700; color: #7d6550; line-height: 1.35; word-break: break-word; }
.ch-text-9 { font-weight: 600; }

/* 輕鬆5對按鈕 */
.btn-five { background:#d6efb6; color:#666; flex: 1; border: 1px solid #afb4c4}
.btn-five.is-active { background: #afda7a; transform: scale(0.99); }