:root { --pink: #FF7EB6; --mint: #7EE0C3; --butter: #FFD86B; --sky: #7CC4FF; --cream: #FFF6E9; --ink: #2B2140; --night: #1b1430; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--cream); overscroll-behavior: none;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif, "Noto Color Emoji"; user-select: none; -webkit-user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
body:not(.touch) .touch-only { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
a { color: var(--sky); }

#top { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; pointer-events: none; }
#top > * { pointer-events: auto; }
#goal { flex: 1; min-width: 0; background: rgba(43, 33, 64, .82); border-radius: 14px; padding: 7px 12px 9px; }
#goal .row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 8px; font-size: 14px; }
#goal .row b { white-space: nowrap; }
#goal b { font-weight: 800; }
#scoreText { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--butter); white-space: nowrap; }
#bar { height: 8px; border-radius: 4px; background: rgba(255, 246, 233, .16); margin-top: 5px; overflow: hidden; }
#barFill { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--pink); transition: width .35s cubic-bezier(.2, 1.4, .4, 1), background .2s; }
#barFill.met { background: var(--mint); }
#grabs { background: var(--butter); color: var(--ink); border-radius: 14px; padding: 4px 10px; text-align: center; line-height: 1; min-width: 52px; }
#grabs b { display: block; font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
#grabs span { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
#grabs.low { background: var(--pink); }
#grabs.bump { animation: bump .3s; }
.icons { display: flex; gap: 6px; }
.icon { position: relative; width: 44px; height: 44px; border-radius: 14px; background: rgba(43, 33, 64, .82); font-size: 19px; display: grid; place-items: center; }
.icon small { position: absolute; right: -3px; bottom: -4px; background: var(--mint); color: var(--ink); border-radius: 8px; padding: 1px 4px; font-size: 9px; font-weight: 800; }
@keyframes bump { 40% { transform: scale(1.22); } }

#bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#shelf { display: flex; gap: 6px; padding: 6px 8px 9px; background: linear-gradient(#3a2d57, #2b2140); border-radius: 16px; border-bottom: 5px solid #c9a36a; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); }
.slot { position: relative; width: 58px; height: 58px; border-radius: 12px; background: rgba(255, 246, 233, .07); display: grid; place-items: center; padding: 0; }
.slot.empty::after { content: ""; width: 20px; height: 20px; border-radius: 50%; border: 2px dashed rgba(255, 246, 233, .22); }
.slot img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.slot.rare { background: rgba(255, 216, 107, .22); }
.slot.sel { outline: 3px solid var(--butter); }
.slot.fire { animation: bump .32s; background: rgba(126, 224, 195, .35); }
.slot.in { animation: slotIn .45s cubic-bezier(.2, 1.6, .4, 1); }
.slot i { position: absolute; left: 4px; right: 4px; bottom: 2px; height: 4px; border-radius: 2px; }
.slot .setmark { position: absolute; top: -5px; right: -4px; background: var(--mint); color: var(--ink); font-size: 9px; font-weight: 900; border-radius: 7px; padding: 1px 4px; }
@keyframes slotIn { from { transform: translateY(-30px) scale(.4); opacity: 0; } }
#tip { max-width: 330px; background: var(--cream); color: var(--ink); border-radius: 14px; padding: 8px 12px; font-size: 13px; line-height: 1.3; text-align: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }
#tip b { display: block; font-size: 14px; }
#tip em { font-style: normal; opacity: .65; font-size: 12px; }
#actions { display: flex; gap: 8px; width: min(330px, 92vw); }
#look { flex: 0 0 68px; height: 62px; border-radius: 20px; background: rgba(43, 33, 64, .9); border: 2px solid rgba(255, 246, 233, .28); font-size: 14px; font-weight: 900; letter-spacing: .06em; line-height: 1.1; touch-action: none; }
#look small { display: block; font-size: 10px; font-weight: 700; opacity: .6; letter-spacing: .04em; }
#look:active { background: var(--sky); color: var(--ink); }
#drop { flex: 1; min-width: 0; height: 62px; border-radius: 20px; background: var(--pink); color: var(--ink); font-size: 24px; font-weight: 900; letter-spacing: .12em; box-shadow: 0 6px 0 #c9508a, 0 10px 20px rgba(0, 0, 0, .35); }
#drop:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9508a; }
#drop:disabled { filter: saturate(.3) brightness(.7); }

#hint { position: fixed; left: 50%; top: calc(74px + env(safe-area-inset-top)); transform: translateX(-50%); background: rgba(43, 33, 64, .85); border-radius: 12px; padding: 7px 14px; font-size: 14px; font-weight: 600; text-align: center; pointer-events: none; max-width: 92vw; }
#mark { display: block; font-size: 11px; line-height: 1.7; opacity: .8; }
#hint small { display: block; font-size: 12px; font-weight: 600; opacity: .7; }
#toast { position: fixed; left: 50%; top: 34%; transform: translate(-50%, -50%); font-size: 30px; font-weight: 900; text-align: center; text-shadow: 0 3px 0 var(--ink), 0 0 24px rgba(0, 0, 0, .6); pointer-events: none; animation: toast 1.5s forwards; white-space: nowrap; }
#toast small { display: block; font-size: 15px; font-weight: 700; }
@keyframes toast { 0% { transform: translate(-50%, -30%) scale(.5); opacity: 0; } 12% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 20% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#pops { position: fixed; inset: 0; pointer-events: none; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 34px; color: var(--butter); text-shadow: 0 3px 0 var(--ink); animation: pop 1.6s forwards; white-space: nowrap; text-align: center; }
.pop small { display: block; font-size: 13px; color: var(--cream); font-weight: 700; }
@keyframes pop { 0% { transform: translate(-50%, -20%) scale(.4); opacity: 0; } 12% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 75% { opacity: 1; } 100% { transform: translate(-50%, -130%) scale(1); opacity: 0; } }
#next { position: fixed; right: 10px; top: calc(70px + env(safe-area-inset-top)); animation: bump .4s; }

.pill { min-height: 46px; padding: 0 20px; border-radius: 23px; background: rgba(255, 246, 233, .14); font-weight: 800; font-size: 16px; }
.pill.primary { background: var(--butter); color: var(--ink); box-shadow: 0 4px 0 #c79a2c; }
.pill.small { min-height: 44px; font-size: 13px; padding: 0 14px; font-weight: 700; }
.pill:disabled { opacity: .4; }
.pill.door { border: 1.5px dashed rgba(255, 246, 233, .4); background: none; }

#card { position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(360px, 92vw); background: var(--cream); color: var(--ink); border-radius: 22px; padding: 14px 18px 12px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: cardIn .35s cubic-bezier(.2, 1.5, .4, 1); pointer-events: none; }
@keyframes cardIn { from { transform: translate(-50%, 60px) scale(.8); opacity: 0; } }
#card h2 { margin: 6px 0 4px; font-size: 26px; font-weight: 900; }
#card p { margin: 0; }
#cardRule { font-size: 17px; font-weight: 800; }
#cardBio { font-size: 13px; opacity: .65; margin-top: 4px !important; font-style: italic; }
.badges { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.badges span { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; border-radius: 9px; padding: 3px 8px; background: var(--ink); color: var(--cream); }
.badges .rare { background: var(--butter); color: var(--ink); }
.badges .new { background: var(--mint); color: var(--ink); }
.badges .double { background: var(--pink); color: var(--ink); }
#card .go { margin-top: 8px; font-size: 12px; opacity: .55; font-weight: 700; }

.sheet { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(430px, 94vw); max-height: 92vh; overflow-y: auto; background: #2b2140f2; border: 2px solid rgba(255, 246, 233, .14); border-radius: 26px; padding: 20px 18px 18px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); z-index: 5; }
.sheet h2 { margin: 2px 0 6px; font-size: 28px; font-weight: 900; color: var(--butter); }
.sheet p { margin: 6px 0; font-size: 15px; line-height: 1.35; }
.kicker { text-transform: uppercase; letter-spacing: .1em; font-size: 12px !important; font-weight: 800; color: var(--mint); }
.buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 14px 0 6px; }
#how { text-align: left; font-size: 13px; background: rgba(255, 246, 233, .07); border-radius: 14px; padding: 8px 12px; margin-top: 10px; line-height: 1.5; }
#how b { color: var(--butter); }
#menuShelf, #swapRow { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
#swapRow .slot { width: 60px; height: 60px; }
#swapRow .slot.newcomer { box-shadow: 0 0 0 2px var(--mint); }
#swapInfo { min-height: 3.4em; font-size: 13px !important; }
#more { margin-top: 12px; }
#ask { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(255, 246, 233, .14); }
#voteRow { display: flex; gap: 6px; overflow-x: auto; margin: 0 -18px 8px; padding: 0 18px; scrollbar-width: none; }
#voteRow::-webkit-scrollbar { display: none; }
#voteRow .pill { flex: none; }
.more { font-size: 12px !important; opacity: .85; margin-top: 12px !important; }
#bookGrid { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 12px 0; text-align: left; }
.series { background: rgba(255, 246, 233, .07); border-radius: 14px; padding: 8px 10px; }
.series h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; }
.series .figs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fig { text-align: center; font-size: 11px; line-height: 1.25; }
.fig img { width: 64px; height: 64px; object-fit: contain; display: block; margin: 0 auto; }
.fig.unfound img { filter: brightness(0) invert(.25); opacity: .7; }
.fig b { display: block; font-size: 12px; }
.fig span { opacity: .7; }

#loading { position: fixed; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; background: var(--night); z-index: 9; font-weight: 700; }
#loading i { width: 46px; height: 46px; margin: 0 auto; border-radius: 50%; background: linear-gradient(var(--cream) 50%, var(--pink) 50%); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* desktop: the shelf and the HUD move into the margins */
@media (min-width: 900px) and (min-height: 560px) {
  #top { padding: 16px 20px; gap: 12px; }
  #goal { flex: 0 0 320px; }
  #top .icons { margin-left: auto; }
  #bottom { left: auto; right: 20px; bottom: 50%; transform: translateY(50%); padding: 0; flex-direction: row; align-items: center; }
  #shelf { flex-direction: column; border-bottom: 0; border-right: 5px solid #c9a36a; padding: 8px 9px 8px 8px; }
  .slot { width: 70px; height: 70px; }
  #tip { max-width: 240px; }
  #hint { top: 84px; }
  #menu { width: 600px; }
  #next { top: 84px; right: 20px; }
}
@media (max-height: 520px) { .slot { width: 46px; height: 46px; } #drop, #look { height: 48px; } }
