/* Level colours; ThemeController updates them whenever the level changes. */
:root{
    --page-color: #9ECCEE;
    --sky-top: #4aa6ea;
    --sky-bottom: #d4ecff;
    /* Size of the game world in canvas pixels; main.js raises the height on phones held upright. */
    --world-width: 770;
    --world-height: 700;
    --gutter: 16px;
    --accent: #ca8c3a;
    --font: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
}

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body{
    height: 100%;
}

/* No double-tap zoom anywhere on the page (touch-action applies to everything inside). */
html{
    touch-action: manipulation;
}

body{
    background: var(--page-color);
    background-image: linear-gradient(180deg, color-mix(in srgb, var(--sky-top) 70%, black), var(--page-color));
    font-family: var(--font);
    overflow: hidden;
    transition: background-color .6s;
    -webkit-tap-highlight-color: transparent;
}

/* Fills the screen (dvh follows Safari's toolbar) and keeps clear of the iPhone notch and home bar. */
/* Pinned to the edges of the viewport (dvh follows Safari's toolbar, fixed does too and is simpler). */
.app{
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding:
        max(8px, env(safe-area-inset-top))
        max(var(--gutter), env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(var(--gutter), env(safe-area-inset-left));
    user-select: none;
    -webkit-user-select: none;
}

/* The space left for the canvas; a size container, so the canvas can fit it in both directions. */
.stage{
    flex: 1;
    min-height: 0;
    width: 100%;
    display: grid;
    place-items: center;
    container-type: size;
}

/* Keeps the world's aspect ratio and fits the stage on both desktop and phone. */
.game-canvas{
    display: block;
    width: min(100cqw, 100cqh * var(--world-width) / var(--world-height));
    height: auto;
    aspect-ratio: var(--world-width) / var(--world-height);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
    touch-action: none;
    -webkit-touch-callout: none;
}

.toolbar{
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.toolbar__button{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 120px;
    padding: 12px 18px;
    font: bold 15px var(--font);
    color: #2d3436;
    background: rgba(255, 255, 255, .9);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform .15s, box-shadow .3s, background .3s;
}
/* Touch screens keep :hover after a tap, which would leave the button lit; only real mice get it. */
@media (hover: hover){
    .toolbar__button:hover:not(:disabled){
        background: var(--accent);
        color: #fff;
        box-shadow: 0 0 5px var(--accent), 0 0 25px var(--accent);
    }
}
.toolbar__button:focus-visible{
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 5px var(--accent), 0 0 25px var(--accent);
}
.toolbar__button:active:not(:disabled){
    transform: scale(.96);
}
.toolbar__button:disabled{
    opacity: .5;
    cursor: default;
}

/*
 * Phones: one row of tab-bar style buttons, icon above a small label.
 * --phone-top-gap keeps the top of the game and the Hangar below browser bars drawn over the page
 * (e.g. the search bar of the Google app on iPhone), which do not count as a safe area.
 */
@media (max-width: 600px){
    :root{
        --phone-top-gap: 56px;
    }
    .app{
        padding-top: max(var(--phone-top-gap), env(safe-area-inset-top));
        gap: 8px;
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }
    .game-canvas{
        border-radius: 10px;
    }
    .toolbar{
        width: 100%;
        flex-wrap: nowrap;
        gap: 6px;
    }
    .toolbar__button{
        flex: 1 1 0;
        flex-direction: column;
        gap: 2px;
        min-width: 0;
        min-height: 52px;
        padding: 6px 2px;
        border-radius: 14px;
    }
    .toolbar__icon{
        font-size: 20px;
        line-height: 1;
    }
    /* Six buttons share a phone's width, so a long label is cut rather than widening its button. */
    .toolbar__label{
        max-width: 100%;
        overflow: hidden;
        font-size: 10.5px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
}

.modal{
    margin: auto;
    min-width: min(320px, calc(100vw - 32px));
    max-width: min(420px, calc(100vw - 32px));
    padding: 24px;
    border: none;
    border-radius: 12px;
    background: #fff;
    color: #222;
    font-family: var(--font);
    box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.modal::backdrop{
    background: rgba(0, 0, 0, .45);
}
.modal__message{
    margin-bottom: 16px;
    font-size: 18px;
    line-height: 1.4;
    white-space: pre-line;
}
.modal__input{
    width: 100%;
    margin-bottom: 16px;
    padding: 10px 12px;
    font-size: 16px;
    border: 2px solid #9ECCEE;
    border-radius: 6px;
    outline: none;
}
.modal__input:focus{
    border-color: var(--accent);
}
.modal__actions{
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.modal__button{
    padding: 10px 20px;
    font-size: 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: .3s;
}
.modal__button--cancel{
    background: #e5e5e5;
}
.modal__button--confirm{
    background: var(--accent);
    color: #fff;
}
.modal__button:hover,
.modal__button:focus-visible{
    box-shadow: 0 0 5px currentColor;
}
.modal__button--confirm:hover,
.modal__button--confirm:focus-visible{
    box-shadow: 0 0 5px var(--accent), 0 0 20px var(--accent);
}
[hidden]{
    display: none !important;
}

/* ---------- Coin icon (HTML) ---------- */
.coin-icon{
    display: inline-block;
    width: 1em;
    height: 1em;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff6a8, #ffd23f 60%, #e0a800);
    box-shadow: inset 0 0 0 2px #b8860b;
    vertical-align: -0.15em;
}

/* ---------- Hangar (shop) ---------- */
.shop{
    margin: auto;
    width: min(860px, calc(100vw - 2 * var(--gutter)));
    max-height: calc(100vh - 32px);
    padding: 0;
    border: none;
    border-radius: 18px;
    background: #1e2a3a;
    color: #f1f2f6;
    font-family: var(--font);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    overflow: hidden;
}
.shop[open]{
    display: flex;
    flex-direction: column;
}
.shop::backdrop{
    background: rgba(0, 0, 0, .55);
}
.shop__header{
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 22px 10px;
}
.shop__title{
    flex: 1;
    font-size: 28px;
    letter-spacing: .5px;
}
.shop__wallet{
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 20px;
    font-weight: bold;
    color: #ffd23f;
    background: rgba(255, 255, 255, .08);
    border-radius: 999px;
}
.shop__close{
    width: 38px;
    height: 38px;
    font-size: 18px;
    color: inherit;
    background: rgba(255, 255, 255, .1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}
.shop__close:hover,
.shop__close:focus-visible{
    background: #ff4757;
}
.shop__tabs{
    display: flex;
    gap: 8px;
    padding: 0 22px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.shop__tab{
    padding: 9px 16px;
    font: bold 15px var(--font);
    color: #c8d6e5;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, .15);
    border-radius: 999px;
    cursor: pointer;
}
.shop__tab[aria-selected="true"]{
    color: #1e2a3a;
    background: #ffd23f;
    border-color: #ffd23f;
}
.shop__grid{
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    align-content: start;
    gap: 14px;
    padding: 18px 22px 22px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.shop-card{
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    background: #2a3a50;
    border: 2px solid transparent;
    border-radius: 14px;
}
.shop-card.is-highlighted{
    border-color: #2ed573;
}
.shop-card__body{
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
}
/* The Workshop summary of the equipped plane spans the whole row. */
.shop-card--wide{
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 18px;
}
.shop-card--wide .shop-card__preview{
    flex: 0 0 140px;
}
.shop-card__preview{
    display: grid;
    place-items: center;
    height: 120px;
    background: radial-gradient(circle, rgba(255, 255, 255, .12), transparent 70%);
    border-radius: 10px;
}
.shop-card__preview canvas{
    width: 120px;
    height: 120px;
}
.shop-card__icon{
    font-size: 60px;
}
.shop-card__title{
    font-size: 18px;
}
.shop-card__description{
    flex: 1;
    font-size: 14px;
    line-height: 1.35;
    color: #c8d6e5;
}
.shop-card__stats{
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
}
.shop-card__stat{
    padding: 3px 9px;
    font-size: 12px;
    font-weight: bold;
    color: #a4f0ff;
    background: rgba(79, 195, 247, .15);
    border-radius: 999px;
}
.shop-card__pips{
    display: flex;
    gap: 5px;
}
.shop-card__pip{
    width: 16px;
    height: 8px;
    background: rgba(255, 255, 255, .15);
    border-radius: 4px;
}
.shop-card__pip.is-filled{
    background: #2ed573;
}
.shop-card__action{
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
    padding: 10px;
    font: bold 15px var(--font);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .15s, filter .2s;
}
.shop-card__action:hover:not(:disabled){
    filter: brightness(1.12);
}
.shop-card__action:active:not(:disabled){
    transform: scale(.97);
}
.shop-card__action--buy{
    color: #1e2a3a;
    background: #ffd23f;
}
.shop-card__action--equip{
    color: #fff;
    background: #2f7fd6;
}
.shop-card__action--equipped{
    color: #2ed573;
    background: rgba(46, 213, 115, .12);
    cursor: default;
}
.shop-card__action--buy:disabled{
    color: #ff6b81;
    background: rgba(255, 255, 255, .08);
    cursor: not-allowed;
}
.shop-card__price{
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/*
 * Phones: the Hangar becomes a sheet rising from the bottom edge, stopping below the top gap
 * (see --phone-top-gap), with scrollable tabs and one card per row (picture on the left).
 */
@media (max-width: 600px){
    .shop{
        inset: max(var(--phone-top-gap), env(safe-area-inset-top)) 0 0 0;
        margin: 0;
        width: 100%;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 18px 18px 0 0;
    }
    .shop__header{
        gap: 10px;
        padding:
            14px
            calc(14px + env(safe-area-inset-right))
            8px
            calc(14px + env(safe-area-inset-left));
    }
    .shop__title{
        font-size: 22px;
    }
    .shop__wallet{
        font-size: 17px;
    }
    .shop__close{
        flex-shrink: 0;
        width: 44px;
        height: 44px;
    }
    .shop__tabs{
        flex-shrink: 0;
        padding: 0 14px 12px;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .shop__tabs::-webkit-scrollbar{
        display: none;
    }
    .shop__tab{
        flex-shrink: 0;
        min-height: 40px;
        white-space: nowrap;
        touch-action: manipulation;
    }
    .shop__grid{
        grid-template-columns: 1fr;
        gap: 10px;
        padding:
            12px
            calc(12px + env(safe-area-inset-right))
            calc(16px + env(safe-area-inset-bottom))
            calc(12px + env(safe-area-inset-left));
    }
    .shop-card,
    .shop-card--wide{
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
    }
    .shop-card__preview,
    .shop-card--wide .shop-card__preview{
        flex: 0 0 84px;
        height: 84px;
    }
    .shop-card__preview canvas{
        width: 84px;
        height: 84px;
    }
    .shop-card__icon{
        font-size: 44px;
    }
    .shop-card__body{
        min-width: 0;
        gap: 6px;
    }
    .shop-card__title{
        font-size: 16px;
    }
    .shop-card__description{
        font-size: 13px;
    }
    .shop-card__action{
        min-height: 44px;
        touch-action: manipulation;
    }
}

/* ---------- Missions and medals in the Hangar ---------- */
.shop-card__progress{
    position: relative;
    height: 22px;
    overflow: hidden;
    background: rgba(255, 255, 255, .1);
    border-radius: 999px;
}
.shop-card__progress-fill{
    position: absolute;
    inset: 0 auto 0 0;
    background: linear-gradient(90deg, #2ed573, #7bed9f);
    border-radius: 999px;
}
.shop-card__progress-label{
    position: relative;
    display: block;
    font-size: 12px;
    font-weight: bold;
    line-height: 22px;
    text-align: center;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}
.shop-card.is-locked .shop-card__icon{
    filter: grayscale(1);
    opacity: .45;
}

/* ---------- Settings ---------- */
.settings{
    margin: auto;
    width: min(420px, calc(100vw - 32px));
    padding: 20px 22px 22px;
    border: none;
    border-radius: 18px;
    background: #1e2a3a;
    color: #f1f2f6;
    font-family: var(--font);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.settings::backdrop{
    background: rgba(0, 0, 0, .55);
}
.settings__header{
    display: flex;
    align-items: center;
    margin-bottom: 14px;
}
.settings__title{
    flex: 1;
    font-size: 26px;
}
.settings__close{
    width: 44px;
    height: 44px;
    font-size: 18px;
    color: inherit;
    background: rgba(255, 255, 255, .1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}
.settings__close:hover,
.settings__close:focus-visible{
    background: #ff4757;
}
.settings__row{
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.settings__row--check{
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.settings__label{
    font-size: 16px;
    font-weight: bold;
}
.settings__row input[type="range"]{
    width: 100%;
    accent-color: #ffd23f;
}
.settings__row input[type="checkbox"]{
    width: 26px;
    height: 26px;
    accent-color: #2ed573;
}
.noscript{
    padding: 16px;
    color: #fff;
    text-align: center;
}

.settings__links{
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 14px 0 0;
}

.settings__link{
    font-size: 14px;
    font-weight: bold;
    color: #a4f0ff;
    text-align: center;
}

.settings__button{
    width: 100%;
    min-height: 44px;
    margin-top: 16px;
    font: bold 15px var(--font);
    color: #1e2a3a;
    background: #ffd23f;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    touch-action: manipulation;
}

/*
 * Installed on the Home Screen there are no browser bars over the page, and the opaque status bar
 * sits above the page, so only a small margin is needed.
 */
@media (max-width: 600px) and (display-mode: standalone){
    :root{
        --phone-top-gap: 8px;
    }
}

/* ---------- What's new ---------- */
.news{
    margin: auto;
    width: min(480px, calc(100vw - 32px));
    max-height: min(640px, calc(100dvh - 48px));
    padding: 0;
    border: none;
    border-radius: 18px;
    background: #1e2a3a;
    color: #f1f2f6;
    font-family: var(--font);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.news[open]{
    display: flex;
    flex-direction: column;
}
.news::backdrop{
    background: rgba(0, 0, 0, .55);
}
.news__header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.news__title{
    font-size: 24px;
}
.news__version{
    margin-top: 2px;
    font-size: 14px;
    color: #ffd23f;
}
.news__close{
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    font-size: 18px;
    color: inherit;
    background: rgba(255, 255, 255, .1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}
.news__close:hover,
.news__close:focus-visible{
    background: #ff4757;
}
.news__list{
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px 20px 10px;
}
.news__release{
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.news__release:not(.is-latest){
    opacity: .75;
}
.news__release-title{
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 18px;
}
.news__badge{
    padding: 2px 8px;
    font-size: 11px;
    color: #fff;
    background: #ff4757;
    border-radius: 999px;
}
.news__date{
    margin-left: auto;
    font-size: 12px;
    font-weight: normal;
    color: #b2bec3;
}
.news__items{
    display: flex;
    flex-direction: column;
    gap: 8px;
    list-style: none;
}
.news__item{
    display: flex;
    gap: 10px;
    font-size: 15px;
    line-height: 1.35;
}
.news__icon{
    flex: 0 0 24px;
    text-align: center;
}
.news__link{
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    font-size: 14px;
    font-weight: bold;
    color: #a4f0ff;
    text-align: center;
    text-decoration: none;
    border-top: 1px solid rgba(255, 255, 255, .1);
}
