  :root {
    --pink: #ff6b9d; --pink-dark: #e84d85;
    --blue: #4dabf7; --blue-dark: #2c89d9;
    --yellow: #ffd43b; --yellow-dark: #f5b800;
    --purple: #b197fc; --purple-dark: #8c6fe8;
    --orange: #ff9f43;
    --red: #ff6b6b;
    --green: #51cf66; --green-dark: #3aa84d;
    --teal: #4dd4ac;
    --cream: #fff8e7;
    --brown: #8b5a2b;
    --ink: #2d1f12;
    --grass-1: #7ed957; --grass-2: #5cb83a;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
  html, body {
    height: 100%; overflow: hidden;
    font-family: 'Fredoka', sans-serif;
    color: var(--ink); user-select: none; -webkit-user-select: none;
    font-size: 17px;
  }
  body { background: linear-gradient(180deg, #ffd6e7 0%, #c8e7ff 60%, #fff4cc 100%); position: relative; }
  button { font-family: inherit; cursor: pointer; }

  .scene-meadow { background: linear-gradient(180deg, #ffd6e7 0%, #c8e7ff 60%, #fff4cc 100%); }
  .scene-beach  { background: linear-gradient(180deg, #ffe5b4 0%, #ffd6a5 40%, #87ceeb 100%); }
  .scene-forest { background: linear-gradient(180deg, #b8e0a8 0%, #7ec06b 60%, #5a8c47 100%); }
  .scene-space  { background: linear-gradient(180deg, #1a1a3e 0%, #4a3aa8 50%, #ff6b9d 100%); }
  .scene-candy  { background: linear-gradient(180deg, #ffb3d9 0%, #ffe0f0 50%, #c9b3ff 100%); }

  .clouds { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
  .cloud { position: absolute; background: rgba(255,255,255,0.85); border-radius: 50%; animation: drift linear infinite; }
  .cloud::before, .cloud::after { content: ''; position: absolute; background: rgba(255,255,255,0.85); border-radius: 50%; }
  .cloud-1 { width: 80px; height: 30px; top: 8%; left: -100px; animation-duration: 60s; }
  .cloud-1::before { width: 40px; height: 40px; top: -20px; left: 15px; }
  .cloud-1::after { width: 50px; height: 50px; top: -25px; left: 35px; }
  .cloud-2 { width: 60px; height: 22px; top: 22%; left: -100px; animation-duration: 80s; animation-delay: -20s; }
  .cloud-2::before { width: 30px; height: 30px; top: -15px; left: 10px; }
  .cloud-2::after { width: 40px; height: 40px; top: -20px; left: 25px; }
  @keyframes drift { from { transform: translateX(0); } to { transform: translateX(calc(100vw + 200px)); } }

  .screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; padding: 16px; }
  .screen.active { display: flex; }

  #profiles, #welcome, #newProfile { justify-content: flex-start; text-align: center; padding: 30px 20px 20px; overflow-y: auto; }
  .game-title {
    font-family: 'Lilita One', cursive;
    font-size: clamp(40px, 9vw, 68px);
    color: white;
    text-shadow: 3px 3px 0 var(--pink-dark), 6px 6px 0 var(--ink), 0 0 30px rgba(255,107,157,0.5);
    line-height: 1; margin-bottom: 10px;
    animation: titleBounce 2s ease-in-out infinite;
    letter-spacing: 1px;
  }
  .game-title .heart { color: var(--red); display: inline-block; animation: heartbeat 1.5s ease-in-out infinite; }
  @keyframes titleBounce { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
  @keyframes heartbeat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
  .subtitle { font-size: 20px; color: var(--ink); margin-bottom: 20px; font-weight: 600; }

  .profile-list, .buddy-list, .pet-picker { display: grid; gap: 10px; }
  .profile-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); width: 100%; max-width: 600px; gap: 14px; margin-bottom: 20px; }
  .pet-picker { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; width: 100%; max-width: 480px; gap: 12px; }
  .buddy-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .buddies-section { margin-bottom: 18px; width: 100%; max-width: 500px; }

  .profile-tile, .buddy-tile, .pet-card {
    background: white; border: 4px solid var(--ink); border-radius: 22px;
    padding: 12px 8px 10px; box-shadow: 0 4px 0 var(--ink);
    cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; position: relative;
  }
  .profile-tile { padding: 16px 10px 12px; border-radius: 24px; box-shadow: 0 5px 0 var(--ink); }
  .profile-tile:hover, .buddy-tile:hover, .pet-card:hover { transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink); }
  .profile-tile:active, .buddy-tile:active, .pet-card:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
  .pet-card { padding: 14px 10px 12px; box-shadow: 0 5px 0 var(--ink); }
  .pet-card.selected { background: var(--yellow); transform: translateY(-5px); box-shadow: 0 10px 0 var(--ink); }

  .profile-tile.add-new {
    background: var(--green); color: white;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 130px;
  }
  .profile-tile .avatar {
    width: 70px; height: 70px; margin: 0 auto 6px; border-radius: 50%;
    background: var(--yellow); border: 3px solid var(--ink);
    display: flex; align-items: center; justify-content: center; font-size: 38px;
  }
  .profile-tile .p-name, .buddy-tile .b-name, .pet-card .name {
    font-family: 'Lilita One', cursive; letter-spacing: 0.3px;
  }
  .profile-tile .p-name { font-size: 19px; margin-top: 2px; }
  .buddy-tile .b-name { font-size: 18px; margin-top: 4px; }
  .pet-card .name { font-size: 20px; margin-top: 6px; text-align: center; }
  .profile-tile .p-info, .buddy-tile .b-info { font-size: 12px; color: #666; margin-top: 2px; }
  .profile-tile .add-emoji { font-size: 44px; }
  .profile-tile .add-text { font-family: 'Lilita One', cursive; font-size: 16px; margin-top: 4px; letter-spacing: 0.3px; }

  .buddy-tile svg, .pet-card svg { width: 100%; height: 80px; display: block; margin: 0 auto; }
  .buddy-tile svg { width: 80px; }

  .delete-x {
    position: absolute; top: -6px; right: -6px;
    width: 26px; height: 26px;
    background: var(--red); color: white;
    border: 2px solid var(--ink); border-radius: 50%;
    font-family: 'Lilita One', cursive; font-size: 14px;
    cursor: pointer; line-height: 1; box-shadow: 0 2px 0 var(--ink);
  }

  .avatar-picker {
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px;
  }
  .avatar-option {
    background: white; border: 3px solid var(--ink); border-radius: 14px;
    padding: 8px 4px; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
    font-size: 28px; line-height: 1; transition: transform 0.1s;
  }
  .avatar-option:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .avatar-option.selected { background: var(--yellow); transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

  .top-back-btn {
    position: absolute; top: 12px; left: 12px;
    background: white; border: 3px solid var(--ink); border-radius: 14px;
    padding: 6px 14px; font-family: 'Lilita One', cursive; font-size: 14px;
    box-shadow: 0 3px 0 var(--ink); z-index: 10;
  }
  .top-back-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .profile-badge {
    position: absolute; top: 12px; right: 12px;
    background: var(--purple); color: white; border: 3px solid var(--ink);
    border-radius: 14px; padding: 6px 12px;
    font-family: 'Lilita One', cursive; font-size: 14px;
    box-shadow: 0 3px 0 var(--ink); z-index: 10;
    display: flex; align-items: center; gap: 6px;
  }
  .section-label {
    font-family: 'Lilita One', cursive; font-size: 22px;
    color: var(--pink-dark); margin-bottom: 10px; letter-spacing: 0.5px;
  }

  .name-input-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
  .name-input-wrap label { font-size: 17px; font-weight: 600; }
  .name-input {
    font-family: 'Fredoka', sans-serif; font-size: 20px; font-weight: 600;
    padding: 11px 18px; border: 3px solid var(--ink); border-radius: 14px;
    background: white; text-align: center; width: 240px; color: var(--ink);
    outline: none; box-shadow: 0 3px 0 var(--ink);
  }
  .name-input:focus { background: var(--cream); }

  .big-btn {
    font-family: 'Lilita One', cursive; font-size: 22px; color: white;
    background: var(--pink); border: 4px solid var(--ink); border-radius: 18px;
    padding: 12px 28px; box-shadow: 0 5px 0 var(--ink);
    transition: transform 0.1s, box-shadow 0.1s; letter-spacing: 1px;
  }
  .big-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); }
  .big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
  .big-btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .big-btn.green { background: var(--green); }
  .big-btn.blue { background: var(--blue); }
  .big-btn.purple { background: var(--purple); }
  .big-btn.red { background: var(--red); }
  .big-btn.small { font-size: 16px; padding: 9px 18px; border-radius: 14px; }

  #home, #aquarium { padding: 0; }
  .top-bar {
    width: 100%; padding: 10px 12px;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.55); backdrop-filter: blur(8px);
    border-bottom: 3px solid var(--ink); z-index: 5;
  }
  .home-btn {
    background: white; border: 3px solid var(--ink); border-radius: 14px;
    padding: 6px 12px; font-family: 'Lilita One', cursive; font-size: 14px;
    box-shadow: 0 3px 0 var(--ink); letter-spacing: 0.3px;
    display: flex; align-items: center; gap: 4px;
  }
  .home-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .pet-name-tag {
    font-family: 'Lilita One', cursive; font-size: 18px;
    background: white; padding: 6px 14px;
    border: 3px solid var(--ink); border-radius: 16px;
    box-shadow: 0 3px 0 var(--ink); letter-spacing: 0.3px;
    flex: 1; text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    margin: 0 6px;
  }
  .coin-display {
    display: flex; align-items: center; gap: 6px;
    background: var(--yellow); border: 3px solid var(--ink);
    border-radius: 16px; padding: 6px 14px 6px 8px;
    font-family: 'Lilita One', cursive; font-size: 18px;
    box-shadow: 0 3px 0 var(--ink);
  }
  .coin-icon {
    width: 24px; height: 24px;
    background: radial-gradient(circle at 35% 35%, #fff5b8, var(--yellow-dark));
    border: 2px solid var(--brown); border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; color: var(--brown); font-weight: 900;
  }

  .stats-row, .aqua-stats { display: flex; gap: 8px; padding: 8px 12px; width: 100%; z-index: 5; }
  .stat-bar {
    flex: 1; background: white;
    border: 3px solid var(--ink); border-radius: 14px;
    padding: 5px 8px; box-shadow: 0 3px 0 var(--ink);
    display: flex; align-items: center; gap: 6px;
  }
  .aqua-stats .stat-bar { background: rgba(255,255,255,0.95); }
  .stat-icon { font-size: 18px; }
  .stat-fill-wrap { flex: 1; height: 11px; background: #ffe0e0; border-radius: 5px; overflow: hidden; border: 2px solid var(--ink); }
  .stat-fill { height: 100%; transition: width 0.5s ease; border-radius: 3px; }
  .stat-fill.happiness { background: linear-gradient(90deg, #ff8fb1, var(--pink)); }
  .stat-fill.hunger { background: linear-gradient(90deg, #ffd96b, var(--orange)); }
  .stat-fill.energy { background: linear-gradient(90deg, #84d8ff, var(--blue)); }

  .pet-stage {
    flex: 1; width: 100%; position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: flex-end;
    overflow: hidden;
  }
  .ground {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 30%; background: linear-gradient(180deg, var(--grass-1), var(--grass-2));
    border-top: 4px solid var(--ink);
  }
  .scene-beach .ground { background: linear-gradient(180deg, #f4d59c, #e8b96e); }
  .scene-forest .ground { background: linear-gradient(180deg, #6ba84f, #3d6b2c); }
  .scene-space .ground { background: linear-gradient(180deg, #8a76d4, #5a4a8e); }
  .scene-candy .ground { background: linear-gradient(180deg, #ffb3d9, #ff8fc4); }

  /* Grass blades scattered across the meadow */
  .grass-blade {
    position: absolute; bottom: 0;
    width: 8px; height: 16px;
    background: var(--grass-2);
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
    pointer-events: none;
    animation: grassSway 3s ease-in-out infinite;
  }
  @keyframes grassSway {
    0%, 100% { transform: skewX(-2deg); }
    50% { transform: skewX(2deg); }
  }

  /* Meadow decorations: little flowers */
  .meadow-flower {
    position: absolute;
    pointer-events: none;
    font-size: 16px;
    animation: flowerSway 4s ease-in-out infinite;
  }
  @keyframes flowerSway {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
  }

  .pet-display {
    position: absolute; z-index: 2;
    bottom: 8%; left: 50%;
    transform: translateX(-50%); cursor: pointer;
  }
  .pet-display.bobbing { animation: petBob 3s ease-in-out infinite; }
  .pet-display svg { width: 220px; height: 220px; display: block; filter: drop-shadow(0 6px 8px rgba(0,0,0,0.18)); }
  @keyframes petBob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-10px); }
  }
  .pet-display.happy { animation: petJoy 0.6s ease-in-out 2; }
  @keyframes petJoy {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(0); }
    25% { transform: translateX(-50%) translateY(-30px) rotate(-10deg); }
    75% { transform: translateX(-50%) translateY(-20px) rotate(10deg); }
  }
  .pet-display.eating { animation: petEat 0.4s ease-in-out 3; }
  @keyframes petEat {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.1, 0.9); }
  }

  /* Tail wagging animation - applied to the inner tail group */
  .tail-wag { transform-origin: 30% 60%; animation: tailWag 0.6s ease-in-out infinite; }
  @keyframes tailWag {
    0%, 100% { transform: rotate(-12deg); }
    50% { transform: rotate(12deg); }
  }
  .tail-swish { transform-origin: 50% 80%; animation: tailSwish 1.4s ease-in-out infinite; }
  @keyframes tailSwish {
    0%, 100% { transform: rotate(-6deg); }
    50% { transform: rotate(6deg); }
  }
  /* Blink */
  .pet-eye-blink { animation: blink 5s infinite; }
  @keyframes blink {
    0%, 92%, 100% { transform: scaleY(1); }
    94%, 96% { transform: scaleY(0.1); }
  }

  .scene-toy {
    position: absolute; z-index: 3; pointer-events: none;
    font-size: 60px; filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2));
  }
  .scene-toy.bouncing-ball { animation: ballBounce 1.6s ease-in-out infinite; }
  @keyframes ballBounce {
    0%, 100% { transform: translateY(0) rotate(0); }
    25% { transform: translateY(-80px) rotate(180deg); }
    50% { transform: translateY(0) rotate(360deg); }
    75% { transform: translateY(-50px) rotate(540deg); }
  }
  .scene-toy.rolling-yarn { animation: yarnRoll 4s linear infinite; }
  @keyframes yarnRoll {
    0% { transform: translateX(-30px) rotate(0); }
    50% { transform: translateX(30px) rotate(360deg); }
    100% { transform: translateX(-30px) rotate(720deg); }
  }
  .scene-toy.feather-floating { animation: featherFloat 3s ease-in-out infinite; }
  @keyframes featherFloat {
    0%, 100% { transform: translateY(0) rotate(-15deg); }
    50% { transform: translateY(-50px) rotate(15deg); }
  }
  .scene-toy.mirror-shimmer { animation: mirrorShimmer 2s ease-in-out infinite; }
  @keyframes mirrorShimmer {
    0%, 100% { transform: rotate(-5deg) scale(1); filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2)) brightness(1); }
    50% { transform: rotate(5deg) scale(1.05); filter: drop-shadow(0 4px 4px rgba(0,0,0,0.2)) brightness(1.4); }
  }

  .pet-display.playing-ball { animation: playJump 1.6s ease-in-out infinite; }
  @keyframes playJump {
    0%, 50%, 100% { transform: translateX(-50%) translateY(0); }
    25% { transform: translateX(-50%) translateY(-30px); }
    75% { transform: translateX(-50%) translateY(-20px) rotate(-10deg); }
  }
  .pet-display.playing-yarn { animation: playPounce 1.6s ease-in-out infinite; }
  @keyframes playPounce {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(0); }
    25% { transform: translateX(-50%) translateY(-15px) rotate(-8deg); }
    50% { transform: translateX(-50%) translateY(0) rotate(0); }
    75% { transform: translateX(-50%) translateY(-15px) rotate(8deg); }
  }
  .pet-display.playing-feather { animation: playLook 2s ease-in-out infinite; }
  @keyframes playLook {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(-3deg); }
    50% { transform: translateX(-50%) translateY(-15px) rotate(3deg); }
  }

  .heart-burst {
    position: absolute; font-size: 28px; pointer-events: none;
    animation: heartFloat 1.5s ease-out forwards; z-index: 50;
  }
  @keyframes heartFloat {
    0% { opacity: 1; transform: translateY(0) scale(0.5); }
    100% { opacity: 0; transform: translateY(-100px) scale(1.5); }
  }

  .placed-item {
    position: absolute; z-index: 1; bottom: 4%;
    pointer-events: none; font-size: 50px;
    filter: drop-shadow(0 3px 3px rgba(0,0,0,0.25));
  }
  .placed-item.left { left: 8%; }
  .placed-item.right { right: 8%; }

  .action-bar {
    width: 100%; padding: 10px 10px 14px;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
    background: rgba(255,255,255,0.65); backdrop-filter: blur(8px);
    border-top: 3px solid var(--ink); z-index: 5;
  }
  .action-btn {
    font-family: 'Lilita One', cursive; font-size: 12px; color: var(--ink);
    background: white; border: 3px solid var(--ink); border-radius: 14px;
    padding: 6px 2px; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    min-height: 56px; letter-spacing: 0.3px;
  }
  .action-btn .emoji { font-size: 22px; line-height: 1; }
  .action-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
  .action-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .action-btn.play { background: var(--pink); color: white; }
  .action-btn.feed { background: var(--orange); color: white; }
  .action-btn.shop { background: var(--purple); color: white; }
  .action-btn.math { background: var(--green); color: white; }
  .action-btn.aqua { background: var(--teal); color: white; }

  .stop-play-btn {
    position: absolute; top: 12px; right: 12px; z-index: 10;
    font-family: 'Lilita One', cursive;
    background: var(--red); color: white;
    border: 3px solid var(--ink); border-radius: 16px;
    padding: 8px 16px; font-size: 15px;
    box-shadow: 0 3px 0 var(--ink); display: none; letter-spacing: 0.3px;
  }
  .stop-play-btn.active { display: block; }
  .stop-play-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

  /* ============ AQUARIUM ============ */
  #aquarium {
    background:
      linear-gradient(180deg,
        rgba(20,60,90,0.6) 0%,
        rgba(40,110,160,0.3) 30%,
        rgba(60,160,200,0.2) 60%,
        rgba(80,200,210,0.3) 100%),
      linear-gradient(180deg, #0d3b5c 0%, #1d6293 40%, #2da2c2 75%, #4dd4ac 100%);
  }
  .aquarium-stage {
    flex: 1; width: 100%; position: relative; overflow: hidden;
  }
  /* Caustic light rays from above */
  .light-ray {
    position: absolute;
    top: 0;
    width: 60px; height: 100%;
    background: linear-gradient(180deg,
      rgba(255,255,255,0.18) 0%,
      rgba(255,255,255,0.08) 40%,
      transparent 80%);
    transform: skewX(-12deg);
    pointer-events: none;
    animation: rayShimmer 6s ease-in-out infinite;
  }
  .light-ray.r2 { width: 30px; animation-duration: 8s; animation-delay: -2s; }
  .light-ray.r3 { width: 80px; animation-duration: 10s; animation-delay: -4s; }
  @keyframes rayShimmer {
    0%, 100% { opacity: 0.4; transform: skewX(-12deg) translateX(0); }
    50% { opacity: 0.7; transform: skewX(-8deg) translateX(20px); }
  }
  /* Water surface with ripple */
  .water-surface {
    position: absolute; top: 0; left: 0; right: 0;
    height: 14px;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.55), transparent),
      repeating-linear-gradient(90deg, rgba(255,255,255,0.3) 0 8px, transparent 8px 20px);
    animation: waterRipple 4s ease-in-out infinite;
    pointer-events: none;
  }
  @keyframes waterRipple {
    0%, 100% { transform: translateY(0); opacity: 0.8; }
    50% { transform: translateY(2px); opacity: 1; }
  }
  /* Sandy floor with texture */
  .aqua-floor {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 18%;
    background:
      radial-gradient(circle at 20% 30%, #f5dba8 4px, transparent 5px),
      radial-gradient(circle at 70% 50%, #d4b478 3px, transparent 4px),
      radial-gradient(circle at 45% 70%, #f5dba8 3px, transparent 4px),
      radial-gradient(circle at 85% 20%, #d4b478 3px, transparent 4px),
      linear-gradient(180deg, #e8c98a 0%, #c9a060 100%);
    border-top: 3px solid var(--ink);
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.15);
  }
  .aqua-floor::before {
    /* gentle dune outline */
    content: '';
    position: absolute; top: -8px; left: 0; right: 0;
    height: 14px;
    background: radial-gradient(ellipse 100px 14px at 30% 100%, #d4b478, transparent),
                radial-gradient(ellipse 140px 12px at 70% 100%, #d4b478, transparent);
  }
  /* Bubbles */
  .bubble {
    position: absolute;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.95), rgba(255,255,255,0.4) 60%, rgba(255,255,255,0.2));
    border: 1px solid rgba(255,255,255,0.6);
    border-radius: 50%;
    pointer-events: none;
    animation: bubbleUp linear infinite;
  }
  @keyframes bubbleUp {
    0% { transform: translateY(0) translateX(0) scale(0.5); opacity: 0.9; }
    50% { transform: translateY(-50vh) translateX(10px) scale(0.9); opacity: 0.8; }
    100% { transform: translateY(-100vh) translateX(-5px) scale(1); opacity: 0; }
  }
  /* Sea plants - animated swaying */
  .sea-plant {
    position: absolute;
    bottom: 18%;
    pointer-events: none;
    transform-origin: bottom center;
    animation: plantSway 4s ease-in-out infinite;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
  }
  .sea-plant svg { display: block; }
  @keyframes plantSway {
    0%, 100% { transform: rotate(-4deg); }
    50% { transform: rotate(4deg); }
  }

  /* SVG fish container */
  .aqua-fish {
    position: absolute;
    pointer-events: none;
    filter: drop-shadow(0 4px 6px rgba(0,0,30,0.3));
    will-change: transform;
  }
  .aqua-fish svg {
    width: 90px; height: 60px; display: block;
  }
  .aqua-fish.swim-right { animation: fishSwimRight linear infinite; }
  .aqua-fish.swim-left { animation: fishSwimLeft linear infinite; }
  @keyframes fishSwimRight {
    0% { transform: translateX(-120px); }
    100% { transform: translateX(calc(100vw + 60px)); }
  }
  @keyframes fishSwimLeft {
    0% { transform: translateX(calc(100vw + 60px)) scaleX(-1); }
    100% { transform: translateX(-120px) scaleX(-1); }
  }
  /* Wiggle inside the fish */
  .fish-body { animation: fishWiggle 0.5s ease-in-out infinite; transform-origin: 30% 50%; }
  @keyframes fishWiggle {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
  }
  .fish-tail { animation: tailFlap 0.4s ease-in-out infinite; transform-origin: 90% 50%; }
  @keyframes tailFlap {
    0%, 100% { transform: scaleX(1) rotate(-15deg); }
    50% { transform: scaleX(0.9) rotate(15deg); }
  }
  .aqua-decoration {
    position: absolute; bottom: 18%;
    pointer-events: none; font-size: 60px;
    filter: drop-shadow(0 3px 3px rgba(0,0,0,0.4));
  }
  .aqua-empty-msg {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: white; text-align: center;
    font-family: 'Lilita One', cursive;
    font-size: 24px;
    text-shadow: 2px 2px 0 var(--ink);
    padding: 20px;
  }
  .aqua-empty-msg .small-text {
    font-family: 'Fredoka', sans-serif; font-size: 16px;
    font-weight: 600; margin-top: 12px;
    text-shadow: 1px 1px 0 var(--ink);
  }

  /* MODAL */
  .modal-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100; padding: 14px;
  }
  .modal-overlay.active { display: flex; }
  .modal {
    background: var(--cream); border: 4px solid var(--ink);
    border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
    max-width: 520px; width: 100%; max-height: 90vh;
    overflow-y: auto; padding: 20px; position: relative;
    animation: modalPop 0.3s ease-out;
  }
  @keyframes modalPop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  .modal-title {
    font-family: 'Lilita One', cursive; font-size: 26px;
    text-align: center; margin-bottom: 14px;
    color: var(--pink-dark); letter-spacing: 0.3px;
  }
  .close-btn {
    position: absolute; top: 10px; right: 10px;
    width: 38px; height: 38px;
    border-radius: 50%; background: var(--red);
    border: 3px solid var(--ink); color: white;
    font-size: 20px; font-family: 'Lilita One', cursive;
    cursor: pointer; box-shadow: 0 3px 0 var(--ink); line-height: 1;
  }
  .close-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

  .math-mode-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .mode-card {
    background: white; border: 3px solid var(--ink); border-radius: 16px;
    padding: 12px 8px; cursor: pointer; text-align: center;
    box-shadow: 0 3px 0 var(--ink); transition: transform 0.1s;
  }
  .mode-card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .mode-card.locked { opacity: 0.55; cursor: not-allowed; }
  .mode-card .mode-emoji { font-size: 34px; line-height: 1; }
  .mode-card .mode-name { font-family: 'Lilita One', cursive; font-size: 17px; margin-top: 4px; letter-spacing: 0.3px; }
  .mode-card .mode-range { font-size: 13px; color: #555; margin-top: 1px; }
  .mode-card .lock-info { font-size: 12px; color: var(--red); font-weight: 700; margin-top: 3px; }

  .problem-display {
    background: white; border: 4px solid var(--ink);
    border-radius: 18px; padding: 22px 18px;
    text-align: center; margin-bottom: 14px;
    box-shadow: 0 4px 0 var(--ink); position: relative;
  }
  .problem-text {
    font-family: 'Lilita One', cursive;
    font-size: 52px; color: var(--ink);
    line-height: 1.1; letter-spacing: 1px;
  }
  .problem-text .op { color: var(--pink-dark); margin: 0 8px; }

  .timer-ring { position: relative; width: 64px; height: 64px; margin: 0 auto 6px; }
  .timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
  .timer-ring .timer-bg { fill: none; stroke: #ffe0e0; stroke-width: 6; }
  .timer-ring .timer-fg {
    fill: none; stroke: var(--green); stroke-width: 6; stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear, stroke 0.3s;
  }
  .timer-ring .timer-fg.tier-good { stroke: var(--yellow-dark); }
  .timer-ring .timer-fg.tier-ok { stroke: var(--orange); }
  .timer-ring .timer-fg.tier-slow { stroke: var(--red); }
  .timer-ring .timer-fg.tier-expired { stroke: #888; }
  .timer-ring .timer-num {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Lilita One', cursive; font-size: 22px; color: var(--ink);
  }
  .timer-ring .timer-num.expired { color: #888; font-size: 18px; }
  .timer-ring.pulsing { animation: timerPulse 1s ease-in-out infinite; }
  @keyframes timerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
  }

  .speed-badge {
    display: inline-block; padding: 3px 12px; border-radius: 12px;
    font-family: 'Lilita One', cursive; font-size: 14px;
    color: white; margin-top: 4px; letter-spacing: 0.3px;
  }
  .speed-badge.tier-fast { background: var(--green); }
  .speed-badge.tier-good { background: var(--yellow-dark); color: var(--ink); }
  .speed-badge.tier-ok { background: var(--orange); }
  .speed-badge.tier-slow { background: var(--red); }
  .speed-badge.tier-expired { background: #888; }

  .answer-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .answer-btn {
    font-family: 'Lilita One', cursive; font-size: 30px; color: var(--ink);
    background: white; border: 4px solid var(--ink); border-radius: 18px;
    padding: 16px; cursor: pointer; box-shadow: 0 4px 0 var(--ink);
    transition: transform 0.1s, background 0.2s; letter-spacing: 1px;
  }
  .answer-btn:hover { transform: translateY(-2px); }
  .answer-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
  .answer-btn.correct { background: var(--green); color: white; animation: pop 0.4s ease-out; }
  .answer-btn.wrong { background: var(--red); color: white; animation: shake 0.4s ease-out; }
  @keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

  .feedback-msg {
    text-align: center; font-family: 'Lilita One', cursive;
    font-size: 21px; margin: 10px 0; min-height: 28px;
    color: var(--green-dark); letter-spacing: 0.3px;
  }
  .feedback-msg.wrong { color: var(--pink-dark); }
  .feedback-msg.expired { color: #888; }

  .progress-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 10px; font-weight: 700; font-size: 15px;
  }
  .streak-flame {
    background: linear-gradient(135deg, var(--orange), var(--red));
    color: white; padding: 4px 12px; border-radius: 14px;
    border: 2px solid var(--ink); font-family: 'Lilita One', cursive; font-size: 16px;
  }

  .shop-tabs {
    display: flex; gap: 6px; margin-bottom: 14px;
    flex-wrap: wrap; justify-content: center;
  }
  .shop-tab {
    font-family: 'Lilita One', cursive;
    background: white; border: 2px solid var(--ink);
    border-radius: 13px; padding: 6px 12px;
    cursor: pointer; box-shadow: 0 2px 0 var(--ink);
    font-size: 14px; letter-spacing: 0.2px;
  }
  .shop-tab.active { background: var(--yellow); transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }

  .shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .shop-item {
    background: white; border: 3px solid var(--ink); border-radius: 16px;
    padding: 12px 8px; text-align: center;
    box-shadow: 0 3px 0 var(--ink); cursor: pointer; transition: transform 0.1s;
  }
  .shop-item:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
  .shop-item.owned { background: #d4f7dc; }
  .shop-item.equipped { background: var(--yellow); }
  .shop-item.cant-afford { opacity: 0.55; }
  .shop-item .item-emoji { font-size: 40px; line-height: 1; }
  .shop-item .item-svg { width: 70px; height: 70px; margin: 0 auto; display: block; }
  .shop-item .item-name { font-family: 'Lilita One', cursive; font-size: 15px; margin: 4px 0 3px; letter-spacing: 0.2px; }
  .shop-item .item-sci { font-size: 11px; color: #777; font-style: italic; margin-bottom: 2px; }
  .shop-item .item-price { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; }
  .mini-coin {
    width: 16px; height: 16px;
    background: radial-gradient(circle at 35% 35%, #fff5b8, var(--yellow-dark));
    border: 2px solid var(--brown); border-radius: 50%; display: inline-block;
  }
  .item-status { font-size: 12px; margin-top: 3px; font-weight: 600; color: var(--green-dark); }

  .confetti-piece {
    position: absolute; width: 12px; height: 12px;
    pointer-events: none; animation: confettiFall 2s linear forwards; z-index: 200;
  }
  @keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
  }

  .helper-text { font-size: 13px; color: #666; text-align: center; margin-top: 8px; font-style: italic; }
  .empty-msg { grid-column: 1/-1; text-align: center; padding: 22px 10px; font-size: 17px; font-weight: 600; }
  .empty-msg small { font-weight: 400; font-size: 14px; }

  .toy-level-bar {
    height: 6px; background: #ffe0e0; border-radius: 3px;
    border: 1.5px solid var(--ink); margin-top: 5px; overflow: hidden;
  }
  .toy-level-fill {
    height: 100%; background: linear-gradient(90deg, var(--green), var(--green-dark));
    transition: width 0.5s ease; border-radius: 1.5px;
  }

  .coin-burst {
    position: absolute; font-family: 'Lilita One', cursive;
    font-size: 32px; color: var(--yellow-dark);
    text-shadow: 2px 2px 0 var(--ink);
    pointer-events: none;
    animation: coinBurst 1.4s ease-out forwards;
    z-index: 300; white-space: nowrap;
  }
  @keyframes coinBurst {
    0% { opacity: 0; transform: translateY(20px) scale(0.5); }
    20% { opacity: 1; transform: translateY(0) scale(1.3); }
    50% { opacity: 1; transform: translateY(-30px) scale(1); }
    100% { opacity: 0; transform: translateY(-90px) scale(0.9); }
  }

  .debug-section { margin-bottom: 14px; padding: 10px; background: white; border: 3px solid var(--ink); border-radius: 14px; }
  .debug-section-title { font-family: 'Lilita One', cursive; font-size: 16px; color: var(--purple-dark); margin-bottom: 8px; letter-spacing: 0.3px; }
  .debug-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
  .debug-btn {
    font-family: 'Lilita One', cursive; background: var(--blue); color: white;
    border: 2px solid var(--ink); border-radius: 10px;
    padding: 6px 12px; font-size: 13px; cursor: pointer;
    box-shadow: 0 2px 0 var(--ink); letter-spacing: 0.3px;
  }
  .debug-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--ink); }
  .debug-btn.green { background: var(--green); }
  .debug-btn.purple { background: var(--purple); }
  .debug-btn.red { background: var(--red); }
  .debug-btn.orange { background: var(--orange); }
  .debug-input {
    font-family: 'Fredoka', sans-serif; font-size: 14px;
    padding: 6px 10px; border: 2px solid var(--ink);
    border-radius: 10px; width: 80px; text-align: center;
    box-shadow: 0 2px 0 var(--ink); background: white;
  }
  .debug-info {
    font-size: 12px; color: #555; background: #f5f5f5;
    padding: 6px 10px; border-radius: 8px; margin-bottom: 8px; font-family: monospace;
  }
  .debug-tip { font-size: 12px; color: #666; text-align: center; margin-top: 8px; font-style: italic; }

  @media (max-width: 380px) {
    .pet-display svg { width: 180px; height: 180px; }
    .problem-text { font-size: 42px; }
    .answer-btn { font-size: 26px; padding: 14px; }
    .action-btn .emoji { font-size: 20px; }
    .action-btn { font-size: 11px; min-height: 52px; }
    .avatar-picker { grid-template-columns: repeat(5, 1fr); }
    .aqua-fish svg { width: 70px; height: 48px; }
  }
