:root {
    --dusk: #171a2e;
    --warm: #ffd9a8;
    --cream: #fbf1dd;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
    background: var(--dusk);
    color: var(--cream);
    font: 400 17px/1.4 "Bricolage Grotesque", sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--warm); outline-offset: 3px; }

#stage, #stage canvas { position: fixed; inset: 0; display: block; touch-action: none; }

/* Title */
#title {
    position: fixed; inset: 0; z-index: 5;
    display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start;
    padding: clamp(24px, 6vw, 72px);
    background: linear-gradient(to top, rgba(16, 14, 34, .72), transparent 55%);
    transition: opacity 1.1s ease, visibility 1.1s;
}
/* The name is the progress bar: the ball paints it in, then drops in the cup. */
#poster {
    position: fixed; inset: 0; z-index: 1; width: 100%; height: 100%;
    object-fit: cover;
    transform: scale(1.06);
    filter: blur(calc((1 - var(--p, 0)) * 26px)) brightness(calc(.62 + var(--p, 0) * .38));
    transition: opacity 1.3s ease;
}
.ready #poster { opacity: 0; pointer-events: none; }

#name {
    position: relative;
    width: max-content;
    max-width: 100%;
    font-size: clamp(3.4rem, 14.5vw, 13rem);
    line-height: .9;
    font-weight: 800;
    letter-spacing: -.045em;
    white-space: nowrap;
}
.name-line { display: block; color: transparent; -webkit-text-stroke: 1.5px rgba(251, 241, 221, .7); }
.name-fill {
    position: absolute; inset: 0;
    color: var(--cream);
    text-shadow: 0 2px 40px rgba(20, 10, 40, .4);
    clip-path: inset(-20% calc(100% - var(--p, 0) * 106%) -20% -5%);
}
#turf {
    position: absolute; left: 0; right: -.28em; bottom: -.075em; height: 2px;
    background: rgba(251, 241, 221, .55);
    transition: opacity .6s ease;
}
#ball {
    position: absolute; bottom: -.065em; left: calc(var(--p, 0) * 100%);
    width: .085em; height: .085em; margin-left: -.0425em;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff 40%, #cfc8ba);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
#cup {
    position: absolute; right: -.26em; bottom: -.08em; width: .12em; height: .03em;
    border-radius: 50%; background: #0e0c1c;
    transition: opacity .6s ease;
}
#cup::before { content: ""; position: absolute; left: 50%; bottom: 0; width: 2px; height: .72em; background: var(--cream); }
#cup b { position: absolute; left: calc(50% + 2px); bottom: .5em; width: .2em; height: .14em; background: #c8322b; transform-origin: left center; }
.sunk #ball { animation: sink .62s cubic-bezier(.5, 0, .9, .6) forwards; }
.sunk #cup b { animation: wave .7s ease-in-out .35s; }
@keyframes sink {
    0% { left: 100%; transform: none; opacity: 1; }
    72% { left: calc(100% + .2em); transform: none; opacity: 1; }
    100% { left: calc(100% + .2em); transform: translateY(.05em) scale(.3); opacity: 0; }
}
@keyframes wave { 40% { transform: skewY(9deg) scaleX(.9); } 70% { transform: skewY(-6deg); } }
.ready #turf, .ready #cup, .ready .name-line { opacity: 0; }
.name-line { transition: opacity .4s; }
.ready #ball { display: none; }

