/* Turtle Trails — game styles. GameKit tokens loaded first. */

:root {
    --tt-water-top: #7FD4E6;
    --tt-water-mid: #4FBEDA;
    --tt-water-deep: #2AA6C8;
    --tt-cell-a: #BFF0F7;
    --tt-cell-b: #A6E6F2;
    --tt-sand: #F4E4BE;
    --tt-sand-dk: #E4CB94;
    --tt-ink: #245A66;
}

html, body { overflow: hidden; }
body { background: var(--tt-water-mid); color: var(--tt-ink); }

.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ═══════════ Backdrop ═══════════ */

#backdrop { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bk-water {
    position: absolute; inset: 0;
    background: linear-gradient(to bottom, var(--tt-water-top) 0%, var(--tt-water-mid) 52%, var(--tt-water-deep) 100%);
}
.bk-sun { position: absolute; top: 4%; right: 8%; width: clamp(90px, 13vw, 150px); animation: tt-sun 8s ease-in-out infinite; }
.bk-shimmer { position: absolute; top: 12%; left: 0; width: 100%; height: 26%; opacity: .8; }
.bk-seabed { position: absolute; bottom: 0; left: 0; width: 100%; height: 30%; }
.bk-weed { position: absolute; bottom: 0; width: clamp(70px, 12vw, 120px); transform-origin: bottom center; animation: tt-sway 5s ease-in-out infinite; }
.bk-weed-l { left: 2%; }
.bk-weed-r { right: 2%; transform: scaleX(-1); animation-delay: -2.5s; }

@keyframes tt-sun  { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes tt-sway { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.bk-weed-r { animation-name: tt-sway-r; }
@keyframes tt-sway-r { 0%,100% { transform: scaleX(-1) rotate(-4deg); } 50% { transform: scaleX(-1) rotate(4deg); } }

/* ═══════════ Title ═══════════ */

.title-inner {
    position: relative; z-index: 10;
    width: 100%; max-width: 640px;
    height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    padding: clamp(14px, 4vh, 40px) 18px clamp(18px, 4vh, 44px);
    text-align: center;
}
.game-title {
    font-size: clamp(2.4rem, 9vw, 4.2rem);
    color: #fff;
    line-height: 1.02;
    letter-spacing: 1px;
    text-shadow: 0 4px 0 #2AA6C8, 0 8px 16px rgba(20, 60, 70, .35);
}
.tagline {
    margin-top: 8px;
    font-size: clamp(.95rem, 3.2vw, 1.25rem);
    color: #f0fbff;
    font-weight: bold;
    text-shadow: 0 2px 6px rgba(20, 60, 70, .35);
}
.t-shelly { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
#title-shelly { width: clamp(150px, 42vw, 240px); animation: tt-bob 3s ease-in-out infinite; }
@keyframes tt-bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-14px) rotate(2deg); } }
.t-controls { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }

