/* Keepy Uppy. A party in a living room: sky blue, balloon colors, and fat rounded
   lettering like the printing on a balloon. */
:root {
  --sky: #2a8cf0;
  --sky-deep: #1652b8;
  --cream: #fffaf0;
  --cream-edge: #f0e4cc;
  --ink: #1b2240;
  --ink-soft: #56607d;
  --coral: #ff4d6d;
  --coral-deep: #d6234a;
  --sun: #ffc93a;
  --display: 'Baloo 2', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --ui: 'Fredoka', system-ui, sans-serif;
  --lift: 0 2px 0 rgba(27, 34, 64, 0.1), 0 8px 22px rgba(10, 16, 40, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e1a3a; color: var(--ink); font-family: var(--ui); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font-family: var(--ui); color: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
body.picking #stage { cursor: crosshair; }
/* The camera video plays off to the side: the stage draws it. Kept rendered, since some
   phones stop updating a video that isn't. */
.cam { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

/* ---- Logo: fat white letters with a coral edge, like printing on a balloon ---- */
.logo { display: block; overflow: visible; filter: drop-shadow(0 5px 10px rgba(10, 16, 40, 0.35)); }
.logo text {
  font-family: var(--display); font-weight: 800; font-size: 66px; fill: #fff;
  stroke: var(--coral); stroke-width: 12px; stroke-linejoin: round; paint-order: stroke fill; letter-spacing: -1px;
}

/* ---- Start screen ---- */
.start {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; overflow: auto;
  background:
    radial-gradient(ellipse 70% 50% at 30% 15%, rgba(255, 255, 255, 0.22), transparent 70%),
    linear-gradient(170deg, #4fb2ff 0%, var(--sky) 50%, var(--sky-deep) 100%);
  transition: opacity 0.6s ease;
}
.start.hide { opacity: 0; pointer-events: none; }
.sky { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.sky i {
  position: absolute; bottom: -160px; width: clamp(70px, 11vmin, 130px); aspect-ratio: 0.82; border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  background: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.75) 0 7%, transparent 24%), radial-gradient(circle at 40% 38%, var(--c) 0 45%, var(--d) 100%);
  animation: rise var(--t) linear infinite; animation-delay: var(--w);
}
.sky i:nth-child(1) { left: 8%; --c: #ff4d8d; --d: #c4175a; --t: 14s; --w: -2s; }
.sky i:nth-child(2) { left: 26%; --c: #ffc93a; --d: #d18e00; --t: 17s; --w: -9s; }
.sky i:nth-child(3) { left: 70%; --c: #35d07f; --d: #139653; --t: 15s; --w: -5s; }
.sky i:nth-child(4) { left: 86%; --c: #a45cff; --d: #6d23d1; --t: 19s; --w: -13s; }
.sky i:nth-child(5) { left: 50%; --c: #ff8a2b; --d: #cf5600; --t: 21s; --w: -16s; }
@keyframes rise {
  from { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-65vh) translateX(20px) rotate(5deg); }
  to { transform: translateY(-130vh) rotate(-4deg); }
}
.card {
  position: relative; width: min(100%, 520px); padding: 22px 30px 26px; text-align: center;
  background: var(--cream); border-radius: 30px; box-shadow: 0 0 0 6px #fff, 0 24px 60px rgba(8, 14, 40, 0.45);
  margin: 44px 0 16px;
}
.card .logo.big { width: min(90%, 330px); margin: -70px auto 2px; transform: rotate(-4deg); }
.title { font-family: var(--display); font-weight: 800; font-size: clamp(25px, 5vw, 32px); line-height: 1.05; margin: 0 0 16px; color: var(--ink); text-wrap: balance; }
.steps { list-style: none; counter-reset: step; margin: 0 auto 22px; padding: 0; max-width: 420px; text-align: left; display: grid; gap: 9px; }
.steps li { counter-increment: step; position: relative; padding-left: 40px; font-size: 16.5px; line-height: 1.35; color: var(--ink-soft); }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -2px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 15px; color: #fff; background: var(--coral);
  box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(10, 16, 40, 0.2);
}
.steps b { color: var(--ink); font-weight: 600; }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.primary, .ghost { font-size: 17px; font-weight: 600; border-radius: 999px; padding: 13px 24px; cursor: pointer; border: 0; position: relative; }
.primary { background: var(--coral); color: #fff; box-shadow: 0 0 0 4px #fff, var(--lift); }
.primary:hover { background: var(--coral-deep); }
.primary.big { font-size: 22px; padding: 15px 38px; }
.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.ghost:hover { background: rgba(27, 34, 64, 0.06); }
.small { font-size: 14px; padding: 7px 14px; }
button:disabled { opacity: 0.55; cursor: wait; }
.status { min-height: 1.3em; margin: 14px 0 0; font-size: 15px; color: var(--ink); }
.status.error { color: var(--coral-deep); font-weight: 500; }
.fine { margin: 10px auto 0; max-width: 420px; font-size: 13px; line-height: 1.45; color: var(--ink-soft); }
.credit { margin: 8px 0 0; font-size: 13px; }
.card a { color: var(--ink); text-underline-offset: 2px; }

/* ---- Top bar: logo and score on the left, controls on the right ---- */
.top {
  position: fixed; z-index: 10; top: 0; left: 0; right: 0; display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "brand pickers tools";
  align-items: center; gap: 8px 10px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  opacity: 0; transition: opacity 0.5s 0.3s; pointer-events: none;
}
body.playing .top { opacity: 1; }
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 172px; transform: rotate(-3deg); }
.score {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 18px 4px; border-radius: 999px; background: #fff; box-shadow: var(--lift);
  font-weight: 600; color: var(--ink-soft); font-size: 15px; white-space: nowrap;
}
.score b { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1; color: var(--ink); min-width: 1ch; text-align: center; }
.score .best { font-size: 14px; }
.score.bump b { animation: bump 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.5); }
@keyframes bump { from { transform: scale(1.45); color: var(--coral); } to { transform: scale(1); } }
.score.reset b { animation: drop 0.6s ease-out; }
@keyframes drop { from { color: var(--coral); transform: translateY(-6px); } to { transform: none; } }
body.match .score { display: none; }

.brand { grid-area: brand; }
.pickers { grid-area: pickers; display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.tools { grid-area: tools; display: flex; align-items: center; gap: 8px; }
.seg { display: flex; padding: 4px; gap: 2px; border-radius: 999px; background: rgba(255, 255, 255, 0.92); box-shadow: var(--lift); }
.seg button {
  position: relative; border: 0; background: transparent; padding: 0 14px; height: 38px; border-radius: 999px; cursor: pointer;
  font-size: 15px; font-weight: 600; color: var(--ink-soft); white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--sky); color: #fff; box-shadow: 0 2px 6px rgba(22, 82, 184, 0.35); }
#level button[aria-checked="true"][data-level="medium"] { background: #ff8a2b; box-shadow: 0 2px 6px rgba(207, 86, 0, 0.35); }
#level button[aria-checked="true"][data-level="hard"] { background: var(--coral); box-shadow: 0 2px 6px rgba(214, 35, 74, 0.35); }
.tool {
  position: relative; display: flex; align-items: center; gap: 7px; height: 46px; padding: 0 16px 0 12px; border: 0; border-radius: 999px;
  background: #fff; color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer; box-shadow: var(--lift); transition: transform 0.15s;
}
.tool:hover { transform: translateY(-1px) rotate(-1.5deg); }
.tool:active { transform: scale(0.96); }
.tool:disabled { opacity: 0.5; cursor: default; transform: none; }
.tool svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool.add { background: var(--coral); color: #fff; }
.tool.add svg path:first-child { fill: rgba(255, 255, 255, 0.25); }
.tool.add.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(255, 77, 109, 0.3), var(--lift); } }
.count { font-style: normal; font-size: 13px; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; background: #fff; color: var(--coral-deep); padding: 0 5px; }
body.match #btn-balloon { display: none; }

/* A hand held on a button fills a ring around it until it presses. */
[data-hand]::after {
  content: ''; position: absolute; inset: -6px; border-radius: inherit; pointer-events: none; opacity: 0;
  background: conic-gradient(var(--sun) calc(var(--dwell, 0) * 360deg), transparent 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); mask-composite: exclude;
  padding: 4px;
}
[data-hand].dwelling::after { opacity: 1; }
[data-hand].hand-over { transform: scale(1.06); }

/* ---- Match cards ---- */
.panel-card {
  position: fixed; z-index: 12; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 64px); transform: translateX(-50%); width: min(calc(100% - 32px), 460px);
  padding: 20px 26px 22px; text-align: center; background: rgba(255, 250, 240, 0.96); border-radius: 28px;
  box-shadow: 0 0 0 5px #fff, 0 20px 50px rgba(8, 14, 40, 0.45); animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -12px) scale(0.92); } }
.panel-card h2 { font-family: var(--display); font-weight: 800; font-size: 36px; line-height: 1; margin: 2px 0 8px; color: var(--coral); }
.panel-card .lead { margin: 0 0 14px; color: var(--ink-soft); font-size: 16px; line-height: 1.35; text-wrap: balance; }
.players { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 40px; }
.players li {
  display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-radius: 999px; background: #fff; font-weight: 600;
  box-shadow: 0 2px 6px rgba(27, 34, 64, 0.12);
}
.players .dot { width: 24px; height: 24px; border-radius: 50%; background: var(--c); box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.15), inset 3px 3px 0 rgba(255, 255, 255, 0.35); }
.players .empty { color: var(--ink-soft); font-weight: 500; background: transparent; box-shadow: none; }
.ranked { flex-direction: column; align-items: stretch; max-width: 300px; margin: 6px auto 16px; }
.ranked li { justify-content: flex-start; font-size: 18px; }
.ranked li .hits { margin-left: auto; font-family: var(--display); font-weight: 800; font-size: 22px; }
.ranked li.first { box-shadow: 0 0 0 3px var(--sun), 0 2px 6px rgba(27, 34, 64, 0.12); }
.note { min-height: 1.2em; margin: 0 0 14px; font-size: 15px; color: var(--ink-soft); }
.small-print { margin: 12px 0 0; font-size: 13px; color: var(--ink-soft); }

/* ---- Countdown, banner, hint ---- */
.countdown {
  position: fixed; z-index: 25; left: 50%; top: 45%; transform: translate(-50%, -50%); font-family: var(--display); font-weight: 800;
  font-size: min(42vmin, 320px); line-height: 1; color: var(--coral); pointer-events: none;
  -webkit-text-stroke: 0; filter: drop-shadow(6px 0 0 #fff) drop-shadow(-6px 0 0 #fff) drop-shadow(0 6px 0 #fff) drop-shadow(0 -6px 0 #fff) drop-shadow(0 14px 24px rgba(0, 0, 0, 0.4));
}
.countdown.beat { animation: beat 0.95s ease-out both; }
@keyframes beat { from { transform: translate(-50%, -50%) scale(1.4); opacity: 0; } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1); } to { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } }
.banner {
  position: fixed; z-index: 14; left: 16px; right: 16px; top: 34%; margin: 0 auto; width: fit-content; max-width: calc(100% - 32px); text-align: center;
  font-family: var(--display); font-weight: 800; font-size: clamp(36px, 9vmin, 92px); line-height: 0.95; color: #fff; pointer-events: none;
  text-shadow: 3px 0 0 var(--coral), -3px 0 0 var(--coral), 0 3px 0 var(--coral), 0 -3px 0 var(--coral), 2px 2px 0 var(--coral), -2px 2px 0 var(--coral),
    2px -2px 0 var(--coral), -2px -2px 0 var(--coral), 0 6px 0 var(--coral-deep), 0 12px 26px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: scale(0.7);
}
.banner small { display: block; font-size: 0.45em; margin-top: 8px; color: var(--sun); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 8px 20px rgba(0, 0, 0, 0.3); }
.banner.show { animation: banner 2.2s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
@keyframes banner { 0% { opacity: 0; transform: scale(0.6); } 12% { opacity: 1; transform: scale(1.06); } 20% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
.hint {
  position: fixed; z-index: 12; left: 16px; right: 16px; bottom: 60px; width: fit-content; max-width: 560px; margin: 0 auto; padding: 11px 20px;
  border-radius: 18px; background: #fff; color: var(--ink); font-size: 17px; font-weight: 500; line-height: 1.3; text-align: center; text-wrap: balance;
  box-shadow: var(--lift); transform: translateY(16px); opacity: 0; transition: opacity 0.3s, transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2); pointer-events: none;
}
.hint.show { opacity: 1; transform: none; }

/* ---- Marking areas to ignore ---- */
.picker {
  position: fixed; z-index: 35; left: 16px; right: 16px; bottom: 20px; margin: 0 auto; width: fit-content; max-width: 520px;
  display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 20px; border-radius: 22px; background: #fff; box-shadow: var(--lift);
}
.picker p { margin: 0; font-size: 15px; line-height: 1.3; }

/* ---- Corner: settings, privacy and credit, dim so they don't pull kids' eyes ---- */
.corner {
  position: fixed; z-index: 10; left: max(14px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px; font-size: 12px; opacity: 0.55; transition: opacity 0.2s;
}
.corner:hover, .corner:focus-within { opacity: 1; }
.corner a { color: #fff; text-decoration: none; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }
.corner a:hover { text-decoration: underline; }
.gear { width: 40px; height: 40px; padding: 8px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.92); color: var(--ink); cursor: pointer; box-shadow: var(--lift); }
.gear svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
body:not(.playing) .corner { display: none; }

/* ---- Settings ---- */
.settings {
  position: fixed; z-index: 40; left: 14px; bottom: 64px; width: 330px; max-height: calc(100vh - 90px); max-height: calc(100dvh - 90px); overflow: auto;
  padding: 14px 16px 16px; border-radius: 20px; background: var(--cream); box-shadow: 0 0 0 4px #fff, 0 18px 40px rgba(6, 10, 30, 0.45);
  font-size: 14px; display: flex; flex-direction: column; gap: 10px;
}
.settings header { display: flex; justify-content: space-between; align-items: center; }
.settings h2 { font-family: var(--display); font-weight: 800; margin: 0; font-size: 26px; line-height: 1; color: var(--coral); }
.settings header button { border: 0; background: none; font-size: 28px; line-height: 1; padding: 0 4px; cursor: pointer; }
.settings .row { display: flex; gap: 8px; align-items: flex-start; line-height: 1.3; }
.settings .row input { margin-top: 2px; accent-color: var(--coral); }
.settings .col { display: flex; flex-direction: column; gap: 4px; }
.settings .col span { color: var(--coral-deep); font-weight: 600; }
.settings .buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.settings select, .settings input[type=range] { width: 100%; accent-color: var(--coral); }
.settings select { font-family: var(--ui); font-size: 14px; padding: 5px; border-radius: 10px; border: 1px solid var(--cream-edge); background: #fff; }
.readout { font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.5; white-space: pre-wrap; color: var(--ink-soft);
  background: #fff; border-radius: 10px; padding: 8px; min-height: 3em; }

/* ---- Narrower screens: the controls move under the logo ---- */
@media (max-width: 1040px) {
  .top { grid-template-columns: 1fr auto; grid-template-areas: "brand tools" "pickers pickers"; }
  .pickers { justify-content: center; }
  .panel-card { top: calc(max(10px, env(safe-area-inset-top)) + 118px); }
}
@media (max-width: 560px) {
  .brand .logo { width: 130px; }
  .score { padding: 4px 14px 2px; font-size: 13px; }
  .score b { font-size: 28px; }
  .pickers, .tools { gap: 6px; }
  .seg { padding: 3px; }
  .seg button { padding: 0 10px; height: 34px; font-size: 14px; }
  .tool { height: 42px; padding: 0 12px 0 10px; font-size: 14px; }
  .tool span { display: none; }
  .settings { left: 10px; right: 10px; width: auto; bottom: 62px; max-height: calc(100dvh - 200px); }
  .card { padding: 18px 18px 22px; }
  .panel-card { padding: 16px 18px 18px; }
  .panel-card h2 { font-size: 30px; }
  .corner a { display: none; }
}
/* A phone on its side: one slim row. */
@media (max-height: 500px) and (min-aspect-ratio: 3/2) {
  .top { grid-template-columns: auto 1fr auto; grid-template-areas: "brand pickers tools"; }
  .brand .logo { width: 118px; }
  .score b { font-size: 26px; }
  .seg button { height: 32px; padding: 0 9px; font-size: 13px; }
  .tool { height: 40px; }
  .tool span { display: none; }
  .panel-card { top: 58px; padding: 12px 18px 14px; }
  .panel-card .lead { display: none; }
  .settings { max-height: calc(100dvh - 76px); bottom: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .sky i { animation: none; bottom: auto; top: 30%; }
  .countdown.beat, .banner.show, .score.bump b, .tool.add.pulse, .panel-card { animation-duration: 0.01s; }
  .top, .hint { transition: none; }
}
