/* General elements */

/* This is a game surface: swipes and long presses must not select its labels.
   Keep this separate from touch-action so the investment screen can scroll. */
*, *::before, *::after {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
}

body {
    background: black;
    color: #fafafa;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: none;
}

header {
    height: 49px;
    overflow: hidden;
    -ms-user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
}

section {
    clear: both;
}

a {
    color: white;
    font-weight: bold;
    text-decoration: none;
}


/* General animations */

.hoverable {
    opacity: .84;
    transition: 140ms opacity;
}

.hoverable:hover {
    opacity: 1;
}


/* Header */

#header-right {
    position: absolute;
    top: 0;
    right: 3px;
    opacity: 1;
    transition: 280ms opacity;
}

@media(max-width: 819px) {
    #header-right {
        opacity: 0;
    }
}


/* Game section */

section#game {
    min-height: 100vh;
    min-height: 100dvh;
    touch-action: none;
}

section#game .EightBitter {
    margin: auto;
}

.game-brand {
    position: fixed;
    top: clamp(72px, 8vh, 104px);
    left: clamp(20px, 2.3vw, 48px);
    z-index: 70;
    width: min(330px, 27vw, 34vh);
    box-shadow: 8px 8px 0 #000;
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
}

.game-brand img {
    display: block;
    width: 100%;
    height: auto;
}

.game-brand.is-offstage {
    display: none;
}


/* iPad and touch controls */

.touch-controls {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 950;
    display: none;
    align-items: flex-end;
    justify-content: space-between;
    padding:
        0
        max(18px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(18px, env(safe-area-inset-left));
    pointer-events: none;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
}

html.touch-device .touch-controls {
    display: flex;
}

.touch-controls__movement,
.touch-controls__actions {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.touch-controls__actions {
    gap: 14px;
}

.touch-control {
    position: relative;
    display: grid;
    place-items: center;
    width: clamp(72px, 9vw, 94px);
    height: clamp(64px, 8vw, 86px);
    padding: 0;
    border: 4px solid #fce0a8;
    border-right-color: #7c300c;
    border-bottom-color: #7c300c;
    border-radius: 0;
    background: rgba(184, 76, 32, .9);
    color: #fff;
    box-shadow: 5px 5px 0 rgba(0, 0, 0, .55);
    font: 10px/1 "Press Start", monospace;
    text-shadow: 2px 2px 0 #703010;
    pointer-events: auto;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.touch-control--action {
    width: clamp(74px, 9vw, 96px);
    height: clamp(74px, 9vw, 96px);
    border-radius: 50%;
    background: rgba(228, 0, 88, .92);
    border-color: #ffd0df #78002e #78002e #ffd0df;
    text-shadow: 2px 2px 0 #78002e;
}

.touch-control--run {
    transform: translateY(-2px);
}

.touch-control--jump {
    transform: translateY(-17px);
}

.touch-control strong,
.touch-control small {
    pointer-events: none;
}

.touch-control strong {
    font: 19px/1 "Press Start", monospace;
}

.touch-control small {
    margin-top: -16px;
    font: 7px/1 "Press Start", monospace;
}

.touch-control.is-pressed {
    transform: translate(4px, 4px);
    filter: brightness(1.18);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, .55);
}

.touch-control--run.is-pressed {
    transform: translate(4px, 6px);
}

.touch-control--jump.is-pressed {
    transform: translate(4px, -13px);
}

/* When Safari starts missing frames, keep input and physics responsive while
   reducing only decorative compositing work around the game canvas. */
html.performance-reduced .touch-control {
    filter: none !important;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, .48);
    text-shadow: 1px 1px 0 #703010;
}

#jiffy-performance-diagnostics {
    position: fixed;
    z-index: 5000;
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 7px 9px;
    border: 2px solid #fce0a8;
    background: rgba(0, 0, 0, .82);
    color: #fff;
    font: 7px/1.5 "Press Start", monospace;
    pointer-events: none;
}