#title p { max-width: 30em; margin: 26px 0 26px; font-size: 1.2rem; }
#title #load-status { margin: 0; min-height: 52px; font-size: 1rem; }
.ready #load-status { display: none; }
.title-actions { display: none; gap: 22px; align-items: center; animation: rise .7s ease both; }
.ready .title-actions { display: flex; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
#enter { padding: 14px 30px; background: var(--cream); color: var(--dusk); font-weight: 700; font-size: 1.1rem; border-radius: 999px; transition: transform .2s; }
#enter:hover { transform: scale(1.04); }
#tour { text-decoration: underline; text-underline-offset: 4px; }
.started #title { opacity: 0; visibility: hidden; pointer-events: none; }

/* In-world HUD */
#hud { position: fixed; top: 18px; right: 22px; z-index: 6; display: flex; gap: 20px; font-size: .92rem; text-shadow: 0 1px 8px rgba(0, 0, 0, .5); }
#hud button { display: flex; align-items: center; gap: 7px; }
#hud button span { text-decoration: underline; text-underline-offset: 3px; }
#hud kbd { min-width: 20px; height: 20px; display: grid; place-items: center; border-radius: 5px; border: 1px solid rgba(251, 241, 221, .6); border-bottom-width: 2px; font: 700 .72rem "Bricolage Grotesque", sans-serif; text-shadow: none; }
body:not(.started) #hud kbd { display: none; }
#sound { display: none; }
.started #sound { display: flex; }

#dot { position: fixed; left: 50%; top: 50%; width: 5px; height: 5px; margin: -2.5px; border-radius: 50%; background: rgba(255, 255, 255, .75); box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); z-index: 3; opacity: 0; transition: opacity .3s; }
.started:not(.inspecting) #dot { opacity: 1; }

#prompt {
    position: fixed; left: 50%; bottom: 13vh; z-index: 4;
    display: flex; gap: 10px; align-items: center;
    padding: 8px 18px 8px 8px; border-radius: 999px;
    background: rgba(20, 16, 38, .62); backdrop-filter: blur(10px);
    transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
    transition: opacity .18s, transform .18s;
}
#prompt.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#prompt kbd { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--cream); color: var(--dusk); font: 700 .9rem "Bricolage Grotesque", sans-serif; }

#help, #toast {
    position: fixed; left: 50%; bottom: 26px; z-index: 4;
    transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
    text-align: center; text-shadow: 0 1px 10px rgba(0, 0, 0, .7);
    opacity: 0; transition: opacity .5s; pointer-events: none;
}
#help.on, #toast.on { opacity: 1; }
.inspecting #help { opacity: 0; }

/* Controls, drawn like game keycaps. They light up as you press them. */
#keys {
    position: fixed; left: 50%; bottom: 22px; z-index: 4;
    transform: translateX(-50%);
    display: none; align-items: flex-end; gap: 30px;
    font-size: .86rem;
    text-shadow: 0 1px 8px rgba(0, 0, 0, .7);
    opacity: .9;
    pointer-events: none;
    transition: opacity .3s;
}
.started #keys { display: flex; animation: rise .8s ease 4.8s both; }
.inspecting #keys { opacity: 0; }
#keys > div { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 76px; justify-content: flex-end; }
#keys .wasd { display: grid; grid-template-columns: repeat(3, 32px); gap: 4px; justify-items: center; }
#keys .wasd kbd:first-child { grid-column: 2; }
#keys .wasd kbd:nth-child(2) { grid-column: 1; }
#keys .wasd span { grid-column: 1 / -1; margin-top: 2px; }
#keys kbd {
    width: 32px; height: 32px; display: grid; place-items: center;
    border-radius: 7px;
    border: 1.5px solid rgba(251, 241, 221, .75);
    border-bottom-width: 3.5px;
    background: rgba(22, 18, 42, .5);
    backdrop-filter: blur(6px);
    color: var(--cream);
    font: 700 .84rem "Bricolage Grotesque", sans-serif;
    text-shadow: none;
    transition: transform .07s, background .07s, color .07s, border-bottom-width .07s;
}
#keys kbd.wide { width: 62px; }
#keys kbd.down { background: var(--cream); color: var(--dusk); border-bottom-width: 1.5px; transform: translateY(2px); }
@media (pointer: coarse) { #keys { display: none !important; } }

#toast { bottom: 22vh; font-size: 1.5rem; font-weight: 700; }

#stick { display: none; position: fixed; right: 26px; bottom: calc(26px + env(safe-area-inset-bottom)); z-index: 4; width: 116px; height: 116px; border-radius: 50%; background: rgba(255, 255, 255, .14); border: 1.5px solid rgba(255, 255, 255, .4); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px; border-radius: 50%; background: rgba(255, 255, 255, .72); }
@media (pointer: coarse) {
    .started:not(.inspecting) #stick { display: block; }
    #prompt kbd { display: none; }
    #prompt { padding: 12px 20px; }
    #help { bottom: 164px; }
}

#resume {
    position: fixed; left: 50%; top: 50%; z-index: 4;
    transform: translate(-50%, 18px);
    padding: 7px 16px; border-radius: 999px;
    background: rgba(20, 16, 38, .62); backdrop-filter: blur(10px);
    font-size: .95rem;
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.free.started:not(.inspecting) #resume { opacity: 1; }
@media (pointer: coarse) { #resume, #hud kbd { display: none !important; } }

#fade { position: fixed; inset: 0; z-index: 3; background: #0c0a18; opacity: 0; pointer-events: none; transition: opacity .3s; }
#fade.on { opacity: 1; }

/* Cards */
#cards {
    position: fixed; z-index: 7; top: 0; bottom: 74px; right: clamp(16px, 6vw, 96px);
    width: min(520px, calc(100vw - 32px));
    display: none; align-items: center; justify-content: center;
    perspective: 1400px;
}
#cards.on { display: flex; }
#card-controls {
    position: fixed; z-index: 8; bottom: 22px; right: clamp(16px, 6vw, 96px);
    width: min(520px, calc(100vw - 32px));
    display: none; justify-content: space-between;
    text-shadow: 0 1px 8px rgba(0, 0, 0, .7);
}
#card-controls.on { display: flex; }
#card-controls button { text-decoration: underline; text-underline-offset: 3px; }
#card-close { font-weight: 700; }

