:root {
    --menu_check_size: 8rem;
    --settings_check_size: 8rem;
    --range_indicator_width: calc(var(--settings_check_size) * 2);
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}
html {
    font-size: 4px;
}
body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
body, button, select {
    font-family: monospace;
    font-weight: 800;
    font-size: 3rem;
}
button {
    background: none;
    display: block;
    padding: 0;
    border: none;
}
button:not(:disabled) {
    cursor: pointer;
}
a {
    color: white;
}
*:focus {
    outline: none;
}
* {
    -webkit-tap-highlight-color: transparent;
}
.hidden { visibility: hidden; }
.checked {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}
.checked+.check {
    cursor: pointer;
}
#container {
    width: 100%;
    flex-grow: 1;
    position: relative;
}
#container:active { cursor: move; }
#container { overflow: hidden; }
#container.paused{ filter: grayscale(0.5); }
canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: block;
    margin: auto;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

.splash, .title {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
    text-align: center;
    overflow: hidden;
}
.splash {
    background-color: #484848;
    color: white;
    opacity: 0;
    animation: fadein 0.5s ease-in-out 0.1s 1 forwards;
}
@keyframes fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}
.title {
    background-color: #193bcb;
}
.splash:before, .title:before, .title:after {
    content: "";
    display: block;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}
.splash:before {
    width: 256px;
    height: 256px;
    background-image: url('images/CoffeeBland.png');
}
@media (min-width: 512px) and (min-height: 512px) {
    .splash:before { width: 512px; height: 512px; }
}
.title:before, .title:after {
    max-width: 100%;
    max-height: 100%;
}
.title--no-splash:before, .title--no-splash:after {
    opacity: 0;
    animation: fadein 0.5s ease-in-out 0.1s 1 forwards;
}
.title:before {
    width: 640px;
    height: 480px;
    background-image: url('images/TitleScreen.png');
}
.title.win:before {
    background-image: url('images/GodHappy.png');
}
.title.lost:before {
    background-image: url('images/GodAngry.png');
}
.title:after {
    width: 480px;
    height: 120px;
    background-image: url('images/Title.png');
}

.menu-container {
    position: absolute;
    top: var(--safe_margin_top, 0px);
    bottom: var(--safe_margin_bottom, 0px);
    right: var(--safe_margin_right, 0px);
    text-align: right;
    user-select: none;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    animation: fadein 0.5s ease-in-out 0.1s 1 forwards;
}
.menu-container * { pointer-events: all; }
.menu-container .check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--menu_check_size);
    padding: 1rem;
    padding-top: var(--menu_check_size);
    opacity: 0.5;
    background-size: var(--menu_check_size) var(--menu_check_size);
    background-position: center 0px;
    background-repeat: no-repeat;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}
.menu-container .checked:active+.check { opacity: 1; }
.menu-btn+.check { background-image: url('images/Settings.png'); }
.menu-btn:checked+.check { background-image: url('images/Close.png'); }

@media (hover: none) {
    :root {
        --menu_check_size: 10rem;
    }
}

.menu {
    display: none;
    text-shadow: 0 1px black;
    color: white;
    text-transform: uppercase;
    text-align: left;
    font-size: 3.5rem;
    overflow: auto;
    background: rgba(0, 0, 0, 0.3);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding-left: calc(3rem + var(--safe_margin_left, 0px));
    padding-top: calc(2rem + var(--safe_margin_top, 0px));
    padding-right: calc(3rem + var(--safe_margin_right, 0px));
    padding-bottom: calc(2rem + var(--safe_margin_bottom, 0px));
    flex-direction: column;
    align-items: center;
}
.menu-btn:checked+.check+.menu { display: flex; }

.menu div {
    width: 100%;
    max-width: 62rem;
    flex-shrink: 0;
    display: flex;
    flex-flow: row;
    align-items: center;
    position: relative;
    overflow: hidden;
    border-bottom: solid 1px #01041d;
}
.menu > *:first-child {
    border-top-left-radius: 3rem;
    border-top-right-radius: 3rem;
    margin-top: auto;
}
.menu > *:last-child {
    border-bottom-left-radius: 3rem;
    border-bottom-right-radius: 3rem;
    margin-bottom: auto;
}
@media (hover: hover) {
    .menu div:hover label,
    .menu a:hover,
    .menu select:hover {
        background: #3f5566;
    }
}
.menu div:active label,
.menu a:active,
.menu select:active,
.input--keyboard .menu div:focus-within label,
.input--keyboard .menu div a:focus,
.input--keyboard .menu div select:focus,
.input--gamepad .menu div:focus-within label,
.input--gamepad .menu div a:focus,
.input--gamepad .menu div select:focus {
    background: #3f5566;
}
.menu label, .menu a, .menu select {
    background: #26333d;
}
.menu label, .menu a {
    padding: 2rem 3rem;
    flex-grow: 1;
}
.menu label, .menu input {
    cursor: pointer;
}
.menu input { margin: 0; }

