@font-face { font-family: 'Fredoka'; src: url('assets/fonts/fredoka-latin.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }
:root {
  --ink: #4a3550; --ink2: #6d5874; --paper: #fffaf3; --pink: #ff6f91; --pink2: #ff9fc7; --blue: #2f9be8; --gold: #f2a81d;
  --mint: #3fcf8e; --mint-d: #23a56c; --lilac: #9f8cff; --shadow: 0 6px 0 rgba(74, 53, 80, 0.22);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7fd0ff; color: var(--ink); font-family: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif; overscroll-behavior: none; }
body { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid #ffffff; outline-offset: 3px; }
.ic { width: 1.25em; height: 1.25em; flex: none; }
.ic.big { width: 1.8em; height: 1.8em; }

/* HUD */
#hud { position: fixed; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
.chip { background: rgba(255, 255, 255, 0.92); border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 20px; box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
#hud-level { margin-right: auto; }
.icon-btn { width: 52px; height: 52px; border-radius: 50%; background: #ffffff; color: var(--ink); display: grid; place-items: center; box-shadow: var(--shadow); font-size: 22px; flex: none; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(74, 53, 80, 0.22); }

/* Screens */
.screen { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; padding: calc(14px + var(--safe-t)) 16px calc(18px + var(--safe-b)); }
.screen.dim { background: rgba(74, 53, 80, 0.38); justify-content: center; backdrop-filter: blur(2px); }
#menu { justify-content: space-between; }
.menu-top { width: 100%; display: flex; justify-content: flex-end; }
.logo { margin: 0 0 auto; position: relative; isolation: isolate; display: flex; flex-direction: column; align-items: center; line-height: 0.92; font-weight: 700; letter-spacing: 1px; text-align: center; }
.logo span { display: block; color: #ffffff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 rgba(74, 53, 80, 0.3); animation: bob 2.2s ease-in-out infinite; }
.logo .l1 { font-size: clamp(54px, 15vw, 92px); color: #ffd84d; }
.logo .l2 { font-size: clamp(60px, 17vw, 104px); color: var(--pink2); animation-delay: -1.1s; }
.logo::before { content: ''; position: absolute; inset: -14% -22%; z-index: -1; border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 252, 245, 0.95), rgba(255, 252, 245, 0.85) 62%, rgba(255, 252, 245, 0)); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.menu-bottom { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 420px; }
.big-btn { min-height: 72px; min-width: 220px; padding: 12px 30px; border-radius: 999px; font-size: 32px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 12px; color: #ffffff; background: linear-gradient(180deg, #ff8fb0, var(--pink)); box-shadow: 0 7px 0 #c9456b, 0 10px 18px rgba(74, 53, 80, 0.25); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); }
.big-btn.go { background: linear-gradient(180deg, #5fe3a6, var(--mint)); box-shadow: 0 7px 0 var(--mint-d), 0 10px 18px rgba(74, 53, 80, 0.25); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--mint-d); }
#play-btn { width: 100%; max-width: 340px; position: relative; }
#play-btn::after { content: ""; position: absolute; inset: -4px; border-radius: inherit; border: 4px solid rgba(255, 255, 255, 0.85); pointer-events: none; animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(0.96); opacity: 0.9; } 100% { transform: scale(1.12, 1.3); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #play-btn::after, .logo span, .stretch { animation: none; } }
.menu-row { display: flex; gap: 14px; justify-content: center; width: 100%; }
.round-btn { flex: 1; max-width: 120px; min-height: 76px; border-radius: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 17px; font-weight: 700; color: #ffffff; box-shadow: var(--shadow); }
.round-btn .ic { width: 30px; height: 30px; }
.round-btn.pink { background: linear-gradient(180deg, #ffa3c4, #ff7aa8); }
.round-btn.gold { background: linear-gradient(180deg, #ffd26b, #f5ad2a); }
.round-btn.blue { background: linear-gradient(180deg, #8fd0ff, #4fb0f2); }
.mid-btn { min-height: 56px; min-width: 120px; padding: 8px 22px; border-radius: 999px; background: #ffffff; color: var(--ink); font-size: 20px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: var(--shadow); }
.mid-btn.go { background: var(--mint); color: #ffffff; box-shadow: 0 5px 0 var(--mint-d); }
.mid-btn.wide { width: 100%; }
.mid-btn:active { transform: translateY(3px); }
.mid-btn:disabled, .buy-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.card { background: var(--paper); border-radius: 32px; padding: 26px 24px 24px; width: min(360px, 100%); display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; box-shadow: 0 10px 0 rgba(74, 53, 80, 0.2), 0 20px 40px rgba(74, 53, 80, 0.25); border: 4px solid #ffffff; }
.card.pop { animation: pop 0.42s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card h2 { margin: 0; font-size: 40px; }
.card p { margin: 0; font-size: 21px; line-height: 1.3; color: var(--ink2); }
.card .row { display: flex; gap: 12px; }
.cheer { color: var(--pink); }
.soft { color: var(--lilac); }
.sum { font-size: 24px !important; font-weight: 600; }
.reward { display: flex; align-items: center; gap: 10px; font-size: 54px; font-weight: 700; color: var(--gold); text-shadow: 0 3px 0 rgba(74, 53, 80, 0.15); }
.best { color: var(--pink) !important; font-weight: 700; }
.stretch { width: 120px; height: 90px; background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 90'%3E%3Cpath d='M30 52 8 18M90 52l22-34' stroke='%234a3550' stroke-width='9' stroke-linecap='round'/%3E%3Cpath d='M30 52 8 18M90 52l22-34' stroke='%23ff9fc7' stroke-width='5' stroke-linecap='round'/%3E%3Cellipse cx='60' cy='55' rx='30' ry='32' fill='%23ff9fc7' stroke='%234a3550' stroke-width='3.5'/%3E%3Cellipse cx='50' cy='50' rx='3.5' ry='5' fill='%232b1d33'/%3E%3Cellipse cx='70' cy='50' rx='3.5' ry='5' fill='%232b1d33'/%3E%3Cpath d='M52 62q8 7 16 0' stroke='%232b1d33' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); animation: bob 1.6s ease-in-out infinite; }

/* Panels */
.screen.panel { background: linear-gradient(180deg, #fff3f8, #f1f6ff); padding-left: 0; padding-right: 0; }
.panel-head { width: 100%; max-width: 520px; display: flex; align-items: center; gap: 12px; padding: 0 16px 10px; }
.panel-head h2 { margin: 0 auto 0 0; font-size: 34px; }
.panel-body { width: 100%; max-width: 520px; flex: 1; overflow-y: auto; padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 12px; touch-action: pan-y; }
.section-title { margin: 10px 4px 0; font-size: 22px; color: var(--ink2); }
.shop-item { background: #ffffff; border-radius: 22px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 4px 0 rgba(74, 53, 80, 0.12); }
.shop-item .thumb { width: 60px; height: 60px; flex: none; border-radius: 16px; background: #f7f0ff; display: grid; place-items: center; overflow: hidden; }
.shop-item .thumb canvas, .shop-item .thumb img { width: 56px; height: 56px; }
.shop-item .info { flex: 1; min-width: 0; }
.shop-item .name { font-size: 20px; font-weight: 700; }
.shop-item .desc { font-size: 16px; color: var(--ink2); }
.buy-btn { min-height: 52px; min-width: 104px; padding: 6px 14px; border-radius: 999px; background: linear-gradient(180deg, #ffd26b, #f5ad2a); color: #ffffff; font-size: 20px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 4px 0 #c98612; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); }
.buy-btn.wear { background: linear-gradient(180deg, #a99bff, var(--lilac)); box-shadow: 0 4px 0 #7563d9; }
.buy-btn.on { background: linear-gradient(180deg, #5fe3a6, var(--mint)); box-shadow: 0 4px 0 var(--mint-d); }
.buy-btn:active { transform: translateY(3px); }
.toggle { width: 100%; min-height: 64px; background: #ffffff; border-radius: 22px; display: flex; align-items: center; gap: 14px; padding: 8px 18px; font-size: 22px; font-weight: 700; box-shadow: 0 4px 0 rgba(74, 53, 80, 0.12); text-align: left; }
.toggle span { flex: 1; }
.toggle .ic { width: 30px; height: 30px; color: var(--lilac); }
.knob { width: 62px; height: 36px; border-radius: 999px; background: #e3dbe9; position: relative; transition: background 0.2s; flex: none; }
.knob::after { content: ''; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #ffffff; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.toggle[aria-checked='true'] .knob { background: var(--mint); }
.toggle[aria-checked='true'] .knob::after { transform: translateX(26px); }
.hint, .version { margin: 0 6px; color: var(--ink2); font-size: 17px; }
.version { opacity: 0.6; font-size: 14px; }
.tabs { display: flex; gap: 8px; }
.tab { flex: 1; min-height: 56px; border-radius: 18px; background: #ffffff; font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 4px 0 rgba(74, 53, 80, 0.12); }
.tab[aria-selected='true'] { background: var(--pink); color: #ffffff; }
.local { background: #fff6d6; border-radius: 18px; padding: 12px 16px; font-size: 19px; font-weight: 600; text-align: center; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.board li { background: #ffffff; border-radius: 16px; padding: 10px 14px; display: flex; gap: 10px; font-size: 19px; align-items: center; }
.board li.me { background: #e6fff2; }
.board .rank { width: 36px; font-weight: 700; color: var(--pink); }
.board .who { flex: 1; }
.board .val { font-weight: 700; }
.board .empty { justify-content: center; color: var(--ink2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chips button { min-height: 50px; min-width: 64px; padding: 6px 14px; border-radius: 999px; background: #ffffff; font-size: 19px; font-weight: 600; box-shadow: 0 3px 0 rgba(74, 53, 80, 0.12); }
.chips button[aria-pressed='true'] { background: var(--blue); color: #ffffff; }
.name-preview { margin: 4px 0; text-align: center; font-size: 34px; font-weight: 700; color: var(--pink); }

#update-banner { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); background: #ffffff; border-radius: 999px; padding: 6px 6px 6px 18px; display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 700; box-shadow: var(--shadow); white-space: nowrap; }

@media (min-width: 700px) and (min-height: 600px) {
  .card { width: 400px; }
}
@media (max-height: 620px) {
  .logo { margin-top: 1vh; }
  .logo .l1 { font-size: 48px; } .logo .l2 { font-size: 56px; }
  .big-btn { min-height: 62px; font-size: 28px; }
}

/* Win celebration: warm glow, turning sun rays behind the coins, falling paper confetti. */
#win.dim { background: radial-gradient(circle at 50% 42%, rgba(255, 240, 180, 0.45), rgba(255, 150, 190, 0.38)); backdrop-filter: blur(1.5px); overflow: hidden; }
.reward { position: relative; isolation: isolate; }
.reward::before { pointer-events: none; content: ""; position: absolute; left: 50%; top: 50%; width: 280px; height: 280px; margin: -140px 0 0 -140px; border-radius: 50%; z-index: -1;
  background: repeating-conic-gradient(rgba(255, 210, 70, 0.32) 0 10deg, transparent 10deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 25%, transparent 68%); mask: radial-gradient(circle, #000 25%, transparent 68%); animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.confetti { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; pointer-events: none; z-index: 0; animation: fall 3s cubic-bezier(.3, .1, .6, 1) both; }
#win .card { position: relative; z-index: 1; }
@keyframes fall { from { transform: translate(0, 0) rotate(0); opacity: 1; } 85% { opacity: 1; } to { transform: translate(var(--dx), 110vh) rotate(var(--r)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .reward::before { animation: none; } }
#win .card { margin-top: 34px; }
.win-buddies { display: flex; justify-content: center; gap: 2px; margin: -74px 0 -6px; height: 70px; pointer-events: none; }
.win-buddies canvas { width: 54px; height: 70px; animation: cheer 0.7s ease-in-out infinite alternate; }
.win-buddies canvas:nth-child(odd) { margin-top: 6px; }
@keyframes cheer { from { transform: translateY(0) scale(1, 1); } to { transform: translateY(-10px) scale(0.96, 1.05); } }
@media (prefers-reduced-motion: reduce) { .win-buddies canvas { animation: none; } }
#win .big-btn, #win .small-btn, #win button { position: relative; z-index: 1; }

/* Notches on the sides (landscape phones) and short screens: cards scroll instead of pushing buttons off-screen. */
:root { --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); }
#hud { left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); }
.screen { padding-left: calc(16px + var(--safe-l)); padding-right: calc(16px + var(--safe-r)); }
.screen.dim { overflow-y: auto; justify-content: safe center; }
.card { max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b)); overflow-y: auto; flex-shrink: 0; }
#win .card { overflow: visible; max-height: none; }
#update-banner { max-width: calc(100vw - 24px); }
@media (max-height: 700px) {
  .card { gap: 10px; padding: 18px 20px; }
  .card h2 { font-size: 32px; }
  .card p { font-size: 18px; }
  .reward { font-size: 40px; }
  .win-buddies { margin-top: -64px; height: 58px; }
  .win-buddies canvas { width: 44px; height: 58px; }
}
@media (max-height: 480px) {
  .win-buddies { display: none; }
  #win .card { margin-top: 0; }
  .card { gap: 8px; padding: 14px 18px; }
  .card h2 { font-size: 28px; }
  .big-btn { min-height: 56px; font-size: 24px; }
  .logo .l1 { font-size: 36px; } .logo .l2 { font-size: 42px; }
  .round-btn { min-height: 60px; }
  .menu-bottom { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) { .card.pop { animation: none; } .confetti { display: none; } }

#sync-notice { position: fixed; z-index: 29; top: calc(10px + var(--safe-t)); left: 5%; width: 90%; padding: 12px; border-radius: 16px; background: white; color: #4a3550; text-align: center; box-shadow: var(--shadow); }
#scores-local { white-space: pre-line; }

/* Notices occupy layout space; they cannot sit over menu or result actions. */
body:has(#update-banner:not([hidden])) .screen { padding-bottom: calc(100px + var(--safe-b)); }
#sync-notice { max-height: 32dvh; overflow-y: auto; touch-action: pan-y; font-size: 16px; }
#sync-notice button { margin: 8px 4px 0; }
body:has(#sync-notice:not([hidden])) .screen { padding-top: calc(240px + var(--safe-t)); overflow-y: auto; }
body:has(#sync-notice:not([hidden])) #hud { top: 240px; }
