/* Candy Swap Train - one consistent "toy rail yard" interface. Everything is sized in rem (set from the screen size by main.js), wagons in em of the candy size. */
@font-face {
    font-family: "CT Display";
    src: url(../assets/fonts/lilita-one-latin-400-normal.woff2) format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "CT Text";
    src: url(../assets/fonts/fredoka-latin-500-normal.woff2) format("woff2");
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: "CT Text";
    src: url(../assets/fonts/fredoka-latin-600-normal.woff2) format("woff2");
    font-weight: 600;
    font-display: swap;
}

:root {
    --ink: #232e68;
    --ink2: #4a5496;
    --cream: #fff8e6;
    --paper: #fffdf5;
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --hd: "CT Display", "Trebuchet MS", system-ui, sans-serif;
    --bd: "CT Text", system-ui, "Segoe UI", sans-serif;
    --wc: #ff9f1c;
}
* {
    box-sizing: border-box;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}
html {
    font-size: 12px;
    height: 100%;
    overflow: hidden;
    background: #3fa9ff;
}
body {
    height: 100%;
    overflow: hidden;
    font-family: var(--bd);
    font-weight: 600;
    color: var(--ink);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    overscroll-behavior: none;
    font-size: 1.5rem;
    line-height: 1.25;
}
img,
svg {
    display: block;
    -webkit-user-drag: none;
}
button {
    font: inherit;
    color: inherit;
    border: 0;
    background: none;
    cursor: pointer;
    padding: 0;
}
[hidden] {
    display: none !important;
}

/* ---------- backdrop ---------- */
#bg {
    position: fixed;
    inset: 0;
    background: #3fa9ff;
}
.bgl {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.6s;
}
.bgl.on {
    opacity: 1;
}
.scn {
    width: 100%;
    height: 100%;
}
.scn .cl {
    animation: cloud 34s ease-in-out infinite alternate;
    transform-box: fill-box;
}
.scn .sun {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    animation: spin 80s linear infinite;
}
@keyframes cloud {
    from {
        translate: -34px 0;
    }
    to {
        translate: 46px 0;
    }
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
#app {
    position: fixed;
    inset: 0;
}
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: calc(var(--sat) + 1rem) calc(var(--sar) + 1.2rem) calc(var(--sab) + 1rem)
        calc(var(--sal) + 1.2rem);
    opacity: 0;
    visibility: hidden;
    transform: translateY(1.2rem) scale(0.985);
    transition:
        opacity 0.3s,
        transform 0.3s,
        visibility 0s 0.3s;
}
.screen.active {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition:
        opacity 0.3s,
        transform 0.3s;
}

/* ---------- buttons: one glossy candy recipe ---------- */
.c-blue {
    --l: #8fd0ff;
    --b: #3a86ff;
    --d: #1d4ab0;
}
.c-purple {
    --l: #cfaaff;
    --b: #9b5de5;
    --d: #5a2aae;
}
.c-orange {
    --l: #ffd073;
    --b: #ff9f1c;
    --d: #b36000;
}
.c-green {
    --l: #86f0ad;
    --b: #2fcf6b;
    --d: #14803f;
}
.c-red {
    --l: #ff9fae;
    --b: #ff4d68;
    --d: #a81d3a;
}
.c-yellow {
    --l: #fff18f;
    --b: #ffd21f;
    --d: #a98300;
}
.rb,
.tbtn,
.dk,
.nb,
.playb,
.arr {
    position: relative;
    color: #fff;
    font-family: var(--hd);
    background: linear-gradient(180deg, var(--l), var(--b));
    border: 0.16rem solid var(--d);
    box-shadow:
        0 0.4rem 0 var(--d),
        inset 0 0.14rem 0 rgba(255, 255, 255, 0.65);
    transition:
        transform 0.12s,
        filter 0.15s,
        box-shadow 0.12s;
}
.rb::before,
.tbtn::before,
.dk::before,
.nb::before,
.playb::before,
.arr::before {
    content: "";
    position: absolute;
    left: 14%;
    right: 14%;
    top: 0.25rem;
    height: 32%;
    border-radius: 2rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0));
    pointer-events: none;
}
.rb:active,
.tbtn:active,
.dk:active,
.nb:active,
.playb:active,
.arr:active {
    transform: translateY(0.34rem);
    box-shadow:
        0 0.06rem 0 var(--d),
        inset 0 0.14rem 0 rgba(255, 255, 255, 0.5);
}
@media (hover: hover) {
    .rb:hover,
    .tbtn:hover,
    .dk:hover,
    .nb:hover,
    .playb:hover,
    .arr:hover {
        filter: brightness(1.08);
        transform: translateY(-0.15rem);
        box-shadow:
            0 0.55rem 0 var(--d),
            inset 0 0.14rem 0 rgba(255, 255, 255, 0.65);
    }
    .rb:hover:active,
    .tbtn:hover:active,
    .dk:hover:active,
    .nb:hover:active,
    .playb:hover:active,
    .arr:hover:active {
        transform: translateY(0.34rem);
        box-shadow: 0 0.06rem 0 var(--d);
    }
}
.rb:focus-visible,
.tbtn:focus-visible,
.dk:focus-visible,
.nb:focus-visible,
.playb:focus-visible,
.arr:focus-visible,
.tk:focus-visible,
.wg:focus-visible,
.switch:focus-visible,
.v-dots button:focus-visible {
    outline: 0.3rem solid #fff;
    outline-offset: 0.2rem;
    box-shadow: 0 0 0 0.55rem var(--ink);
}
.rb:disabled,
.tbtn:disabled,
.dk:disabled,
.arr:disabled {
    filter: grayscale(1) brightness(1.12);
    opacity: 0.55;
    pointer-events: none;
}
.rb {
    width: 4.8rem;
    height: 4.8rem;
    border-radius: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}