.start-btn {
    min-width: 220px; min-height: 72px;
    padding: 14px 44px;
    font-size: clamp(1.3rem, 5vw, 1.7rem);
    font-weight: bold; color: #fff;
    background: linear-gradient(135deg, #FF9E44 0%, #F77F00 100%);
    border: none; border-radius: 50px; cursor: pointer;
    box-shadow: 0 8px 0 #C96400, 0 12px 22px rgba(20, 60, 70, .3);
    transition: transform .12s, box-shadow .12s;
}
.start-btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #C96400, 0 6px 12px rgba(20, 60, 70, .3); }
.btn-pulse { display: inline-block; animation: tt-pulse 1.4s ease-in-out infinite; }
@keyframes tt-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.title-row { display: flex; align-items: center; gap: 12px; }
.star-pill {
    background: rgba(255, 255, 255, .92);
    color: var(--tt-ink); font-weight: bold;
    padding: 8px 18px; border-radius: 40px; font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(20, 60, 70, .2);
}

#level-row { display: flex; gap: clamp(10px, 3vw, 20px); flex-wrap: wrap; justify-content: center; }
.lvl-btn {
    position: relative;
    width: clamp(78px, 20vw, 104px); height: clamp(78px, 20vw, 104px);
    border: 4px solid #fff; border-radius: 22px;
    background: rgba(255, 255, 255, .82);
    box-shadow: 0 6px 16px rgba(20, 60, 70, .22);
    cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; transition: transform .14s;
}
.lvl-btn:active { transform: scale(.94); }
.lvl-btn .lvl-num {
    font-size: clamp(1.6rem, 6vw, 2.2rem); font-weight: bold; color: var(--tt-water-deep); line-height: 1;
}
.lvl-btn .lvl-cap { font-size: .72rem; font-weight: bold; color: var(--tt-ink); opacity: .8; }
.lvl-btn .lvl-stars { font-size: .82rem; letter-spacing: 1px; }
.lvl-btn .lvl-stars .dim { filter: grayscale(1) opacity(.4); }
.lvl-btn .lvl-lock { position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
    font-size: 2rem; background: rgba(255, 255, 255, .72); border-radius: 18px; }
.lvl-btn.locked { cursor: default; }
.lvl-btn.locked .lvl-lock { display: flex; }
.lvl-btn.just-unlocked { animation: tt-unlock .7s cubic-bezier(.2,1.5,.4,1); }
@keyframes tt-unlock { 0% { transform: scale(.6) rotate(-8deg); } 60% { transform: scale(1.14) rotate(4deg); } 100% { transform: scale(1); } }
.lvl-btn.shake { animation: tt-shake .4s; }
@keyframes tt-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ═══════════ Play top bar ═══════════ */

#screen-play { justify-content: flex-start; }
#playtop {
    position: relative; z-index: 20;
    width: 100%; max-width: 680px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px 6px;
}
#level-tag {
    background: rgba(255, 255, 255, .9); color: var(--tt-water-deep);
    font-weight: bold; font-size: clamp(.9rem, 3vw, 1.1rem);
    padding: 8px 16px; border-radius: 30px; box-shadow: 0 4px 10px rgba(20, 60, 70, .18);
}
#move-pill {
    display: flex; align-items: center; gap: 6px;
    background: rgba(255, 255, 255, .9); color: var(--tt-ink);
    font-weight: bold; font-size: clamp(1rem, 3.4vw, 1.25rem);
    padding: 8px 16px; border-radius: 30px; box-shadow: 0 4px 10px rgba(20, 60, 70, .18);
}
#move-pill .mp-ic { font-size: 1.1em; }
#move-pill .mp-par { font-size: .72em; opacity: .7; font-weight: bold; }
#move-count.bump { animation: tt-count 0.3s ease; }
@keyframes tt-count { 0% { transform: scale(1); } 40% { transform: scale(1.45); color: var(--tt-orange, #F77F00); } 100% { transform: scale(1); } }

.reset-btn {
    width: 52px; height: 52px; border: none; border-radius: 50%;
    background: rgba(255, 255, 255, .92); color: var(--tt-water-deep);
    font-size: 1.7rem; cursor: pointer; box-shadow: 0 4px 10px rgba(20, 60, 70, .2);
    display: flex; align-items: center; justify-content: center;
    transition: transform .15s;
}
.reset-btn:active { transform: rotate(-160deg) scale(.9); }
.reset-ic { line-height: 1; font-weight: bold; }

/* ═══════════ Board ═══════════ */

#board-wrap {
    flex: 1; width: 100%;
    display: flex; align-items: center; justify-content: center;
    position: relative; z-index: 15;
    padding: 6px 10px; min-height: 0;
}
#board {
    position: relative;
    border-radius: 20px;
    background: rgba(20, 90, 110, .18);
    box-shadow: 0 10px 30px rgba(20, 60, 70, .28), inset 0 0 0 4px rgba(255, 255, 255, .3);
    padding: 0;
}

.cell {
    position: absolute; border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, .5), inset 0 -3px 6px rgba(20, 90, 110, .18);
}
.cell.light { background: var(--tt-cell-a); }
.cell.dark  { background: var(--tt-cell-b); }
.cell .ripple {
    position: absolute; left: 18%; top: 24%; width: 30%; height: 12%;
    border-radius: 50%; background: rgba(255, 255, 255, .45);
}