.menu input[type=checkbox] {
    position: absolute;
    right: 3rem;
    appearance: none;
}
.checkbox__indicator,
.range__indicator {
    position: absolute;
    right: 3rem;
    height: calc(var(--settings_check_size) * 0.8);
    border-radius: var(--settings_check_size);
    background-color: #171f25;
    pointer-events: none;
}
.checkbox__indicator::after,
.range__indicator::after {
    display: block;
    content: "";
    position: absolute;
    top: 50%;
    margin-top: calc(var(--settings_check_size) / -2);
    width: var(--settings_check_size);
    height: var(--settings_check_size);
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: 0.25s;
}
.checkbox__indicator {
    width: calc(var(--settings_check_size) * 1.4);
}
[type=checkbox]:not(:checked) ~ .checkbox__indicator::after {
    left: calc(var(--settings_check_size) * -0.1);
    filter: grayscale(0.75);
    background-image: url('images/PictoGodSad.png');
}
[type=checkbox]:checked ~ .checkbox__indicator::after {
    left: calc(100% - var(--settings_check_size) * 0.9);
    transform: rotate(360deg);
    background-image: url('images/PictoGodHappy.png');
}

.menu input[type=range] {
    position: absolute;
    right: 3rem;
    height: 100%;
    opacity: 0;
    --range_indicator_width: calc(var(--settings_check_size) * 2);
}
.range__indicator {
    width: calc(var(--range_indicator_width) + var(--settings_check_size) * 0.8);
}
.range__indicator::after {
    left: calc(var(--settings_check_size) * -0.1 + var(--range_percent) * var(--range_indicator_width));
    transform: rotate(calc(var(--range_percent) * 360deg));
    filter: grayscale(calc((1 - var(--range_percent)) * 0.75));
    background-image: url('images/PictoGodHappy.png');
}
.range__indicator--zero::after {
    background-image: url('images/PictoGodSad.png');
}

.menu select {
    padding: 0;
    height: 100%;
    cursor: pointer;
    color: white;
    text-shadow: 0 1px black;
    text-align: right;
    font-size: 3.5rem;
    text-transform: uppercase;
    border: none;
    border-left: 3rem solid transparent;
    border-right: 3rem solid transparent;
}
.menu a {
    cursor: pointer;
    display: block;
    text-decoration: none;
}
.menu .resume-btn {
    text-align: center;
}

.btns {
    position: relative;
    display: flex;
    flex-direction: column-reverse;
    padding-left: var(--safe_margin_left, 0px);
    padding-right: var(--safe_margin_right, 0px);
    padding-bottom: var(--safe_margin_bottom, 0px);
}
.group-select, .group {
    padding-top: 1px;
    display: flex;
    flex-direction: row;
}
.group-select>.check, .group>div {
    flex-grow: 1;
    box-sizing: border-box;
}
.group-select>.check~.check, .group>div~div {
    margin-left: 1px;
}
.group-select>.check, .btn, .tooltip {
    color: white;
    text-shadow: 0 1px black;
    text-align: center;
    user-select: none;
    text-transform: uppercase;
}
.group-select>.check {
    height: 12rem;
    position: relative;
}
.group-select>.check .group-name {
    position: absolute;
    text-align: center;
    left: 0;
    right: 0;
    top: 50%;
    line-height: 3rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}
