:root {
  --ink: #2b2d5b;
  --ink-2: #1c2057;
  --paper: #fdf3dc;
  --paper-2: #f6e6c4;
  --coral: #f26a4b;
  --mustard: #f4b942;
  --teal: #2fa8a0;
  --lilac: #b79ced;
  --accent: var(--mustard);
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink-2); color: var(--ink); font-family: var(--body); overscroll-behavior: none; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
#scene.dragging { cursor: grabbing; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--coral); outline-offset: 2px; }

/* ---------- loader ---------- */
#loader { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; gap: 22px; justify-items: center; background: radial-gradient(circle at 50% 40%, #3a3f8f, #1c2057 70%); color: var(--paper); font-family: var(--display); font-size: 20px; transition: opacity .7s ease, visibility .7s; }
#loader.done { opacity: 0; visibility: hidden; }
.loader-planet { position: relative; width: 84px; height: 84px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #c5d67a, #86bd6c 55%, #2f6f86); box-shadow: 0 0 0 6px rgba(253,243,220,.12), 6px 6px 0 rgba(0,0,0,.25); animation: bob 1.6s ease-in-out infinite; }
.loader-planet i { position: absolute; inset: -14px; border-radius: 50%; border: 2px dashed rgba(253,243,220,.55); animation: spin 5s linear infinite; }
.loader-planet i::after { content: ''; position: absolute; top: -6px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--mustard); box-shadow: 0 0 14px var(--mustard); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* ---------- HUD ---------- */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#ui > * { pointer-events: none; }
#ui button, #ui a, #panel, #places { pointer-events: auto; }

#brand { position: absolute; top: calc(14px + var(--safe-t)); left: calc(16px + var(--safe-l)); color: var(--paper); text-shadow: 0 2px 0 rgba(43,45,91,.55), 0 0 18px rgba(43,45,91,.35); animation: fadeDown .9s .3s both; }
#brand h1 { margin: 0; font: 800 clamp(26px, 3.4vw, 40px)/1 var(--display); letter-spacing: -.01em; }
#brand p { margin: 4px 0 0; font-size: 13px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-10px); } }

#places { position: absolute; top: calc(96px + var(--safe-t)); left: calc(14px + var(--safe-l)); display: flex; flex-direction: column; gap: 8px; animation: fadeDown .9s .5s both; }
#places button { display: flex; align-items: center; gap: 9px; min-height: 40px; padding: 6px 14px 6px 8px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); font-weight: 700; font-size: 14px; text-align: left; transition: transform .12s, box-shadow .12s; }
#places button:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
#places button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
#places .arrow { width: 26px; height: 26px; border-radius: 50%; background: var(--c); display: grid; place-items: center; flex: none; }
#places .arrow svg { width: 14px; height: 14px; transition: transform .15s linear; fill: var(--ink); }
#places .check { margin-left: auto; padding-left: 4px; font-size: 12px; color: var(--teal); opacity: 0; }
#places button.visited .check { opacity: 1; }
#places button.near { background: var(--c); }

#tray { position: absolute; top: calc(14px + var(--safe-t)); right: calc(14px + var(--safe-r)); display: flex; align-items: center; gap: 8px; animation: fadeDown .9s .4s both; }
#stars { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); font: 700 15px var(--body); }
#stars .slots { display: flex; gap: 4px; }
#stars .slot { width: 22px; height: 22px; display: block; }
#stars .slot svg { width: 100%; height: 100%; overflow: visible; }
#stars .slot path { fill: rgba(43,45,91,.12); stroke: rgba(43,45,91,.5); stroke-width: 1.5; stroke-dasharray: 3 2.5; transition: fill .3s, stroke .3s; }
#stars .slot.got path { fill: var(--c); stroke: var(--ink); stroke-dasharray: 0; }
#stars .slot.pop { animation: pop .7s cubic-bezier(.2, 1.6, .4, 1); }
#stars.pulse { animation: pulse .6s ease; }
#stars.near .slot:not(.got) { animation: twinkle 1.1s ease-in-out infinite; }
#stars.near .slot:not(.got):nth-child(2n) { animation-delay: .25s; }
@keyframes twinkle { 50% { transform: scale(1.25) rotate(14deg); } }
@keyframes pop { 0% { transform: scale(.3) rotate(-40deg); } 60% { transform: scale(1.7) rotate(12deg); } 100% { transform: none; } }
@keyframes pulse { 40% { transform: scale(1.06); } }
.round { width: 44px; height: 44px; padding: 0; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); font-size: 18px; font-weight: 700; display: grid; place-items: center; transition: transform .12s, box-shadow .12s; }
.round:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.round:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.round svg { width: 22px; height: 22px; }

