  :root {
    --pink: #ff6fb3;
    --pink-2: #ff97c8;
    --yellow: #ffe066;
    --yellow-2: #ffcc33;
    --blue: #6ec3ff;
    --blue-2: #4aa6ff;
    --green: #6fe28f;
    --purple: #a085ff;
    --ink: #2a2a48;
    --paper: #fff8ef;
    --shadow: 0 10px 30px rgba(40,30,80,.18), 0 2px 6px rgba(40,30,80,.08);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background:
      radial-gradient(1200px 700px at 20% -10%, #ffd6f0 0%, transparent 60%),
      radial-gradient(1100px 700px at 110% 10%, #d3ebff 0%, transparent 60%),
      linear-gradient(180deg, #fff5fb 0%, #eef6ff 100%);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3 { font-family: 'Baloo 2', system-ui, sans-serif; margin: 0; letter-spacing: .3px; }
  button {
    font-family: inherit;
    font-weight: 600;
    border: none;
    cursor: pointer;
    border-radius: 18px;
    padding: 12px 22px;
    color: #fff;
    background: linear-gradient(180deg, var(--pink), #ff4f9e);
    box-shadow: var(--shadow), inset 0 -4px 0 rgba(0,0,0,.18);
    transition: transform .08s ease, box-shadow .15s ease, filter .15s ease;
    font-size: 16px;
  }
  button:hover { filter: brightness(1.05); }
  button:active { transform: translateY(2px); box-shadow: var(--shadow), inset 0 -1px 0 rgba(0,0,0,.18); }
  button.ghost {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 6px 20px rgba(40,30,80,.10), inset 0 -3px 0 rgba(0,0,0,.06);
  }
  button.blue { background: linear-gradient(180deg, var(--blue), var(--blue-2)); }
  button.green { background: linear-gradient(180deg, #8eea9d, #45c971); }
  button.yellow { background: linear-gradient(180deg, var(--yellow), var(--yellow-2)); color: #4a3e00; }
  button.purple { background: linear-gradient(180deg, #b9a4ff, #8c6cff); }
  button.small { padding: 8px 14px; font-size: 14px; border-radius: 12px; }
  input[type=text] {
    font-family: inherit;
    font-size: 16px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 2px solid #ffd6e7;
    background: #fff;
    outline: none;
    width: 100%;
    color: var(--ink);
  }
  input[type=text]:focus { border-color: var(--pink); }

  #app {
    position: fixed; inset: 0;
    display: grid; place-items: center;
  }
  .screen {
    position: absolute; inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .screen.active { display: flex; }
  .card {
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 28px;
    padding: 28px;
    box-shadow: var(--shadow);
    max-width: 760px;
    width: 100%;
    border: 1px solid rgba(255,255,255,.7);
  }
  .title-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
  .title-row .logo { font-size: 38px; }
  .title-row h1 { font-size: 36px; }
  .subtitle { color: #6b6a86; margin-top: 6px; font-size: 16px; }

  .grid { display: grid; gap: 14px; }
  .grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  .spacer { flex: 1; }

  /* Player chips */
  .players { display: flex; flex-wrap: wrap; gap: 8px; }
  .chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: #fff;
    border: 2px solid #ffe1ee;
    border-radius: 999px;
    padding: 6px 12px 6px 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all .12s ease;
  }
  .chip:hover { transform: translateY(-1px); }
  .chip .av {
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 16px; color: #fff;
  }
  .chip.active { border-color: var(--pink); background: #fff0f7; }
  .chip .x {
    font-size: 12px; color: #999; padding: 2px 6px;
    border-radius: 999px;
  }
  .chip .x:hover { background: #ffe1ee; color: var(--pink); }

  /* Level cards */
  .level {
    border-radius: 22px;
    padding: 16px;
    color: #fff;
    cursor: pointer;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    min-height: 130px;
    transition: transform .12s ease;
    border: none;
    text-align: left;
  }
  .level:hover { transform: translateY(-3px); }
  .level h3 { font-size: 22px; }
  .level .meta { opacity: .9; font-size: 13px; }
  .level .badge {
    position: absolute; top: 10px; right: 10px;
    background: rgba(255,255,255,.25); padding: 4px 10px; border-radius: 999px;
    font-size: 12px;
  }
  .level.locked { filter: saturate(.4) brightness(.85); cursor: not-allowed; }
  .level.locked::after {
    content: '🔒'; position: absolute; bottom: 12px; right: 14px; font-size: 20px;
  }

  /* Leaderboard */
  .lb { background: #fff; border-radius: 16px; padding: 12px; }
  .lb table { width: 100%; border-collapse: collapse; }
  .lb th, .lb td { text-align: left; padding: 6px 8px; font-size: 14px; }
  .lb th { color: #97a; font-weight: 600; }
  .lb tr + tr td { border-top: 1px solid #f1eafc; }
  .lb .rank { width: 36px; }
  .lb .score { text-align: right; font-weight: 700; }

  /* Game canvas + HUD */
  #gameWrap { position: fixed; inset: 0; display: none; }
  #gameWrap.active { display: block; }
  #game { width: 100%; height: 100%; display: block; background: #87ceeb; }
  #hud {
    position: absolute; top: 16px; left: 16px; right: 16px;
    display: flex; gap: 12px; align-items: flex-start;
    pointer-events: none;
    font-family: 'Baloo 2', sans-serif;
  }
  .panel {
    background: rgba(255,255,255,.86);
    border-radius: 18px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
    pointer-events: auto;
  }
  .stat { display: flex; align-items: center; gap: 8px; font-weight: 700; }
  .stat .lbl { color: #95a; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; }
  .stat .val { font-size: 22px; }

  /* Flap meter */
  #meter { width: 220px; }
  #meterBar {
    height: 14px; background: #ffe1ee; border-radius: 999px; overflow: hidden;
    margin-top: 6px;
  }
  #meterFill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--green), var(--yellow), var(--pink));
    width: 0%;
    transition: width .12s ease;
  }
  #meterLabel { font-size: 11px; color: #95a; }

  /* Camera PIP */
  #pip {
    position: absolute; right: 16px; bottom: 16px;
    width: 220px; height: 165px;
    border-radius: 18px; overflow: hidden;
    background: #000;
    box-shadow: var(--shadow);
    border: 3px solid #fff;
  }
  #pip video, #pip canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
  #pip canvas { background: transparent; }
  #pip .pipLabel {
    position: absolute; bottom: 6px; left: 8px; right: 8px;
    color: #fff; font-size: 12px; text-shadow: 0 1px 3px rgba(0,0,0,.7);
    display: flex; justify-content: space-between; pointer-events: none;
  }

  /* Calibration overlay */
  #calOverlay {
    position: absolute; inset: 0;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(20,15,40,.55);
    backdrop-filter: blur(4px);
    z-index: 30;
  }
  #calOverlay.active { display: flex; }
  #calOverlay .card { max-width: 520px; text-align: center; }
  .ring {
    width: 92px; height: 92px; border-radius: 50%;
    border: 8px solid #ffe1ee;
    border-top-color: var(--pink);
    margin: 8px auto 6px;
    animation: spin 1.1s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Game over screen */
  #gameOver {
    position: absolute; inset: 0;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(20,15,40,.55);
    z-index: 40;
  }
  #gameOver.active { display: flex; }

  .pill {
    display: inline-block; background: #fff0f7; color: var(--pink);
    border-radius: 999px; padding: 4px 12px; font-weight: 700;
    font-size: 13px;
  }

  .footer-tip { font-size: 13px; color: #777; margin-top: 12px; }

  /* Cute floating bird in menus */
  .float-bird {
    position: absolute; right: 30px; top: 30px;
    font-size: 60px; animation: bob 2.6s ease-in-out infinite;
    pointer-events: none;
  }
  @keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg);} 50% { transform: translateY(-12px) rotate(4deg);} }

  .err {
    background: #fff0f0; color: #b13a3a; padding: 10px 14px; border-radius: 12px;
    font-size: 14px; border: 1px solid #ffd6d6;
  }

  @media (max-width: 720px) {
    .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
    #pip { width: 140px; height: 105px; }
    .title-row h1 { font-size: 28px; }
  }
