:root{
    /* The world's height in world units; main.js sets it to fit the screen (the width is always 400). */
    --world-height: 700;
    --text: #fff7ec;
    --text-muted: #c9bde6;
    --accent: #ffd23f;
    --accent-text: #2a2140;
    --panel: rgba(29, 23, 48, .88);
    --font: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
}

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

html{
    touch-action: manipulation;
}

body{
    min-height: 100dvh;
    background: #1d1730 linear-gradient(180deg, #3b2d5c, #1d1730) no-repeat;
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.noscript{
    padding: 24px;
    font-size: 18px;
}

.noscript a{
    color: var(--accent);
}

/* Fills the screen and keeps clear of the iPhone notch and home bar. */
.app{
    position: fixed;
    inset: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    user-select: none;
    -webkit-user-select: none;
}

/* A size container, so the screen can fit it in both directions. */
.stage{
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    container-type: size;
}

/* Keeps the world's shape: the whole phone screen, or a tall column on a computer. */
.screen{
    position: relative;
    width: min(100cqw, 100cqh * 400 / var(--world-height));
    aspect-ratio: 400 / var(--world-height);
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
}

@media (min-width: 600px){
    .screen{
        border-radius: 18px;
        box-shadow: 0 14px 40px rgba(0, 0, 0, .4);
    }
}

.game-canvas{
    display: block;
    width: 100%;
    height: 100%;
}

/* ---------- Score and buttons over the game ---------- */

.hud{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 12px;
    pointer-events: none;
}

.hud__score{
    font-size: 30px;
    font-weight: bold;
    line-height: 1;
    color: #fff;
    text-shadow: 0 2px 0 rgba(0, 0, 0, .35), 0 0 8px rgba(0, 0, 0, .25);
}

.hud__score small{
    display: block;
    margin-top: 4px;
    font-size: 13px;
    opacity: .9;
}

.hud__buttons{
    display: flex;
    gap: 8px;
}

.round{
    width: 42px;
    height: 42px;
    font-size: 18px;
    color: #fff;
    background: rgba(29, 23, 48, .45);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
}

.round[hidden]{
    display: none;
}

/* ---------- Title, pause and game over ---------- */

.panel{
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    background: var(--panel);
    animation: fade-in .3s ease-out;
}

.panel[hidden]{
    display: none;
}

/* The title screen sits in the upper part, so the critter can be seen bouncing below it. */
.panel[data-panel="title"]{
    justify-content: flex-start;
    gap: 10px;
    padding-top: max(56px, 9%);
    background: linear-gradient(180deg, rgba(29, 23, 48, .85) 45%, rgba(29, 23, 48, 0) 75%);
}

@keyframes fade-in{
    from{ opacity: 0; }
}

.panel__title{
    font-size: clamp(44px, 12cqw, 56px);
    font-weight: bold;
    line-height: 1;
    color: var(--accent);
    text-shadow: 0 4px 0 #c98b00;
}

.panel__text{
    max-width: 300px;
    font-size: 18px;
}

.panel__score{
    font-size: 64px;
    font-weight: bold;
    line-height: 1;
}

.panel__help{
    font-size: 14px;
    color: var(--text-muted);
}

/* Each device sees the controls it has. */
.panel__help--touch{
    display: none;
}

@media (pointer: coarse){
    .panel__help--touch{
        display: block;
    }

    .panel__help--keys{
        display: none;
    }
}

/* The title screen is short on room: its buttons are smaller and share rows. */
.panel[data-panel="title"] .panel__links .button{
    min-height: 40px;
    padding: 0 14px;
    font-size: 15px;
}

.panel[data-panel="title"] .panel__links .button--shop{
    color: var(--accent-text);
    background: #7fe3ff;
}

/* On the title screen the score belongs to the demo bounce: the wallet is shown instead. */
.screen[data-phase="title"] .hud__score{
    visibility: hidden;
}

.panel__links{
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
}

.button{
    min-height: 44px;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: bold 16px var(--font);
    color: var(--text);
    text-decoration: none;
    background: rgba(255, 255, 255, .14);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: transform .1s;
}

.button:active,
.round:active{
    transform: scale(.94);
}

.button[hidden]{
    display: none;
}

.button:focus-visible,
.round:focus-visible{
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.button--accent{
    color: var(--accent-text);
    background: var(--accent);
}

.button--big{
    min-height: 56px;
    min-width: 200px;
    font-size: 22px;
}

/* A short message over the game (a cheat code that worked, or did not). */
.toast{
    position: absolute;
    left: 50%;
    top: 70px;
    z-index: 3;
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    font-weight: bold;
    text-align: center;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 999px;
    transform: translateX(-50%);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
    pointer-events: none;
}

.toast[hidden]{
    display: none;
}

.cheat{
    width: min(360px, calc(100% - 32px));
    margin: auto;
    padding: 20px;
    color: var(--text);
    background: #2a2140;
    border: 0;
    border-radius: 20px;
    font-family: var(--font);
}

.cheat::backdrop{
    background: rgba(10, 8, 20, .6);
}

.cheat__form{
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cheat__label{
    font-weight: bold;
    color: var(--accent);
}

/* 16px or more, so iPhone does not zoom in when the field gets the focus. */
.cheat__input{
    min-height: 44px;
    padding: 0 14px;
    font: 18px var(--font);
    color: var(--text);
    background: rgba(255, 255, 255, .1);
    border: 2px solid rgba(255, 255, 255, .2);
    border-radius: 12px;
}

.cheat__actions{
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- Coins ---------- */

/* A small gold coin, drawn in CSS so it looks the same everywhere (emoji coins differ per phone). */
.coin-icon{
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: .3em;
    vertical-align: -.15em;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 50%, #fff3a0 0 30%, #ffd23f 32% 100%);
    box-shadow: inset 0 -.1em 0 #c98b00, 0 0 0 .06em #c98b00;
}

.hud__coins{
    color: var(--accent);
}

.wallet{
    padding: 4px 16px;
    font-size: 22px;
    font-weight: bold;
    border-radius: 999px;
    background: rgba(255, 255, 255, .12);
}

.panel__earned{
    font-size: 24px;
    font-weight: bold;
    color: var(--accent);
}

/* Boosts in stock, each a chip that is lit when it will be used in the next run. */
.boosts{
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.boosts:empty{
    display: none;
}

.boost{
    min-height: 36px;
    padding: 0 14px;
    font: bold 14px var(--font);
    color: var(--text-muted);
    background: transparent;
    border: 2px dashed rgba(255, 255, 255, .3);
    border-radius: 999px;
    cursor: pointer;
}

.boost[aria-pressed="true"]{
    color: var(--accent-text);
    background: #7fe3ff;
    border: 2px solid #7fe3ff;
}

/* ---------- Shop ---------- */

.shop{
    width: min(560px, calc(100% - 24px));
    max-height: calc(100dvh - 24px);
    margin: auto;
    padding: 0;
    display: none;
    flex-direction: column;
    color: var(--text);
    background: #2a2140;
    border: 0;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    font-family: var(--font);
}

.shop[open]{
    display: flex;
}

.shop::backdrop{
    background: rgba(10, 8, 20, .6);
}

.shop__header{
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 8px 20px;
}

.shop__title{
    flex: 1;
    font-size: 26px;
    color: var(--accent);
}

.shop__wallet{
    font-size: 20px;
    font-weight: bold;
}

.shop__close{
    width: 40px;
    height: 40px;
    font-size: 18px;
    color: var(--text);
    background: rgba(255, 255, 255, .1);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.shop__tabs{
    display: flex;
    gap: 6px;
    padding: 4px 16px 12px;
    overflow-x: auto;
    scrollbar-width: none;
}

.shop__tab{
    flex-shrink: 0;
    min-height: 38px;
    padding: 0 14px;
    font: bold 15px var(--font);
    color: var(--text-muted);
    background: rgba(255, 255, 255, .08);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.shop__tab[aria-selected="true"]{
    color: var(--accent-text);
    background: var(--accent);
}

.shop__grid{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 0 16px 16px;
    overflow-y: auto;
}

.shop-card{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px;
    text-align: center;
    border-radius: 16px;
    background: rgba(255, 255, 255, .07);
    border: 2px solid transparent;
}

.shop-card--worn{
    border-color: var(--accent);
}

.shop-card__picture{
    width: 96px;
    height: 96px;
    display: grid;
    place-items: center;
    font-size: 54px;
    border-radius: 12px;
    background: linear-gradient(180deg, #7ac8ff, #d6f0ff);
}

.shop-card__picture canvas{
    width: 96px;
    height: 96px;
}

.shop-card__name{
    font-weight: bold;
}

.shop-card__text{
    font-size: 13px;
    color: var(--text-muted);
}

.shop-card__button{
    width: 100%;
    min-height: 38px;
    margin-top: auto;
    font: bold 15px var(--font);
    color: var(--text);
    background: rgba(255, 255, 255, .14);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.shop-card__button--buy{
    color: var(--accent-text);
    background: var(--accent);
}

.shop-card__button:disabled{
    cursor: default;
    opacity: .5;
}

.shop-card--worn .shop-card__button:disabled{
    opacity: 1;
    color: var(--accent);
    background: transparent;
}
