/* Riddle Reef — game styles. GameKit tokens load first. */

:root {
    --rr-deep: #063B54;
    --rr-mid: #0A6E8C;
    --rr-teal: #12A5B8;
    --rr-shallow: #4FD0D9;
    --rr-sand: #F2DEA8;
    --rr-coral: #FF7B9C;
    --rr-ink: #08313f;
}

html, body { overflow: hidden; }
body { background: var(--rr-deep); color: #08313f; }

.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    padding: max(10px, env(safe-area-inset-top)) 12px 12px;
}

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

#reef-backdrop {
    position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
    background: linear-gradient(to bottom,
        var(--rr-deep) 0%, var(--rr-mid) 42%, var(--rr-teal) 78%, var(--rr-shallow) 100%);
}
.reef-svg { position: absolute; bottom: 0; left: 0; width: 100%; height: 62%; display: block; }
.rr-weed { animation: rr-sway 5s ease-in-out infinite; transform-origin: bottom center; }
.rr-weed:nth-of-type(2) { animation-duration: 6.5s; animation-delay: -1s; }
@keyframes rr-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

/* rising bubbles + light shafts */
#light-rays {
    position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden;
    background:
        linear-gradient(102deg, transparent 46%, rgba(220,255,255,.10) 49%, transparent 52%),
        linear-gradient(84deg, transparent 66%, rgba(220,255,255,.08) 70%, transparent 74%);
}
#light-rays::before, #light-rays::after {
    content: ''; position: absolute; border-radius: 50%;
    background: radial-gradient(circle, rgba(234,251,255,.5), rgba(234,251,255,0) 70%);
    animation: rr-rise linear infinite;
}
#light-rays::before { left: 22%; bottom: -30px; width: 14px; height: 14px; animation-duration: 11s; }
#light-rays::after  { left: 74%; bottom: -30px; width: 10px; height: 10px; animation-duration: 14s; animation-delay: -5s; }
@keyframes rr-rise { from { transform: translateY(0); opacity: .0; } 15% { opacity: .8; } to { transform: translateY(-108vh); opacity: 0; } }

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

.title-inner {
    position: relative; z-index: 2;
    margin: auto;
    display: flex; flex-direction: column; align-items: center;
    text-align: center; gap: 10px;
    max-width: 560px; width: 100%;
}
.game-title {
    font-size: clamp(2.4rem, 9vw, 4rem);
    color: #FFF8EC;
    letter-spacing: 1px;
    text-shadow: 0 3px 0 #0A6E8C, 0 6px 14px rgba(0,0,0,.35);
    line-height: 1;
}
.tagline {
    font-size: clamp(1rem, 3.6vw, 1.35rem);
    color: #EAFBFF;
    font-weight: bold;
    text-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.title-ollie {
    width: clamp(160px, 34vw, 240px);
    filter: drop-shadow(0 12px 20px rgba(0,0,0,.3));
    animation: rr-float 3.4s ease-in-out infinite;
}
.title-ollie .ollie-svg { width: 100%; height: auto; display: block; }
@keyframes rr-float { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }

.start-btn {
    margin-top: 4px;
    min-height: 72px;
    padding: 16px 54px;
    font-size: clamp(1.3rem, 5vw, 1.7rem);
    font-weight: bold; color: #fff;
    background: linear-gradient(135deg, #FF9838 0%, #F77F00 100%);
    border: none; border-radius: 50px; cursor: pointer;
    box-shadow: 0 8px 22px rgba(247,127,0,.5);
    transition: transform .18s, box-shadow .18s;
}
.start-btn:hover { transform: translateY(-3px) scale(1.04); }
.start-btn:active { transform: scale(.96); }
.btn-pulse { display: inline-block; animation: rr-pulse 1.6s ease-in-out infinite; }
@keyframes rr-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,.9); color: #4A3B5C;
    padding: 8px 18px; border-radius: 30px; font-weight: bold;
    font-size: 1.1rem; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

.level-row { display: flex; gap: 14px; margin-top: 4px; }
.lvl-btn {
    position: relative;
    width: 84px; min-height: 84px;
    border: 4px solid #fff; border-radius: 20px;
    background: rgba(255,255,255,.85);
    box-shadow: 0 6px 16px rgba(0,0,0,.25);
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    transition: transform .15s;
}
.lvl-btn:hover:not(.locked) { transform: translateY(-3px) scale(1.05); }
.lvl-btn:active { transform: scale(.95); }
.lvl-num { font-size: 1.8rem; font-weight: bold; color: #0A6E8C; line-height: 1; }
.lvl-stars { font-size: .8rem; }
.lvl-stars .dim { filter: grayscale(1); opacity: .35; }
.lvl-lock { display: none; position: absolute; font-size: 1.6rem; }
.lvl-btn.locked { background: rgba(200,215,220,.7); }
.lvl-btn.locked .lvl-num, .lvl-btn.locked .lvl-stars { opacity: .25; }
.lvl-btn.locked .lvl-lock { display: block; }
.shake { animation: rr-shake .4s; }
@keyframes rr-shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }

/* ═══════════ Play ═══════════ */

#screen-play { z-index: 10; gap: 8px; }

#play-hud {
    position: relative; z-index: 2;
    display: flex; align-items: center; justify-content: flex-start;
    gap: 14px; flex: 0 0 auto;
    padding: 0 200px 0 4px;   /* reserve the top-right corner for the GameKit HUD */
}
.level-pill {
    background: rgba(255,255,255,.92); color: #0A6E8C;
    font-weight: bold; font-size: 1.05rem;
    padding: 6px 16px; border-radius: 24px; box-shadow: 0 3px 10px rgba(0,0,0,.2);
}
.guesses-left { display: flex; gap: 2px; font-size: 1.35rem; line-height: 1; }
.pearl { animation: rr-pop .3s cubic-bezier(.2,1.6,.4,1) backwards; }