#hint { position: absolute; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); margin: 0; padding: 9px 18px; max-width: calc(100vw - 32px); border-radius: 999px; background: rgba(28, 32, 87, .72); backdrop-filter: blur(6px); color: var(--paper); font-size: 14px; font-weight: 500; text-align: center; transition: opacity .8s, transform .8s; }
#hint.gone { opacity: 0; transform: translate(-50%, 10px); }
#hint kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin: 0 1px; border-radius: 6px; background: var(--paper); color: var(--ink); font: 700 12px var(--body); box-shadow: 0 2px 0 rgba(0,0,0,.35); }

#toast { position: absolute; left: 50%; top: calc(72px + var(--safe-t)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast .t { padding: 10px 18px; border: 2px solid var(--ink); border-radius: 14px; background: var(--paper); box-shadow: 4px 4px 0 var(--ink); font-weight: 700; animation: toastIn .5s cubic-bezier(.2, 1.4, .4, 1), toastOut .5s 3.4s forwards; white-space: nowrap; }
#toast .t b { color: var(--coral); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.9) rotate(-2deg); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- floating labels ---------- */
#labels { position: absolute; inset: 0; overflow: hidden; }
.label { position: absolute; left: 0; top: 0; will-change: transform; padding: 5px 12px 5px 8px; display: flex; align-items: center; gap: 7px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); box-shadow: 2px 2px 0 var(--ink); font: 700 13px var(--body); color: var(--ink); white-space: nowrap; pointer-events: auto; cursor: pointer; transition: opacity .3s; }
.label i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 2px solid var(--ink); flex: none; }
.label::after { content: ''; position: absolute; left: 50%; bottom: -9px; width: 2px; height: 8px; margin-left: -1px; background: var(--ink); }