@media (orientation: portrait) and (max-width: 900px) {
    .game-brand {
        top: 68px;
        left: 14px;
        width: min(240px, 46vw, 26vh);
    }

    .touch-controls {
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .touch-controls__movement,
    .touch-controls__actions {
        gap: 8px;
    }

    .touch-control {
        width: 68px;
        height: 62px;
    }

    .touch-control--action {
        width: 72px;
        height: 72px;
    }
}



/* Control section */

#controls {
    text-align: center;
}

#controls .control {
    position: relative;
    display: inline-block;
    margin-top: 0;
    height: 35px;
    width: 256px;
    border: 3px solid black;
    border-radius: 7px;
    box-shadow: 0 3px 7px black inset;
    background: black;
    font-family: 'Press Start';
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    overflow: hidden;
    transition: 70ms all;
}

#controls.length-4 .control {
    min-width: 25%;
}

#controls.length-5 .control {
    min-width: 20%;
}

#controls .control:hover {
    margin-top: -288px;
    height: 316px; /* 288px + 28px */
    border-color: #99ffcc;
    background: #009966;
    z-index: 70;
}

#controls .control h4 {
    position: absolute;
    right: 0;
    bottom: 7px;
    left: 0;
    margin: 0;
}

#controls .control-inner {
    margin-top: 28px;
    padding: 7px 3px;
    opacity: 0;
    transition: 35ms opacity;
}

#controls .control:hover .control-inner {
    display: block;
    margin-top: 0;
    opacity: 1
}

#controls .select-options {
    position: relative;
    max-height: 277px;
    overflow-y: auto;
}

#controls .select-option-title {
    padding: 11px;
}

#controls .select-option {
    margin: 1px 3px;
    display: inline-block;
    background: #ffcc33;
    border: 3px outset;
    cursor: pointer;
    color: black;
    font-size: 14px;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

#controls .select-option.option-enabled {
    background: #ffcc33;
}

#controls .select-option.option-disabled {
    background: #ccaa33;
}

/* QR-paired iPhone remote */
.phone-controller-pair {
    display: block;
    margin: 14px auto 0;
    padding: 12px 16px;
    border-color: #d5ecff #153f76 #153f76 #d5ecff;
    background: #2b74d6;
    color: #fff;
    font-size: 8px;
    text-shadow: 2px 2px #153f76;
}

