/* ==========================================================================
   Unknot - styles
   Colours live in the variables below. Change them to re-theme the interface.
   ========================================================================== */
@font-face {
    font-family: "Fredoka";
    src: url("../assets/fonts/fredoka-latin-600-normal.woff2") format("woff2");
    font-weight: 600;
    font-display: swap;
}
@font-face {
    font-family: "Fredoka";
    src: url("../assets/fonts/fredoka-latin-700-normal.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: "Nunito";
    src: url("../assets/fonts/nunito-latin-700-normal.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: "Nunito";
    src: url("../assets/fonts/nunito-latin-800-normal.woff2") format("woff2");
    font-weight: 800;
    font-display: swap;
}

:root {
    --ink: #0b1f33;
    --navy: #0f2a43;
    --navy2: #1a4766;
    --panel: #173a57;
    --cream: #fbf3e2;
    --text: #eaf2f8;
    --muted: #a6bdd0;
    --sun: #f6b73c;
    --coral: #ec4c3f;
    --sea: #38a3dc;
    --leaf: #4cc38a;
    --head: "Fredoka", "Trebuchet MS", sans-serif;
    --body: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--navy);
    color: var(--text);
    font-family: var(--body);
    font-weight: 700;
    overscroll-behavior: none;
}
body {
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    background: radial-gradient(ellipse at 50% -10%, #2d6a93 0%, transparent 62%),
        repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.028) 0 14px, transparent 14px 28px),
        linear-gradient(180deg, #123552, #0b2238 70%, #08192a);
}
button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    border: 0;
    background: none;
    padding: 0;
}
button:focus-visible {
    outline: 3px solid #8fd8ff;
    outline-offset: 2px;
}
.bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}
body.playing .bg {
    display: none;
}
.app {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    justify-content: center;
}
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active {
    display: flex;
    animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes rise {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
@keyframes fade {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
.ic {
    width: 1.25em;
    height: 1.25em;
    flex: none;
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45em;
    min-height: 48px;
    padding: 0 1.2em;
    border: 3px solid var(--ink);
    border-radius: 16px;
    background: linear-gradient(180deg, #fffaf0, #f0e3c4);
    color: var(--ink);
    font-family: var(--head);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.01em;
    position: relative;
    white-space: nowrap;
    box-shadow:
        0 5px 0 var(--ink),
        inset 0 2px 0 rgba(255, 255, 255, 0.7);
    transition:
        transform 0.08s,
        box-shadow 0.08s,
        filter 0.15s;
}
.btn:hover {
    filter: brightness(1.05);
}
.btn:active {
    transform: translateY(4px);
    box-shadow:
        0 1px 0 var(--ink),
        inset 0 2px 0 rgba(255, 255, 255, 0.7);
}
.btn:disabled {
    opacity: 0.45;
    filter: grayscale(0.6);
    pointer-events: none;
}
.btn.sun {
    background: linear-gradient(180deg, #ffd461, #f2a926);
}
.btn.coral {
    background: linear-gradient(180deg, #ff7a6b, #e0372b);
    color: #fff;
}
.btn.sea {
    background: linear-gradient(180deg, #6fc6f2, #2d8fcb);
    color: #fff;
}
.btn.leaf {
    background: linear-gradient(180deg, #7fe0b0, #34b479);
    color: #0b2a1c;
}
.btn.sm {
    min-height: 42px;
    font-size: 16px;
    padding: 0 1em;
    border-radius: 14px;
}
.btn.xl {
    min-height: 74px;
    font-size: 34px;
    padding: 0 2.2em;
    border-radius: 24px;
    box-shadow:
        0 8px 0 var(--ink),
        inset 0 3px 0 rgba(255, 255, 255, 0.7);
}
.btn.xl:active {
    transform: translateY(6px);
    box-shadow:
        0 2px 0 var(--ink),
        inset 0 3px 0 rgba(255, 255, 255, 0.7);
}
.btn.xl .ic {
    width: 1em;
    height: 1em;
}
.btn.rb {
    width: 60px;
    height: 60px;
    min-height: 0;
    padding: 0;
    border-radius: 19px;
}
.btn.rb .ic {
    width: 28px;
    height: 28px;
}
.btn.rb.sm {
    width: 46px;
    height: 46px;
    border-radius: 15px;
}
.btn.rb.sm .ic {
    width: 24px;
    height: 24px;
}
.btn.off {
    opacity: 0.7;
}

/* ---------- loader + menu ---------- */
.center-col {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px;
    text-align: center;
    width: min(92vw, 460px);
}
.knot {
    width: clamp(120px, 24vh, 190px);
    height: clamp(120px, 24vh, 190px);
    filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.25));
    animation: sway 5s ease-in-out infinite;
}
@keyframes sway {
    0%,
    100% {
        transform: rotate(-4deg) translateY(0);
    }
    50% {
        transform: rotate(4deg) translateY(-6px);
    }
}
.wordmark {
    margin: 0;
    font-family: var(--head);
    font-weight: 700;
    font-size: clamp(44px, 9.5vh, 64px);
    line-height: 1.05;
    letter-spacing: 0.02em;
    background: repeating-linear-gradient(112deg, #1b57ad 0 0.3em, #f3f6fa 0.3em 0.6em, #7ec4ee 0.6em 0.9em);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 3px 0 var(--ink)) drop-shadow(2px 0 0 var(--ink)) drop-shadow(-2px 0 0 var(--ink))
        drop-shadow(0 -2px 0 var(--ink));
    padding: 0 6px;
}
.wordmark.big {
    font-size: clamp(54px, 12vh, 84px);
}
.tagline {
    margin: 0;
    color: var(--muted);
    font-size: 18px;
    max-width: 26ch;
    line-height: 1.3;
}
.chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 4px 0 6px;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 16px 6px 12px;
    border: 3px solid var(--ink);
    border-radius: 999px;
    background: var(--panel);
    font-family: var(--head);
    font-size: 18px;
    box-shadow: 0 4px 0 var(--ink);
}
.chip .ic {
    width: 22px;
    height: 22px;
}
.menu-row {
    display: flex;
    gap: 18px;
    margin-top: 12px;
    justify-content: center;
}
.mbtn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 92px;
}
.mbtn span {
    font-size: 14px;
    color: var(--muted);
}
.ropebar {
    width: min(72vw, 300px);
    height: 26px;
    border: 3px solid var(--ink);
    border-radius: 14px;
    background: #0a1d30;
    overflow: hidden;
    margin-top: 8px;
    box-shadow: 0 4px 0 var(--ink);
}
.ropebar i {
    display: block;
    height: 100%;
    width: 0;
    background-size: auto 100%;
    background-repeat: repeat-x;
    transition: width 0.2s;
    animation: slide 1.2s linear infinite;
    border-right: 3px solid var(--ink);
}
@keyframes slide {
    to {
        background-position-x: -88px;
    }
}
.loadtxt {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}

/* ---------- menu sign ---------- */
#menu {
    align-items: center;
}
.menu-art {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.sign {
    position: relative;
    z-index: 1;
    margin-top: clamp(72px, 15vh, 130px);
    width: min(88vw, 420px);
    padding: 26px 24px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}
.sign .tagline {
    color: #5a3a16;
    font-weight: 800;
    max-width: 22ch;
}
.sign .knot.sm {
    width: clamp(84px, 15vh, 120px);
    height: clamp(84px, 15vh, 120px);
    margin-top: -10px;
}
.sign .menu-row {
    margin-top: 8px;
}
.sign .mbtn span {
    color: #5a3a16;
    font-weight: 800;
}
#menu .chips {
    position: relative;
    z-index: 1;
    margin-top: auto;
    padding-bottom: 28px;
}
@media (max-height: 700px) {
    .sign {
        margin-top: 64px;
        gap: 8px;
        padding: 20px 20px 22px;
    }
    .sign .tagline {
        font-size: 16px;
    }
}

/* ---------- bars ---------- */
.bar,
.hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px 6px;
    flex: none;
}
.bar-title {
    margin: 0;
    font-family: var(--head);
    font-weight: 700;
    font-size: 30px;
    color: var(--cream);
    text-shadow: 0 3px 0 var(--ink);
}
.scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 16px 30px;
    -webkit-overflow-scrolling: touch;
}

/* ---------- levels ---------- */
.chapters {
    display: flex;
    flex-direction: column;
    gap: 26px;
}
.chap-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 4px 8px;
    font-family: var(--head);
    font-size: 22px;
    color: var(--cream);
    text-shadow: 0 2px 0 var(--ink);
}
.chap-stars {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 17px;
    color: var(--sun);
}
.chap-stars .ic {
    width: 20px;
    height: 20px;
}
.rope-strip {
    height: 16px;
    margin: 0 0 14px;
    border-radius: 8px;
    background-size: auto 100%;
    background-repeat: repeat-x;
    box-shadow:
        0 3px 0 rgba(0, 0, 0, 0.3),
        0 0 0 2px var(--ink);
}
.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}
.lv {
    aspect-ratio: 1;
    min-height: 58px;
    border: 3px solid var(--ink);
    border-radius: 16px;
    background: linear-gradient(180deg, #fffaf0, #efe2c2);
    color: var(--ink);
    box-shadow:
        0 4px 0 var(--ink),
        inset 0 2px 0 rgba(255, 255, 255, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    transition:
        transform 0.08s,
        box-shadow 0.08s;
}
.lv:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--ink);
}
.lv b {
    font-family: var(--head);
    font-weight: 700;
    font-size: 25px;
    line-height: 1;
}
.lv .mini {
    display: flex;
    gap: 1px;
}
.lv .mini .ic {
    width: 14px;
    height: 14px;
    color: #cdbf9f;
}
.lv .mini .ic.on {
    color: var(--sun);
}
.c1 .lv {
    background: linear-gradient(180deg, #e2f5e0, #c3e6bd);
}
.c2 .lv {
    background: linear-gradient(180deg, #ffe7cf, #f7c89a);
}
.c3 .lv {
    background: linear-gradient(180deg, #f2e0fa, #dcbdf0);
}
.c4 .lv {
    background: linear-gradient(180deg, #d9efff, #aed7f5);
}
.lv.locked {
    background: var(--panel) !important;
    color: var(--muted);
    box-shadow: 0 2px 0 var(--ink);
    pointer-events: none;
    opacity: 0.85;
}
.lv .lock {
    width: 24px;
    height: 24px;
}

/* ---------- game ---------- */
.hud .title {
    text-align: center;
    line-height: 1.05;
}
.hud .chap {
    font-size: 13px;
    color: var(--muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.hud .lvl {
    font-family: var(--head);
    font-weight: 700;
    font-size: 28px;
    color: var(--cream);
    text-shadow: 0 3px 0 var(--ink);
}
.status {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 4px 12px 8px;
    flex: none;
}
.st {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 14px;
    min-height: 40px;
    border: 3px solid var(--ink);
    border-radius: 999px;
    background: var(--panel);
    box-shadow: 0 3px 0 var(--ink);
    font-size: 15px;
}
.st-lbl {
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.st b {
    font-family: var(--head);
    font-size: 22px;
    color: var(--cream);
    font-weight: 700;
}
.st-of {
    color: var(--muted);
}
.meter {
    display: block;
    width: 54px;
    height: 10px;
    border: 2px solid var(--ink);
    border-radius: 6px;
    background: #0a1d30;
    overflow: hidden;
}
.meter i {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--sea);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.25s;
}
.meter i.low {
    background: var(--coral);
}
#tangleBox b {
    color: #ff9c8f;
}
#tangleBox.clear b {
    color: var(--leaf);
}
.stage {
    flex: 1;
    min-height: 0;
    position: relative;
    margin: 0 2px;
}
.stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}
.tip {
    flex: none;
    margin: 2px 14px 6px;
    text-align: center;
    color: var(--muted);
    font-size: 15px;
    min-height: 1.4em;
}
.actions {
    flex: none;
    display: flex;
    gap: 10px;
    padding: 4px 14px 16px;
}
.btn.act {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-height: 66px;
    font-size: 16px;
    border-radius: 18px;
}
.btn.act .ic {
    width: 26px;
    height: 26px;
}
.btn.act b {
    font-weight: 700;
}
.toast {
    position: fixed;
    left: 50%;
    top: calc(122px + env(safe-area-inset-top));
    transform: translate(-50%, -14px);
    background: var(--cream);
    color: var(--ink);
    border: 3px solid var(--ink);
    border-radius: 14px;
    padding: 8px 16px;
    font-size: 15px;
    box-shadow: 0 4px 0 var(--ink);
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.2s,
        transform 0.2s;
    z-index: 30;
    max-width: 90vw;
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- dialogs ---------- */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(5, 14, 24, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}
.scrim.open {
    display: flex;
    animation: fade 0.2s ease;
}
.card {
    width: min(92vw, 400px);
    padding: 22px 20px 20px;
    border: 4px solid var(--ink);
    border-radius: 26px;
    background: linear-gradient(180deg, #1d4a6b, #163b57);
    box-shadow: 0 8px 0 var(--ink);
    text-align: center;
}
.card.wide {
    width: min(94vw, 460px);
}
.card h3 {
    margin: 0 0 8px;
    font-family: var(--head);
    font-weight: 700;
    font-size: 32px;
    color: var(--cream);
    text-shadow: 0 3px 0 var(--ink);
}
.card p {
    margin: 6px 0 16px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.4;
}
.card .col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}
.card .btn {
    min-width: 150px;
}
.stars {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 2px 0 6px;
}
.stars .ic.big {
    width: 66px;
    height: 66px;
    color: #3f607c;
    transform: scale(0.6);
    opacity: 0.6;
}
.stars .ic.big.on {
    color: var(--sun);
    animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
@keyframes pop {
    from {
        transform: scale(0.2) rotate(-30deg);
        opacity: 0;
    }
    to {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}
.steps {
    text-align: left;
    margin: 10px 0 18px;
    padding: 0;
    list-style: none;
    counter-reset: s;
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.steps li {
    counter-increment: s;
    position: relative;
    padding: 9px 12px 9px 50px;
    border: 3px solid var(--ink);
    border-radius: 14px;
    background: #0f2f49;
    font-size: 15px;
    line-height: 1.35;
    color: var(--text);
}
.steps li::before {
    content: counter(s);
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--sun);
    color: var(--ink);
    border: 3px solid var(--ink);
    font-family: var(--head);
    font-size: 16px;
    display: grid;
    place-items: center;
}
.steps b {
    color: var(--sun);
}
.set-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    margin: 10px 0;
    border: 3px solid var(--ink);
    border-radius: 16px;
    background: #0f2f49;
    text-align: left;
    flex-wrap: wrap;
}
.set-txt {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 140px;
}
.set-txt b {
    font-family: var(--head);
    font-size: 19px;
    color: var(--cream);
    font-weight: 700;
}
.set-txt small {
    color: var(--muted);
    font-size: 13px;
}

@media (min-width: 820px) and (min-aspect-ratio: 5/4) {
    #game {
        max-width: none;
        left: 0;
        transform: none;
        display: none;
        --ar: 0.86;
        grid-template-columns: 1fr auto 1fr;
        grid-template-rows: auto 1fr auto auto auto 1fr;
        padding: 0 18px 10px;
    }
    #game.active {
        display: grid;
    }
    #game .hud {
        grid-column: 1 / -1;
        grid-row: 1;
        padding: 12px 0 6px;
    }
    #game .stage {
        grid-column: 2;
        grid-row: 2 / 7;
        margin: 0 22px;
        justify-self: center;
        align-self: stretch;
        height: 100%;
        width: min(calc((100vh - 96px) * var(--ar)), calc(100vw - 440px));
    }
    #game .status {
        grid-column: 3;
        grid-row: 3;
        justify-self: start;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 0 0 12px;
        width: 168px;
    }
    #game .status .st {
        justify-content: center;
        white-space: nowrap;
        padding: 5px 10px;
        gap: 6px;
    }
    #game .status .meter {
        width: 34px;
    }
    #game .actions {
        grid-column: 3;
        grid-row: 4;
        justify-self: start;
        flex-direction: column;
        gap: 10px;
        padding: 0;
        width: 168px;
    }
    #game .actions .btn.act {
        flex: none;
        flex-direction: row;
        justify-content: center;
        gap: 9px;
        min-height: 54px;
        font-size: 18px;
    }
    #game .tip {
        grid-column: 3;
        grid-row: 5;
        justify-self: start;
        width: 168px;
        margin: 12px 0 0;
        text-align: left;
        font-size: 14px;
    }
}
@media (max-height: 640px) {
    .knot {
        width: 96px;
        height: 96px;
    }
    .btn.xl {
        min-height: 60px;
        font-size: 28px;
    }
    .btn.act {
        min-height: 56px;
    }
    .btn.rb {
        width: 52px;
        height: 52px;
    }
}
/* ---------- polish ---------- */
.lv {
    animation: tile 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
    animation-delay: calc(var(--i, 0) * 28ms);
}
@keyframes tile {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
.lv.current {
    animation:
        tile 0.4s both,
        beat 1.6s ease-in-out 0.5s infinite;
    animation-delay: calc(var(--i, 0) * 28ms), 0.5s;
    outline: 3px solid var(--sun);
    outline-offset: 3px;
}
@keyframes beat {
    0%,
    100% {
        outline-color: var(--sun);
        outline-offset: 3px;
    }
    50% {
        outline-color: rgba(246, 183, 60, 0.35);
        outline-offset: 6px;
    }
}
@media (hover: hover) {
    .lv:not(.locked):hover {
        transform: translateY(-3px);
        box-shadow:
            0 7px 0 var(--ink),
            inset 0 2px 0 rgba(255, 255, 255, 0.7);
    }
    .btn:hover {
        transform: translateY(-2px);
    }
    .btn:active {
        transform: translateY(4px);
    }
}
.card {
    animation: cardin 0.3s cubic-bezier(0.2, 1.3, 0.4, 1);
}
@keyframes cardin {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
.stars .ic.big:nth-child(2) {
    animation-delay: 0.15s !important;
}
.stars .ic.big:nth-child(3) {
    animation-delay: 0.3s !important;
}
@media (min-width: 720px) {
    #levels {
        max-width: 820px;
    }
    .grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 8px;
    }
    .lv {
        min-height: 0;
        border-radius: 13px;
    }
    .lv b {
        font-size: 21px;
    }
    .lv .mini .ic {
        width: 11px;
        height: 11px;
    }
}
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
