:root {
  --night: #0b0d20; --indigo: #1b1e3f; --panel: rgba(20, 22, 48, 0.86); --line: rgba(232, 185, 106, 0.35);
  --honey: #e8b96a; --mint: #7fe0c2; --coral: #e76f51; --cream: #f4e9d8;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--cream);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(4,5,18,0.55) 100%); }
#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > *, #topbar > * { pointer-events: auto; }
#topbar { position: absolute; top: calc(var(--sat) + 10px); left: 12px; right: 12px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
#topRight { display: flex; gap: 10px; }
#floorLabel { pointer-events: none; font-size: 13px; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(244,233,216,0.75); text-shadow: 0 1px 6px #000; }
.ibtn { width: 46px; height: 46px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: transform .12s; }
.ibtn:active, .pill:active { transform: scale(0.92); }
.ibtn svg { width: 24px; height: 24px; }
#medals { position: absolute; top: calc(var(--sat) + 64px); left: 16px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
#medals .medal { width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f6d58c, #b9842f); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
#medals .medal svg { width: 16px; height: 16px; }
.pill { height: 44px; padding: 0 18px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 4px 14px rgba(0,0,0,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: transform .12s; }
.pill svg { width: 20px; height: 20px; }
#btnBack { position: absolute; left: 14px; bottom: calc(var(--sab) + 96px); }
#btnInspect { position: absolute; right: 14px; bottom: calc(var(--sab) + 96px); border-color: var(--mint); color: var(--mint); }
#tray { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 12px); display: flex; gap: 8px; padding: 8px;
  min-height: 72px; min-width: 72px; max-width: calc(100vw - 16px); border-radius: 20px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0,0,0,0.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#tray:empty { opacity: 0; }
#tray.nope { animation: nope .3s; }
@keyframes nope { 25% { transform: translateX(calc(-50% - 7px)); } 75% { transform: translateX(calc(-50% + 7px)); } }
.slot { width: 56px; height: 56px; flex: 0 1 56px; min-width: 36px; border-radius: 14px; background: rgba(255,255,255,0.06); border: 2px solid transparent; display: grid; place-items: center; transition: transform .15s, border-color .15s, background .15s; }
.slot img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.slot.armed { border-color: var(--mint); background: rgba(127,224,194,0.16); transform: translateY(-8px); box-shadow: 0 0 16px rgba(127,224,194,0.45); }
.slot.new { animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(0.2); opacity: 0; } }

#inspectUI { position: fixed; inset: 0; pointer-events: none; }
#inspectTip { display: none; position: absolute; top: calc(var(--sat) + 70px); width: 100%; text-align: center; font-size: 14px; letter-spacing: .08em; color: rgba(244,233,216,.7); }
#btnInspectClose { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 28px); pointer-events: auto; padding: 0 34px; border-color: var(--mint); color: var(--mint); }

.sheet { position: fixed; left: 12px; right: 12px; top: calc(var(--sat) + 66px); padding: 16px 16px 14px; border-radius: 18px; background: rgba(16,18,40,0.95); border: 1px solid var(--line);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6); animation: drop .22s ease-out; max-width: 460px; margin: 0 auto; }
@keyframes drop { from { transform: translateY(-12px); opacity: 0; } }
.sheet h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--honey); display: flex; justify-content: space-between; align-items: center; }
.sheet p { margin: 6px 0; font-size: 16px; line-height: 1.4; }
.sheet .tip { padding: 8px 0; border-top: 1px solid rgba(255,255,255,0.08); }
.sheet .tip:first-of-type { border-top: 0; }
.sheet .tip small { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: rgba(244,233,216,.5); margin-bottom: 2px; }
.sheet .row { display: flex; gap: 10px; margin-top: 12px; }
.btn { flex: 1; height: 46px; border-radius: 14px; font-weight: 700; font-size: 15px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14); }
.btn.primary { background: linear-gradient(180deg, #f1c984, #d9a04a); color: #2a1c08; border: 0; box-shadow: 0 4px 16px rgba(232,185,106,0.35); }
.btn:active { transform: scale(0.97); }
.btn small { display: block; font-weight: 500; font-size: 11px; opacity: .75; }

#toast { z-index: 4; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 160px); padding: 10px 16px; border-radius: 14px; background: rgba(16,18,40,0.92); border: 1px solid var(--line); font-size: 15px; pointer-events: none; animation: drop .2s; max-width: 86vw; text-align: center; }
#fade { position: fixed; inset: 0; background: var(--night); opacity: 0; pointer-events: none; transition: opacity .6s; }
#fade.on { opacity: 1; pointer-events: auto; }

.overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 20%, #1c2150 0%, #0b0d20 70%); z-index: 5; }
#loading { gap: 18px; letter-spacing: .4em; text-transform: uppercase; font-size: 14px; color: var(--honey); transition: opacity .4s; }
#loading.out { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(232,185,106,.2); border-top-color: var(--honey); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#menu { justify-content: flex-start; overflow: hidden; }
#menu .sky { position: absolute; inset: 0; width: 100%; height: 100%; }
#menu .head { position: relative; margin-top: calc(var(--sat) + 5vh); text-align: center; pointer-events: none; }
#menu h1 { margin: 0; font-size: clamp(34px, 11vw, 54px); letter-spacing: .32em; text-indent: .32em; font-weight: 300; color: var(--cream); text-shadow: 0 0 24px rgba(232,185,106,.45); }
#menu .tag { margin-top: 6px; font-size: 13px; letter-spacing: .16em; color: rgba(244,233,216,.6); }
#menu .foot { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 22px); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0 22px; }
#menu .foot .btn { flex: none; width: min(320px, 100%); height: 54px; font-size: 17px; }
#menu .foot .mini { display: flex; gap: 18px; font-size: 13px; color: rgba(244,233,216,.6); }
#menu .foot .mini button { padding: 8px 6px; text-decoration: underline; text-underline-offset: 3px; }
.win { cursor: pointer; }
.win.avail rect.glass { animation: beckon 1.8s ease-in-out infinite; }
@keyframes beckon { 50% { fill: #3a4a8c; } }

#summary { background: rgba(8,9,24,0.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); padding: 24px; }
#summary .card { width: min(380px, 100%); padding: 26px 22px 20px; border-radius: 24px; background: rgba(18,20,46,0.97); border: 1px solid var(--line); text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: rise .45s cubic-bezier(.2,1.2,.4,1); }
@keyframes rise { from { transform: translateY(30px) scale(.94); opacity: 0; } }
#summary h2 { margin: 0; font-weight: 300; letter-spacing: .2em; text-transform: uppercase; font-size: 22px; }
#summary .sub { color: rgba(244,233,216,.6); font-size: 13px; letter-spacing: .12em; margin-top: 6px; }
#summary .stars { display: flex; justify-content: center; gap: 14px; margin: 22px 0 8px; }
#summary .st { width: 58px; text-align: center; font-size: 10.5px; letter-spacing: .06em; color: rgba(244,233,216,.55); }
#summary .st svg { width: 46px; height: 46px; display: block; margin: 0 auto 4px; opacity: .22; transform: scale(.8); }
#summary .st.on svg { opacity: 1; transform: none; animation: pop .5s cubic-bezier(.3,1.6,.5,1) backwards; filter: drop-shadow(0 0 10px rgba(232,185,106,.7)); }
#summary .st:nth-child(2).on svg { animation-delay: .25s; } #summary .st:nth-child(3).on svg { animation-delay: .5s; }
#summary .medalRow { margin: 14px 0 4px; font-size: 14px; color: var(--honey); display: flex; align-items: center; justify-content: center; gap: 10px; }
#summary .medalRow .medal { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f6d58c, #b9842f); display: grid; place-items: center; }
#summary .medalRow svg { width: 20px; height: 20px; }
#summary .tease { font-size: 14px; color: rgba(244,233,216,.75); margin: 10px 0 0; font-style: italic; }
#summary .row { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
#summary .btn { flex: none; height: 54px; font-size: 17px; }
#summary .btn.ghost { height: 42px; font-size: 14px; background: none; border: 0; color: rgba(244,233,216,.6); }

.ripple { position: absolute; width: 14px; height: 14px; margin: -7px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); animation: ripple .45s ease-out forwards; }
.ripple.hit { border-color: var(--mint); }
@keyframes ripple { to { transform: scale(3.4); opacity: 0; } }
.pulse { position: absolute; width: 44px; height: 44px; margin: -22px; border-radius: 50%; border: 2px solid var(--honey); box-shadow: 0 0 14px rgba(232,185,106,.7), inset 0 0 10px rgba(232,185,106,.4); animation: pulse 1.3s ease-out forwards; }
@keyframes pulse { 0% { transform: scale(.3); opacity: 0; } 25% { opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
.starpop { position: absolute; left: 50%; top: 38%; width: 120px; height: 120px; margin: -60px; animation: starpop 1.5s cubic-bezier(.2,1.3,.4,1) forwards; filter: drop-shadow(0 0 18px rgba(232,185,106,.9)); }
@keyframes starpop { 0% { transform: scale(0) rotate(-40deg); opacity: 0; } 30% { transform: scale(1.1) rotate(8deg); opacity: 1; } 70% { transform: scale(1) rotate(0); opacity: 1; } 100% { transform: translateY(-80px) scale(.4); opacity: 0; } }
@media (orientation: landscape) and (max-height: 560px) {
  #menu .head { position: absolute; left: 3vw; top: 50%; transform: translateY(-50%); width: 30vw; margin: 0; }
  #menu h1 { font-size: clamp(20px, 3.6vw, 34px); letter-spacing: .2em; text-indent: .2em; }
  #menu .tag { font-size: 11px; }
  #menu .foot { left: auto; right: 3vw; width: 30vw; bottom: 50%; transform: translateY(50%); padding: 0; }
  #menu .foot .btn { height: 46px; font-size: 15px; }
}

/* telescope view: round eyepiece mask */
body[data-mask="scope"] #vignette { background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0) 0, rgba(0,0,0,0) calc(min(46vw, 34vh) - 2px), #05060f calc(min(46vw, 34vh)), #05060f 100%); }