#stage {
    position: relative; z-index: 2; flex: 0 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center; gap: 8px;
    max-width: 760px; width: 100%; margin: 0 auto;
    min-height: 0;
}
.ollie-holder { width: clamp(90px, 15vw, 130px); }
.ollie-holder .ollie-svg { width: 100%; height: auto; display: block;
    animation: rr-float 3.6s ease-in-out infinite; }
.speech-bubble {
    background: #FFF8EC; color: #3a2f47; border-radius: 18px;
    padding: 10px 14px; font-size: clamp(.9rem, 2.6vw, 1.1rem); font-weight: bold;
    box-shadow: 0 6px 16px rgba(0,0,0,.22);
    position: relative; min-height: 40px;
    display: flex; align-items: center; justify-content: center; text-align: center;
}
.speech-bubble::after {
    content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
    border: 8px solid transparent; border-right-color: #FFF8EC;
}
.chest-holder { width: clamp(96px, 16vw, 140px); }
.chest-holder .chest-svg { width: 100%; height: auto; display: block; overflow: visible; }

/* chest burst — the signature moment */
.chest-rays { opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(.2) rotate(0deg); }
.chest-glowball { opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(.2); }
.chest-coins { opacity: 0; }
.chest-lid { transform-box: fill-box; transform-origin: bottom left; transition: transform .5s cubic-bezier(.3,1.5,.5,1); }
.chest-holder.burst .chest-lid { transform: rotate(-52deg) translateX(-4px); }
.chest-holder.burst .chest-coins { opacity: 1; transition: opacity .3s .25s; }
.chest-holder.burst .chest-glowball { animation: rr-glow 1.2s ease-out forwards .2s; }
.chest-holder.burst .chest-rays { animation: rr-burst-rays 1.2s ease-out forwards .2s; }
@keyframes rr-glow { 0% { opacity: 0; transform: scale(.2); } 40% { opacity: 1; } 100% { opacity: .5; transform: scale(1.1); } }
@keyframes rr-burst-rays { 0% { opacity: 0; transform: scale(.2) rotate(0deg); } 40% { opacity: 1; } 100% { opacity: .7; transform: scale(1.15) rotate(30deg); } }