.rb img {
    width: 2.8rem;
    height: 2.8rem;
    position: relative;
}
.tbtn {
    min-height: 4.6rem;
    padding: 0 2.2rem;
    border-radius: 2.4rem;
    font-size: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.34rem var(--d);
    white-space: nowrap;
}
.tbtn.small {
    min-height: 3.8rem;
    font-size: 1.6rem;
    padding: 0 1.6rem;
    -webkit-text-stroke: 0.24rem var(--d);
}
.arr {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #fff, #d9e6ff);
    border-color: #8aa4e0;
    box-shadow:
        0 0.3rem 0 #8aa4e0,
        inset 0 0.12rem 0 #fff;
    --d: #8aa4e0;
}
.arr img {
    width: 2rem;
    height: 2rem;
}

/* ---------- loading ---------- */
.loading {
    justify-content: center;
}
.load-box {
    position: relative;
    width: 100%;
    max-width: 40rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.4rem;
}
.load-train {
    position: relative;
    width: 24rem;
}
.lt-e {
    width: 100%;
    animation: chug 0.5s ease-in-out infinite alternate;
}
@keyframes chug {
    to {
        transform: translateY(-0.25rem);
    }
}
.smoke {
    position: absolute;
    left: 73%;
    top: -1rem;
    width: 3rem;
    height: 3rem;
}
.smoke i {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    background: #fff;
    opacity: 0;
    animation: puff 2s ease-out infinite;
}
.smoke i:nth-child(2) {
    animation-delay: 0.66s;
}
.smoke i:nth-child(3) {
    animation-delay: 1.33s;
}
@keyframes puff {
    0% {
        transform: translate(0, 0) scale(0.4);
        opacity: 0.95;
    }
    100% {
        transform: translate(-3rem, -5rem) scale(1.6);
        opacity: 0;
    }
}
.rails {
    width: 100%;
    height: 1.5rem;
    background:
        linear-gradient(#f4f7ff 0 0.35rem, #8088b8 0.35rem 0.55rem, transparent 0.55rem),
        repeating-linear-gradient(90deg, #a9683a 0 1.5rem, transparent 1.5rem 2.6rem) 0 0.75rem/100% 0.75rem
            no-repeat;
    margin-top: -1.7rem;
}
.load-title {
    font-family: var(--hd);
    font-size: 3.2rem;
    color: #fff;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.5rem var(--ink);
    text-shadow: 0 0.3rem 0 var(--ink);
    text-align: center;
    line-height: 1;
}
.load-bar {
    width: 100%;
    max-width: 30rem;
    height: 2rem;
    border-radius: 1.2rem;
    background: #fff;
    border: 0.22rem solid var(--ink);
    box-shadow: 0 0.3rem 0 var(--ink);
    overflow: hidden;
}
.load-bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 1rem;
    background: repeating-linear-gradient(
        115deg,
        #ff5d73 0 1.4rem,
        #ffa62b 1.4rem 2.8rem,
        #ffd93d 2.8rem 4.2rem,
        #46c45a 4.2rem 5.6rem,
        #3a7bff 5.6rem 7rem
    );
    background-size: 9.8rem 100%;
    animation: stripes 1s linear infinite;
}
@keyframes stripes {
    to {
        background-position: 9.8rem 0;
    }
}

/* ---------- menu ---------- */
.menu {
    justify-content: center;
    gap: 0;
}
.m-center {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 38rem;
    margin-bottom: 11rem;
}
.logo {
    text-align: center;
    line-height: 0.9;
    font-family: var(--hd);
    font-weight: 400;
}
.logo .l1 {
    display: block;
    font-size: 5.2rem;
}
.logo .w {
    display: block;
}
.logo .w i {
    display: inline-block;
    font-style: normal;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.55rem var(--ink);
    text-shadow: 0 0.4rem 0 var(--ink);
    animation: bob 2.6s ease-in-out infinite;
    animation-delay: calc(var(--k) * 0.11s);
}
@keyframes bob {
    0%,
    100% {
        transform: translateY(0) rotate(-1deg);
    }
    50% {
        transform: translateY(-0.35rem) rotate(1deg);
    }
}
.logo .l2 {
    display: block;
    margin-top: 0.9rem;
}
.logo em {
    position: relative;
    display: inline-block;
    font-style: normal;
    font-size: 3.2rem;
    letter-spacing: 0.35em;
    padding: 0.55rem 1.6rem 0.55rem 2rem;
    border-radius: 1rem;
    color: #fff;
    background: linear-gradient(#ff7388, #e02a45);
    border: 0.22rem solid var(--ink);
    box-shadow:
        0 0.4rem 0 var(--ink),
        inset 0 0.14rem 0 rgba(255, 255, 255, 0.55);
    paint-order: stroke fill;
    -webkit-text-stroke: 0.28rem #8f1230;
}
.logo em::before,
.logo em::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 0.8rem;
    height: 0.8rem;
    margin-top: -0.4rem;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff7c2, #e0a400);
    border: 0.12rem solid var(--ink);
}
.logo em::before {
    left: 0.45rem;
}
.logo em::after {
    right: 0.45rem;
}
.playb {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    min-width: 24rem;
    padding: 0.8rem 2.8rem 0.8rem 0.9rem;
    border-radius: 4rem;
    --l: #86f0ad;
    --b: #2fcf6b;
    --d: #14803f;
    box-shadow:
        0 0.5rem 0 var(--d),
        inset 0 0.16rem 0 rgba(255, 255, 255, 0.65);
}
.pl-ic {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff, #d4e3ff);
    border: 0.18rem solid var(--d);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    position: relative;
}
.pl-ic img {
    width: 2.7rem;
    height: 2.7rem;
    margin-left: 0.25rem;
}
.pl-t {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1;
    position: relative;
}
.pl-t b {
    font-size: 3rem;
    font-weight: 400;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.45rem var(--d);
}
.pl-t small {
    font-family: var(--bd);
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 0.3rem;
    color: #eafff2;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.22rem var(--d);
}
.m-row {
    display: flex;
    gap: 1rem;
    width: 100%;
}
.nb {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 6.6rem;
    padding: 0.6rem 0.3rem;
    border-radius: 2rem;
    font-size: 1.7rem;
    line-height: 1;
}
.nb img {
    width: 2.9rem;
    height: 2.9rem;
    position: relative;
}
.nb span {
    paint-order: stroke fill;
    -webkit-text-stroke: 0.3rem var(--d);
    position: relative;
}
.m-prog {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    max-width: 30rem;
}
.m-prog .bar {
    width: 100%;
    height: 1.5rem;
    border-radius: 1rem;
    background: #fff;
    border: 0.2rem solid var(--ink);
    box-shadow: 0 0.25rem 0 var(--ink);
    overflow: hidden;
}
.m-prog .bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 1rem;
    background: linear-gradient(#ffe27a, #ffa62b);
    transition: width 0.6s;
}
.m-prog span {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 1.5rem;
    color: #fff;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.3rem var(--ink);
}
.m-prog .star {
    width: 1.9rem;
    height: 1.9rem;
}
.m-track {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--sab) + 0.4rem);
    height: 11rem;
    overflow: hidden;
    pointer-events: none;
}
.m-train {
    position: absolute;
    bottom: 1.1rem;
    left: 0;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    animation: ride 22s linear infinite;
    will-change: transform;
}
@keyframes ride {
    from {
        transform: translateX(-62rem);
    }
    to {
        transform: translateX(100vw);
    }
}
.m-train .eng {
    position: relative;
    width: 11.5rem;
    flex: none;
    margin-right: 0.4rem;
}
.m-train .eng img {
    width: 100%;
}
.m-train .eng .smoke {
    left: 70%;
    top: -1.4rem;
}
.m-track .rails {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    height: 1.5rem;
}
.m-train .mw {
    font-size: 5rem;
}

