/* finesse · existing Halloween palette · rounded forms · edge HUD · Canvas 2D · playful merge game; scoped layout update, existing art retained */
:root { --ui-gap: clamp(8px, 2.5vw, 16px);
  --edge-top: calc(var(--ui-gap) + env(safe-area-inset-top));
  --edge-right: calc(var(--ui-gap) + env(safe-area-inset-right));
  --edge-bottom: calc(var(--ui-gap) + env(safe-area-inset-bottom));
  --edge-left: calc(var(--ui-gap) + env(safe-area-inset-left)); }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; overflow-x: clip; background: #120a26; touch-action: none;
  font-family: "Baloo 2", "Fredoka", "Arial Rounded MT Bold", -apple-system, "PingFang SC", sans-serif; color: #fff;
  -webkit-user-select: none; user-select: none; }
#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#game { position: absolute; display: block; touch-action: none; }
html, body { overscroll-behavior: none; -webkit-touch-callout: none; height: 100dvh; }
#saProbe { position: fixed; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { touch-action: manipulation; min-width: 44px; min-height: 44px; white-space: nowrap; }
button:focus-visible { outline: 3px solid #ffd27a; outline-offset: 4px; }
@media (hover: hover) { .pill:hover { background: rgba(255,255,255,.18); } .big-btn:hover { filter: brightness(1.08); } }
.pill:active { transform: scale(.95); }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; color: inherit; }

/* Secondary controls follow viewport safe edges, leaving the cauldron and drop lane clear. */
#hud { position: fixed; top: var(--edge-top); left: var(--edge-left); right: var(--edge-right);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; z-index: 2; }
.hud-left, .hud-right { display: flex; gap: 8px; align-items: flex-start; min-width: 0; }
.hud-right .icon-btn { pointer-events: auto; flex-shrink: 0; }
.score-box, .best-box, .next-box { background: rgba(30, 14, 60, .72); border: 2px solid rgba(255, 180, 90, .55); border-radius: 14px;
  padding: 4px 10px; display: flex; flex-direction: column; align-items: center; min-width: 64px; backdrop-filter: blur(4px); }
.lbl { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #ffc77a; font-weight: 700; }
#score { font-size: 26px; font-weight: 800; line-height: 1.1; text-shadow: 0 2px 0 #6b2fd6; font-variant-numeric: tabular-nums; }
#best { font-size: 18px; font-weight: 800; line-height: 1.3; color: #e6d6ff; font-variant-numeric: tabular-nums; }
.next-box { padding: 4px 6px; }
#nextCv { width: 44px; height: 44px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; background: rgba(30, 14, 60, .72); border: 2px solid rgba(255, 180, 90, .55); font-size: 14px; }
.score-pop { animation: pop .25s ease-out; }
@keyframes pop { 50% { transform: scale(1.25); } }

#btnBoo { position: fixed; left: var(--edge-left); bottom: var(--edge-bottom); z-index: 2;
  display: flex; align-items: center; gap: 4px; padding: 6px 12px 6px 8px; border-radius: 22px;
  background: linear-gradient(#a56bff, #6b2fd6); border: 3px solid #fff; box-shadow: 0 4px 0 #3b1580, 0 0 18px rgba(165,107,255,.7); font-weight: 800; font-size: 15px; }
#btnBoo.armed { background: linear-gradient(#ffb347, #ff6a00); box-shadow: 0 4px 0 #8a3a00, 0 0 24px rgba(255,150,40,.9); animation: wob .6s infinite; }
#btnBoo.empty { filter: grayscale(1) brightness(.7); }
#booCount { background: #fff; color: #6b2fd6; border-radius: 10px; padding: 0 6px; font-size: 13px; }
.boo-face { font-size: 20px; }
@keyframes wob { 50% { transform: rotate(-6deg) scale(1.06); } }
#booHint { position: fixed; left: var(--edge-left); bottom: calc(var(--edge-bottom) + 60px); max-width: calc(100vw - var(--edge-left) - var(--edge-right));
  z-index: 2; background: rgba(255,120,0,.94); padding: 6px 12px; border-radius: 14px; font-weight: 700; font-size: 14px; pointer-events: none; }

#guide { position: fixed; right: var(--edge-right); bottom: var(--edge-bottom); z-index: 2; pointer-events: none; text-align: right;
  max-width: min(340px, calc(100vw - var(--edge-left) - var(--edge-right) - 130px)); }
#guide .guide-txt { color: #e6d6ff; font-weight: 700; font-size: 13px; text-shadow: 0 2px 2px #120a26, 0 0 8px #120a26; line-height: 1.5; }

#toast { position: absolute; left: 50%; top: 30%; z-index: 2; transform: translate(-50%, -50%); pointer-events: none; font-weight: 900; font-size: 30px;
  text-shadow: 0 3px 0 #6b2fd6, 0 0 16px rgba(0,0,0,.8); opacity: 0; white-space: nowrap; }
#toast.show { animation: toast 1.4s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -80%) scale(1); } }

