:root {
    color-scheme: dark;
    --bg: #090d12;
    --surface: rgba(20, 26, 34, .84);
    --surface-strong: #171e27;
    --line: rgba(255, 255, 255, .09);
    --text: #f6f2e9;
    --muted: #9aa5b2;
    --gold: #e6b85c;
    --gold-bright: #ffd987;
    --red: #e66a62;
    --green: #77c995;
    --shadow: 0 26px 80px rgba(0, 0, 0, .42);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 18% 5%, rgba(198, 142, 55, .16), transparent 30rem),
        radial-gradient(circle at 88% 74%, rgba(48, 102, 113, .14), transparent 34rem),
        linear-gradient(145deg, #0d1218 0%, #080b10 58%, #10161d 100%);
    color: var(--text);
    font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .17;
    background-image:
        linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.container {
    position: relative;
    z-index: 1;
    width: min(1160px, 100%);
    margin: 0 auto;
    padding: 38px 28px 48px;
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    grid-template-areas:
        "hero hero"
        "panel game";
    gap: 28px 34px;
}

.hero {
    grid-area: hero;
    text-align: left;
    padding-left: 4px;
}

.eyebrow {
    margin-bottom: 8px;
    color: var(--gold);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .23em;
}

h1 {
    margin: 0;
    color: #fffaf0;
    font-family: Georgia, "Songti SC", serif;
    font-size: clamp(34px, 5vw, 54px);
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: .04em;
    text-shadow: 0 8px 32px rgba(0, 0, 0, .5);
}

.title-mark {
    display: inline-grid;
    place-items: center;
    width: .88em;
    color: var(--gold-bright);
    filter: drop-shadow(0 0 14px rgba(230, 184, 92, .38));
}

.desc {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 15px;
    letter-spacing: .05em;
}

.panel {
    grid-area: panel;
    align-self: start;
    position: sticky;
    top: 24px;
    overflow: hidden;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background:
        linear-gradient(150deg, rgba(255, 255, 255, .055), transparent 45%),
        var(--surface);
    box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, .08);
    backdrop-filter: blur(20px);
}

.panel::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: .72;
}