@media (hover: hover) {
    .group-select>.check:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }
}
.group-select>.checked:checked+.check {
    background-color: rgba(255, 255, 255, 0.2);
}
.group-select>.checked:active+.check {
    background-color: rgba(255, 255, 255, 0.3);
}
.group.hidden { display: none; }
.group>div {
    width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.btn {
    position: relative;
    background-color: rgba(255, 255, 255, 0.3);
    overflow: hidden;
    filter: brightness(0.75) grayscale(0.75);

    width: 100%;
    min-height: 14rem;
    flex-grow: 1;
}
.btn span  {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
}
.btn:disabled {
    background: none;
    filter: brightness(0.6) grayscale(1) !important;
}
.btn:disabled:after, .btn:disabled:before { animation-duration: 1000000s; }
@media (hover: hover) {
    .btn:hover { filter: brightness(1) grayscale(0); }
}
.btn:active { filter: brightness(1) grayscale(0); }

.btn:after,
.train:before, .untrain:before,
.baby:before, .summon:before,
.attack:before, .convert:before, .retreat:before {
    content: "";
    display: block;
    position: absolute;
    left: 50%;
    top: 50%;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    z-index: -1;
}

.train, .untrain, .attack, .convert {
    background-image: url('images/Arrow.png');
    background-repeat: no-repeat;
    background-position: center;
}
.retreat {
    background-image: url('images/ArrowFlipped.png');
    background-repeat: no-repeat;
    background-position: calc(50% - 16px) 50%;
}
.train span:first-child, .untrain span:first-child {
    padding-right: 32px;
}
.train span:last-child, .untrain span:last-child {
    padding-left: 32px;
}
.train:before, .untrain:before,
.baby:before, .summon:before,
.attack:before, .convert:before,
.train:after, .untrain:after,
.attack:after, .convert:after,
.retreat:before, .retreat:after {
    width: 8px;
    height: 12px;
    margin-top: -10px;
    transform: scale(2);
    animation: jobAnim 1s steps(1) infinite;
    filter: brightness(0.2)
        sepia(100%)
        hue-rotate(180deg)
        saturate(10);
}
@keyframes jobAnim {
    0% { background-position: 0px 36px; }
    33% { background-position: 8px 36px; }
    66% { background-position: 16px 36px; }
}
.train:before, .untrain:before,
.attack:before, .convert:before {
    margin-left: -20px;
}
.retreat:before {
    margin-left: -4px;
}
.train:after, .untrain:after,
.attack:after, .convert:after, .retreat:after {
    margin-left: 12px;
}

.warrior:before, .warrior:after, .attack:before, .retreat:before {
    background-image: url('images/Warrior.png');
}
.priest:before, .priest:after, .convert:before, .retreat:after {
    background-image: url('images/Priest.png');
}
.builder:before, .builder:after {
    background-image: url('images/Builder.png');
}

.train:before, .untrain:after,
.baby:before, .summon:before,
.attack:after, .convert:after {
    background-image: url('images/Villager.png');
}

.build, .forestate {
    text-align: right;
    padding-right: 8px;
    box-sizing: border-box;
}
.house:after {
    width: 60px;
    margin-left: -30px;
    height: 110px;
    margin-top: -48px;
    background-position: 0px 110px;
    background-image: url('images/House.png');
}
.barracks:after,
.workshop:after {
    width: 100px;
    margin-left: -50px;
    height: 110px;
    margin-top: -45px;
    background-position: 0px 110px;
}
.barracks:after {
    background-image: url('images/Barracks.png');
}
.workshop:after {
    background-image: url('images/Workshop.png');
}
.temple:after {
    background-image: url('images/Temple.png');
    width: 100px;
    margin-left: -50px;
    height: 130px;
    margin-top: -52px;
    background-position: 0px 130px;
}
.greenHouse:after {
    background-image: url('images/GreenHouse.png');
    width: 56px;
    margin-left: -28px;
    height: 164px;
    margin-top: -70px;
    background-position: 0px 164px;
}

.bridge:after {
    background-image: url('images/Bridge.png');
    width: 178px;
    margin-left: -89px;
    height: 138px;
    margin-top: -28px;
    background-position: 0px 138px;
}

.forestate:after, .deforest:after {
    width: 30px;
    margin-left: -15px;
    height: 90px;
    margin-top: -32px;
    background-position: 0px 90px;
}
.forestate:after {
    background-image: url('images/Tree.png');
}
.deforest:after {
    background-image: url('images/FallingTree.png');
}
.sacrifice:after {
    width: 32px;
    margin-left: -16px;
    height: 128px;
    margin-top: -96px;
    background-image: url('images/Lightning.png');
}

.baby:after, .summon:after {
    background-image: url('images/SpecialEffects.png');
    width: 8px;
    margin-left: -4px;
    height: 12px;
    margin-top: -10px;
    transform: scale(2);
}
.baby:before, .summon:before {
    margin-left: -4px;
}
.baby:after {
    animation: baby 2s steps(1) reverse infinite;
}
.summon:after {
    animation: summon 2s steps(1) reverse infinite;
}
@keyframes baby {
    0% { background-position: 0px 12px; }
    16% { background-position: 8px 12px; }
    33% { background-position: 16px 12px; }
    50% { background-position: 24px 12px; }
    66% { background-position: 32px 12px; }
    83% { background-position: 40px 12px; }
}
@keyframes summon {
    0% { background-position: 0px 24px; }
    16% { background-position: 8px 24px; }
    33% { background-position: 16px 24px; }
    50% { background-position: 24px 24px; }
    66% { background-position: 32px 24px; }
    83% { background-position: 40px 24px; }
}

.pray:after {
    background-image: url('images/Pray.png');
    width: 16px;
    margin-top: -8px;
    height: 16px;
    margin-left: -8px;
    transform: scale(2);
}

.convert:before, .attack:before {
    animation-name: goRight;
}
.convert:after, .attack:after {
    filter: brightness(0.2)
        sepia(100%)
        hue-rotate(350deg)
        saturate(75);
}
@keyframes goRight {
    0% { background-position: 0px 48px; }
    33% { background-position: 8px 48px; }
    66% { background-position: 16px 48px; }
}

.tooltip {
    display: flex;
    position: absolute;
    pointer-events: none;
    flex-wrap: wrap;
    left: 0;
    right: 0;
    top: 0;
    padding: 0.5em;
    font-size: 2.5rem;
    line-height: 2.5rem;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

body:not(.show-tooltips) .tooltip,
body:not(.show-tooltips) .binding,
body:not(.show-tooltips).input--gamepad .menu-container .check {
    display: none;
}

.binding {
    display: flex;
    align-items: center;
}

.binding__key {
    display: inline-block;
    padding: 2px calc(4px + 0.2em);
    padding-bottom: 4px;
    line-height: 1.2em;
    box-sizing: border-box;
    font-size: 2rem;
    color: white;
    text-shadow: none;
    text-align: center;
    user-select: none;
    text-transform: uppercase;
    background: var(--binding_background, rgba(0, 0, 0, 0.3));
    border-radius: 1.5em;
    box-shadow: inset 0px -2px rgba(0, 0, 0, 0.5);

    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.5);
    paint-order: stroke fill;
}

.binding__key--face-red {
    --binding_background: rgb(212, 57, 9);
}

.binding__key--face-green {
    --binding_background: rgb(110, 189, 20);
}

.binding__key--face-yellow {
    --binding_background: rgb(231, 179, 6);
}

.binding__key--face-blue {
    --binding_background: rgb(35, 88, 233);
}

.tip {
    position: absolute;
    display: flex;
    flex-direction: column;
    top: 50%;
    left: 0;
    right: 0;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 4rem 4rem rgba(0, 0, 0, 0.3);
    text-align: center;
    z-index: 1;
    user-select: none;
    animation: fade-in 1s;
}
@keyframes fade-in {
    0% { opacity: 0; }
    75% { transform: translateY(2rem); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}
.tip.hidden {
    animation: fade-out 0.25s;
}
@keyframes fade-out {
    0% { transform: translateY(0); opacity: 1; visibility: visible; }
    100% { transform: translateY(-2rem); opacity: 0; visibility: visible; }
}
.tip.initial { animation: none; }
.tip > * {
    text-transform: uppercase;
    text-shadow: 0 1px black;
    color: white;
    font-weight: 800;
    padding: 4rem;
}
.tip .text {
    flex-grow: 1;
    white-space: pre-line;
    font-size: 3rem;
    pointer-events: none;
}
.tip button {
    cursor: pointer;
    font-size: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    transition: box-shadow 0.25s, background 0.25s;
}
@media (hover: hover) {
    .tip button:hover {
        box-shadow: 0 0 4rem 4rem rgba(0, 0, 0, 0.1);
        background-color: rgba(0, 0, 0, 0.1);
    }
}
.tip button:active {
    box-shadow: 0 0 4rem 4rem rgba(0, 0, 0, 0.2);
    background-color: rgba(0, 0, 0, 0.2);
}

.notify {
    position: absolute;
    top: 4rem;
    left: 4rem;
    right: 4rem;
    z-index: 1;
    color: white;
    text-transform: uppercase;
    white-space: pre-wrap;
    text-align: left;
    pointer-events: none;
    user-select: none;
}
.notify>div {
    position: absolute;
    animation-name: notification;
    animation-timing-function: linear;
}
.notify .extra {
    font-size: 0.8em;
}
@keyframes notification {
    0% {
        transform: translateY(1rem);
        opacity: 0;
    }
    10% {
        transform: translateY(0rem);
        opacity: 1;
    }
    75% {
        transform: translateY(0rem);
        opacity: 0.3;
    }
    100% {
        transform: translateY(-1rem);
        opacity: 0;
    }
}

.fps-counter {
    position: absolute;
    bottom: 0;
    right: 0;
    margin: 1rem;
    z-index: 1;
    user-select: none;
    pointer-events: none;
    text-shadow: 0 1px white;
}

@keyframes fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}
.fadein {
    animation: fadein 0.5s forwards;
}

@keyframes fadeout {
    from { opacity: 1; }
    to { opacity: 0; }
}
.fadeout {
    animation: fadeout 0.5s forwards;
}

/* RESPONSIVE! */
@media (max-width:640px) and (max-aspect-ratio: 640/600) {
    .title:before, .title:after { height: 0; }
    .title:before { padding-top: 75%; }
    .title:after { padding-top: 18.75%; }
}
@media (min-aspect-ratio: 4/3) {
    body {
        flex-direction: row-reverse;
    }
    .btns {
        flex-direction: row;
        padding-top: var(--safe_margin_top, 0px);
        padding-right: 0px;
    }
    .group-select, .groups, .group {
        width: auto;
        height: 100%;
    }
    .group-select, .group {
        padding-top: 0;
        padding-right: 1px;
        flex-direction: column;
    }
    .group-select>.check, .group>div {
        height: initial;
    }
    .group-select>.check~.check, .group>div~div {
        margin-left: 0px;
        margin-top: 1px;
    }
    .group-select>.check { width: 12rem; }
    .group>div { width: 14rem; }
    .btn { min-height: initial; }
    .group-select>.check .group-name {
        writing-mode: vertical-lr;
        text-shadow: 0 -1px black;
        transform: translateX(-50%) rotate(180deg);
        left: 50%;
        right: initial;
        top: 0;
        bottom: 0;
    }
    .group-select>.check .group-name .binding {
        writing-mode: initial;
        transform: rotate(180deg);
    }
}

@media (min-width: 600px) and (min-height: 600px) {
    html { font-size: 5px; }
}
@media (min-width: 840px) and (min-height: 840px) {
    html { font-size: 6px; }
}
@media (min-width: 1260px) and (min-height: 1260px) {
    html { font-size: 8px; }
}

@media (max-aspect-ratio: 4/3) and (max-width: 320px),
    (min-aspect-ratio: 4/3) and (max-width: 500px) {
    .tooltip { font-size: 2rem; }
}
@media (max-aspect-ratio: 4/3) and (max-width: 280px),
    (min-aspect-ratio: 4/3) and (max-height: 280px) {
    .group-select>.check { font-size: 2.5rem; }
}
@media (min-aspect-ratio: 4/3) and (min-width: 500px) {
    .group-select>.check { width: 12rem; }
    .group>div { width: 16rem; }
}
@media (min-aspect-ratio: 4/3) and (min-width: 600px) {
    .group-select>.check { width: 13rem; }
    .group>div { width: 18rem; }
}
@media (min-aspect-ratio: 4/3) and (min-width: 700px) {
    .group-select>.check { width: 14rem; }
    .group>div { width: 20rem; }
}
@media (min-aspect-ratio: 4/3) and (min-width: 800px) {
    .group-select>.check { width: 14rem; }
    .group>div { width: 22rem; }
}

@media (max-aspect-ratio: 4/3) and (min-height: 500px) {
    .group-select>.check { height: 12rem; }
    .btn { min-height: 16rem; }
}
@media (max-aspect-ratio: 4/3) and (min-height: 600px) {
    .group-select>.check { height: 13rem; }
    .btn { min-height: 18rem; }
}
@media (max-aspect-ratio: 4/3) and (min-height: 700px) {
    .group-select>.check { height: 14rem; }
    .btn { min-height: 20rem; }
}
@media (max-aspect-ratio: 4/3) and (min-height: 800px) {
    .group-select>.check { height: 14rem; }
    .btn { min-height: 22rem; }
}

@media (pointer:coarse) {
    .menu label, .menu a, .menu select {
        line-height: 30px;
    }
}