.card { position: relative; width: 100%; max-height: 100%; overflow: auto; color: #1b1a17; box-shadow: 0 34px 70px -20px rgba(4, 2, 16, .75), 0 6px 18px rgba(4, 2, 16, .35); }
.card h2 { line-height: 1; }

/* Scorecard */
.scorecard { padding: 22px 24px; background: #f5efdf; font-family: "Barlow Condensed", sans-serif; font-size: 1.14rem; border-top: 10px solid #1f4d38; }
.scorecard header { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #1f4d38; padding-bottom: 10px; color: #1f4d38; }
.scorecard h2 { font-size: 3.6rem; font-weight: 700; letter-spacing: -.01em; text-transform: uppercase; }
.scorecard header p { text-align: right; font-size: .95rem; line-height: 1.15; }
.scorecard .lede { margin: 12px 0; font-size: 1.32rem; line-height: 1.2; }
.scorecard table { width: 100%; border-collapse: collapse; }
.scorecard th, .scorecard td { border: 1px solid #1f4d38; padding: 6px 10px; text-align: left; }
.scorecard th { background: #1f4d38; color: #f5efdf; font-weight: 500; }
.scorecard td:first-child { width: 58px; text-align: center; font-weight: 700; }
.scorecard td:last-child { font-family: "Caveat", cursive; font-size: 1.5rem; line-height: 1.05; color: #243b7a; }
.scorecard .note { margin: 12px 0; }
.scorecard footer { display: flex; justify-content: space-between; gap: 16px; font-weight: 700; color: #1f4d38; }

/* Wine label */
.label { padding: 12px; max-width: 400px; background: #ece2cc; box-shadow: 0 34px 70px -20px rgba(4, 2, 16, .75); font-family: "Libre Caslon Text", serif; text-align: center; }
.label-inner { padding: 34px 26px; border: 1px solid #5a1630; outline: 3px double #5a1630; outline-offset: -7px; color: #3a0f20; }
.label .estate { font-style: italic; }
.label h2 { margin: 10px 0 6px; font-size: 3.1rem; font-weight: 700; line-height: 1.02; color: #5a1630; }
.label svg { display: block; width: 120px; margin: 4px auto 10px; color: #5a1630; }
.label p { line-height: 1.55; }
.label a { display: inline-block; margin-top: 18px; color: #5a1630; font-weight: 700; }

/* Cassette J-card */
.jcard { display: grid; grid-template-columns: 58px 1fr; background: #f2e6c9; font-family: "Bricolage Grotesque", sans-serif; }
.jcard .spine { background: #e2552e; color: #fff4dc; writing-mode: vertical-rl; transform: rotate(180deg); display: grid; place-items: center; font-weight: 800; letter-spacing: .28em; font-size: 1.15rem; }
.jcard-face { padding: 20px 24px; background: repeating-linear-gradient(0deg, transparent 0 27px, rgba(40, 60, 120, .16) 27px 28px), #f2e6c9; }
.jcard .side { font-weight: 700; color: #e2552e; }
.jcard h2 { font-size: 3.5rem; font-weight: 800; letter-spacing: -.03em; color: #1c2a55; }
.jcard .hand { font: 700 1.75rem/1.1 "Caveat", cursive; color: #1c2a55; margin: 10px 0 16px; }
.reels { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px; background: #1c1c1e; border-radius: 10px; }
.reels i { width: 54px; height: 54px; border-radius: 50%; background: conic-gradient(#f2e6c9 0 12%, #1c1c1e 12% 33%, #f2e6c9 33% 45%, #1c1c1e 45% 66%, #f2e6c9 66% 78%, #1c1c1e 78%); animation: spin 2.4s linear infinite; }
.reels b { flex: 1; height: 34px; background: #6b4a33; border-radius: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.bars { display: flex; align-items: center; gap: 4px; height: 44px; margin: 14px 0 10px; }
.bars i { flex: 1; height: 30%; background: #e2552e; border-radius: 2px; animation: talk 1s ease-in-out infinite alternate; }
.bars i:nth-child(3n) { animation-duration: .7s; }
.bars i:nth-child(3n+1) { animation-duration: 1.3s; animation-delay: -.4s; }
.bars i:nth-child(4n) { animation-duration: .55s; animation-delay: -.2s; }
@keyframes talk { to { height: 100%; } }
.jcard a { font-weight: 700; color: #1c2a55; }

/* Trove */
.ledger { padding: 34px 32px; background: radial-gradient(120% 90% at 20% 0, #4a3524, #241810); color: #f0dcae; font-family: "IM Fell English", serif; font-size: 1.28rem; line-height: 1.4; border: 2px solid #b08a44; outline: 1px solid #b08a44; outline-offset: -9px; }
.ledger .stamp { display: inline-block; padding: 2px 10px; border: 2px solid #d9a441; color: #e8b64f; transform: rotate(-3deg); font-size: 1rem; }
.ledger h2 { margin: 14px 0 12px; font-size: 5rem; font-weight: 400; color: #f7c95e; }
.ledger a { display: inline-block; margin-top: 18px; color: #f7c95e; }

/* Trading card */
.holo { background: none; box-shadow: none; overflow: visible; max-width: 400px; --rx: 0deg; --ry: 0deg; --px: 50%; --py: 30%; }
.holo-inner { position: relative; overflow: hidden; padding: 16px; border-radius: 18px; background: linear-gradient(150deg, #0e3f2c, #123a6b); color: #fff; box-shadow: 0 34px 70px -20px rgba(4, 2, 16, .8); transform: rotateX(var(--rx)) rotateY(var(--ry)); transition: transform .12s linear; }
.holo h2 { font-size: 1.85rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 12px; }
.holo img { display: block; width: 100%; height: auto; border-radius: 8px; border: 3px solid #f5d76e; }
.holo p { margin: 12px 0; }
.holo a { position: relative; z-index: 1; font-weight: 700; color: #f5d76e; }
.shine { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: color-dodge; opacity: .5; background: radial-gradient(circle at var(--px) var(--py), rgba(255, 255, 255, .7), transparent 42%), linear-gradient(115deg, transparent 20%, rgba(255, 90, 170, .45) 38%, rgba(90, 220, 255, .45) 50%, rgba(255, 240, 120, .45) 62%, transparent 80%); background-size: 100% 100%, 240% 240%; background-position: 0 0, var(--px) var(--py); }

/* Book */
#cards:has(.book) { width: min(760px, calc(100vw - 32px)); }
.book { display: grid; grid-template-columns: .82fr 1fr; background: #f6efe0; font-family: "Libre Caslon Text", serif; }
.book .page { min-width: 0; }
.book .left { background: #111; box-shadow: inset -22px 0 26px -18px rgba(0, 0, 0, .7); }
.book .left img { display: block; width: 100%; height: 100%; object-fit: cover; }
.book .right { padding: 26px 26px 24px; box-shadow: inset 22px 0 26px -18px rgba(70, 40, 10, .4); }
.book h2 { font-size: 1.6rem; font-weight: 400; font-style: italic; line-height: 1.15; margin-bottom: 14px; }
.book ol { padding-left: 1.5em; }
.book li { margin-bottom: 8px; font-size: .98rem; line-height: 1.3; }
.book a { text-decoration-color: rgba(0, 0, 0, .3); text-underline-offset: 3px; }
.book a:hover { color: #8a2a1a; }

/* Notepad */
.notepad { padding: 34px 28px 28px 54px; max-width: 430px; background: repeating-linear-gradient(0deg, transparent 0 31px, rgba(60, 90, 150, .28) 31px 32px), linear-gradient(90deg, transparent 39px, rgba(200, 60, 50, .4) 39px 40px, transparent 40px), #fbf0a8; font: 500 1.55rem/32px "Caveat", cursive; transform: rotate(-.6deg); }
.notepad h2 { font-size: 2.4rem; font-weight: 700; line-height: 32px; margin-bottom: 32px; }
.notepad p { margin-bottom: 32px; }
.notepad a { font-weight: 700; color: #1c2a55; }

/* Payphone */
.dial { padding: 30px; max-width: 400px; background: linear-gradient(160deg, #4a4e55, #24262b); color: #eef0f2; border-radius: 10px; border: 1px solid #70757e; font-family: "Bricolage Grotesque", sans-serif; }
.dial h2 { font-size: 3rem; font-weight: 800; letter-spacing: -.03em; margin-bottom: 12px; }
.dial p + p { margin-top: 10px; }
.dial .line { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 12px; color: #ffcf7a; font-weight: 600; }
.dial .line::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #ffcf7a; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .2; } }
.dial a { display: inline-block; margin-top: 18px; padding: 12px 26px; border-radius: 999px; background: var(--cream); color: var(--dusk); text-decoration: none; font-weight: 700; }

/* Postcard */
.postcard { display: grid; grid-template-columns: 1fr 1px 1fr; gap: 0; background: #f7f0df; aspect-ratio: 3 / 2; max-width: 520px; }
.postcard::before { content: ""; grid-column: 2; grid-row: 1; margin: 22px 0; background: #b7ab92; }
.post-left { grid-column: 1; grid-row: 1; padding: 26px 22px; display: flex; flex-direction: column; justify-content: center; }
.postcard .hand { font: 500 1.6rem/1.2 "Caveat", cursive; color: #243b7a; }
.postcard .sig { margin-top: 14px; font-size: 2rem; font-weight: 700; }
.post-right { grid-column: 3; grid-row: 1; padding: 20px; display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; font: 700 1.05rem "Barlow Condensed", sans-serif; }
.post-right a { border-bottom: 1px solid #b7ab92; text-decoration: none; padding-bottom: 3px; }
.post-right a:first-of-type { font: 700 1.35rem "Caveat", cursive; color: #243b7a; }
.stamp-box { align-self: flex-end; margin-bottom: auto; width: 62px; height: 76px; display: grid; place-items: center; background: #c8322b; color: #fff6e8; outline: 4px dotted #f7f0df; outline-offset: -2px; font: 800 1.9rem "Bricolage Grotesque", sans-serif; }
.stamp-box i { font-style: normal; }

/* Text version: plain and quiet, in the same dusk colors as the world. */
#text { display: none; max-width: 34rem; margin: 0 auto; padding: clamp(84px, 14vh, 128px) 24px 88px; font: 400 1.0625rem/1.7 "Libre Caslon Text", Georgia, serif; color: var(--cream); }
#text h1 { margin-bottom: 24px; font: 800 clamp(3.1rem, 13vw, 4.8rem)/.95 "Bricolage Grotesque", sans-serif; letter-spacing: -.04em; }
#text h2 { margin: 46px 0 12px; font: 700 1.05rem/1.3 "Bricolage Grotesque", sans-serif; color: var(--warm); }
#text ul { padding: 0; list-style: none; }
#text li { margin-bottom: 11px; }
#text a { color: var(--cream); text-decoration-color: rgba(255, 217, 168, .5); text-underline-offset: 3px; }
#text a:hover { color: var(--warm); text-decoration-color: currentColor; }
#text .making a { font-weight: 700; }
body.lofi { background: var(--dusk); overflow: auto; }
body.lofi #stage, body.lofi #poster, body.lofi #keys, body.lofi #title, body.lofi #dot, body.lofi #prompt, body.lofi #help, body.lofi #stick, body.lofi #cards, body.lofi #card-controls, body.lofi #sound { display: none !important; }
body.lofi #text { display: block; }
body.lofi #hud { position: absolute; text-shadow: none; }
body.no-webgl #text-toggle { display: none; }
#no-3d { display: none; }
body.no-webgl #no-3d { display: block; margin-bottom: 32px; font-style: italic; color: var(--warm); }

@media (max-width: 820px) {
    #cards { right: 16px; left: 16px; width: auto; top: auto; bottom: 66px; height: 62vh; align-items: flex-end; }
    #cards:has(.book) { width: auto; }
    #card-controls { right: 16px; left: 16px; width: auto; }
    .book { grid-template-columns: 1fr; }
    .book .left { display: none; }
    .postcard { aspect-ratio: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .sunk #ball, .sunk #cup b, .dial .line::before { animation: none; }
    .reels i, .bars i { animation: none; }
    .bars i { height: 60%; }
}