.phone-controller-pair span { color: #ffe34f; }

.phone-controller-modal {
    position: fixed;
    z-index: 9000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(13, 20, 34, .82);
    font-family: "Press Start", monospace;
}

.phone-controller-modal[hidden] { display: none; }

.phone-controller-card {
    position: relative;
    width: min(520px, 94vw);
    padding: 30px 34px 32px;
    border: 6px solid #fce0a8;
    border-right-color: #111;
    border-bottom-color: #111;
    background: #5c94fc;
    color: #fff;
    text-align: center;
    box-shadow: 12px 12px 0 rgba(0, 0, 0, .5);
    text-shadow: 3px 3px #111;
}

.phone-controller-card h2 {
    margin: 15px 0 22px;
    font-size: clamp(17px, 3vw, 26px);
    line-height: 1.45;
}

.phone-controller-close {
    position: absolute;
    top: 10px;
    right: 12px;
    border: 0;
    background: transparent;
    color: #fff;
    font: 26px/1 Arial, sans-serif;
    text-shadow: 2px 2px #111;
}

.phone-controller-qr-stage {
    position: relative;
    width: min(318px, 76vw);
    margin: 0 auto 20px;
    padding: 0 16px 16px 0;
}

.phone-controller-qr-wrap {
    position: relative;
    width: min(286px, 68vw);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    margin: 0 auto;
    border: 7px solid #fff;
    background: #fff;
    box-shadow: 6px 6px #111;
    color: #111;
    text-shadow: none;
}

.phone-controller-qr-wrap img { display: block; width: 100%; height: 100%; }
.phone-controller-qr-wrap img[hidden] { display: none; }
.phone-controller-qr-badge {
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 50%;
    width: 21%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    transform: translate(-50%, -50%);
    border: 4px solid #fff;
    border-radius: 4px;
    background: #101218;
    box-shadow: 2px 2px #111;
}
.phone-controller-qr-badge[hidden] { display: none; }
.phone-controller-qr-badge img { width: 88%; height: 88%; object-fit: contain; image-rendering: pixelated; }
.phone-controller-qr-mario {
    position: absolute;
    z-index: 3;
    right: 0;
    bottom: 0;
    width: clamp(42px, 11vw, 58px);
    height: auto;
    image-rendering: pixelated;
    filter: drop-shadow(3px 3px 0 #111);
    pointer-events: none;
}
.phone-controller-qr-loading { font-size: 8px; line-height: 2; }
.phone-controller-status { min-height: 28px; margin: 0; color: #ffe34f; font-size: 9px; line-height: 1.6; }
.phone-controller-help { margin: 14px 0 0; font-size: 7px; line-height: 1.8; }
.phone-controller-direct { display: inline-block; margin-top: 11px; color: #fff; font-size: 7px; text-underline-offset: 4px; }
.phone-controller-direct[hidden] { display: none; }
.phone-controller-retry { margin-top: 18px; font-size: 9px; }
.phone-controller-modal[data-state="connected"] .phone-controller-card { background: #56a927; }
.phone-controller-modal[data-state="error"] .phone-controller-status { color: #ffd0d0; }

html.phone-controller-connected .touch-controls { display: none !important; }

@media (max-height: 720px) {
    .phone-controller-card { padding: 20px 26px; }
    .phone-controller-card h2 { margin: 8px 0 13px; font-size: 17px; }
    .phone-controller-qr-stage { width: min(248px, 56vh); margin-bottom: 12px; }
    .phone-controller-qr-wrap { width: min(220px, 48vh); }
    .phone-controller-help { margin-top: 8px; }
}

#controls .select-option.select-option-inset {
    border: 3px inset;
}

#controls .select-option.select-option-large {
    padding: 14px 0;
    font-size: 15px;
    line-height: 140%;
}

#controls .disabled {
    opacity: .49 !important;
    cursor: default !important;
    -ms-user-select: none !important;
    -moz-user-select: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}


/* Controls - option buttons */

#controls .options-button-option {
    position: relative;
    display: block;
    left: 0;
    right: 0;
    padding: 4px 0;
    /* width: 70px; */
}

#controls input[type=number] {
    display: inline;
    margin-left: -3px;
    padding-left: 17px;
    width: 42px;
    /* font-size: 1em; */
    font-family: "Press Start";
}

#controls select {
    /* font-size: 1em; */
    font-family: "Press Start";
}


/* Controls - options */

#controls #control-Options .select-options td {
    padding-top: 7px;
    padding-bottom: 7px;
}


/* Controls - option keys */

#controls .options-label-Keys {
    padding-left: 14px;
}

#controls .options-cell-Keys {
    padding: 7px 0;
}

#controls .options-key-option {
    display: inline;
}

#controls .options-key-option:not(:last-of-type):after {
    content: ", ";
}


/* Controls - tables */

#controls table {
    width: 100%;
    border-spacing: 1px;
}

#controls .maps-grid-option {
    display: table-cell;
    padding: 3px;
}

#controls .maps-grid-option-extra {
    display: block;
    margin: 7px 2px 0 1px;
    padding: 3px 0;
}

#controls .maps-grid-input {
    margin: 0 2px 0 1px;
    width: 98%;
    box-sizing: border-box;
    font-family: 'Press Start';
    text-align: center;
}


/* Controls - uploader */

#controls .select-upload {
    cursor: pointer;
    overflow: hidden;
}

#controls .select-upload-input {
    display: none;
}


/* Text sections */

section.section-text {
    margin: auto;
    padding: 21px 70px;
    max-width: 910px;
    font-size: 1.4em;
    text-align: center;
}

.link-github {
    color: #cfc;
}

.link-facebook {
    color: #ccf;
}

.link-twitter {
    color: #cff;
}

@media(max-width: 350px) {
    section.section-text {
        padding: 14px 7px;
    }
}