/* ---------- mini wagons (menu train, level tiles) and the full wagon share one look ---------- */
.mw,
.wg {
    --wl: #ff9aa9;
    --wd: #b3243c;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    flex: none;
}
.mw .jar,
.wg .jar {
    position: relative;
    flex: 1;
    margin: 0 0.07em;
    border-radius: 0.34em 0.34em 0.14em 0.14em;
    border: 0.075em solid var(--wd);
    background:
        linear-gradient(
            100deg,
            rgba(255, 255, 255, 0) 0 12%,
            rgba(255, 255, 255, 0.6) 14% 22%,
            rgba(255, 255, 255, 0) 24% 70%,
            rgba(255, 255, 255, 0.35) 72% 76%,
            rgba(255, 255, 255, 0) 78%
        ),
        linear-gradient(180deg, #ffffff, #dcecff);
    box-shadow:
        inset 0 -0.25em 0.3em -0.1em rgba(60, 100, 190, 0.28),
        inset 0 0 0 0.04em rgba(255, 255, 255, 0.9);
}
.mw .jar::before,
.wg .jar::before {
    content: "";
    position: absolute;
    left: -0.12em;
    right: -0.12em;
    top: -0.17em;
    height: 0.26em;
    border-radius: 0.13em;
    background: linear-gradient(180deg, var(--wl), var(--wc));
    border: 0.065em solid var(--wd);
    box-shadow: inset 0 0.05em 0 rgba(255, 255, 255, 0.65);
    z-index: 1;
}
.mw .ch,
.wg .ch {
    position: relative;
    height: 0.46em;
    margin: 0 -0.02em;
    border-radius: 0.15em;
    border: 0.07em solid var(--wd);
    background:
        radial-gradient(circle, rgba(255, 255, 255, 0.85) 0 0.045em, transparent 0.05em) 0 50%/0.42em 100%
            repeat-x,
        linear-gradient(180deg, var(--wl), var(--wc) 55%, var(--wd));
}
.mw .ch::after,
.wg .ch::after {
    content: "";
    position: absolute;
    right: -0.24em;
    top: 50%;
    width: 0.22em;
    height: 0.1em;
    margin-top: -0.05em;
    background: #4d5488;
    border-radius: 0.05em;
}
.mw .ch::before,
.wg .ch::before {
    content: "";
    position: absolute;
    left: -0.24em;
    top: 50%;
    width: 0.22em;
    height: 0.1em;
    margin-top: -0.05em;
    background: #4d5488;
    border-radius: 0.05em;
}
.mw .wh,
.wg .wh {
    position: absolute;
    bottom: -0.24em;
    width: 0.54em;
    height: 0.54em;
    border-radius: 50%;
    border: 0.07em solid #1d2150;
    background:
        radial-gradient(circle, #ffc72b 0 0.06em, #1d2150 0.065em 0.1em, transparent 0.105em),
        repeating-conic-gradient(#fff6c8 0 12deg, #e8b000 12deg 45deg);
    z-index: 2;
}
.mw .wh.a,
.wg .wh.a {
    left: 0.22em;
}
.mw .wh.b,
.wg .wh.b {
    right: 0.22em;
}

/* the wagon you play with */
.wg {
    font-size: var(--s, 40px);
    width: 1.64em;
    height: calc((var(--cap, 4) + 0.95) * 1em);
    transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1);
    background: none;
}
.wg .bed {
    position: absolute;
    left: 0.05em;
    right: 0.05em;
    bottom: 0.04em;
    top: 0.12em;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    z-index: 2;
}
.cd {
    width: 1em;
    height: 1em;
    flex: none;
    transition: transform 0.22s cubic-bezier(0.3, 1.7, 0.5, 1);
}
.cd.up {
    transform: translateY(-0.55em);
}
.wg.sel {
    transform: translateY(-0.05em);
}
.wg.sel .jar {
    box-shadow:
        0 0 0 0.07em #fff,
        0 0 0 0.13em #ffd21f,
        inset 0 -0.25em 0.3em -0.1em rgba(60, 100, 190, 0.28);
}
.wg.ok::after {
    content: "";
    position: absolute;
    left: 50%;
    top: -0.15em;
    margin-left: -0.22em;
    border: 0.22em solid transparent;
    border-top: 0.3em solid #2fcf6b;
    border-bottom: 0;
    animation: tip 0.7s ease-in-out infinite alternate;
    z-index: 5;
}
@keyframes tip {
    to {
        transform: translateY(0.15em);
    }
}
.wg.ok .jar {
    box-shadow:
        0 0 0 0.06em #fff,
        0 0 0 0.11em #2fcf6b,
        inset 0 -0.25em 0.3em -0.1em rgba(60, 100, 190, 0.28);
}
.wg.hfrom .jar,
.wg.hto .jar {
    animation: hint 1s ease-in-out infinite;
}
.wg.hto {
    --hc: #2fcf6b;
}
.wg.hfrom {
    --hc: #ffb400;
}
@keyframes hint {
    0%,
    100% {
        box-shadow:
            0 0 0 0.06em #fff,
            0 0 0 0.1em var(--hc);
    }
    50% {
        box-shadow:
            0 0 0 0.12em #fff,
            0 0 0 0.2em var(--hc);
    }
}
.wg.full .jar {
    background: linear-gradient(180deg, #fffbe0, #ffeaa0);
    border-color: #c89400;
}
.wg.full::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0.02em;
    width: 0.5em;
    height: 0.48em;
    margin-left: -0.25em;
    z-index: 6;
    background: linear-gradient(#fff6a0, #ffc400);
    clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    animation: starin 0.5s cubic-bezier(0.3, 1.8, 0.5, 1) both;
}
@keyframes starin {
    from {
        transform: scale(0) rotate(-120deg);
    }
}
.cd.mys {
    animation: wob 2.4s ease-in-out infinite;
}
@keyframes wob {
    0%,
    100% {
        transform: rotate(-4deg);
    }
    50% {
        transform: rotate(4deg);
    }
}
.cd.pop {
    animation: reveal 0.5s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes reveal {
    from {
        transform: scale(0.4) rotate(-25deg);
    }
}
.wg.shake {
    animation: shake 0.38s;
}
@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-0.1em);
    }
    50% {
        transform: translateX(0.1em);
    }
    75% {
        transform: translateX(-0.06em);
    }
}
.flyer {
    position: fixed;
    z-index: 70;
    pointer-events: none;
    margin: 0;
}

/* ---------- game screen ---------- */
.game {
    padding-bottom: calc(var(--sab) + 0.8rem);
}
.top {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 90rem;
    flex: none;
}
.ticket {
    position: relative;
    flex: 1;
    max-width: 36rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 4.8rem;
    padding: 0.3rem 1.8rem;
    line-height: 1;
    border-radius: 1rem;
    background:
        radial-gradient(circle at 0 50%, transparent 0 0.7rem, var(--paper) 0.75rem) left/51% 100% no-repeat,
        radial-gradient(circle at 100% 50%, transparent 0 0.7rem, var(--paper) 0.75rem) right/51% 100%
            no-repeat;
    filter: drop-shadow(0 0.3rem 0 var(--ink));
}
.ticket::before {
    content: "";
    position: absolute;
    inset: 0.35rem 0.9rem;
    border: 0.14rem dashed #c8cdea;
    border-radius: 0.6rem;
    pointer-events: none;
}
.ticket b {
    font-family: var(--hd);
    font-weight: 400;
    font-size: 2.3rem;
    position: relative;
}
.ticket span {
    font-size: 1.3rem;
    color: var(--ink2);
    position: relative;
    margin-top: 0.1rem;
}
.info {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    margin-top: 1rem;
    flex: none;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    height: 3.4rem;
    padding: 0 1.2rem;
    border-radius: 2rem;
    background: var(--paper);
    border: 0.2rem solid var(--ink);
    box-shadow: 0 0.3rem 0 var(--ink);
    font-size: 1.4rem;
    line-height: 1;
}
.chip small {
    font-size: 1.35rem;
    color: var(--ink2);
}
.chip b {
    font-family: var(--hd);
    font-weight: 400;
    font-size: 2rem;
}
.gs {
    display: flex;
    gap: 0.1rem;
}
.gs .star {
    width: 1.9rem;
    height: 1.9rem;
}
.star {
    fill: #ffd21f;
    stroke: #a97800;
    stroke-width: 1.6;
    stroke-linejoin: round;
    flex: none;
}
.star.off {
    fill: #d4d9ee;
    stroke: #9aa2c6;
}
.play {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 90rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 0.8rem;
}
.scene {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.yard {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(var(--s, 40px) * 0.3);
    font-size: var(--s, 40px);
}
.row {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0.16em;
    padding-bottom: 0.44em;
}
.row::after {
    content: "";
    position: absolute;
    left: -3%;
    right: -3%;
    bottom: 0;
    height: 0.34em;
    background:
        linear-gradient(#f4f7ff 0 0.07em, #7f88b8 0.07em 0.12em, transparent 0.12em),
        repeating-linear-gradient(90deg, #a9683a 0 0.38em, transparent 0.38em 0.66em) 0 0.14em/100% 0.2em
            no-repeat;
    z-index: 0;
}
.row .wg {
    z-index: 1;
}
.dock {
    display: flex;
    gap: 0.8rem;
    flex: none;
}
.dk {
    flex: 1;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: 6.4rem;
    padding: 0.5rem 0.2rem;
    border-radius: 1.8rem;
    font-size: 1.5rem;
    line-height: 1;
}
.dk img {
    width: 2.8rem;
    height: 2.8rem;
    position: relative;
}
.dk span {
    position: relative;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.26rem var(--d);
}
.dk em {
    position: absolute;
    top: -0.8rem;
    right: -0.3rem;
    min-width: 2.3rem;
    height: 2.3rem;
    border-radius: 1.2rem;
    background: #fff;
    color: var(--d);
    border: 0.2rem solid var(--d);
    font-style: normal;
    font-family: var(--hd);
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.3rem;
}
.yard.go .wg {
    animation: leave 1.1s ease-in both;
    animation-delay: calc(var(--n, 0) * 70ms);
}
.yard.go .wh {
    animation: roll 0.35s linear infinite;
}
@keyframes leave {
    40% {
        transform: translateY(-0.08em);
    }
    to {
        transform: translateX(120vw);
    }
}
@keyframes roll {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- level select ---------- */
.levels {
    align-items: center;
}
.lv-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 60rem;
    flex: none;
}
.station {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 5.4rem;
    padding: 0.4rem 0.6rem;
    border-radius: 2.2rem;
    background: var(--paper);
    border: 0.22rem solid var(--ink);
    box-shadow: 0 0.35rem 0 var(--ink);
}
.st-t {
    flex: 1;
    text-align: center;
    line-height: 1;
    min-width: 0;
}
.st-t h2 {
    font-family: var(--hd);
    font-weight: 400;
    font-size: 2.3rem;
    color: var(--wc);
    paint-order: stroke fill;
    -webkit-text-stroke: 0.38rem var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.st-t small {
    display: block;
    font-size: 1.3rem;
    color: var(--ink2);
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 4rem;
    padding: 0 1.2rem;
    border-radius: 2rem;
    background: var(--paper);
    border: 0.2rem solid var(--ink);
    box-shadow: 0 0.3rem 0 var(--ink);
    font-family: var(--hd);
    font-size: 2rem;
    flex: none;
}
.pill .star {
    width: 2.2rem;
    height: 2.2rem;
}
.v-dots {
    display: flex;
    gap: 0.8rem;
    margin: 1.1rem 0 0.3rem;
    flex: none;
}
.v-dots button {
    width: 1.3rem;
    height: 1.3rem;
    border-radius: 50%;
    background: #fff;
    border: 0.2rem solid var(--ink);
    transition: transform 0.2s;
}
.v-dots button.on {
    background: var(--wc);
    transform: scale(1.4);
}
.line-map {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 60rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lv-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    gap: 1.1rem 0.9rem;
    justify-items: center;
    font-size: var(--s, 50px);
    width: 100%;
    padding: 0.2rem 0;
}
.tk {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1em;
    position: relative;
    animation: tilein 0.4s ease both;
    animation-delay: calc(var(--i, 0) * 16ms);
}
@keyframes tilein {
    from {
        opacity: 0;
        transform: translateY(0.4em) scale(0.9);
    }
}
.tst {
    display: flex;
    gap: 0.02em;
    height: 0.34em;
}
.tst .star {
    width: 0.32em;
    height: 0.32em;
    stroke-width: 1.8;
}
.tk .mw {
    font-size: 1em;
    width: 1.64em;
    height: 1.76em;
}
.tk .mw .jar {
    display: flex;
    align-items: center;
    justify-content: center;
}
.tk .mw b {
    position: relative;
    z-index: 2;
    font-family: var(--hd);
    font-weight: 400;
    font-size: 0.62em;
    line-height: 1;
    color: #fff;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.14em var(--wd);
    margin-top: 0.28em;
}
.tk .cg {
    position: absolute;
    top: 0.04em;
    width: 0.5em;
    height: 0.5em;
    z-index: 1;
}
.tk .cg.a {
    left: 0.2em;
}
.tk .cg.b {
    right: 0.2em;
}
.tk .lk {
    width: 0.6em;
    height: 0.6em;
    position: relative;
    z-index: 2;
    margin-top: 0.1em;
}
.tk.locked .mw {
    --wc: #aab2d0 !important;
    --wl: #d4d9ec !important;
    --wd: #6c76a0 !important;
    filter: saturate(0.35);
}
.tk.current .mw {
    animation: cur 1.2s ease-in-out infinite;
}
.tk.current .mw .jar {
    box-shadow:
        0 0 0 0.07em #fff,
        0 0 0 0.14em #ffd21f;
}
@keyframes cur {
    50% {
        transform: translateY(-0.1em);
    }
}
@media (hover: hover) {
    .tk:not(.locked):hover .mw {
        transform: translateY(-0.08em);
        transition: transform 0.15s;
    }
}
.tk:not(.locked):active .mw {
    transform: translateY(0.05em);
}
.lv-sub {
    flex: none;
    margin-top: 0.6rem;
    font-size: 1.5rem;
    color: #fff;
    paint-order: stroke fill;
    -webkit-text-stroke: 0.3rem var(--ink);
    text-align: center;
}

/* ---------- popups ---------- */
.modal-back {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--sat) + 3rem) 1.4rem 1.4rem;
    background: rgba(35, 46, 104, 0.55);
    animation: fade 0.25s;
}
.modal {
    position: relative;
    width: 100%;
    max-width: 42rem;
    max-height: 100%;
    overflow: auto;
    border-radius: 2.4rem;
    background: var(--cream);
    border: 0.26rem solid var(--ink);
    box-shadow: 0 0.6rem 0 var(--ink);
    padding: 3.4rem 1.6rem 1.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    text-align: center;
    animation: pop 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes fade {
    from {
        opacity: 0;
    }
}
@keyframes pop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
}
.modal h2 {
    position: absolute;
    top: -2.6rem;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-family: var(--hd);
    font-weight: 400;
    font-size: 2.6rem;
    line-height: 1;
    padding: 0.7rem 2.4rem;
    border-radius: 1.3rem;
    color: #fff;
    background: linear-gradient(#ff9a4d, #ff7a1f);
    border: 0.2rem solid var(--ink);
    box-shadow:
        0 0.3rem 0 var(--ink),
        inset 0 0.12rem 0 rgba(255, 255, 255, 0.5);
    paint-order: stroke fill;
    -webkit-text-stroke: 0.34rem #a84a00;
}
.modal-body {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}
.modal-btns {
    display: flex;
    gap: 0.8rem;
    width: 100%;
    justify-content: center;
}
.modal-btns .tbtn {
    flex: 1;
    min-width: 0;
    padding: 0 1rem;
    font-size: 1.9rem;
}
.how {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    text-align: left;
}
.how li {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.55rem;
    line-height: 1.2;
}
.chip-i {
    flex: none;
    width: 4.4rem;
    height: 4.4rem;
    border-radius: 1.3rem;
    background: #fff;
    border: 0.18rem solid var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
}
.chip-i img {
    width: 3.2rem;
    height: 3.2rem;
}
.row-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 1.8rem;
}
.row-toggle span {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}
.row-toggle span img {
    width: 2.6rem;
    height: 2.6rem;
    filter: brightness(0.55) saturate(1.4) hue-rotate(-10deg);
}
.switch {
    position: relative;
    width: 6.2rem;
    height: 3.5rem;
    border-radius: 2rem;
    background: #c5cbe4;
    border: 0.2rem solid var(--ink);
    box-shadow: 0 0.25rem 0 var(--ink);
    transition: background 0.2s;
    flex: none;
}
.switch::after {
    content: "";
    position: absolute;
    left: 0.3rem;
    top: 0.3rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #fff;
    border: 0.18rem solid var(--ink);
    transition: transform 0.2s;
}
.switch[aria-checked="true"] {
    background: #2fcf6b;
}
.switch[aria-checked="true"]::after {
    transform: translateX(2.7rem);
}
.about {
    font-size: 1.3rem;
    color: var(--ink2);
}
.win-train {
    display: flex;
    align-items: flex-end;
    gap: 0.3rem;
    font-size: 3.6rem;
}
.win-train .eng {
    width: 8.6rem;
}
.win-train .eng img {
    width: 100%;
}
.win-train .mw {
    width: 1.64em;
    height: 1.7em;
    font-size: 1em;
}
.win-stars {
    display: flex;
    gap: 0.6rem;
}
.win-stars .star {
    width: 5.4rem;
    height: 5.4rem;
    stroke-width: 1.4;
}
.win-stars .star.on {
    animation: starpop 0.55s cubic-bezier(0.3, 1.8, 0.5, 1) both;
}
.win-stars .s2 {
    animation-delay: 0.26s !important;
}
.win-stars .s3 {
    animation-delay: 0.52s !important;
}
.win-stars .star.off {
    opacity: 0.7;
    transform: scale(0.8);
}
@keyframes starpop {
    from {
        transform: scale(0) rotate(-120deg);
    }
}
.win-sub {
    font-size: 1.6rem;
}
.confetti {
    position: absolute;
    top: -2rem;
    z-index: 80;
    pointer-events: none;
    animation-name: conf;
    animation-timing-function: ease-in;
    animation-fill-mode: forwards;
}
@keyframes conf {
    to {
        transform: translateY(110vh) rotate(var(--rot, 540deg));
        opacity: 0.9;
    }
}
#toast {
    position: fixed;
    left: 50%;
    top: calc(var(--sat) + 9rem);
    z-index: 90;
    transform: translate(-50%, -1rem);
    opacity: 0;
    pointer-events: none;
    padding: 0.8rem 1.5rem;
    border-radius: 1.6rem;
    background: var(--ink);
    color: #fff;
    font-size: 1.5rem;
    max-width: 90%;
    text-align: center;
    transition:
        opacity 0.25s,
        transform 0.25s;
}
#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- wide screens ---------- */
@media (min-aspect-ratio: 11/10) {
    .menu {
        flex-direction: row;
        justify-content: center;
    }
    .m-center {
        margin-bottom: 9rem;
    }
    .play {
        flex-direction: row;
        align-items: stretch;
    }
    .dock {
        flex-direction: column;
        justify-content: center;
        width: 8.4rem;
    }
    .dk {
        flex: 0 0 auto;
        min-height: 7rem;
    }
    .m-track {
        height: 10rem;
    }
}
@media (max-height: 520px) {
    .logo .l1 {
        font-size: 3.6rem;
    }
    .logo em {
        font-size: 2.2rem;
    }
    .m-center {
        gap: 0.9rem;
        margin-bottom: 8rem;
    }
    .playb {
        min-width: 20rem;
    }
    .pl-ic {
        width: 4.2rem;
        height: 4.2rem;
    }
    .pl-t b {
        font-size: 2.5rem;
    }
    .m-prog {
        display: none;
    }
    .nb {
        min-height: 4.8rem;
        flex-direction: row;
        gap: 0.6rem;
    }
}
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* candies inside mini wagons (menu train, win dialog) */
.m-train .mw,
.win-train .mw {
    width: 1.64em;
    height: 2.1em;
}
.m-train .mw .cg,
.win-train .mw .cg {
    position: absolute;
    left: 50%;
    margin-left: -0.39em;
    width: 0.78em;
    height: 0.78em;
    z-index: 1;
}
.m-train .mw .cg.a,
.win-train .mw .cg.a {
    bottom: 0.06em;
}
.m-train .mw .cg.b,
.win-train .mw .cg.b {
    bottom: 0.8em;
}
.win-train .mw {
    font-size: 3.4rem;
}

/* layout safety */
.scene {
    min-width: 0;
}
.dock {
    flex: none;
}
.lv-head > * {
    min-width: 0;
}
.lv-head .station {
    flex: 1 1 0;
}
.lv-head .pill,
.lv-head .rb {
    flex: none;
}
.st-t h2 {
    font-size: 2rem;
}
.m-train {
    animation-delay: -9s;
}
.logo .l1 {
    font-size: 5.8rem;
}
.m-train .mw {
    font-size: 3.7rem;
}
.m-train .eng {
    width: 10rem;
}
.m-track {
    height: 9.5rem;
}
.m-center {
    margin-bottom: 8.5rem;
}
@media (max-aspect-ratio: 3/4) {
    .lv-head {
        flex-wrap: wrap;
        row-gap: 1rem;
    }
    .lv-head #btnLevelsBack {
        order: 1;
    }
    .lv-head .pill {
        order: 2;
        margin-left: auto;
    }
    .lv-head .station {
        order: 3;
        flex: 1 1 100%;
    }
    .st-t h2 {
        font-size: 2.3rem;
    }
}
.m-track {
    height: 12rem;
}
.m-train {
    bottom: 2.6rem;
}
.m-center {
    margin-bottom: 10rem;
}
.modal {
    overflow: visible;
}
.modal-body {
    max-height: calc(100vh - 22rem);
    overflow: auto;
    padding: 0 0.3rem;
}
@media (min-aspect-ratio: 11/10) and (max-height: 520px) {
    .dock {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 17rem;
        align-content: center;
        gap: 0.7rem;
    }
    .dk {
        min-height: 5rem;
        flex-direction: row;
        gap: 0.4rem;
        font-size: 1.3rem;
    }
    .dk img {
        width: 2.2rem;
        height: 2.2rem;
    }
    .info {
        margin-top: 0.6rem;
    }
    .top .rb {
        width: 4.2rem;
        height: 4.2rem;
    }
}

/* ---------- menu: always fits the window (JS sets --ms) ---------- */
.menu {
    justify-content: flex-start;
    flex-direction: column !important;
    padding-bottom: calc(var(--sab) + 12.6rem);
}
.m-center {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 !important;
    max-width: none;
    justify-content: center;
    align-items: center;
    overflow: visible;
}
.m-in {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 38rem;
    zoom: var(--ms, 1);
}
@media (max-height: 520px) {
    .m-in {
        gap: 0.9rem;
    }
    .menu {
        padding-bottom: calc(var(--sab) + 11rem);
    }
}
/* level tile: candies peek out above the lid instead of covering the number */
.tk .cg {
    top: -0.36em;
    width: 0.46em;
    height: 0.46em;
}
.tk .cg.a {
    left: 0.22em;
}
.tk .cg.b {
    right: 0.22em;
}
.row-toggle {
    overflow: visible;
}
.row-toggle .tbtn {
    margin-bottom: 0.4rem;
}
.modal-body {
    padding: 0 0.3rem 0.6rem;
}
.menu {
    padding-bottom: calc(var(--sab) + 13.2rem) !important;
}

/* bunting strip for wide screens (the picture itself is cropped there) */
.bun {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 5.4rem;
    background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%20368%2056%22%3E%3Cpath%20d%3D%22M0%206Q46%2020%2092%206Q138%2020%20184%206Q230%2020%20276%206Q322%2020%20368%206%22%20fill%3D%22none%22%20stroke%3D%22%23fff%22%20stroke-width%3D%223%22%20opacity%3D%22.85%22/%3E%3Cpath%20d%3D%22M7%2011L46%2052L85%2011Q46%2022%207%2011Z%22%20fill%3D%22%23ff5d73%22/%3E%3Cpath%20d%3D%22M7%2011L46%2052L46%2020Z%22%20fill%3D%22%23fff%22%20opacity%3D%22.18%22/%3E%3Cpath%20d%3D%22M99%2011L138%2052L177%2011Q138%2022%2099%2011Z%22%20fill%3D%22%23ffd93d%22/%3E%3Cpath%20d%3D%22M99%2011L138%2052L138%2020Z%22%20fill%3D%22%23fff%22%20opacity%3D%22.18%22/%3E%3Cpath%20d%3D%22M191%2011L230%2052L269%2011Q230%2022%20191%2011Z%22%20fill%3D%22%233a7bff%22/%3E%3Cpath%20d%3D%22M191%2011L230%2052L230%2020Z%22%20fill%3D%22%23fff%22%20opacity%3D%22.18%22/%3E%3Cpath%20d%3D%22M283%2011L322%2052L361%2011Q322%2022%20283%2011Z%22%20fill%3D%22%2346c45a%22/%3E%3Cpath%20d%3D%22M283%2011L322%2052L322%2020Z%22%20fill%3D%22%23fff%22%20opacity%3D%22.18%22/%3E%3C/svg%3E")
        repeat-x 0 0/36.8rem 5.4rem;
    display: none;
    pointer-events: none;
}
@media (min-aspect-ratio: 6/5) {
    .bun {
        display: block;
    }
    .bn {
        display: none;
    }
}
@media (min-aspect-ratio: 6/5) {
    .menu {
        padding-top: calc(var(--sat) + 4.6rem) !important;
    }
}
