:root {
  --sky: #dff3ff;
  --ink: #2b3a55;
  --card: #ffffff;
  --blue: #3aa0ff;
  --green: #35c46a;
  --orange: #ff9a3c;
  --red: #ff5d5d;
  --shadow: 0 6px 0 rgba(43, 58, 85, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--sky);
  color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  min-height: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

h1 { font-size: clamp(28px, 6vw, 44px); margin: 12px 0 4px; text-align: center; }
p.sub { text-align: center; margin: 0 0 20px; font-size: 20px; opacity: 0.75; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
}
button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(43, 58, 85, 0.18); }
button:focus-visible { outline: 4px solid var(--orange); outline-offset: 2px; }

.btn { padding: 12px 22px; font-size: 22px; font-weight: 700; }
.btn.go { background: var(--green); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.quiet { background: transparent; box-shadow: none; font-size: 18px; opacity: 0.7; }

.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.bar .title { flex: 1; font-size: 24px; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { gap: 8px; }
@media (max-width: 420px) { .icon { width: 48px; height: 48px; font-size: 24px; } }
.icon { width: 56px; height: 56px; font-size: 28px; flex: none; }

/* Players */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.player { position: relative; padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.player .face { font-size: 64px; line-height: 1.1; }
.player .name { font-size: 24px; font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .stars { font-size: 16px; opacity: 0.75; }
.player.add { border: 4px dashed rgba(43, 58, 85, 0.3); background: transparent; box-shadow: none; }
.player-slot { position: relative; }
.player-slot .player { width: 100%; }
.player-slot .remove {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  font-size: 14px; background: #eef2f7; box-shadow: none; opacity: 0.7;
}

.form { background: var(--card); border-radius: 24px; padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.form label { font-size: 22px; font-weight: 700; }
.form input {
  font: inherit; font-size: 26px; padding: 12px 16px; border-radius: 16px; border: 3px solid #cfd8e6; width: 100%;
  user-select: text; -webkit-user-select: text;
}
.faces { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.faces button { font-size: 38px; height: 64px; box-shadow: none; background: #eef2f7; }
.faces button[aria-pressed="true"] { background: #ffe9a8; outline: 4px solid var(--orange); }
.row { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }

/* Level list */
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 14px; padding-bottom: 24px; }
.level { height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 30px; font-weight: 800; }
.level small { font-size: 15px; letter-spacing: 1px; height: 18px; }
.level.done { background: #d9f7e3; }
.level.next { background: #fff3c4; animation: bob 1.2s ease-in-out infinite; }
.level.locked { opacity: 0.45; box-shadow: none; cursor: default; }
@keyframes bob { 50% { transform: translateY(-5px); } }

/* A game screen */
.play { flex: 1; display: flex; flex-direction: column; align-items: center; }
.play .bar { width: 100%; }
.counts { font-size: 18px; opacity: 0.75; margin-bottom: 8px; text-align: center; }
.board-wrap { width: 100%; display: flex; align-items: center; justify-content: center; min-height: 200px; touch-action: none; }
.pad { display: grid; grid-template-columns: repeat(3, 68px); grid-template-rows: repeat(2, 68px); gap: 8px; margin: 12px 0 4px; }
.pad button { font-size: 30px; }
.pad .up { grid-column: 2; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.hint { font-size: 16px; opacity: 0.6; margin: 8px 0 0; text-align: center; }

/* Win */
.win { position: fixed; inset: 0; background: rgba(43, 58, 85, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.win .card { background: var(--card); border-radius: 28px; padding: 24px 28px; text-align: center; max-width: 420px; width: 100%; animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1); }
.win h2 { font-size: 40px; margin: 0; }
.win .big { font-size: 56px; letter-spacing: 6px; margin: 8px 0; }
.win p { font-size: 20px; margin: 0 0 18px; }
.win .row { justify-content: center; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.win .friend { font-size: 68px; line-height: 1; animation: peek 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) 0.15s backwards; }
.win .big span { display: inline-block; animation: starpop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) calc(var(--i) * 0.25s + 0.3s) backwards; }
.win .card.big-win { background: linear-gradient(#fff6c9, #fff 60%); outline: 6px solid #ffd54a; }
.win .card.big-win .friend { animation: peek 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) 0.15s backwards, wobble 0.8s ease-in-out 0.8s infinite alternate; }
@keyframes peek { from { transform: translateY(40px) scale(0); } }
@keyframes starpop { from { transform: scale(0) rotate(-180deg); } }
@keyframes wobble { from { transform: rotate(-8deg); } to { transform: rotate(8deg) scale(1.08); } }

/* Surprises */
.party { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 11; }
.party span { position: absolute; }
.fall { top: -40px; font-size: 28px; animation: fall linear forwards; }
.rise { bottom: -70px; font-size: 46px; animation: rise ease-in forwards; }
.spark { width: 10px; height: 10px; border-radius: 50%; opacity: 0; animation: burst 1s ease-out forwards; }
.runner { bottom: 10px; right: -80px; font-size: 50px; animation: run linear forwards; }
.runner i { display: inline-block; font-style: normal; animation: hop 0.3s ease-in-out infinite alternate; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@keyframes rise { to { transform: translate(var(--sway), -125vh); } }
@keyframes burst { 0% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); } }
@keyframes run { to { transform: translateX(calc(-100vw - 180px)); } }
@keyframes hop { to { transform: translateY(-16px); } }

/* Home page */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
a.game { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 12px; text-decoration: none; text-align: center; }
a.game .icon-big { font-size: 64px; line-height: 1.1; }
a.game .name { font-size: 22px; font-weight: 800; }
a.game .about { font-size: 15px; opacity: 0.75; }
a.game .stars { font-size: 16px; opacity: 0.8; min-height: 20px; }

a.icon, a.game, a.btn {
  color: inherit; text-decoration: none; border-radius: 20px; background: var(--card); box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
}
a.icon { display: flex; align-items: center; justify-content: center; }
a.btn { display: inline-block; }
a.btn.quiet { background: transparent; box-shadow: none; }
a.icon:active, a.game:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(43, 58, 85, 0.18); }
a:focus-visible { outline: 4px solid var(--orange); outline-offset: 2px; }
.row.center { justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .level.next { animation: none; }
}

.account { text-align: center; margin-top: 28px; font-size: 16px; opacity: 0.8; }
.unsaved { position: fixed; left: 12px; bottom: 12px; background: #fff3c4; border-radius: 14px; padding: 8px 14px; font-size: 16px; box-shadow: var(--shadow); z-index: 20; }
[hidden] { display: none !important; }
