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

body {
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, #f0e2c4 0%, #d9c39a 60%, #c5a878 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 16px;
    touch-action: none;
    font-family: 'Caveat', 'Ma Shan Zheng', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #3d2817;
}

[lang="zh"] body {
    font-family: 'Ma Shan Zheng', 'Caveat', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

#langBtn {
    position: fixed;
    top: 16px;
    right: 16px;
    padding: 6px 14px;
    font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.65);
    color: #3d2817;
    border: 1px solid rgba(61, 40, 23, 0.15);
    border-radius: 999px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#langBtn:hover {
    background: rgba(255, 255, 255, 0.92);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

#langBtn:active {
    transform: translateY(0);
}

#title {
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    font-weight: 400;
    margin-bottom: 28px;
    color: #3d2817;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
    letter-spacing: 0.15em;
    user-select: none;
}

[lang="en"] #title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    letter-spacing: 0.02em;
}

#stage {
    position: relative;
    width: 90vw;
    height: 60vw;
    max-width: 800px;
    max-height: 533px;
    padding: 26px 26px 38px;
    background:
        repeating-linear-gradient(
            180deg,
            rgba(0, 0, 0, 0.08) 0,
            rgba(0, 0, 0, 0.08) 1px,
            transparent 1px,
            transparent 5px
        ),
        linear-gradient(
            90deg,
            #6b4423 0%,
            #8b5a2b 20%,
            #a87545 50%,
            #8b5a2b 80%,
            #6b4423 100%
        );
    border-radius: 6px;
    box-shadow:
        inset 0 2px 0 rgba(255, 220, 180, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.4),
        inset 3px 0 0 rgba(255, 220, 180, 0.2),
        inset -3px 0 0 rgba(0, 0, 0, 0.25),
        0 20px 40px rgba(0, 0, 0, 0.35),
        0 8px 0 rgba(0, 0, 0, 0.15);
}

/* 黑板下方粉笔灰托盘 */
#stage::before {
    content: '';
    position: absolute;
    left: 26px;
    right: 26px;
    bottom: 8px;
    height: 14px;
    background:
        radial-gradient(ellipse 6% 80% at 18% 50%, rgba(255,255,255,0.7), transparent 60%),
        radial-gradient(ellipse 5% 70% at 38% 50%, rgba(255,255,255,0.4), transparent 60%),
        radial-gradient(ellipse 7% 80% at 62% 50%, rgba(255,255,255,0.55), transparent 60%),
        radial-gradient(ellipse 4% 60% at 82% 50%, rgba(255,255,255,0.35), transparent 60%),
        linear-gradient(180deg, #5a3a1e, #4a2f18);
    border-radius: 2px;
    box-shadow:
        inset 0 1px 0 rgba(255, 220, 180, 0.15),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse 70% 60% at 30% 20%, rgba(255,255,255,0.04), transparent 70%),
        radial-gradient(ellipse 60% 80% at 80% 80%, rgba(255,255,255,0.02), transparent 70%),
        radial-gradient(ellipse 40% 40% at 60% 50%, rgba(255,255,255,0.015), transparent 70%),
        #1c3a2c;
    border-radius: 3px;
    cursor: crosshair;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        inset 0 0 40px rgba(0, 0, 0, 0.5),
        inset 0 0 2px rgba(0, 0, 0, 0.8);
}

#hint {
    position: absolute;
    inset: 26px 26px 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(245, 245, 240, 0.22);
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: clamp(1.3rem, 3vw, 2rem);
    letter-spacing: 0.3em;
    text-indent: 0.3em;
    pointer-events: none;
    transition: opacity 0.4s ease;
    animation: hintBreath 3s ease-in-out infinite;
}

[lang="en"] #hint {
    font-family: 'Caveat', cursive;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-indent: 0;
}

#hint.gone {
    opacity: 0;
    animation: none;
}

@keyframes hintBreath {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

#result {
    position: absolute;
    inset: 26px 26px 38px;
    border-radius: 3px;
    background: rgba(10, 25, 18, 0.7);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 1;
    transition: opacity 0.3s ease;
    user-select: none;
    pointer-events: none;
}

#result.hidden { opacity: 0; }

#grade {
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: clamp(1.4rem, 4vw, 2rem);
    letter-spacing: 0.6em;
    text-indent: 0.6em;
    color: var(--tier-color, rgba(255,255,255,0.7));
    margin-bottom: 8px;
    text-shadow: 0 0 12px var(--tier-glow, transparent);
}

[lang="en"] #grade {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    letter-spacing: 0.05em;
    text-indent: 0;
}

#score {
    font-family: 'Caveat', 'Ma Shan Zheng', cursive;
    font-size: clamp(4.5rem, 16vw, 8.5rem);
    font-weight: 700;
    line-height: 1;
    color: var(--tier-color, #f5f5f0);
    text-shadow:
        0 2px 12px rgba(0, 0, 0, 0.7),
        0 0 24px var(--tier-glow, transparent);
    font-variant-numeric: tabular-nums;
}

#score .msg {
    display: inline-block;
    font-size: 0.3em;
    font-weight: 400;
    opacity: 0.85;
    line-height: 1.4;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    padding: 0 1em;
    max-width: 90%;
}

[lang="zh"] #score .msg {
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    letter-spacing: 0.1em;
}

[lang="en"] #score .msg {
    font-family: 'Caveat', 'Ma Shan Zheng', cursive;
    font-weight: 600;
}

#badge {
    margin-top: 14px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#badge.show {
    padding: 6px 18px;
    background: linear-gradient(135deg, #fde047, #facc15);
    color: #3d2817;
    border-radius: 999px;
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: 1rem;
    letter-spacing: 0.15em;
    text-indent: 0.15em;
    box-shadow:
        0 0 24px rgba(250, 204, 21, 0.6),
        0 4px 12px rgba(0, 0, 0, 0.4);
    animation: badgePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[lang="en"] #badge.show {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.05em;
    text-indent: 0;
}

@keyframes badgePop {
    0% { transform: scale(0.4) rotate(-12deg); opacity: 0; }
    60% { transform: scale(1.12) rotate(4deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

#meta {
    margin-top: 16px;
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: 0.95rem;
    color: rgba(245, 245, 240, 0.55);
    letter-spacing: 0.15em;
}

[lang="en"] #meta {
    font-family: 'Caveat', cursive;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}

#actions {
    margin-top: 28px;
    display: flex;
    gap: 14px;
}

#result:not(.hidden) #actions button {
    pointer-events: auto;
}

#actions button {
    padding: 10px 24px;
    font-family: 'Ma Shan Zheng', 'Caveat', cursive;
    font-size: 1rem;
    letter-spacing: 0.15em;
    text-indent: 0.15em;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

[lang="en"] #actions button {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
    text-indent: 0;
}

#resetBtn {
    background: rgba(245, 245, 240, 0.92);
    color: #1c3a2c;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#resetBtn:hover {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

#shareBtn {
    background: linear-gradient(135deg, #fde047, #facc15);
    color: #3d2817;
    box-shadow: 0 4px 14px rgba(250, 204, 21, 0.5);
}

#shareBtn:hover {
    background: linear-gradient(135deg, #fef08a, #fde047);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(250, 204, 21, 0.6);
}

#shareBtn:disabled,
#xBtn:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
}

#xBtn {
    background: #0f0f0f;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#xBtn::before {
    content: '𝕏';
    font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-size: 1.05em;
    font-weight: 700;
    line-height: 1;
}

#xBtn:hover {
    background: #2a2a2a;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

#actions button:active {
    transform: translateY(0);
}