/* history of past guesses */
#history-wrap {
    position: relative; z-index: 2; flex: 1 1 auto; min-height: 0;
    width: 100%; max-width: 560px; margin: 0 auto;
    display: flex; flex-direction: column; justify-content: flex-end;
}
.history {
    overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column; gap: 6px;
    padding: 4px 6px;
}
.hist-row {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    background: rgba(255,255,255,.16); border-radius: 16px;
    padding: 5px 12px;
}
.hist-row.fresh { animation: rr-pop .35s cubic-bezier(.2,1.5,.4,1); }
.hist-shells { display: flex; gap: 5px; }
.hist-shell { width: 30px; height: 30px; display: inline-block; }
.hist-shell .shell-svg { width: 100%; height: 100%; display: block; }
.pips {
    display: inline-grid; grid-auto-flow: column; grid-template-rows: 1fr 1fr; gap: 3px;
    padding: 3px 6px; background: rgba(8,49,63,.35); border-radius: 10px;
}
.pip { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 -1px 2px rgba(0,0,0,.25); }
.pip.green { background: #7CB518; }
.pip.yellow { background: #FCBF49; }
.pip.white { background: #EAF3F5; }
.pip.blank { background: rgba(255,255,255,.18); box-shadow: none; }

/* current guess row */
.current {
    position: relative; z-index: 2; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center; gap: 14px;
    flex-wrap: wrap;
}
.slots { display: flex; gap: 10px; }
.slot {
    position: relative;
    width: clamp(58px, 13vw, 82px); height: clamp(58px, 13vw, 82px);
    border-radius: 18px;
    border: 4px dashed rgba(255,255,255,.7);
    background: rgba(255,255,255,.14);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s, border-color .2s, background .2s;
}
.slot:active { transform: scale(.94); }
.slot .slot-q { font-size: 2rem; color: rgba(255,255,255,.6); font-weight: bold; }
.slot.filled {
    border-style: solid;
    border-color: var(--sh, #fff);
    background: #FFF8EC;
    animation: rr-pop .28s cubic-bezier(.2,1.6,.4,1);
}
.slot.filled .shell-svg { width: 84%; height: 84%; }
.slot.locked { border-color: #FCBF49; cursor: default; box-shadow: 0 0 0 3px rgba(252,191,73,.5); }
.lock-badge { position: absolute; top: -8px; right: -8px; font-size: .95rem; }
.nudge-wobble { animation: rr-shake .4s; }

.check-btn {
    min-height: 60px; padding: 12px 30px;
    font-size: clamp(1.15rem, 3.6vw, 1.4rem);
    display: inline-flex; align-items: center; gap: 8px;
}
.check-ic { font-size: 1.2em; }

/* palette */
.palette {
    position: relative; z-index: 2; flex: 0 0 auto;
    display: flex; justify-content: center; gap: clamp(8px, 2vw, 16px);
    flex-wrap: wrap;
    padding: 8px 6px 2px;
}
.pal-shell {
    width: clamp(60px, 13vw, 84px); height: clamp(60px, 13vw, 84px);
    border-radius: 20px;
    border: 4px solid #fff;
    background: #FFF8EC;
    box-shadow: 0 6px 14px rgba(0,0,0,.28);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s;
}
.pal-shell:hover { transform: translateY(-4px) scale(1.06); }
.pal-shell:active { transform: scale(.9); }
.pal-shell .shell-svg { width: 82%; height: 82%; display: block; }

@keyframes rr-pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ═══════════ Info button + overlay ═══════════ */

.info-btn {
    position: fixed; bottom: 14px; left: 14px; z-index: 30;
    width: 54px; height: 54px; border: none; border-radius: 50%;
    background: rgba(255,255,255,.92);
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    font-size: 1.5rem; cursor: pointer; transition: transform .15s;
}
.info-btn:hover { transform: scale(1.1); }
.info-btn:active { transform: scale(.92); }

.overlay {
    position: fixed; inset: 0; z-index: 800;
    display: flex; align-items: center; justify-content: center;
    background: rgba(6,59,84,.55); padding: 20px;
    animation: gk-fade-in .25s ease-out;
}
.overlay-card { position: relative; max-width: min(92vw, 480px); }
.overlay-card h3 { color: #0A6E8C; margin-bottom: 10px; font-size: 1.4rem; }
.overlay-card p { line-height: 1.5; margin-bottom: 12px; font-size: 1.02rem; }
.close-btn {
    position: absolute; top: 10px; right: 10px;
    width: 48px; height: 48px; border: none; border-radius: 50%;
    background: #FF7B9C; color: #fff; font-size: 1.3rem; cursor: pointer;
}
.tip-row { display: flex; gap: 12px; align-items: flex-start;
    background: #EAFBFF; border-radius: 16px; padding: 12px 14px; }
.tip-icons { font-size: 1.6rem; flex: 0 0 auto; }
.tip-row p { margin: 0; font-size: .96rem; }

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

#ghost-hand {
    position: fixed; z-index: 40; pointer-events: none;
    animation: rr-hand-tap 1.1s ease-in-out infinite;
}
@keyframes rr-hand-tap { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-12px);} }

/* ═══════════ Landscape squeeze ═══════════ */

@media (max-height: 620px) {
    .title-ollie { width: clamp(120px, 22vw, 180px); }
    .ollie-holder { width: clamp(74px, 11vw, 104px); }
    .chest-holder { width: clamp(84px, 12vw, 118px); }
}

@media (prefers-reduced-motion: reduce) {
    .title-ollie, .ollie-holder .ollie-svg, .rr-weed, .btn-pulse,
    #light-rays::before, #light-rays::after, .pearl, .hist-row.fresh, .slot.filled { animation: none; }
    .chest-lid { transition: none; }
    #ghost-hand { animation: none; }
}