.sprite { position: absolute; pointer-events: none; }
.sprite svg { width: 100%; height: 100%; display: block; }

.sp-target { z-index: 2; }
.sp-target.filled .tt-target-svg { animation: tt-target-lit 1.2s ease infinite; }
@keyframes tt-target-lit { 0%,100% { filter: none; } 50% { filter: drop-shadow(0 0 8px #FFD86B); } }

.sp-rock { z-index: 6; }
.sp-egg  { z-index: 5; }
.sp-egg.wobble .tt-egg-body { animation: tt-egg-wobble .5s ease-in-out 3; transform-origin: 50% 82%; transform-box: fill-box; }
@keyframes tt-egg-wobble { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-11deg); } 75% { transform: rotate(11deg); } }
.sp-egg.crack { animation: tt-egg-pop .4s ease forwards; }
@keyframes tt-egg-pop { to { transform: scale(.2); opacity: 0; } }

.sp-shell { z-index: 8; transition: transform .18s cubic-bezier(.3,1.3,.5,1); }
.sp-shell.pushed .tt-shell-body { animation: tt-shell-squish .3s ease; }
@keyframes tt-shell-squish { 0% { transform: scale(1); } 40% { transform: scale(1.14, .86); } 100% { transform: scale(1); } }

.sp-turtle { z-index: 12; transition: transform .17s cubic-bezier(.3,1.25,.5,1); }
.sp-turtle.step .tt-turtle-body { animation: tt-hop .2s ease; }
@keyframes tt-hop { 0% { transform: translateY(0) scale(1); } 45% { transform: translateY(-10%) scale(1.05,.95); } 100% { transform: translateY(0) scale(1); } }
.sp-turtle.blocked { animation: tt-nudge .25s ease; }
@keyframes tt-nudge { 0%,100% { } 50% { } }
.sp-turtle .tt-turtle-head { transform-origin: 50% 22%; transform-box: fill-box; }
.sp-baby { z-index: 13; }
.sp-baby.hatch { animation: tt-baby-rise .6s cubic-bezier(.2,1.5,.4,1); }
@keyframes tt-baby-rise { 0% { transform: translateY(30%) scale(.2); opacity: 0; } 60% { transform: translateY(-6%) scale(1.12); opacity: 1; } 100% { transform: translateY(0) scale(1); } }

.spark {
    position: absolute; width: 22px; height: 22px; z-index: 20; pointer-events: none;
    animation: tt-spark .9s ease-out forwards;
}
@keyframes tt-spark {
    0% { transform: scale(0) rotate(0); opacity: 0; }
    30% { transform: scale(1.2) rotate(40deg); opacity: 1; }
    100% { transform: scale(.3) rotate(140deg) translateY(-26px); opacity: 0; }
}

/* ═══════════ D-pad ═══════════ */

#dpad {
    position: relative; z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, clamp(62px, 15vw, 84px));
    grid-template-rows: repeat(3, clamp(62px, 15vw, 84px));
    gap: 8px;
    margin: 6px 0 clamp(12px, 3vh, 26px);
}
.dpad-btn {
    border: none; border-radius: 20px; cursor: pointer;
    background: linear-gradient(150deg, #35B7D6 0%, #1E9BC0 100%);
    box-shadow: 0 6px 0 #157C9C, 0 8px 16px rgba(20, 60, 70, .3);
    display: flex; align-items: center; justify-content: center;
    padding: 14%;
    transition: transform .1s, box-shadow .1s, background .1s;
    min-width: 48px; min-height: 48px;
}
.dpad-btn:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 #157C9C, 0 3px 8px rgba(20, 60, 70, .3);
}
.dpad-btn.nudge-hint { animation: tt-hintpulse 1s ease-in-out infinite; }
@keyframes tt-hintpulse {
    0%, 100% { background: linear-gradient(150deg, #35B7D6 0%, #1E9BC0 100%); transform: scale(1); }
    50% { background: linear-gradient(150deg, #FFCf5A 0%, #F79E1E 100%); transform: scale(1.08); }
}
.dpad-hub {
    grid-area: 2 / 2 / 3 / 3;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #E8F8FC, #BDEBF4);
    box-shadow: inset 0 -3px 6px rgba(20, 90, 110, .25);
    margin: 22%;
}
.d-up    { grid-area: 1 / 2 / 2 / 3; }
.d-left  { grid-area: 2 / 1 / 3 / 2; }
.d-right { grid-area: 2 / 3 / 3 / 4; }
.d-down  { grid-area: 3 / 2 / 4 / 3; }
.tt-arrow-svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 2px rgba(20,60,70,.25)); }
.d-up    .tt-arrow-svg { transform: rotate(0deg); }
.d-right .tt-arrow-svg { transform: rotate(90deg); }
.d-down  .tt-arrow-svg { transform: rotate(180deg); }
.d-left  .tt-arrow-svg { transform: rotate(-90deg); }

/* ═══════════ Ghost hand ═══════════ */

#ghost-hand {
    position: fixed; z-index: 800; width: 74px; height: 92px;
    pointer-events: none;
    animation: tt-hand 1.2s ease-in-out infinite;
    filter: drop-shadow(0 4px 6px rgba(20, 60, 70, .35));
}
#ghost-hand svg { width: 100%; height: 100%; }
@keyframes tt-hand { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }

/* ═══════════ Info button + overlays ═══════════ */

.info-btn {
    position: fixed; bottom: 12px; left: 12px; z-index: 850;
    width: 52px; height: 52px; border: none; border-radius: 50%;
    background: rgba(255, 255, 255, .9); font-size: 1.5rem; cursor: pointer;
    box-shadow: 0 4px 12px rgba(20, 60, 70, .25);
}
.info-btn:active { transform: scale(.92); }

.overlay {
    position: fixed; inset: 0; z-index: 920;
    display: flex; align-items: center; justify-content: center;
    background: rgba(30, 70, 80, .5); padding: 18px;
    animation: gk-fade-in .25s ease-out;
}
.overlay-card { position: relative; max-width: min(92vw, 460px); max-height: 90vh; overflow-y: auto; }
.overlay-card h3 { color: var(--tt-water-deep); margin-bottom: 10px; font-size: 1.4rem; }
.overlay-card p { line-height: 1.5; margin-bottom: 10px; font-size: 1.02rem; }
.close-btn {
    position: absolute; top: 10px; right: 10px;
    width: 48px; height: 48px; border: none; border-radius: 50%;
    background: #FFE0B8; color: #C96400; font-size: 1.3rem; font-weight: bold; cursor: pointer;
}
.close-btn:active { transform: scale(.9); }
#info-demo {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: 6px 0 12px; flex-wrap: wrap;
}
#info-demo .demo-cell { width: 44px; height: 44px; }
.tip-row { display: flex; gap: 12px; align-items: flex-start; background: #EAF9FC; border-radius: 16px; padding: 12px 14px; }
.tip-icons { font-size: 1.6rem; }
.tip-row p { margin: 0; font-size: .96rem; }

@media (prefers-reduced-motion: reduce) {
    #title-shelly, .bk-sun, .bk-weed, .btn-pulse, .sp-turtle, .sp-shell,
    .dpad-btn.nudge-hint, #ghost-hand, .sp-turtle.step .tt-turtle-body,
    .sp-egg.wobble .tt-egg-body, .sp-baby.hatch, .spark, #move-count.bump {
        animation: none !important;
    }
    .sp-turtle, .sp-shell { transition: none !important; }
}
