/* ================= 華容道 · 檀木鎏金 ================= */
:root {
    --lacquer-0: #120b07;
    --lacquer-1: #1d130c;
    --lacquer-2: #2a1b11;
    --gold: #d4af37;
    --gold-light: #ecd27a;
    --gold-dim: rgba(212, 175, 55, 0.28);
    --cinnabar: #c0392b;
    --silk: #f2e7d0;
    --ink: #0c0805;
    --muted: #9c8a70;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(70% 50% at 50% 0%, rgba(212, 175, 55, 0.07), transparent 70%),
        radial-gradient(60% 40% at 50% 110%, rgba(192, 57, 43, 0.08), transparent 70%),
        linear-gradient(170deg, var(--lacquer-1), var(--lacquer-0) 65%);
    color: var(--silk);
    font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 12px;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(212, 175, 55, 0.35); }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

/* ---- 飘浮金屑 ---- */
.embers {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.ember {
    position: fixed;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(236, 210, 122, 0.9), rgba(236, 210, 122, 0) 70%);
    box-shadow: 0 0 10px 2px rgba(212, 175, 55, 0.3);
    animation: emberFloat linear infinite;
}

@keyframes emberFloat {
    0% { transform: translateY(102vh) translateX(0); opacity: 0; }
    12% { opacity: 0.9; }
    50% { transform: translateY(48vh) translateX(2.5vw); }
    88% { opacity: 0.9; }
    100% { transform: translateY(-6vh) translateX(-2vw); opacity: 0; }
}

/* ---- 舞台 ---- */
.stage {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 420px;
}

/* ---- 标题 ---- */
.masthead { text-align: center; }