.screen { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; }
#title { background: radial-gradient(ellipse at 50% 30%, rgba(60,20,110,.35), rgba(10,4,24,.82)); }
.title-wrap { text-align: center; padding: 70px 20px 84px; max-width: 520px; width: 100%; min-width: 0; }
.eyebrow { display: inline-block; background: rgba(255,140,26,.18); border: 1.5px solid #ff8c1a; color: #ffc77a; padding: 4px 14px; border-radius: 20px; font-weight: 700; font-size: 14px; }
#title > .eyebrow { position: absolute; top: var(--edge-top); left: 50%; transform: translateX(-50%); max-width: calc(100% - var(--edge-left) - var(--edge-right)); white-space: nowrap; }
.logo { margin: 0 0 10px; font-size: clamp(56px, 17vw, 96px); line-height: 1; font-weight: 900; letter-spacing: .02em; overflow-wrap: anywhere; min-width: 0; }
.logo span { display: block; background: linear-gradient(#ffd27a, #ff7a00); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 5px 0 #4a1a96) drop-shadow(0 0 18px rgba(255,122,0,.45)); }
.logo span + span { background: linear-gradient(#e2c9ff, #9a5cff); -webkit-background-clip: text; background-clip: text; }
.tag { color: #e6d6ff; font-size: 16px; line-height: 1.45; margin-bottom: 12px; }
#chainCv { width: 100%; max-width: 460px; min-width: 0; height: auto; margin: 4px 0 14px; }
.big-btn { display: inline-block; min-width: 200px; padding: 14px 34px; font-size: 26px; font-weight: 900; border-radius: 40px;
  background: linear-gradient(#ffb347, #ff6a00); border: 3px solid #fff3d6; box-shadow: 0 6px 0 #8a3a00, 0 10px 24px rgba(255,106,0,.45); text-shadow: 0 2px 0 #8a3a00; transition: transform .1s; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a3a00; }
.big-btn.small { min-width: 0; padding: 10px 24px; font-size: 20px; }
#btnPlay { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); } }
.title-row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.pill { padding: 8px 16px; border-radius: 20px; background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.3); font-weight: 700; font-size: 15px; }
.pill.off { opacity: .45; text-decoration: line-through; }
#title > .title-tools { position: absolute; left: var(--edge-left); right: var(--edge-right); bottom: var(--edge-bottom); margin: 0; gap: 8px; flex-wrap: nowrap; }
.version { position: absolute; right: var(--edge-right); bottom: calc(var(--edge-bottom) + 56px); font-size: 11px; color: #bdabd7; letter-spacing: .06em; }

.modal { background: rgba(10,4,24,.72); backdrop-filter: blur(3px); }
.card { background: linear-gradient(#3a1d6e, #22104a); border: 3px solid #ff9f40; border-radius: 26px; padding: 22px 20px; text-align: center; width: min(92vw, 380px);
  box-shadow: 0 12px 40px rgba(0,0,0,.6); animation: cardIn .35s cubic-bezier(.2,1.4,.4,1); max-height: calc(100dvh - var(--edge-top) - var(--edge-bottom)); overflow: auto; touch-action: pan-y; }
@keyframes cardIn { from { transform: scale(.7); opacity: 0; } }
.card h2 { font-size: 26px; margin-bottom: 12px; color: #ffd27a; text-shadow: 0 3px 0 #4a1a96; overflow-wrap: anywhere; min-width: 0; }
.over-card { padding: 16px; }
#shareImg { aspect-ratio: 1080 / 1350; background: rgba(255,255,255,.06); width: 100%; max-width: 260px; border-radius: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.5); display: block; margin: 0 auto; }
.over-card .big-btn { margin-top: 14px; }
.new-best { display: inline-block; background: #ff3d7f; padding: 2px 14px; border-radius: 12px; font-weight: 900; margin-bottom: 8px; animation: wob .8s infinite; }
@media (max-height: 640px) { .over-card h2 { font-size: 20px; margin-bottom: 6px; } #shareImg { max-width: 190px; } .logo { font-size: 52px; } .tag { font-size: 14px; } }

@media (max-width: 360px) {
  .score-box, .best-box { min-width: 56px; padding-inline: 7px; }
  .hud-left, .hud-right { gap: 6px; }
  #score { font-size: 24px; }
  #title > .title-tools .pill { padding-inline: 12px; }
  #guide .guide-txt { font-size: 12px; }
}

/* Compact landscape keeps the game art central and utilities at the viewport edges. */
@media (orientation: landscape) and (max-height: 500px) {
  .title-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center;
    gap: 12px 28px; max-width: 660px; padding: 48px 20px 64px; }
  .logo, .tag { grid-column: 1; }
  .logo { grid-row: 1; font-size: 54px; margin: 0; }
  .tag { grid-row: 2; font-size: 13px; margin: 0; }
  #chainCv { grid-column: 2; grid-row: 1; margin: 0; align-self: end; }
  #btnPlay { grid-column: 2; grid-row: 2; justify-self: center; align-self: start; }
  .big-btn { padding: 10px 26px; font-size: 22px; }
  #title > .eyebrow { font-size: 12px; padding-block: 3px; }
  .card { padding-block: 16px; }
  #shareImg { max-width: 132px; }
  .over-card .big-btn { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  #btnPlay, #btnBoo.armed, .new-best, .score-pop, .card { animation: none; }
  button { transition: none !important; }
  #toast.show { animation: toastReduced 1.4s linear; }
}
@keyframes toastReduced { 0%, 100% { opacity: 0; } 10%, 85% { opacity: 1; } }