/* ---------- content panel ---------- */
#panel { position: absolute; right: calc(22px + var(--safe-r)); top: 50%; width: min(410px, calc(100vw - 32px)); max-height: min(78vh, 700px); overflow: auto; padding: 26px 24px 24px; border: 2px solid var(--ink); border-radius: 20px; background: var(--paper); background-image: radial-gradient(rgba(43,45,91,.07) 1px, transparent 1.4px); background-size: 7px 7px; box-shadow: 7px 7px 0 var(--accent), 7px 7px 0 2px var(--ink); transform: translateY(-50%) rotate(1.5deg); animation: panelIn .55s cubic-bezier(.2, 1.3, .4, 1) both; overscroll-behavior: contain; touch-action: pan-y; user-select: text; -webkit-user-select: text; scrollbar-width: thin; }
#panel.out { animation: panelOut .28s ease-in forwards; }
@keyframes panelIn { from { opacity: 0; transform: translateY(-46%) translateX(40px) rotate(6deg); } to { opacity: 1; transform: translateY(-50%) rotate(-.4deg); } }
@keyframes panelOut { to { opacity: 0; transform: translateY(-50%) translateX(40px) rotate(4deg); } }
#panel .tape { position: absolute; top: -13px; left: 50%; width: 92px; height: 26px; margin-left: -46px; background: var(--accent); opacity: .92; transform: rotate(-3deg); border-left: 2px dashed rgba(43,45,91,.25); border-right: 2px dashed rgba(43,45,91,.25); }
#panel .close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); font-size: 22px; line-height: 1; display: grid; place-items: center; padding: 0 0 3px; }
#panel .close:hover { background: var(--accent); }
#panel header { display: flex; align-items: center; gap: 14px; margin: 4px 40px 14px 0; }
#panel header .icon { flex: none; width: 54px; height: 54px; border-radius: 16px; background: var(--accent); border: 2px solid var(--ink); display: grid; place-items: center; transform: rotate(-4deg); }
#panel header .icon svg { width: 32px; height: 32px; }
#panel header small { display: block; font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; opacity: .6; }
#panel h2 { margin: 0; font: 800 34px/1.05 var(--display); letter-spacing: -.015em; }
#panel .body { font-size: 15.5px; line-height: 1.55; }
#panel .lede { margin: 0 0 12px; font-size: 16.5px; }
#panel a { color: var(--coral); font-weight: 700; text-underline-offset: 3px; }
#panel h3 { margin: 0 0 2px; font: 700 18px/1.2 var(--display); display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; }
#panel h3 .year { font: 700 11px var(--body); letter-spacing: .08em; padding: 2px 8px; border-radius: 999px; background: var(--ink); color: var(--paper); }
#panel .cards { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
#panel .card { display: flex; gap: 12px; padding: 12px 14px; border: 2px solid var(--ink); border-radius: 14px; background: #fff9ea; animation: rise .5s calc(.12s + var(--i) * .07s) both cubic-bezier(.2, 1.2, .4, 1); }
#panel .card p { margin: 0; font-size: 14.5px; opacity: .88; }
#panel .card .num { flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); border: 2px solid var(--ink); display: grid; place-items: center; font: 800 13px var(--display); }
#panel .card .num.quill { font-size: 16px; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
#panel .contact { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
#panel .contact li { display: grid; gap: 4px; animation: rise .5s calc(.1s + var(--i) * .08s) both cubic-bezier(.2, 1.2, .4, 1); }
#panel .contact .k { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; opacity: .6; }
#panel .contact .v { font-weight: 700; font-size: 16px; }
#panel .btn { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border: 2px solid var(--ink); border-radius: 14px; background: var(--accent); color: var(--ink); text-decoration: none; font-weight: 700; box-shadow: 3px 3px 0 var(--ink); transition: transform .12s, box-shadow .12s; word-break: break-all; }
#panel .btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
#panel .contact .status { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; background: rgba(47,168,160,.16); }
#panel .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 0 rgba(47,168,160,.6); animation: ping 1.8s infinite; flex: none; }
@keyframes ping { 70% { box-shadow: 0 0 0 10px rgba(47,168,160,0); } 100% { box-shadow: 0 0 0 0 rgba(47,168,160,0); } }
#panel .all section { margin-bottom: 24px; }
#panel .all section > h3 { font-size: 22px; padding-bottom: 6px; border-bottom: 2px dashed rgba(43,45,91,.3); margin-bottom: 8px; }
#panel .plain { padding-left: 18px; }