.title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.masthead h1 {
    font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
    font-weight: 400;
    font-size: clamp(3rem, 12vw, 4.2rem);
    letter-spacing: 0.12em;
    line-height: 1.1;
    background: linear-gradient(160deg, var(--gold-light) 20%, var(--gold) 55%, #9c7c1e 90%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 14px rgba(212, 175, 55, 0.25));
}

.seal {
    font-size: 0.8rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    color: var(--silk);
    background: linear-gradient(150deg, #d5493a, var(--cinnabar) 60%, #8e2418);
    border: 1px solid rgba(242, 231, 208, 0.35);
    border-radius: 6px;
    padding: 5px 7px;
    writing-mode: vertical-rl;
    line-height: 1.15;
    box-shadow: 0 4px 12px -4px rgba(192, 57, 43, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: rotate(3deg);
}

.subtitle {
    margin-top: 4px;
    font-size: 0.85rem;
    letter-spacing: 0.5em;
    text-indent: 0.5em;
    color: var(--muted);
}

/* ---- 棋盘框 ---- */
.board-frame {
    position: relative;
    padding: 14px;
    border-radius: 14px;
    background: linear-gradient(155deg, #3a2716, var(--lacquer-2) 45%, #1c110a);
    border: 1px solid rgba(212, 175, 55, 0.22);
    box-shadow:
        0 30px 60px -18px rgba(0, 0, 0, 0.85),
        0 0 70px -24px rgba(212, 175, 55, 0.3),
        inset 0 1px 0 rgba(236, 210, 122, 0.12);
    animation: frameSettle 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes frameSettle {
    0% { opacity: 0; transform: perspective(1100px) rotateX(16deg) translateY(34px); }
    100% { opacity: 1; transform: perspective(1100px) rotateX(0deg) translateY(0); }
}

.bracket {
    position: absolute;
    width: 22px;
    height: 22px;
    border: 2.5px solid var(--gold);
    opacity: 0.85;
    filter: drop-shadow(0 0 5px rgba(212, 175, 55, 0.5));
    pointer-events: none;
}

.b-tl { top: 5px; left: 5px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.b-tr { top: 5px; right: 5px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.b-bl { bottom: 5px; left: 5px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.b-br { bottom: 5px; right: 5px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }

/* ---- 棋盘 ---- */
.board {
    position: relative;
    width: min(80vw, 336px);
    aspect-ratio: 4 / 5;
    border-radius: 6px;
    background:
        /* 淡金格线 */
        repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), rgba(212, 175, 55, 0.06) calc(25% - 1px), rgba(212, 175, 55, 0.06) 25%),
        repeating-linear-gradient(0deg, transparent 0, transparent calc(20% - 1px), rgba(212, 175, 55, 0.06) calc(20% - 1px), rgba(212, 175, 55, 0.06) 20%),
        radial-gradient(120% 100% at 50% 0%, #241609, var(--ink) 75%);
    box-shadow: inset 0 0 34px rgba(0, 0, 0, 0.75);
    overflow: hidden;
    touch-action: none;
}

.exit-marker {
    position: absolute;
    bottom: 0;
    left: 25%;
    width: 50%;
    height: 14px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 0;
    border-bottom: 3px double var(--cinnabar);
    opacity: 0.85;
}

.exit-marker span {
    font-size: 0.72rem;
    letter-spacing: 0.35em;
    text-indent: 0.35em;
    color: #d5493a;
    font-weight: 600;
    margin-bottom: 2px;
    text-shadow: 0 0 8px rgba(192, 57, 43, 0.6);
}

/* ---- 棋子 ---- */
.block {
    position: absolute;
    padding: 3px;
    cursor: pointer;
    z-index: 10;
    transition: left 0.2s cubic-bezier(0.4, 0, 0.2, 1), top 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: left, top;
}

.portrait {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    border-radius: 5px;
    pointer-events: none;
    box-shadow:
        0 6px 14px -6px rgba(0, 0, 0, 0.8),
        inset 0 0 0 1px rgba(236, 210, 122, 0.12);
    transition: box-shadow 0.2s, filter 0.2s, transform 0.15s;
}

.block:hover .portrait {
    filter: brightness(1.12) saturate(1.05);
}

.block.selected { z-index: 30; }

.block.selected .portrait {
    box-shadow:
        0 0 0 2.5px var(--gold),
        0 0 22px rgba(212, 175, 55, 0.75),
        0 10px 20px -8px rgba(0, 0, 0, 0.9);
    transform: scale(0.97);
    animation: selectedPulse 1.2s ease-in-out infinite;
}

@keyframes selectedPulse {
    0%, 100% { box-shadow: 0 0 0 2.5px var(--gold), 0 0 16px rgba(212, 175, 55, 0.55), 0 10px 20px -8px rgba(0, 0, 0, 0.9); }
    50% { box-shadow: 0 0 0 2.5px var(--gold-light), 0 0 30px rgba(212, 175, 55, 0.95), 0 10px 20px -8px rgba(0, 0, 0, 0.9); }
}

/* 曹操专属：微金边 */
.block-caocao .portrait {
    box-shadow:
        0 0 0 1.5px rgba(212, 175, 55, 0.4),
        0 8px 18px -6px rgba(0, 0, 0, 0.85);
}

/* 入场发牌动画（仅 reset 时附加 .deal） */
.block.deal {
    animation: dealIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes dealIn {
    0% { opacity: 0; transform: translateY(-26px) scale(0.85); }
    60% { opacity: 1; transform: translateY(4px) scale(1.02); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* 非法移动抖动 */
.block.denied .portrait {
    animation: denied 0.28s ease;
}

@keyframes denied {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    50% { transform: translateX(4px); }
    75% { transform: translateX(-2px); }
}

/* 曹操出关 */
.block.escaping {
    transition: top 0.8s cubic-bezier(0.55, 0, 0.85, 0.4), opacity 0.8s ease 0.25s;
    z-index: 40;
    opacity: 0;
}

/* ---- 移动尘屑 ---- */
.dust {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(236, 210, 122, 0.85), rgba(236, 210, 122, 0) 70%);
    pointer-events: none;
    z-index: 25;
    animation: dustFly 0.55s cubic-bezier(0, 0.7, 0.3, 1) forwards;
}

@keyframes dustFly {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.2); }
}

/* ---- 金雨 ---- */
.confetti {
    position: absolute;
    top: -12px;
    width: 7px;
    height: 12px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 45;
    animation: confettiFall var(--dur) cubic-bezier(0.25, 0.4, 0.45, 1) forwards;
}

@keyframes confettiFall {
    0% { opacity: 1; transform: translateY(0) translateX(0) rotate(0deg); }
    85% { opacity: 1; }
    100% { opacity: 0; transform: translateY(460px) translateX(var(--sway)) rotate(var(--spin)); }
}

/* ---- 胜利遮罩 ---- */
.victory-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 14px;
    background: rgba(10, 6, 3, 0.82);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.victory-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.victory-title {
    font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
    font-size: 3rem;
    letter-spacing: 0.15em;
    background: linear-gradient(160deg, var(--gold-light), var(--gold) 60%, #9c7c1e);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 18px rgba(212, 175, 55, 0.5));
}

.victory-overlay.show .victory-title {
    animation: brushIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes brushIn {
    0% { opacity: 0; transform: scale(1.6); filter: blur(8px) drop-shadow(0 0 18px rgba(212, 175, 55, 0.5)); }
    100% { opacity: 1; transform: scale(1); filter: blur(0) drop-shadow(0 0 18px rgba(212, 175, 55, 0.5)); }
}

.victory-steps {
    color: var(--muted);
    font-size: 1rem;
    letter-spacing: 0.2em;
}

.victory-overlay .btn {
    min-width: 150px;
    margin-top: 6px;
}

.victory-steps span {
    color: var(--gold-light);
    font-weight: 900;
    font-size: 1.3rem;
    font-variant-numeric: tabular-nums;
}

/* ---- HUD ---- */
.hud {
    display: flex;
    gap: 10px;
    width: min(80vw, 336px);
}

.chip {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    color: var(--muted);
    background: rgba(42, 27, 17, 0.6);
    border: 1px solid rgba(212, 175, 55, 0.16);
    border-radius: 999px;
    padding: 7px 10px;
}

.chip strong {
    color: var(--gold-light);
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    margin-left: 4px;
}

.chip-status { color: var(--silk); }

/* ---- 按钮 ---- */
.controls {
    display: flex;
    gap: 10px;
    width: min(80vw, 336px);
}

.btn {
    padding: 11px 8px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    cursor: pointer;
    color: var(--silk);
    background: linear-gradient(160deg, #33220f, var(--lacquer-2));
    border: 1px solid rgba(212, 175, 55, 0.25);
    box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(236, 210, 122, 0.1);
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: rgba(212, 175, 55, 0.55);
    box-shadow: 0 10px 22px -8px rgba(0, 0, 0, 0.8), 0 0 18px -6px rgba(212, 175, 55, 0.5);
}

.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-gold {
    color: #2a1c05;
    background: linear-gradient(160deg, var(--gold-light), var(--gold) 55%, #a8821f);
    border-color: rgba(255, 240, 190, 0.5);
    font-weight: 900;
    box-shadow: 0 6px 18px -6px rgba(212, 175, 55, 0.55);
}

.btn-gold:hover:not(:disabled) {
    box-shadow: 0 10px 26px -8px rgba(212, 175, 55, 0.75);
}

.controls .btn { flex: 1; }

.btn-icon {
    flex: 0 0 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.btn-icon .ic { width: 19px; height: 19px; display: block; }
.btn-icon .ic-off { display: none; }
.btn-icon.muted { color: var(--muted); }
.btn-icon.muted .ic-on { display: none; }
.btn-icon.muted .ic-off { display: block; }

/* ---- 提示 ---- */
.hint {
    font-size: 0.75rem;
    letter-spacing: 0.25em;
    text-indent: 0.25em;
    color: rgba(156, 138, 112, 0.65);
}

/* ---- 响应式 ---- */
@media (max-width: 400px) {
    .board-frame { padding: 10px; }
    .masthead h1 { font-size: 2.8rem; }
    .controls { flex-wrap: wrap; }
    .btn { font-size: 0.88rem; }
}

/* ---- 减少动态 ---- */
@media (prefers-reduced-motion: reduce) {
    .board-frame { animation: none; }
    .block.deal { animation: none; }
    .block.selected .portrait { animation: none; }
    .ember { display: none; }
    * { transition-duration: 0.01ms !important; }
}
