/* ==========================================================================
   Color Lab Monsters - v2.0 design. One clean stylesheet: bright lab-paper background, white cards with
   ink outlines and hard shadows, colourful buttons. Everything is sized in em; the root size (--u, set in
   js/game.js) scales from small phones up to large desktop screens.
   ========================================================================== */
@font-face { font-family: "Fredoka"; src: url(../assets/fonts/fredoka-latin-600-normal.woff2) format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Fredoka"; src: url(../assets/fonts/fredoka-latin-700-normal.woff2) format("woff2"); font-weight: 700 900; font-display: swap; }

:root {
    --ink: #2b1b4d; --paper: #ffffff; --cream: #fff6e6;
    --sun: #ffc93c; --mint: #22c7a9; --coral: #ff5d73; --sky: #38b6ff; --grape: #8e5cf0; --pink: #ff8fb1;
    --u: 1; --ol: 0.16em;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
    font-family: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", sans-serif; font-weight: 600; color: var(--ink);
    background:
        radial-gradient(circle at 50% -10%, #ffffff 0, rgba(255,255,255,0) 55%),
        radial-gradient(circle, rgba(43,27,77,.07) 1.4px, transparent 1.6px) 0 0 / 22px 22px,
        linear-gradient(180deg, #bfe7ff, #e9f8ff 70%, #fff4d9);
}
img { display: block; pointer-events: none; -webkit-user-drag: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
button:focus-visible { outline: 0.2em solid var(--ink); outline-offset: 0.15em; }
#app { position: relative; height: 100%; max-width: 1900px; margin: 0 auto; font-size: calc(16px * var(--u)); }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; padding: max(.7em, env(safe-area-inset-top)) .9em max(.7em, env(safe-area-inset-bottom)); }
.screen.active { display: flex; animation: scr .32s cubic-bezier(.2,.9,.3,1); }
@keyframes scr { from { opacity: 0; transform: translateY(.8em) scale(.985); } }

/* soft floating bubbles (decoration) */
.bubbles i { position: fixed; border-radius: 50%; background: rgba(255,255,255,.55); border: .12em solid rgba(255,255,255,.9); pointer-events: none; animation: float 14s ease-in-out infinite; }
.bubbles i:nth-child(1) { width: 5em; height: 5em; left: 5%; top: 66%; }
.bubbles i:nth-child(2) { width: 3em; height: 3em; left: 90%; top: 22%; animation-delay: -3s; }
.bubbles i:nth-child(3) { width: 7em; height: 7em; left: 82%; top: 70%; animation-delay: -6s; }
.bubbles i:nth-child(4) { width: 2.4em; height: 2.4em; left: 14%; top: 14%; animation-delay: -9s; }
.bubbles i:nth-child(5) { width: 3.6em; height: 3.6em; left: 52%; top: 4%; animation-delay: -4s; }
.bubbles i:nth-child(6) { width: 2em; height: 2em; left: 44%; top: 90%; animation-delay: -11s; }
@keyframes float { 50% { transform: translateY(-1.6em); } }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5em; padding: .55em 1.4em; border-radius: 999px; border: var(--ol) solid var(--ink); font-weight: 700; font-size: 1.2em; line-height: 1.1; color: var(--ink); box-shadow: 0 .2em 0 var(--ink); transition: transform .1s, box-shadow .1s, filter .12s; }
.btn:active, .icon-btn:active { transform: translateY(.17em); box-shadow: 0 .03em 0 var(--ink); }
.btn img { width: 1.3em; height: 1.3em; }
.btn-sun { background: var(--sun); } .btn-sky { background: var(--sky); color: #fff; } .btn-mint { background: var(--mint); color: #fff; } .btn-coral { background: var(--coral); color: #fff; }
.btn-mint, .btn-sky, .btn-coral { text-shadow: 0 .07em 0 rgba(43,27,77,.55); }
.btn.big { font-size: 1.9em; padding: .4em 1.9em; }
.btn.big img { width: 1.1em; height: 1.1em; }
.btn.small { font-size: 1em; padding: .35em 1.2em; background: #fff; color: var(--ink); box-shadow: 0 .14em 0 var(--ink); }
.btn.small img { width: 1.3em; height: 1.3em; filter: invert(1) brightness(.25) sepia(1) hue-rotate(220deg) saturate(3); }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn { width: 2.7em; height: 2.7em; border-radius: 50%; border: var(--ol) solid var(--ink); background: var(--sky); display: grid; place-items: center; box-shadow: 0 .17em 0 var(--ink); flex: none; transition: transform .1s, box-shadow .1s, filter .12s; }
.icon-btn img { width: 56%; }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
#btnLvHome, #btnPlHome { background: var(--sky); } #btnHint { background: var(--sun); } #btnReset { background: var(--coral); } #btnSound { background: var(--mint); } #pgPrev, #pgNext { background: var(--grape); }
#btnHint img { filter: invert(1) brightness(.25) sepia(1) hue-rotate(220deg) saturate(3); }
@media (hover: hover) { .btn:not(:disabled):hover, .icon-btn:not(:disabled):hover { filter: brightness(1.07); transform: translateY(-.1em); } }

/* ---- loading ---- */
#loading { justify-content: center; gap: 1em; text-align: center; }
.load-logo { height: 9em; animation: wobble 2.4s ease-in-out infinite; }
.load-title { font-size: 2.1em; font-weight: 700; text-shadow: 0 .08em 0 #fff; }
.load-bottles { display: flex; gap: .8em; } .load-bottles img { height: 3.6em; animation: jump .9s ease-in-out infinite; }
.load-bottles img:nth-child(2) { animation-delay: .15s; } .load-bottles img:nth-child(3) { animation-delay: .3s; }
@keyframes jump { 50% { transform: translateY(-.8em); } }
.load-bar { width: min(78vw, 24em); height: 1.5em; border-radius: 999px; background: #fff; padding: .2em; border: var(--ol) solid var(--ink); }
.load-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #ff5d73, #ffc93c, #22c7a9, #38b6ff, #8e5cf0); }
.load-meta { width: min(78vw, 24em); display: flex; justify-content: space-between; font-size: 1em; }

/* ---- menu ---- */
#menu { justify-content: center; gap: .5em; text-align: center; }
.logo { height: 9.5em; animation: wobble 3.5s ease-in-out infinite; filter: drop-shadow(0 .25em 0 rgba(43,27,77,.12)); }
@keyframes wobble { 50% { transform: rotate(4deg) translateY(-.4em); } }
h1 { font-size: 2.9em; line-height: .98; font-weight: 700; color: var(--ink); text-shadow: 0 .06em 0 #fff, 0 .12em 0 rgba(43,27,77,.15); }
h1 span { display: block; color: var(--coral); -webkit-text-stroke: .05em var(--ink); paint-order: stroke fill; text-shadow: 0 .08em 0 var(--ink); }
.tagline { font-size: 1.15em; opacity: .85; text-wrap: balance; }
.menu-stats { display: flex; gap: .6em; font-size: 1em; }
.menu-stats span { display: flex; align-items: center; gap: .35em; background: #fff; border: .13em solid var(--ink); padding: .15em .8em; border-radius: 999px; }
.menu-stats img { width: 1.3em; } .menu-stats i { font-style: normal; }
.menu-btns { display: flex; flex-direction: column; align-items: center; gap: .8em; margin-top: .6em; }
.menu-row { display: flex; gap: .7em; } .menu-row .btn { font-size: 1.1em; padding: .5em 1.2em; }
.btn em { font-style: normal; }
.ver { font-size: .75em; opacity: .55; margin-top: .3em; }
.menu-deco { position: absolute; bottom: 6%; width: 11em; aspect-ratio: 1; animation: bob 3.2s ease-in-out infinite; filter: drop-shadow(0 .3em 0 rgba(43,27,77,.14)); }
.menu-deco.left { left: 3%; } .menu-deco.right { right: 3%; animation-delay: -1.6s; }
.menu-deco canvas, .menu-deco img { position: absolute; inset: 0; width: 100%; height: 100%; }
@keyframes bob { 50% { transform: translateY(-.8em) rotate(3deg); } }

/* ---- headers ---- */
.top { width: 100%; max-width: 62em; display: flex; align-items: center; justify-content: space-between; gap: .6em; flex: none; }
.top h2 { font-size: 1.5em; font-weight: 700; text-align: center; flex: 1; white-space: nowrap; text-shadow: 0 .07em 0 #fff; }
.tools { display: flex; gap: .5em; }
.total-stars { display: flex; align-items: center; gap: .35em; font-weight: 700; background: #fff; padding: .25em .8em; border-radius: 999px; border: var(--ol) solid var(--ink); box-shadow: 0 .14em 0 var(--ink); white-space: nowrap; }
.total-stars img { width: 1.4em; }

/* ---- level select ---- */
#levels { gap: .7em; }
.world { font-weight: 700; font-size: 1.05em; background: var(--sun); padding: .25em 1.2em; border-radius: 999px; border: var(--ol) solid var(--ink); box-shadow: 0 .14em 0 var(--ink); flex: none; }
.grid { flex: 1; min-height: 0; width: 100%; max-width: 44em; display: grid; grid-template-columns: repeat(5, 1fr); grid-auto-rows: minmax(0, 1fr); align-content: center; gap: .8em; padding: .2em .2em .5em; }
.lv { position: relative; height: 100%; max-height: 6.6em; border-radius: 1.1em; border: var(--ol) solid var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1em; font-weight: 700; font-size: 1.9em; color: var(--ink); box-shadow: 0 .14em 0 var(--ink); transition: transform .1s, box-shadow .1s; align-self: center; width: 100%; }
.lv:nth-child(5n+1) { background: var(--sun); } .lv:nth-child(5n+2) { background: #5fe0c6; } .lv:nth-child(5n+3) { background: #7fcfff; } .lv:nth-child(5n+4) { background: var(--pink); } .lv:nth-child(5n) { background: #c4a6ff; }
.lv:active { transform: translateY(.12em); box-shadow: 0 .02em 0 var(--ink); }
.lv .st { display: flex; gap: .05em; } .lv .st img { width: .42em; }
.lv.locked { background: #cdd8ea; border-color: #8b97b3; box-shadow: 0 .14em 0 #8b97b3; pointer-events: none; }
.lv.locked img.lk { width: 44%; opacity: .9; }
@media (hover: hover) { .lv:not(.locked):hover { transform: translateY(-.12em); } }
.pager { display: flex; align-items: center; justify-content: center; gap: 1em; flex: none; padding-top: .2em; }
.flip img { transform: scaleX(-1); }
.dots { display: flex; gap: .55em; } .dots i { width: .8em; height: .8em; border-radius: 50%; background: #fff; border: .12em solid var(--ink); }
.dots i.on { background: var(--coral); transform: scale(1.3); }

/* ---- game ---- */
#play { gap: .6em; }
.stage { flex: 1; min-height: 0; width: 100%; max-width: 62em; display: grid; grid-template-columns: 1.15fr 1fr; gap: .8em; }
.card { background: rgba(255,255,255,.82); border: var(--ol) solid var(--ink); border-radius: 1.6em; padding: .7em; box-shadow: 0 .22em 0 var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: space-between; min-height: 0; min-width: 0; }
.bubble { display: flex; align-items: center; gap: .5em; background: var(--cream); border: .14em solid var(--ink); border-radius: 1.1em; padding: .3em .8em; font-weight: 700; font-size: 1.2em; position: relative; flex: none; }
.bubble u { text-decoration: none; color: var(--coral); }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -.62em; margin-left: -.45em; border: .45em solid transparent; border-bottom: 0; border-top-color: var(--ink); }
.chip { width: 1.8em; aspect-ratio: 1; border-radius: 50%; border: .16em solid var(--ink); flex: none; }
.monster { position: relative; flex: 1; min-height: 0; aspect-ratio: 1; max-width: 100%; margin-top: .4em; align-self: center; filter: drop-shadow(0 .3em 0 rgba(43,27,77,.14)); }
.m-body, .m-face, .liquid-wrap, .glass { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.monster.shake { animation: shake .5s; } .monster.happy { animation: hop .5s 3; }
@keyframes shake { 20%, 60% { transform: translateX(-.7em) rotate(-3deg); } 40%, 80% { transform: translateX(.7em) rotate(3deg); } }
@keyframes hop { 50% { transform: translateY(-1em) scale(1.05); } }
.hint { display: flex; flex-wrap: wrap; gap: .25em; justify-content: center; align-items: center; background: #fff; border: .13em dashed var(--ink); border-radius: 1em; padding: .2em .7em; font-weight: 700; font-size: .95em; flex: none; margin-top: .3em; }
.hint[hidden] { display: none; } .hint img { height: 1.8em; }
.beaker-card { gap: .4em; }
.beaker { position: relative; flex: 1; min-height: 0; aspect-ratio: 300 / 360; max-width: 100%; align-self: center; }
.fall { position: absolute; left: 48%; top: -4%; width: 7%; aspect-ratio: .8; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; animation: fall .45s ease-in forwards; z-index: 2; border: .1em solid var(--ink); }
@keyframes fall { to { transform: translateY(480%); opacity: .6; } }
.counter { white-space: nowrap; font-weight: 700; font-size: 1.05em; background: var(--ink); color: #fff; padding: .15em 1em; border-radius: 999px; flex: none; }
.counter.full { background: var(--coral); }

.shelf { display: flex; justify-content: center; align-items: flex-end; gap: .4em; width: 100%; max-width: 62em; flex: none; background: rgba(255,255,255,.82); border: var(--ol) solid var(--ink); border-radius: 1.4em; box-shadow: 0 .2em 0 var(--ink); padding: .5em .4em .35em; }
.bt { position: relative; display: flex; flex-direction: column; align-items: center; flex: 1; max-width: 7.5em; min-width: 0; transition: transform .1s; }
.bt img { height: clamp(3.6em, 11vh, 6.4em); max-width: 90%; object-fit: contain; }
.bt:active { transform: translateY(.3em) scale(.96); }
.bt.pour { animation: tilt .3s; } @keyframes tilt { 40% { transform: rotate(-14deg) translateY(-.5em); } }
.bt b { position: absolute; right: .2em; top: 0; min-width: 1.6em; height: 1.6em; border-radius: .8em; background: var(--sun); color: var(--ink); display: grid; place-items: center; font-size: .95em; padding: 0 .4em; border: .13em solid var(--ink); }
.bt b:empty, .bt b[data-n="0"] { display: none; }
.bt span { font-size: .85em; font-weight: 700; }
@media (hover: hover) { .bt:hover { transform: translateY(-.25em); } }
.bottom { width: 100%; max-width: 62em; display: flex; align-items: center; gap: .8em; flex: none; justify-content: space-between; }
.msg { flex: 1; font-size: 1.05em; font-weight: 600; line-height: 1.2; text-wrap: balance; }
#btnFeed { font-size: 1.4em; padding: .45em 1.6em; }

/* ---- dialogs ---- */
.modal { position: fixed; inset: 0; background: rgba(43,27,77,.5); display: grid; place-items: center; padding: 1em; z-index: 10; }
.modal[hidden] { display: none; }
.dialog { background: #fff; color: var(--ink); border: var(--ol) solid var(--ink); border-radius: 1.8em; padding: 1.2em 1.4em 1.3em; max-width: 25em; width: 100%; text-align: center; box-shadow: 0 .35em 0 var(--ink); animation: dlg .32s cubic-bezier(.2,1.4,.4,1); max-height: 94vh; overflow: auto; font-size: 1em; }
@keyframes dlg { from { transform: scale(.75); opacity: 0; } }
.dialog h3 { font-size: 1.75em; margin-bottom: .2em; line-height: 1.1; text-wrap: balance; }
.dialog p { font-size: 1em; line-height: 1.35; margin: .4em 0; text-wrap: balance; }
.dialog ol { text-align: left; padding-left: 1.4em; font-size: 1em; line-height: 1.45; margin: .6em 0; }
.dialog .stars { display: flex; justify-content: center; gap: .3em; margin: .3em 0 .6em; }
.dialog .stars img { width: 3.4em; } .dialog .stars img:nth-child(2) { margin-top: -.6em; }
.dialog .stars img.on { animation: starpop .5s both; } .dialog .stars img.on:nth-child(2) { animation-delay: .2s; } .dialog .stars img.on:nth-child(3) { animation-delay: .4s; }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } to { transform: none; } }
.dialog .row { display: flex; gap: .6em; justify-content: center; flex-wrap: wrap; margin-top: .9em; }
.dialog .btn { font-size: 1.05em; padding: .45em 1.2em; }
.swatch { display: inline-block; width: 1.7em; height: 1.7em; border-radius: 50%; border: .16em solid var(--ink); vertical-align: middle; margin: 0 .3em; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: .8em; padding: .6em .2em; border-bottom: .12em dashed rgba(43,27,77,.22); font-weight: 600; font-size: 1.1em; }
.switch { width: 3.6em; height: 2em; border-radius: 1em; background: #cfd6e6; border: .14em solid var(--ink); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; left: .15em; top: .15em; width: 1.4em; height: 1.4em; border-radius: 50%; background: #fff; border: .13em solid var(--ink); transition: transform .2s; }
.switch.on { background: var(--mint); } .switch.on::after { transform: translateX(1.6em); }
.dialog .small-note { font-size: .8em; opacity: .6; margin-top: .6em; }

/* ---- portrait phones: monster and beaker each get a wide card, so both stay big ---- */
@media (max-width: 700px) and (orientation: portrait) {
    .stage { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; gap: .6em; }
    .bottom { flex-direction: column; gap: .4em; text-align: center; align-items: stretch; }
    .bottom .btn { width: 100%; }
    .grid { grid-template-columns: repeat(4, 1fr); }
    .menu-deco { width: 5em; top: 2.5%; bottom: auto; } .menu-deco.left { left: 3%; } .menu-deco.right { right: 3%; }
    h1 { font-size: 3.1em; } .logo { height: 11em; } .tagline { font-size: 1.25em; } .menu-stats { font-size: 1.1em; } .btn.big { font-size: 2.1em; } .menu-row .btn { font-size: 1.25em; } #menu { gap: .8em; }
}
@media (orientation: portrait) and (min-width: 561px) { .menu-deco { width: 7em; top: 3%; bottom: auto; } }
@media (max-height: 480px) {
    .menu-deco { display: none; }
    .stage { grid-template-columns: 1fr 1fr; }
    #menu { flex-direction: row; flex-wrap: wrap; align-content: center; justify-content: center; column-gap: 1.5em; }
    .menu-btns { flex-direction: row; flex-wrap: wrap; justify-content: center; margin-top: 0; }
    .logo { height: 6em; } h1 { font-size: 1.9em; } .tagline, .menu-stats, .ver { display: none; }
    .bottom { flex-direction: row; } .bt img { height: clamp(2.6em, 14vh, 4em); }
    .btn.big { font-size: 1.4em; } .top h2 { font-size: 1.2em; } .icon-btn { width: 2.3em; height: 2.3em; }
    .grid { grid-template-columns: repeat(10, 1fr); grid-auto-rows: auto; } .lv { height: auto; max-height: none; aspect-ratio: 1; font-size: 1.3em; border-radius: .8em; } .lv .st { display: none; } .lv.locked img.lk { width: 40%; }
    .dialog { padding: .8em 1em; } .dialog .stars img { width: 2.4em; }
}
/* wide screens: monster, beaker and a control panel side by side */
@media (min-width: 1150px) and (min-aspect-ratio: 13/10) {
    #play.active { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .9fr) 21em; grid-template-rows: auto minmax(0, 1fr) auto; column-gap: 1em; row-gap: .8em; align-items: stretch; }
    #play .top { grid-column: 1 / -1; grid-row: 1; max-width: none; }
    #play .stage { display: contents; }
    #play .monster-card { grid-column: 1; grid-row: 2 / 4; } #play .beaker-card { grid-column: 2; grid-row: 2 / 4; }
    #play .shelf { grid-column: 3; grid-row: 2; align-self: stretch; max-width: none; flex-wrap: wrap; justify-content: center; align-content: center; gap: .8em .3em; padding: .8em .6em; }
    #play .shelf .bt { flex: 0 0 31%; max-width: none; } #play .shelf .bt img { height: 6.2em; }
    #play .bottom { grid-column: 3; grid-row: 3; max-width: none; flex-direction: column; align-items: stretch; gap: .6em; text-align: center; }
    #play .bottom .msg { flex: none; min-height: 2.5em; display: grid; place-items: center; }
    #play #btnFeed { width: 100%; font-size: 1.6em; padding: .45em 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* monster and beaker cards: text on the left, picture on the right (phones in portrait, short landscape screens) */
@media (max-width: 700px) and (orientation: portrait), (max-height: 480px) {
    .monster-card, .beaker-card { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr auto; align-items: center; justify-items: center; column-gap: .4em; padding: .5em .7em; }
    .monster-card .bubble { grid-column: 1; grid-row: 1; align-self: center; font-size: 1.1em; flex-direction: column; text-align: center; padding: .4em .7em; }
    .monster-card .bubble::after { left: auto; right: -.7em; bottom: 50%; margin: 0 0 -.45em; border: .45em solid transparent; border-right: 0; border-left-color: var(--ink); }
    .monster-card .monster { grid-column: 2; grid-row: 1 / 3; height: 100%; width: auto; max-height: 100%; margin: 0; }
    .monster-card .hint { grid-column: 1; grid-row: 2; margin: 0; }
    .beaker-card .beaker { grid-column: 2; grid-row: 1 / 3; height: 100%; width: auto; max-height: 100%; }
    .beaker-card .counter { grid-column: 1; grid-row: 1 / 3; font-size: 1.1em; padding: .4em .8em; text-align: center; }
}