/* ---------- celebration ---------- */
#celebrate { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle, rgba(28,32,87,.1), rgba(28,32,87,.55)); pointer-events: auto !important; animation: fade .6s both; }
#celebrate .card { position: relative; max-width: min(440px, calc(100vw - 32px)); padding: 34px 28px 26px; text-align: center; border: 2px solid var(--ink); border-radius: 26px; background: var(--paper); box-shadow: 8px 8px 0 var(--coral), 8px 8px 0 2px var(--ink); animation: celIn .8s cubic-bezier(.2, 1.5, .4, 1) both; }
#celebrate h2 { margin: 0 0 8px; font: 800 clamp(30px, 6vw, 42px)/1.05 var(--display); }
#celebrate p { margin: 0 0 20px; font-size: 16px; line-height: 1.5; }
#celebrate .row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
#celebrate button { padding: 12px 20px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); font-weight: 700; box-shadow: 3px 3px 0 var(--ink); }
#celebrate button.primary { background: var(--mustard); }
#celebrate .burst { width: 110px; height: 110px; margin: -80px auto 8px; filter: drop-shadow(4px 4px 0 var(--ink)); animation: spinStar 6s linear infinite; }
@keyframes celIn { from { opacity: 0; transform: scale(.6) rotate(-8deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes spinStar { to { transform: rotate(360deg); } }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none !important; }

/* ---------- touch controls ---------- */
#stickZone { position: absolute; left: 0; bottom: 0; width: 58%; height: 62%; display: none; pointer-events: auto !important; touch-action: none; }
#stick { position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(253,243,220,.7); background: rgba(28,32,87,.28); backdrop-filter: blur(3px); opacity: .55; transition: opacity .2s; }
#stick.active { opacity: 1; }
#thumb { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); box-shadow: 2px 3px 0 rgba(43,45,91,.7); }
#jumpBtn { position: absolute; right: calc(22px + var(--safe-r)); bottom: calc(34px + var(--safe-b)); width: 76px; height: 76px; border-radius: 50%; border: 2px solid var(--ink); background: var(--mustard); box-shadow: 4px 4px 0 var(--ink); font: 800 14px var(--display); display: none; touch-action: none; }
#jumpBtn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
body.touch #stickZone, body.touch #jumpBtn { display: block; }
body.touch #jumpBtn { display: grid; place-items: center; }

/* ---------- fallback (no WebGL) ---------- */
#fallback { position: fixed; inset: 0; overflow: auto; padding: 40px 20px; background: radial-gradient(circle at 50% 0, #3a3f8f, #1c2057 60%); color: var(--paper); }
#fallback .wrap { max-width: 720px; margin: 0 auto; }
#fallback h1 { font: 800 44px var(--display); margin: 0 0 6px; }
#fallback section { margin: 28px 0; padding: 20px; border-radius: 16px; background: var(--paper); color: var(--ink); }
#fallback h2 { margin-top: 0; font-family: var(--display); }
#fallback a { color: var(--coral); }
body.fb { overflow: auto; touch-action: auto; user-select: text; }
#fallback .cards, #fallback .contact { list-style: none; padding: 0; display: grid; gap: 10px; }
#fallback .num { display: none; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  #brand { top: calc(62px + var(--safe-t)); }
  #brand h1 { font-size: 22px; }
  #brand p { display: none; }
  #places { top: auto; bottom: calc(150px + var(--safe-b)); left: auto; right: calc(12px + var(--safe-r)); flex-direction: column; align-items: flex-end; gap: 6px; }
  #places button { min-height: 34px; padding: 4px 10px 4px 5px; font-size: 12.5px; }
  #places .arrow { width: 22px; height: 22px; }
  #places .check { display: none; }
  #tray { gap: 6px; }
  #stars { height: 40px; padding: 0 10px; gap: 6px; font-size: 13px; }
  #stars .slot { width: 17px; height: 17px; }
  .round { width: 40px; height: 40px; }
  #panel { top: calc(60px + var(--safe-t)); left: 12px; right: 12px; width: auto; max-height: 43vh; padding: 20px 18px 18px; transform: rotate(-.3deg); animation-name: panelInM; }
  #panel.out { animation-name: panelOutM; }
  #panel h2 { font-size: 27px; }
  #panel header .icon { width: 44px; height: 44px; }
  #panel .body { font-size: 14.5px; }
  #toast { top: calc(60px + var(--safe-t)); }
  #hint { bottom: calc(14px + var(--safe-b)); font-size: 13px; }
  body.touch #hint { bottom: calc(196px + var(--safe-b)); left: calc(14px + var(--safe-l)); transform: none; max-width: 56vw; border-radius: 16px; text-align: left; }
  body.touch #hint.gone { transform: translateY(10px); }
  .label { font-size: 12px; padding: 3px 9px 3px 6px; }
}
@keyframes panelInM { from { opacity: 0; transform: translateY(-30px) rotate(-3deg); } to { opacity: 1; transform: rotate(-.3deg); } }
@keyframes panelOutM { to { opacity: 0; transform: translateY(-30px); } }
@media (max-width: 820px) and (max-height: 500px) { #panel { max-height: 70vh; left: auto; width: 46vw; } }

@media (prefers-reduced-motion: reduce) {
  #panel, #panel .card, #panel .contact li, #celebrate .card, #brand, #places, #tray { animation-duration: .01s !important; animation-delay: 0s !important; }
}
