  @import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Karla:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

 :root{
  --bg: #C88259;
  --bg-2: #C88259;
  --card: #FBF3E7;
  --ink: #6B4226;
  --ink-soft: #8A5A3A;
  --marigold: #E68A2E;
  --marigold-dark: #B36A1D;
  --rose: #E2748A;
  --sage: #8FB996;
  --line: rgba(107,66,38,0.08);
}

.loading-screen{
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5vh;
  background: url('Background.jpg');
  background-repeat: repeat;
  background-size: 340px auto;
  background-color: var(--bg);
  transition: opacity .5s ease;
}
.loading-screen.fade-out{
  opacity: 0;
  pointer-events: none;
}
.loading-logo{
  max-height: 18vh;
  width: auto;
  max-width: 60%;
}
.loading-spinner{
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 5px solid #FFFFFF;
  border-top-color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  animation: loading-spin 0.9s linear infinite;
}
@keyframes loading-spin{
  to{ transform: rotate(360deg); }
}
.loading-text{
  font-family:'Fredoka', sans-serif;
  font-weight:700;
  font-size: clamp(15px, 2.2vh, 20px);
  color: var(--ink);
  background:#FFFFFF;
  border:2px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  border-radius: 14px;
  padding: 1.2vh 20px;
}

html.resume-game .title-screen{ display:none; }
html.resume-game #avatarBtn{ display:none; }
html.resume-game .app{ display:flex; opacity:1; }
html.resume-game #appBackBtn{ display:flex; opacity:1; }
html.resume-streak .title-screen{ display:none; }
html.resume-streak #avatarBtn{ display:none; }
html.resume-streak .streak-screen{ display:block; opacity:1; transform:scale(1); }


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

      html{
    overflow: hidden;
  }
   html,body{
  margin:0; padding:0; height:100%;
  overflow: hidden;
  background: url('Background.jpg');
  background-repeat: repeat;
  background-size: 340px auto;
  font-family: 'Karla', sans-serif;
  color: var(--card);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

       .app{
    max-width: 480px;
    margin: 0 auto;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(8px, 5vh, 64px) 18px clamp(6px, 2.5vh, 40px);
    box-sizing: border-box;
  }

  /* ---------- Header ---------- */
  .brand{
    display:flex; align-items:center; gap:10px;
    margin-bottom: 4px;
  }
  .brand-mark{ width:34px; height:34px; flex-shrink:0; }
  h1{
    font-family:'Fredoka', sans-serif;
    font-weight:700;
    font-size: 28px;
    letter-spacing: 0.2px;
    margin: 0;
    color: var(--card);
  }
    .tagline{
    font-size: 12.5px;
    color: rgba(251,243,231,0.65);
    margin: 2px 0 20px;
    text-align:center;
    max-width: 320px;
    line-height: 1.5;
  }
  .whisker{
    width: 120px; height: 10px; margin-bottom: 22px; opacity:0.5;
  }

    .mode-tabs{
    display:none;
    gap:6px;
    background: rgba(251,243,231,0.06);
    border: 1px solid rgba(251,243,231,0.1);
    border-radius: 14px;
    padding: 4px;
    margin-bottom: 16px;
  }
        .mode-tab{
    font-family:'Karla', sans-serif; font-weight:700; font-size: 13px;
    border:none; cursor:pointer; background:none; color: #FFFFFF;
    -webkit-text-stroke: 0.6px #000000;
    paint-order: stroke fill;
    padding: 8px 18px; border-radius: 10px;
    transition: background .15s, color .15s;
  }
  .mode-tab.active{
    background: linear-gradient(180deg, #F5B876, var(--marigold-dark));
    color: #2A1B0C;
  }

        .hud{
    width:100%;
    max-width: 380px;
    margin: 0 auto clamp(6px, 2vh, 16px);
    display:grid; grid-template-columns: 1fr 1fr 1fr; align-items:center;
    flex-shrink: 0;
  }
  .hud-item{
    display:flex; flex-direction:column; align-items:center; gap:2px;
  }
  .hud-item:nth-child(1){ justify-self:start; }
  .hud-item:nth-child(2){ justify-self:center; }
  .hud-item:nth-child(3){ justify-self:end; }
           .hud-label{
    font-size: 12px; text-transform:uppercase; letter-spacing: 1.2px;
    color: #FFFFFF;
    -webkit-text-stroke: 0.6px #000000;
    paint-order: stroke fill;
    font-weight:600;
  }
    .hud-score{
    font-size: 14px; font-weight:800; letter-spacing: 0.3px;
    color: #FFFFFF;
    -webkit-text-stroke: 0.6px #000000;
    paint-order: stroke fill;
    margin-bottom: 1px;
    display: inline-block;
  }
  .hud-score.bump{
    animation: scoreBump .4s cubic-bezier(.34,1.56,.64,1);
  }
  @keyframes scoreBump{
    0%{ transform: scale(1); color: #FFFFFF; }
    35%{ transform: scale(1.35); color: #FFD966; }
    100%{ transform: scale(1); color: #FFFFFF; }
  }
      .hud-value{
    font-family:'JetBrains Mono', monospace; font-weight:700; font-size:19px;
    color: #FFFFFF;
    -webkit-text-stroke: 0.6px #000000;
    paint-order: stroke fill;
  }
  .hearts{ display:flex; gap:4px; }
    .heart{ width:18px; height:18px; transition: transform .25s, opacity .25s; }
  .heart.lost{ opacity:0.45; filter: grayscale(1); transform: scale(0.85); }
  .heart.break{ animation: heartBreak .5s ease; }
  @keyframes heartBreak{
    0%{ transform: scale(1); } 30%{ transform: scale(1.3) rotate(-8deg); }
    60%{ transform: scale(0.7) rotate(6deg); } 100%{ transform: scale(0.8); }
  }

  /* ---------- Board ---------- */
       .board-wrap{
    background: var(--card);
    border-radius: 22px;
    padding: clamp(8px, 2.5vh, 14px);
    box-shadow: 0 18px 40px -12px rgba(0,0,0,0.55), 0 2px 0 rgba(255,255,255,0.03) inset;
    width: min(380px, 100%, 48vh);
    margin: 0 auto clamp(8px, 2vh, 18px);
    position: relative;
    box-sizing: border-box;
    flex-shrink: 1;
  }
  .board-loading{
    position:absolute; inset:14px; border-radius:14px;
    background: var(--card);
    display:none; flex-direction:column; align-items:center; justify-content:center; gap:12px;
    font-weight:700; font-size:13px; color: var(--ink-soft);
  }
  .board-loading.show{ display:flex; }
  .spinner{
    width:28px; height:28px; border-radius:50%;
    border: 3px solid rgba(42,34,51,0.12);
    border-top-color: var(--marigold-dark);
    animation: spin .8s linear infinite;
  }
  @keyframes spin{ to{ transform: rotate(360deg); } }
    .board{
    display: grid;
    gap: 0;
    touch-action: manipulation;
    background: rgba(42,34,51,0.35);
    border-radius: 10px;
  }
   .cell{
    position: relative;
    aspect-ratio: 1/1;
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    user-select:none;
    transition: background-color .25s ease;
  }
    .cell.cell-enter{
    animation: cellEnter .65s cubic-bezier(.34,1.56,.64,1) both;
  }
  @keyframes cellEnter{
    0%{ opacity:0; transform: scale(0.35) rotate(-8deg); }
    60%{ opacity:1; transform: scale(1.08) rotate(3deg); }
    100%{ opacity:1; transform: scale(1) rotate(0); }
  }
    .cell img.cat-icon{ width: 62%; height: 62%; object-fit: contain; }
    .cell .xmark{
    font-family:'Fredoka', sans-serif;
    font-weight:800;
    font-size: 1.4em;
    color: #fff;
    text-shadow: 0 1px 3px rgba(42,34,51,0.35);
    display: inline-block;
    animation: xmarkPop .3s cubic-bezier(.34,1.56,.64,1);
  }
  @keyframes xmarkPop{
    0%{ transform: scale(0) rotate(-20deg); opacity:0; }
    60%{ transform: scale(1.25) rotate(6deg); opacity:1; }
    100%{ transform: scale(1) rotate(0); }
  }
  .cell.given{ cursor: default; }
  .cell.given::after{
    content:''; position:absolute; inset: 8%;
    border-radius: 8px;
    box-shadow: inset 0 0 0 2px rgba(42,34,51,0.18);
    pointer-events:none;
  }
     .cell img.cat-icon{
    animation: catBreathe 2.6s ease-in-out .4s infinite;
    transform-origin: 50% 60%;
  }
  .cell.pop .cat-icon{
    animation: catPop .4s cubic-bezier(.34,1.56,.64,1), catBreathe 2.6s ease-in-out .4s infinite;
  }
  @keyframes catPop{
    0%{ transform: scale(0) rotate(-15deg); opacity:0; }
    60%{ transform: scale(1.18) rotate(4deg); opacity:1; }
    100%{ transform: scale(1) rotate(0); }
  }
    @keyframes catBreathe{
    0%, 100%{ transform: scale(1); }
    50%{ transform: scale(1.15); }
  }
  .cell.shake{ animation: shakeCell .4s; }
  @keyframes shakeCell{
    0%,100%{ transform: translateX(0); }
    20%{ transform: translateX(-6px); }
    40%{ transform: translateX(6px); }
    60%{ transform: translateX(-4px); }
    80%{ transform: translateX(4px); }
  }
        .cell.flash-bad{ background: rgba(226,116,138,0.55) !important; }
  .cell.cell-exit .cat-icon{
    animation: catExit .26s ease forwards;
  }
  @keyframes catExit{
    0%{ transform: scale(1) rotate(0); opacity: 1; }
    100%{ transform: scale(0.2) rotate(-14deg); opacity: 0; }
  }

          .score-popup{
    position: absolute;
    margin-left: 6px;
    --popX: 0%;
    transform: translate(var(--popX), -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    pointer-events: none;
    z-index: 50;
    animation: scorePopup 1s ease-out forwards;
    white-space: nowrap;
  }
  .score-popup.score-popup-left{
    margin-left: 0;
    margin-right: 6px;
    --popX: -100%;
  }
        .score-confetti-piece{
    position: absolute;
    width: 7px; height: 11px;
    margin: -5px 0 0 -3px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 49;
           animation: scoreConfettiBurst 2.2s cubic-bezier(.25,.75,.4,1) forwards;
  }
  @keyframes scoreConfettiBurst{
    0%{ transform: translate(0,0) rotate(0deg) scale(1); opacity: 1; }
    100%{ transform: translate(var(--dx), calc(var(--dy) + 60px)) rotate(var(--rot)) scale(0.6); opacity: 0; }
  }

   .score-popup .score-praise{
    font-family:'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 13px;
    -webkit-text-stroke: 0.6px #000000;
    paint-order: stroke fill;
  }
  .score-popup .score-amount{
    font-family:'Fredoka', sans-serif;
    font-weight: 800;
    font-size: 20px;
    -webkit-text-stroke: 0.8px #000000;
    paint-order: stroke fill;
  }
       @keyframes scorePopup{
    0%{ transform: translate(var(--popX), -50%) scale(0.5); opacity: 0; }
    15%{ transform: translate(var(--popX), -50%) scale(1.15); opacity: 1; }
    30%{ transform: translate(var(--popX), -50%) scale(1); opacity: 1; }
    100%{ transform: translate(var(--popX), -130%) scale(1); opacity: 0; }
  }

  /* ---------- Controls ---------- */
      .controls{
    display:flex; gap: clamp(14px, 4vw, 28px); width:100%; margin-bottom: clamp(4px, 1.5vh, 10px);
    justify-content:center; align-items:center;
    flex-shrink: 0;
  }
  button{
    font-family:'Karla', sans-serif; font-weight:700; font-size: 13.5px;
    border:none; cursor:pointer;
    border-radius: 14px;
    padding: 12px 14px;
    display:flex; align-items:center; justify-content:center; gap:6px;
    transition: transform .12s ease, filter .12s ease;
  }
      button:active{ transform: scale(0.95); }
    .icon-btn{
    background:none; border:none; padding:0; box-shadow:none; flex:none;
    position: relative;
  }
    .hint-badge{
    position: absolute; top: -2px; right: -2px;
    min-width: 20px; height: 20px; padding: 0 4px;
    border-radius: 999px;
    background: #FF0000;
    color: #fff;
    font-family: 'Karla', sans-serif; font-weight: 800; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2px var(--bg);
  }
  .hint-badge.zero{
    background: var(--card);
    color: var(--ink);
  }
         .icon-btn img{
    width: clamp(44px, 9vh, 72px); height: clamp(44px, 9vh, 72px); object-fit: contain;
    transition: transform .18s ease;
  }
  
  .icon-btn:hover img{ transform: scale(1.1) rotate(-4deg); }
  .icon-btn:active img{ transform: scale(0.9); }
  .btn-icon{ width: 20px; height: 20px; object-fit: contain; flex-shrink:0; }
  .btn-secondary{
    flex:1;
    background: rgba(251,243,231,0.08);
    color: var(--card);
    border: 1px solid rgba(251,243,231,0.14);
  }
  .btn-secondary:hover{ background: rgba(251,243,231,0.14); }
  .btn-secondary:disabled{ opacity:0.35; cursor:default; }
    .btn-primary{
    flex:1;
    background: linear-gradient(180deg, #F5B876, var(--marigold-dark));
    color: #2A1B0C;
    box-shadow: 0 4px 0 #9C6425;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .btn-primary:hover{ transform: translateY(-2px) scale(1.02); box-shadow: 0 6px 0 #9C6425; }
  .btn-primary:active{ box-shadow: 0 1px 0 #9C6425; transform: translateY(3px) scale(0.98); }

         .rules-toggle{
    background:none; color: #FFFFFF; font-size:12px; font-weight:600;
    padding: 6px 4px; text-decoration: underline; text-underline-offset:3px;
    flex-shrink: 0;
    transition: transform .18s ease;
  }
  .rules-toggle:hover{
    transform: scale(1.06);
  }
  .rules{
    width:100%;
    background: rgba(251,243,231,0.06);
    border: 1px solid rgba(251,243,231,0.1);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 12.8px;
    line-height: 1.65;
    color: #D9D2E6;
    margin-top: 4px;
    display:none;
  }
  .rules.open{ display:block; }
  .rules b{ color: var(--marigold); }
  .rules ol{ margin: 6px 0 0; padding-left: 18px; }

        .rules-modal-text{
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .rule-row{
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(107,66,38,0.06);
    border-radius: 14px;
    padding: 10px 14px;
  }
  .rule-text{
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
  }
  .rule-tap{
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-top: 2px;
  }
  .rule-diagram{
    display: grid;
    gap: 3px;
    flex-shrink: 0;
  }
  .diagram-3x3{
    grid-template-columns: repeat(3, 22px);
    grid-template-rows: repeat(3, 22px);
  }
  .diagram-patch{
    grid-template-columns: repeat(2, 26px);
    grid-template-rows: 26px;
  }
  .rule-cell{
    border-radius: 5px;
    background: rgba(107,66,38,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
  }
   .rule-cell.dog{
    background: rgba(230,138,46,0.18);
    font-size: 13px;
  }
  .rule-cell img.rule-dog-icon{
    width: 80%;
    height: 80%;
    object-fit: contain;
    pointer-events: none;
  }
  .rule-cell.mark{
    color: var(--rose);
    font-weight: 800;
    font-size: 11px;
  }
  .rule-cell.patch-a{
    background: #FCE1A8;
    font-size: 14px;
    border-radius: 6px;
  }
  .rule-cell.patch-b{
    background: #BFE3C7;
    font-size: 14px;
    border-radius: 6px;
  }
  /* ---------- Win Modal ---------- */
    .win-backdrop{
    position:fixed; inset:0; background: rgba(20,15,30,0.72);
    display:none; align-items:center; justify-content:center; z-index: 60;
    backdrop-filter: blur(2px);
    padding: 20px;
    opacity: 0;
    transition: opacity .3s ease;
  }
  .win-backdrop.visible{ display:flex; }
  .win-backdrop.show{ opacity: 1; }
  .win-modal{
    position:relative;
    background: var(--card);
    border: 4px solid var(--ink);
    border-radius: 26px;
    padding: 30px 24px 26px;
    width: min(340px, 90vw);
    text-align:center;
    overflow: hidden;
    box-shadow: 0 20px 45px -10px rgba(0,0,0,0.5);
    transform: scale(0.7) translateY(30px);
    opacity: 0;
    transition: transform .38s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
  }
  .win-backdrop.show .win-modal{
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  .win-confetti{
    position:absolute; inset:0; pointer-events:none; overflow:hidden;
    border-radius: 22px;
  }
  .confetti-piece{
    position:absolute; top:-12px;
    width:8px; height:14px;
    opacity:0.95;
    animation-name: confettiFall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
  }
  @keyframes confettiFall{
    0%{ transform: translateY(0) rotate(0deg); opacity:1; }
    85%{ opacity:1; }
    100%{ transform: translateY(360px) rotate(540deg); opacity:0; }
  }
        .streak-celebration{
    position: fixed; inset: 0;
    background: rgba(20,15,30,0.78);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center; justify-content: center;
    z-index: 90;
    pointer-events: none;
    opacity: 1;
  }
    .streak-celebration.show{ display:flex; animation: streakCelebIn .5s ease forwards; }
  @keyframes streakCelebIn{ from{ opacity:0; } to{ opacity:1; } }
  .streak-celebration.fade-out{ animation: streakCelebFade .7s ease forwards; }
  @keyframes streakCelebFade{ to{ opacity:0; } }

    .streak-celebration-glow{
    position:absolute;
    width: 480px; height:480px;
    border-radius:50%;
    background: radial-gradient(circle, rgba(255,214,0,0.95) 0%, rgba(255,193,7,0.5) 45%, rgba(255,193,7,0) 72%);
    opacity: 0;
    transform: scale(0.6);
  }
  .streak-celebration-glow.charging{
    animation: streakCharge 2.6s ease-in-out forwards;
  }
    @keyframes streakCharge{
    0%{ opacity:0; transform:scale(0.3); }
    15%{ opacity:0.6; transform:scale(0.667); }
    100%{ opacity:1; transform:scale(1); }
  }

  .streak-celebration-rays{
    position:absolute;
    width: 460px; height:460px;
    opacity:0;
    border-radius:50%;
    background: conic-gradient(from 0deg,
      transparent 0deg, rgba(255,214,120,0.95) 8deg, transparent 20deg,
      transparent 40deg, rgba(255,214,120,0.95) 48deg, transparent 60deg,
      transparent 80deg, rgba(255,214,120,0.95) 88deg, transparent 100deg,
      transparent 120deg, rgba(255,214,120,0.95) 128deg, transparent 140deg,
      transparent 160deg, rgba(255,214,120,0.95) 168deg, transparent 180deg,
      transparent 200deg, rgba(255,214,120,0.95) 208deg, transparent 220deg,
      transparent 240deg, rgba(255,214,120,0.95) 248deg, transparent 260deg,
      transparent 280deg, rgba(255,214,120,0.95) 288deg, transparent 300deg,
      transparent 320deg, rgba(255,214,120,0.95) 328deg, transparent 340deg,
      transparent 360deg);
  }
  .streak-celebration-rays.burst{
    animation: streakBurst 1.1s ease-out forwards;
  }
  @keyframes streakBurst{
    0%{ opacity:0; transform: scale(0.3) rotate(0deg); }
    35%{ opacity:1; }
    100%{ opacity:0; transform: scale(2.1) rotate(50deg); }
  }

  .streak-celebration-icon{
    position:relative;
    width: 210px; height:210px;
    object-fit: contain;
    transform: scale(0.9);
    filter: drop-shadow(0 10px 24px rgba(0,0,0,0.45));
  }
  .streak-celebration-icon.pulse{
    animation: streakIconPulse 1.6s ease-in-out infinite;
  }
  @keyframes streakIconPulse{
    0%,100%{ transform: scale(0.88); }
    50%{ transform: scale(1.08); }
  }
    .streak-celebration-icon.pop{
    animation: streakIconPop .9s cubic-bezier(.34,1.56,.64,1) forwards;
  }
  @keyframes streakIconPop{
    0%{ transform: scale(0.6) rotate(-10deg); }
    55%{ transform: scale(1.3) rotate(6deg); }
    100%{ transform: scale(1) rotate(0deg); }
  }
    .streak-celebration-icon.settle-pulse{
    animation: streakIconSettlePulse 2s ease-in-out infinite;
  }
  @keyframes streakIconSettlePulse{
    0%,100%{ transform: scale(1); }
    50%{ transform: scale(1.1); }
  }

  .streak-celebration-count{
    position:absolute;
    bottom: calc(50% - 250px);
    font-family:'Fredoka', sans-serif;
    font-weight:800;
    font-size: 30px;
    color:#fff;
    -webkit-text-stroke:1.4px #000;
    paint-order: stroke fill;
    opacity:0;
  }
  .streak-celebration-count.show-count{
    animation: streakCountIn .7s ease-out forwards;
  }
  @keyframes streakCountIn{
    0%{ opacity:0; transform: translateY(10px) scale(0.8); }
    100%{ opacity:1; transform: translateY(0) scale(1); }
  }

    .win-puppy{
    width: 140px; height:auto;
    position: relative;
    z-index: 2;
    margin-top: 6px;
    margin-bottom: 18px;
    animation: winPuppyBounce 1.1s ease-in-out infinite;
    filter: drop-shadow(0 10px 14px rgba(0,0,0,0.3));
  }
  
  @keyframes winPuppyBounce{
    0%,100%{ transform: translateY(0) rotate(-3deg); }
    50%{ transform: translateY(-14px) rotate(3deg); }
  }
  
  .win-title{
    position:relative; z-index:2;
    font-family:'Fredoka', sans-serif;
    font-weight:700;
    font-size: 36px;
    color:#FFF6E4;
    text-shadow:
      -2px -2px 0 #6B4226, 2px -2px 0 #6B4226,
      -2px  2px 0 #6B4226, 2px  2px 0 #6B4226,
       0 5px 0 #5A3620;
    margin: 4px 0 6px;
    letter-spacing: 1px;
  }
  .win-text{
    position:relative; z-index:2;
    font-size: 13.5px;
    color:#4A2E14;
    font-weight:600;
    margin: 0 0 20px;
    opacity:0.9;
  }
      .win-continue{
    position:relative; z-index:2;
    width:100%;
    background: #FBF3E7;
    color: #6B4226;
    border: 2px solid #6B4226;
    border-radius: 999px;
    box-shadow: 0 3px 0 #6B4226;
  }
  .win-continue:active{ box-shadow: 0 1px 0 #6B4226; transform: translateY(2px) scale(0.98); }

    /* ---------- Modal (Out of lives) ---------- */
  .modal-backdrop{
    position:fixed; inset:0; background: rgba(20,15,30,0.72);
    display:none; align-items:center; justify-content:center; z-index: 50;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .3s ease;
  }
    .modal-backdrop.visible{ display:flex; }
  .modal-backdrop.show{ opacity: 1; }
  .modal{
    position: relative;
    background: var(--card); color: var(--ink);
    border: 4px solid var(--ink);
    border-radius: 26px; padding: 28px 24px 24px; text-align:center;
    width: min(320px, 84vw);
    box-shadow: 0 20px 45px -10px rgba(0,0,0,0.5);
    transform: scale(0.7) translateY(30px);
    opacity: 0;
    transition: transform .38s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
  }
  .modal-backdrop.show .modal{
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  .modal-puppy{
    width: 140px; height: auto;
    object-fit: contain;
    margin: 4px auto 10px;
    display: block;
    filter: drop-shadow(0 8px 10px rgba(0,0,0,0.25));
  }
  .modal-puppy.flop{
    animation: pupFlop .5s cubic-bezier(.34,1.56,.64,1);
  }
  @keyframes pupFlop{
    0%{ transform: scale(0.6) translateY(-10px); opacity:0; }
    60%{ transform: scale(1.08) translateY(2px); opacity:1; }
    100%{ transform: scale(1) translateY(0); }
  }
  .modal h2{ font-family:'Fredoka',sans-serif; margin:0 0 6px; font-size:24px; color:#B24B5C; }
  .modal p{ font-size: 13.5px; color:#6B6379; margin: 0 0 20px; line-height:1.5; }
  .modal button{ width:100%; }

    footer{
    margin-top: auto; padding-top: 26px;
    font-size: 11px; color: rgba(251,243,231,0.28);
    text-align:center; line-height:1.6;
  }

    /* ---------- Title screen ---------- */
  .app{
    display:none;
    opacity:0;
    transform: translateY(16px) scale(0.98);
    transition: opacity .38s ease, transform .38s ease;
  }
  .app.visible{ display:flex; }
  .app.show{ opacity:1; transform: translateY(0) scale(1); }
     .title-screen{
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2vh 6vw;
    text-align: center;
    box-sizing: border-box;
    transition: opacity .38s ease, transform .38s ease;
  }
  .title-screen.fade-out{
    opacity: 0;
    transform: scale(0.94);
    pointer-events: none;
  }
  .title-logo-img{
  max-height: 20vh;
  width: auto;
  max-width: 65%;
  margin-bottom: 1vh;
}
  .streak-card{
  position: relative;
  height: 30vh;
  max-height: 300px;
  margin-top: 0;
  margin-bottom: 4vh;
}
.streak-card.streak-loading{ visibility: hidden; }
  .streak-card img.streak-bg{
    height: 100%;
    width: auto;
    display: block;
  }
  .streak-count{
    position: absolute;
    left: 9%;
    right: 9%;
    top: 77%;
    height: 15%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border-radius:999px;
    font-weight:800;
    font-size: clamp(16px, 2.6vh, 22px);
    color: var(--ink);
  }
  .title-btns{
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1.5vh;
    margin-top: 2vh;
  }
          .title-play{
    width: 100%;
    padding: 2vh 18px;
    font-size: clamp(15px, 2.2vh, 20px);
    margin: 0;
    background: #FFFFFF;
    color: var(--ink);
    border: 2px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .title-play:hover{ transform: translateY(-3px) scale(1.03); box-shadow: 0 7px 0 var(--ink); }
  .title-play:active{ box-shadow: 0 1px 0 var(--ink); transform: translateY(1px) scale(0.98); }
    .title-daily{
    width: 100%;
    background: #FFFFFF;
    color: var(--ink);
    font-size: clamp(15px, 2.2vh, 20px);
    font-weight: 800;
    text-decoration: none;
    border-radius: 14px;
    padding: 2vh 18px;
    border: 2px solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    margin: 0;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .title-daily:hover{ transform: translateY(-3px) scale(1.03); box-shadow: 0 7px 0 var(--ink); }
  .title-daily:active{ box-shadow: 0 1px 0 var(--ink); transform: translateY(1px) scale(0.98); }

  /* ---------- Streak button + Daily Streak screen ---------- */
.streak-card{
  background:none; border:none; padding:0; cursor:pointer; display:block;
  font:inherit; -webkit-appearance:none; appearance:none;
  transition: transform .18s ease;
}
.streak-card:hover{ transform: scale(1.04); }
.streak-card:active{ transform: scale(0.97); }

.streak-screen{
  position: fixed; inset: 0; z-index: 60;
  display:none;
  opacity: 0;
  transform: scale(0.94);
  transition: opacity .38s ease, transform .38s ease;
  background: transparent;
  overflow: hidden;
}
.streak-screen.visible{ display:block; }
.streak-screen.show{ opacity: 1; transform: scale(1); }

.streak-screen-inner{
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  padding: clamp(10px, 4vh, 22px) 22px clamp(10px, 4vh, 50px);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  box-sizing:border-box;
}
.streak-top{
  width:100%;
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom: 18px;
}
.streak-back, .app-back{
  width:56px; height:56px; border-radius:50%;
  padding:0; flex-shrink:0;
  background: none;
  display:flex; align-items:center; justify-content:center;
}
.streak-back:hover, .app-back:hover, .sfx-btn:hover{
  transform: scale(1.12) rotate(-6deg);
}
.streak-back{
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 65;
}
.streak-back img, .app-back img, .sfx-btn img{
  width:100%; height:100%; object-fit:contain;
  transition: transform .18s ease;
}
.app-back{
  display: none;
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 5;
  opacity: 0;
  transition: opacity .38s ease;
}
.app-back.visible{ display:flex; }
.app-back.show{ opacity: 1; }
.streak-title{
  font-family:'Fredoka', sans-serif; font-weight:700; font-size:19px;
  color:#FFFFFF;
  -webkit-text-stroke: 0.6px #6B4226;
  paint-order: stroke fill;
  margin:0;
}
.streak-top-spacer{ width:40px; }

  .streak-hero-bone{ width: 42%; max-width: min(210px, 24vh); height:auto; margin: clamp(2px,1vh,6px) 0 clamp(6px,2vh,14px); }

.streak-big-number{
  font-family:'Fredoka', sans-serif; font-weight:700; font-size: clamp(30px, 8vh, 52px);
  color:#FFFFFF;
  -webkit-text-stroke: 1px #6B4226;
  paint-order: stroke fill;
  line-height:1;
}
.streak-current-label{
  font-family:'Fredoka', sans-serif; font-weight:700; font-size:17px;
  color:#FFFFFF;
  -webkit-text-stroke: 0.6px #6B4226;
  paint-order: stroke fill;
  margin-top:6px;
}
.streak-best-pill{
  margin-top:10px; background:#fff; color:#6B4226; font-weight:700; font-size:13.5px;
  padding:8px 18px; border-radius:999px; box-shadow: 0 2px 6px rgba(107,66,38,0.12);
}

.streak-banner{
  width:100%; max-width:420px; max-height: 22vh; height:auto; object-fit: contain; margin-top: clamp(8px, 3vh, 26px); border-radius:16px;
}

.streak-week{
  width:100%; max-width:420px;
  display:flex; justify-content:space-between; align-items:flex-start; gap:6px;
  margin-top: clamp(8px, 2.5vh, 20px);
}
.streak-day{
  display:flex; flex-direction:column; align-items:center; gap:8px;
  flex:1;
}
.streak-day-label{
  font-size:11px; font-weight:700; letter-spacing:0.4px;
  color:#FFFFFF;
  -webkit-text-stroke: 0.5px #6B4226;
  paint-order: stroke fill;
}
.streak-day.is-today .streak-day-label{ color:#FFFFFF; }
.streak-day-icon{
  width: clamp(26px, 5vh, 38px); height: clamp(26px, 5vh, 38px);
  display:flex; align-items:center; justify-content:center;
  overflow: hidden;
}
.streak-day-icon img{ width:100%; height:100%; object-fit:contain; }
.streak-day-icon.done{
  background:#E68A2E; border-radius:50%;
  box-shadow: 0 0 0 2px #FFFFFF;
}
.streak-day-icon.done::after{
  content:'✓'; color:#fff; font-weight:800; font-size:16px;
  -webkit-text-stroke: 1.5px #FFFFFF;
  paint-order: stroke fill;
}

/* ---------- SFX toggle button (always on top, top-right) ---------- */
.sfx-btn{
  position: fixed;
  top: 18px;
  right: 18px;
  width: 56px; height: 56px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  z-index: 200;
  transition: opacity .38s ease, transform .18s ease;
}
.sfx-btn.fade-out{
  opacity: 0;
  pointer-events: none;
}
.sfx-btn img{
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.sfx-btn:active{ transform: scale(0.95); }

/* ---------- Avatar button (title screen) ---------- */
.avatar-btn{
  position: fixed;
  top: 18px;
  left: 18px;
  width: 56px; height: 56px;
  padding: 0;
  border: 3px solid #6B4226;
  border-radius: 14px;
  background: #FBF3E7;
  overflow: hidden;
  cursor: pointer;
  z-index: 5;
  transition: opacity .38s ease, transform .18s ease;
}
.avatar-btn:hover{ transform: scale(1.1) rotate(-4deg); }
.avatar-btn.fade-out{
  opacity: 0;
  pointer-events: none;
}
.avatar-btn img{
  width: 100%; height: 100%;
  object-fit: contain;
  padding: 4px;
  display: block;
}
.avatar-btn:active{ transform: scale(0.95); }

/* ---------- Profile modal ---------- */
.profile-backdrop{
  display: none; align-items: center; justify-content: center; z-index: 70;
  position: fixed; inset: 0; background: rgba(20,15,30,0.72);
  backdrop-filter: blur(2px);
  padding: 20px;
  opacity: 0;
  transition: opacity .3s ease;
}
#profileBackdrop.profile-backdrop.visible{ display:flex; }
#profileBackdrop.profile-backdrop.show{ opacity: 1; }
.profile-modal{
  background: var(--card); color: var(--ink);
  border-radius: 20px; padding: 26px 22px;
  width: min(360px, 92vw);
  animation: none;
  transform: scale(0.7) translateY(30px);
  opacity: 0;
  transition: transform .38s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
}
#profileBackdrop.show .profile-modal{
  transform: scale(1) translateY(0);
  opacity: 1;
}
#rulesBackdrop.profile-backdrop{
  opacity: 0;
  transition: opacity .3s ease;
}
#rulesBackdrop.profile-backdrop.show{
  opacity: 1;
}
#rulesBackdrop.visible{ display:flex; }
#rulesBackdrop .profile-modal{
  border: 3px solid var(--ink);
  animation: none;
  transform: scale(0.7) translateY(30px);
  opacity: 0;
  transition: transform .38s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
}
#rulesBackdrop.show .profile-modal{
  transform: scale(1) translateY(0);
  opacity: 1;
}
.profile-top{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom: 18px;
}
.profile-title{
  font-family:'Fredoka', sans-serif; font-weight:700; font-size:22px;
  color: var(--ink); margin:0;
}
.profile-close{
  width:34px; height:34px; border-radius:50%;
  background:none; color: var(--ink);
  display:flex; align-items:center; justify-content:center;
  font-size:16px; padding:0;
}
.profile-id-row{
  display:flex; align-items:center; gap:14px;
  margin-bottom: 20px;
}
.profile-avatar-preview{
  width:64px; height:64px; border-radius:14px;
  border: 3px solid #8FC94A;
  background: rgba(107,66,38,0.06);
  object-fit: contain; padding: 4px;
  flex-shrink:0;
}
.profile-name-box{
  flex:1;
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  background: rgba(107,66,38,0.06);
  border-radius: 999px;
  padding: 10px 8px 10px 18px;
}
.profile-name-input{
  flex:1; min-width:0; border:none; background:none; outline:none;
  font-family:'Karla', sans-serif; font-weight:700; font-size:15px;
  color: var(--ink);
}
.profile-name-edit{
  width:30px; height:30px; border-radius:50%;
  background: var(--marigold);
  color:#fff; font-size:13px;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.profile-avatar-label{
  font-weight:700; font-size:13px; color: var(--ink-soft);
  margin-bottom:10px;
}
.profile-avatar-grid{
  display:grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.avatar-option{
  position:relative;
  border-radius:14px; padding:0; border:none; overflow:hidden;
  aspect-ratio: 1 / 1;
  background: rgba(107,66,38,0.06);
  cursor:pointer;
}
.avatar-option img{ width:100%; height:100%; object-fit:contain; padding:6px; box-sizing:border-box; display:block; }
.avatar-option.selected{ box-shadow: 0 0 0 3px var(--sage); }
.avatar-check{
  position:absolute; right:4px; bottom:4px;
  width:18px; height:18px; border-radius:50%;
  background: var(--sage); color:#fff;
  font-size:11px; font-weight:800;
  display:none; align-items:center; justify-content:center;
}
.avatar-option.selected .avatar-check{ display:flex; }
.profile-confirm{ width:100%; }

/* ---------- Tutorial ---------- */
.tutorial-screen{
  display:none;
  position:fixed; inset:0; z-index:120;
  background: url('Background.jpg');
  background-repeat: repeat; background-size:340px auto;
  align-items:center; justify-content:center;
  padding: 24px 18px;
  box-sizing:border-box;
}
.tutorial-screen.show{ display:flex; }
.tutorial-board-wrap{
  background: var(--card);
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 18px 40px -12px rgba(0,0,0,0.55), 0 2px 0 rgba(255,255,255,0.03) inset;
  width: 100%;
  max-width: 340px;
  box-sizing: border-box;
}
.tutorial-board{
  display:grid;
  gap:0;
  touch-action: manipulation;
}
.tutorial-curtain{
  display:none;
  position:fixed; inset:0; z-index:130;
  pointer-events:none;
}
.tutorial-curtain.show{ display:block; }
.tutorial-spotlight{
  position:fixed;
  border-radius: 0;
  box-shadow: 0 0 0 9999px rgba(20,15,30,0.78), inset 0 0 0 4px #F2A65A;
  pointer-events:none;
  transition: all .35s cubic-bezier(.4,0,.2,1);
}
.tutorial-finger{
  display:none;
  position:fixed;
  z-index:140;
  font-size: 30px;
  pointer-events:none;
  animation: fingerBounce 1s ease-in-out infinite;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}
.tutorial-finger.show{ display:block; }
@keyframes fingerBounce{
  0%,100%{ transform: translateY(0); }
  50%{ transform: translateY(-8px); }
}
.tutorial-card{
  display:none;
  position:fixed;
  left: calc(50% + 190px);
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  z-index:140;
  background: var(--card);
  color: var(--ink);
  border-radius:18px;
  padding: 16px 18px;
  width: min(260px, 26vw);
  box-shadow: 0 18px 40px -12px rgba(0,0,0,0.55);
  text-align:center;
}
.tutorial-card.show{ display:block; }

@media (max-width: 700px), (orientation: portrait){
  .tutorial-card{
    left: 50%;
    top: auto;
    bottom: 24px;
    transform: translateX(-50%);
    width: min(320px, 84vw);
  }
}
.tutorial-card-diagram{ display:flex; justify-content:center; margin-bottom:8px; }
.tutorial-card-text{
  font-family:'Fredoka', sans-serif; font-weight:600; font-size:15px;
  margin: 0 0 10px; line-height:1.4;
}
.tutorial-next{ width:100%; }
.tutorial-done-backdrop{
  display:none;
  position:fixed; inset:0; z-index:150;
  background: rgba(20,15,30,0.72);
  align-items:center; justify-content:center;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .3s ease;
}
.tutorial-done-backdrop.visible{ display:flex; }
.tutorial-done-backdrop.show{ opacity: 1; }
.tutorial-done-modal{
  background: var(--card); color: var(--ink);
  border-radius: 20px; padding: 30px 26px; text-align:center;
  width: min(320px, 84vw);
  border: 3px solid var(--ink);
  transform: scale(0.7) translateY(30px);
  opacity: 0;
  transition: transform .38s cubic-bezier(.34,1.56,.64,1), opacity .3s ease;
}
.tutorial-done-backdrop.show .tutorial-done-modal{
  transform: scale(1) translateY(0);
  opacity: 1;
}
.tutorial-done-puppy{ width: 40%; max-width:150px; margin: 0 auto 10px; display:block; border: 3px solid var(--ink); border-radius: 12px; }
.tutorial-done-title{ font-family:'Fredoka',sans-serif; margin:0 0 6px; font-size:22px; }
.tutorial-done-text{ font-size: 13.5px; color: var(--ink); margin: 0 0 20px; line-height:1.5; }
#tutorialDoneBtn{
  display:block; margin:0 auto; width:auto; min-width:160px;
  background:#FFFFFF; color: var(--ink);
  border: 2px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
}
#tutorialDoneBtn:active{ box-shadow: 0 1px 0 var(--ink); }

/* ===== Bigger game view on desktop only (not mobile) ===== */
@media (min-width: 701px) and (orientation: landscape){
  .app{
    max-width: 700px;
  }
  .board-wrap{
    width: min(600px, 100%, 68vh);
  }
  .hud{
    max-width: 560px;
  }
}