* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    background: #ffc0cb;
    font-size: 20px;
    font-family: "微软雅黑", "宋体", sans-serif;
    color: #000;
}

a { color: inherit; }

#main { width: 100%; padding: 12px 0 36px; }

#wrap {
    position: relative;
    width: 1100px;
    min-height: 680px;
    margin: 0 auto;
    padding: 80px 0 40px;
}

#tree-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 1100px;
    height: 680px;
    overflow: hidden;
    background-repeat: no-repeat;
}

#text {
    position: relative;
    z-index: 1;
    width: 440px;
    margin-left: 60px;
}

#code { display: none; font-size: 18px; line-height: 1.8; overflow-wrap: anywhere; }

#clock-box {
    position: relative;
    z-index: 1;
    display: none;
    margin: 30px 40px 0 60px;
    font-size: 26px;
    line-height: 1.7;
}

#clock-box a { font-size: inherit; text-decoration: none; }
#clock { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.clock-part { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
#clock .digit { font-size: 48px; font-variant-numeric: tabular-nums; }
#tree-background { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#canvas { position: relative; display: block; width: 1100px; height: 680px; }
#code[data-typing="true"]::after { content: "_"; animation: typing-cursor 1s step-end infinite; }
@keyframes typing-cursor { 50% { opacity: 0; } }
#error { display: none; padding: 60px 20px; text-align: center; line-height: 1.8; }
.hand { cursor: pointer; }
.say { margin-left: 5px; }
.space { display: inline-block; width: 90px; }

#start-story {
    position: absolute;
    z-index: 2;
    top: 61%;
    left: 50%;
    min-height: 44px;
    padding: 10px 18px;
    font: inherit;
    font-size: 16px;
    color: #8c2943;
    background: rgb(255 247 249 / 85%);
    border: 1px solid rgb(156 52 80 / 20%);
    border-radius: 24px;
    cursor: pointer;
    transform: translateX(-50%);
    white-space: nowrap;
}

#start-story[hidden] { display: none; }
#start-story:focus-visible, #music-toggle:focus-visible { outline: 3px solid #a32651; outline-offset: 3px; }

#music-toggle {
    position: fixed;
    z-index: 10;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    max-width: calc(100vw - 28px);
    padding: 9px 15px;
    font: inherit;
    font-size: 14px;
    color: #8c2943;
    background: rgb(255 247 249 / 95%);
    border: 1px solid rgb(156 52 80 / 22%);
    border-radius: 24px;
    box-shadow: 0 4px 16px rgb(132 34 69 / 10%);
    cursor: pointer;
    touch-action: manipulation;
}

.music-note { font-size: 22px; line-height: 1; }
.is-playing .music-note { animation: music-sway 1.8s ease-in-out infinite; }
@keyframes music-sway { 50% { transform: rotate(12deg); } }
@media (prefers-reduced-motion: reduce) {
    .is-playing .music-note, #code[data-typing="true"]::after { animation: none; }
}

@media (max-width: 1100px) {
    #main { padding: 62px 16px 30px; }
    #wrap { display: flex; flex-direction: column; width: 100%; min-height: 0; padding: 0; }
    #tree-stage {
        position: relative;
        order: 0;
        width: 100%;
        height: auto;
        aspect-ratio: 1100 / 680;
        background-position: center;
        background-size: 100% auto;
    }
    #canvas { width: 100%; height: auto; }
    #text { order: 1; width: 100%; margin: 10px 0 0; padding: 18px 12px; }
    #code { font-size: 26px; line-height: 1.8; }
    #clock-box { order: 2; width: 100%; margin: 18px 0 0; padding: 0 12px; font-size: 25px; }
    #clock .digit { font-size: 38px; }
}

@media (max-width: 600px) {
    #main { padding: 64px 14px max(28px, env(safe-area-inset-bottom)); }
    #tree-stage { aspect-ratio: 1100 / 680; background-size: 100% auto; }
    #canvas { width: 100%; height: auto; }
    #text { padding: 16px 8px; }
    #code { font-size: clamp(26px, 7vw, 30px); line-height: 1.8; }
    #clock-box { padding: 0 8px; font-size: 24px; }
    #clock { gap: 2px 12px; }
    #clock .digit { font-size: 40px; }
    .space { width: 48px; }
    #start-story { top: 72%; max-width: calc(100% - 16px); font-size: 18px; padding: 10px 14px; }
    #music-toggle { font-size: 16px; }
}