.panel-heading,
.difficulty-row,
.score {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-heading {
    margin-bottom: 20px;
    font-size: 17px;
    font-weight: 800;
}

.local-badge {
    padding: 5px 8px;
    border: 1px solid rgba(119, 201, 149, .3);
    border-radius: 999px;
    background: rgba(119, 201, 149, .08);
    color: var(--green);
    font-size: 9px;
    letter-spacing: .12em;
}

.difficulty-row {
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.difficulty-row label {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

select {
    width: 180px;
    min-width: 0;
    padding: 10px 34px 10px 12px;
    border: 1px solid rgba(230, 184, 92, .28);
    border-radius: 12px;
    outline: none;
    background: #121922;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}

select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(230, 184, 92, .12);
}

select:disabled {
    cursor: default;
    opacity: .62;
}

.dice-area {
    margin-top: 18px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 9px;
}

.dice-card {
    min-width: 0;
    padding: 12px 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, .035);
    text-align: center;
}

.dice-label,
.dice-value {
    display: block;
}

.dice-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.dice {
    display: block;
    margin: 4px 0 2px;
    color: var(--gold-bright);
    font-family: Georgia, serif;
    font-size: 39px;
    line-height: 1;
    text-shadow: 0 0 16px rgba(230, 184, 92, .24);
}

.dice-value {
    color: var(--text);
    font-size: 12px;
    font-weight: 800;
}

.dice-vs {
    color: #687482;
    font-size: 10px;
    font-weight: 800;
    writing-mode: vertical-rl;
    letter-spacing: .12em;
}

.dice-area.rolling .dice {
    animation: dice-roll .55s cubic-bezier(.2, .8, .25, 1);
}

button {
    border: 0;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform .2s, box-shadow .2s, filter .2s, opacity .2s;
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.05);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button.dice-roll-button {
    width: 100%;
    margin-top: 14px;
    padding: 11px 16px;
    border: 1px solid rgba(230, 184, 92, .4);
    border-radius: 13px;
    background: linear-gradient(135deg, #f0c875, #b77b2e);
    color: #211507;
    box-shadow: 0 10px 28px rgba(183, 123, 46, .17);
    font-size: 14px;
}

button.dice-roll-button:disabled {
    cursor: default;
    filter: grayscale(.5);
    opacity: .5;
}

#status {
    min-height: 58px;
    margin-top: 16px;
    padding: 12px 13px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .075);
    border-radius: 14px;
    background: rgba(0, 0, 0, .2);
    color: #e9edf2;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
}

.score {
    margin-top: 16px;
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: rgba(255, 255, 255, .025);
}

.score-card {
    min-width: 76px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.score-card span {
    color: var(--muted);
    font-size: 12px;
}

.score-card strong {
    font-family: Georgia, serif;
    font-size: 25px;
}

.score-win strong {
    color: var(--green);
}

.score-lose strong {
    color: var(--red);
}

.score-divider {
    width: 1px;
    height: 28px;
    background: var(--line);
}

.game {
    grid-area: game;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-shell {
    width: min(100%, 632px);
    padding: 14px;
    border: 1px solid rgba(255, 221, 154, .25);
    border-radius: 30px;
    background:
        linear-gradient(145deg, rgba(255, 239, 204, .18), transparent 24%),
        linear-gradient(135deg, #6d431f, #2c180d 52%, #875626);
    box-shadow:
        0 32px 90px rgba(0, 0, 0, .52),
        inset 0 1px rgba(255, 255, 255, .16),
        inset 0 -8px 18px rgba(0, 0, 0, .3);
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    border: 1px solid rgba(73, 38, 12, .65);
    border-radius: 18px;
    background: #c9934f;
    box-shadow:
        inset 0 0 30px rgba(82, 40, 10, .24),
        0 3px 8px rgba(0, 0, 0, .36);
    touch-action: none;
    cursor: pointer;
}

.restart-button,
.result-button {
    padding: 12px 34px;
    border-radius: 999px;
    background: #f5efe4;
    color: #1b222b;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
}

.restart-button {
    margin-top: 16px;
}

.hidden {
    display: none !important;
}

#result {
    position: fixed;
    inset: 0;
    z-index: 100;
    padding: 24px;
    display: grid;
    place-items: center;
    background: rgba(4, 7, 10, .72);
    backdrop-filter: blur(12px);
}

.result-box {
    width: min(370px, 100%);
    padding: 34px;
    border: 1px solid rgba(230, 184, 92, .3);
    border-radius: 26px;
    background:
        radial-gradient(circle at 50% 0, rgba(230, 184, 92, .13), transparent 48%),
        #151b23;
    box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
    text-align: center;
    animation: result-in .36s cubic-bezier(.2, .9, .25, 1.15);
}

.result-icon {
    margin-bottom: 10px;
    color: var(--gold-bright);
    font-size: 36px;
    text-shadow: 0 0 22px rgba(230, 184, 92, .4);
}

.result-box h2 {
    margin: 0 0 24px;
    color: #fffaf0;
    font-family: Georgia, "Songti SC", serif;
    font-size: 27px;
    line-height: 1.35;
}

@keyframes dice-roll {
    0% { transform: rotate(0) scale(.72); }
    52% { transform: rotate(210deg) scale(1.22); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes result-in {
    from { transform: translateY(20px) scale(.9); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

@media (max-width: 900px) {
    .container {
        width: min(720px, 100%);
        grid-template-columns: 1fr;
        grid-template-areas: "hero" "panel" "game";
        padding: 28px 22px 42px;
    }

    .hero {
        text-align: center;
        padding: 0;
    }

    .panel {
        position: relative;
        top: auto;
        width: min(500px, 100%);
        margin: 0 auto;
    }
}

@media (max-width: 560px) {
    .container {
        padding: 22px 12px 34px;
        gap: 20px;
    }

    .eyebrow {
        font-size: 9px;
    }

    h1 {
        font-size: 34px;
    }

    .desc {
        padding: 0 18px;
        font-size: 13px;
    }

    .panel {
        padding: 18px;
        border-radius: 20px;
    }

    .difficulty-row {
        align-items: flex-start;
        flex-direction: column;
    }

    select {
        width: 100%;
    }

    .board-shell {
        padding: 8px;
        border-radius: 20px;
    }

    canvas {
        border-radius: 13px;
    }

}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
