:root {
    font-family: "PingFang TC", "Noto Sans TC", sans-serif;
    color: #42594e;
    background: #edf3ee;
    font-synthesis: none;
    --muted: #819087;
    --line: #bbcbc0;
    --surface: rgba(255, 255, 255, .55);
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; background: #edf3ee; }
main { height: 100svh; min-height: 480px; position: relative; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; outline: none; touch-action: none; }
header {
    position: absolute; top: 38px; left: 48px; right: 48px;
    display: flex; justify-content: space-between; align-items: center;
    pointer-events: none;
}
.brand {
    display: flex; gap: 12px; align-items: center;
    font: 600 11px/1.6 sans-serif; letter-spacing: 2.5px;
    color: inherit; text-decoration: none; pointer-events: auto;
}
.brand-star { font-size: 40px; font-weight: 400; color: #a6b69a; }
.intro { position: absolute; left: 9%; top: 31%; pointer-events: none; }
.eyebrow { font-size: 9px; letter-spacing: 3px; margin: 0 0 23px; color: var(--muted); }
h1 {
    font-family: "Songti TC", "Noto Serif TC", serif; font-weight: 400;
    font-size: clamp(30px, 3.2vw, 52px); line-height: 1.6; letter-spacing: 5px; margin: 0 0 20px;
}
.description { font-size: 13px; line-height: 2.2; letter-spacing: 2px; color: var(--muted); }
.little-line { display: block; width: 28px; height: 1px; background: var(--line); margin: 25px 0; }
.instruction { font-size: 11px; line-height: 2.2; letter-spacing: 1px; color: var(--muted); }
footer {
    position: absolute; bottom: 27px; left: 48px; right: 48px;
    display: flex; justify-content: space-between; align-items: center;
    pointer-events: none;
}
footer > span { font-size: 8px; letter-spacing: 1.7px; color: var(--muted); }
footer p { font-size: 11px; letter-spacing: 1px; display: flex; gap: 7px; align-items: center; }
.count-dot { width: 5px; height: 5px; background: #b79161; border-radius: 50%; }
#count { display: inline-block; min-width: .7em; text-align: center; }
#toast {
    position: absolute; bottom: 100px; left: 50%;
    background: var(--surface); border: 1px solid var(--line); backdrop-filter: blur(10px);
    padding: 12px 20px; border-radius: 24px; font-size: 12px;
    pointer-events: none; white-space: nowrap; visibility: hidden; opacity: 0;
}
#loading {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    font-size: 13px; letter-spacing: 2px; text-align: center; max-width: 80vw;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.sr-only:focus {
    clip-path: none; left: 50%; bottom: 70px; width: auto; height: auto;
    padding: 12px; transform: translateX(-50%); z-index: 5;
}
button:focus-visible, a:focus-visible { outline: 2px solid #b58c50; outline-offset: 5px; }
body.dark { color: #e5e8d6; --muted: #a2b5ba; --line: #4e6870; --surface: rgba(30, 52, 62, .75); }
body.dark .brand-star { color: #dfc990; }

/* View controls */
.view-controls { position: absolute; right: 28px; bottom: 83px; display: flex; flex-direction: column; gap: 5px; }
.view-controls button {
    width: 35px; height: 35px; border: 1px solid var(--line); border-radius: 50%;
    background: var(--surface); color: inherit; font: 18px sans-serif; cursor: pointer;
    backdrop-filter: blur(10px);
}
.view-controls button:hover { background: var(--line); }

/* Pull cord */
#theme {
    position: fixed; top: 0; right: 43px; width: 60px; height: 126px; padding: 0;
    border: 0; background: transparent; color: #8e9d84; pointer-events: auto; cursor: grab;
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.pull-cord { position: absolute; inset: 0; width: 60px; height: 240px; overflow: visible; pointer-events: none; }
.pull-line { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.pull-ball {
    fill: currentColor; stroke: rgba(255, 255, 255, .35); stroke-width: 1;
    filter: drop-shadow(0 3px 3px rgba(54, 66, 49, .12)); transition: fill .2s;
}
.pull-label {
    position: absolute; top: 97px; left: 0; width: 60px; text-align: center;
    font-size: 10px; letter-spacing: 1.6px; pointer-events: none;
}
#theme.pulling { cursor: grabbing; }
#theme.armed .pull-ball { fill: #c29b54; }
body.dark #theme { color: #e3c382; }
body.dark #theme.armed .pull-ball { fill: #fff2c2; }
#theme:focus-visible { outline: 1px dashed currentColor; outline-offset: 4px; border-radius: 0 0 28px 28px; }

/* Brand credit */
.site-credit {
    position: absolute; left: 48px; bottom: 65px; z-index: 2;
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    color: var(--muted); text-decoration: none;
}
.site-credit img { display: block; width: 112px; height: auto; }
.site-credit > span { font: 10px/1.5 sans-serif; letter-spacing: .6px; }
.site-credit:hover { color: inherit; }
.site-credit > span > span { margin-left: 3px; font-size: 11px; }
body.dark .site-credit img { filter: drop-shadow(0 0 1px rgba(255, 255, 255, .85)); }

/* Ornament drawer */
.ornament-drawer {
    --drawer-bg: #f8faf6;
    --drawer-selected: #e5eee6;
    --drawer-ring: #668a70;
    position: absolute; z-index: 4; left: 0; bottom: 144px;
    display: flex; flex-direction: row-reverse; align-items: flex-end;
    max-width: calc(100vw - 12px);
}
body.dark .ornament-drawer { --drawer-bg: #263e45; --drawer-selected: #38554f; --drawer-ring: #a5c3a4; }
.ornament-drawer button { color: inherit; font-family: inherit; font-weight: inherit; cursor: pointer; }
.ornament-tab {
    display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 0 12px;
    background: var(--drawer-bg); border: 1px solid var(--line); border-radius: 0 12px 12px 0;
    margin-left: -1px; margin-bottom: 12px; font-size: 13px; position: relative;
}
.ornament-tab[aria-expanded="true"] { border-left-color: var(--drawer-bg); }
.ornament-tab-icon { font-size: 19px; color: #b38b49; line-height: 1; }
body.dark .ornament-tab-icon { color: #e3c382; }
.ornament-tab-arrow { font-size: 13px; transform: rotate(90deg); }
.ornament-tab[aria-expanded="true"] .ornament-tab-arrow { transform: rotate(-90deg); }
.ornament-panel {
    width: 250px; padding: 10px; background: var(--drawer-bg); border: 1px solid var(--line);
    border-radius: 0 14px 14px 0; box-shadow: 0 8px 24px #16342619;
}
.ornament-panel[hidden] { display: none; }
.ornament-categories { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.ornament-categories button { border: 0; background: transparent; min-height: 42px; padding: 5px 9px; font-size: 12px; }
.ornament-categories [aria-selected="true"] { box-shadow: inset 0 -2px var(--drawer-ring); }
.ornament-categories button:disabled { opacity: .46; cursor: default; }
.ornament-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.ornament-options .ornament-option {
    display: grid; align-content: center; justify-items: center; gap: 3px;
    min-width: 0; min-height: 64px; border: 1px solid transparent; border-radius: 9px;
    background: transparent; padding: 3px 1px; font-size: 11px; line-height: 1.3;
}
.ornament-option img { display: block; object-fit: contain; }
.ornament-options .ornament-option[aria-pressed="true"] { border-color: var(--drawer-ring); background: var(--drawer-selected); }
.ornament-hint { font-size: 11px; line-height: 1.45; margin: 8px 1px 0; }
.ornament-drawer-open #toast { z-index: 5; }

@media (min-width: 701px) and (min-height: 501px) {
    .ornament-drawer-open .intro .description,
    .ornament-drawer-open .intro .little-line,
    .ornament-drawer-open .intro .instruction { visibility: hidden; }
}

/* Phones and short screens: the menu moves to the bottom */
@media (max-width: 700px), (max-height: 500px) {
    .ornament-drawer {
        left: 50%; bottom: max(51px, calc(env(safe-area-inset-bottom) + 38px));
        width: min(calc(100% - 34px), 330px);
        flex-direction: column; align-items: flex-start;
        transform: translateX(-50%); pointer-events: none;
    }
    .ornament-tab, .ornament-panel { pointer-events: auto; }
    .ornament-tab { margin: 0 0 -1px; border-radius: 12px 12px 0 0; }
    .ornament-tab[aria-expanded="true"] { border-left-color: var(--line); border-bottom-color: var(--drawer-bg); }
    .ornament-tab-arrow { transform: none; }
    .ornament-tab[aria-expanded="true"] .ornament-tab-arrow { transform: rotate(180deg); }
    .ornament-panel { width: 100%; border-radius: 0 14px 14px 14px; }
    .ornament-drawer-open .intro,
    .ornament-drawer-open .view-controls,
    .ornament-drawer-open .site-credit { visibility: hidden; }
    .ornament-drawer-open #toast { bottom: calc(52px + 230px + env(safe-area-inset-bottom)); }
    .site-credit { bottom: 110px; }
}

@media (max-width: 700px) {
    header { top: 24px; left: 24px; right: 24px; }
    .brand { font-size: 9px; letter-spacing: 1.8px; }
    .brand-star { font-size: 30px; }
    .intro { top: 105px; left: 28px; }
    .eyebrow { font-size: 8px; margin-bottom: 12px; letter-spacing: 2px; }
    h1 { font-size: 29px; line-height: 1.45; margin-bottom: 9px; letter-spacing: 3px; }
    .description { font-size: 11px; line-height: 1.8; margin: 8px 0; }
    .little-line, .instruction { display: none; }
    footer { left: 24px; right: 24px; bottom: 20px; justify-content: center; }
    footer > span { display: none; }
    #toast { bottom: 74px; font-size: 11px; }
    .view-controls { right: 20px; bottom: 90px; }
    .view-controls button { width: 32px; height: 32px; }
    #theme { right: 22px; }
    .site-credit { left: 24px; bottom: 68px; gap: 5px; }
    .site-credit img { width: 98px; }
    .site-credit > span { font-size: 9px; }
}

@media (max-height: 500px) and (min-width: 540px) {
    main { min-height: 0; }
    .ornament-drawer { width: min(calc(100% - 36px), 490px); }
    .ornament-options { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .ornament-drawer-open #toast { bottom: 213px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
