
// Flip - A Game About Perspective
// ==============================
// Author:     Evan Henley
// Author URI: henleyedition.com

$tile-size:      50px;
$arrow-key-size: 40px;

$dark-color: #333;
$background-color: lighten($dark-color, 20%);
$light-color: lighten($dark-color, 70%);

@import '_flip-icons';

// Keyframes

@keyframes unflipX {
    0% { transform: rotateX(180deg); }
    100% { transform: rotateX(0); }
}
@keyframes flipX {
    0%   { transform: rotateX(0); }
    100% { transform: rotateX(180deg); }
}
@keyframes reduce {
    0%   { font-size: 180%; }
    100% { font-size: 140%; }
}
@keyframes fire {
    0%, 100% { transform: scale(1) rotate(0); }
    25%  { transform: scale(1.1) rotate(-6deg); }
    50%  { transform: scale(1) rotate(0); }
    75%  { transform: scale(1.1) rotate(6deg); }
}
@keyframes fire-flipped {
    0%, 100% { transform: scale(1) rotate(0) rotateX(180deg); }
    25% { transform: scale(1.1) rotate(-6deg) rotateX(180deg); }
    50% { transform: scale(1) rotate(0) rotateX(180deg); }
    75% { transform: scale(1.1) rotate(6deg) rotateX(180deg); }
}
@keyframes fly-away {
    25%  {
        transform: rotate(-45deg) scale(2);
    }
    100% {
        transform: rotate(-45deg) scale(2) translate(2000px, 200px);
    }
}

// The stuff

body {
    font-family: Consolas, Monaco, 'Andale Mono', monospace;
    background: $background-color;
    color: $light-color;
    perspective: 1600px;
    text-align: center;
}

.header {
    perspective: 400px;
}

#title {
    transition: transform 0.5s;
    transform-origin: center center;
    &.spin {
        transform: rotateY(360deg) translateZ(1px);
    }
}

.title-flip {
    display: inline-block;
    transform: rotateY(180deg);
    color: $dark-color;
}

#container {
    position: relative;
    display: block;
    padding: 50px 0;
    width: 100%;
    text-align: center;
    overflow: hidden;
    perspective: 1600px;
}

// wraps #game-board and #player
#game-board-wrapper {
    position: relative;
    height: 500px;
    width: 500px;
    display: inline-block;
    transition: transform 1s;
    cursor: default;
    perspective: 800px;
    transform-style: preserve-3d;
    transform: rotateY(0deg);
    &.peek {
        transform: rotateY(180deg);
    }
}

// wraps #game-board-front and #game-board-back
#game-board {
    position: relative;
    height: 100%;
    width: 100%;
    padding: 1px;
    transition: transform 0.5s;
    transform-style: preserve-3d;
    &.flipX {
        transform: rotateX(180deg) rotateY(0);
    }
    &.flipY {
        transform: rotateX(0) rotateY(180deg);
    }
    &.flipX.flipY {
        transform: rotateX(180deg) rotateY(180deg);
    }
}

#game-board-front,
#game-board-back {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    transition: filter 0.5s,
                -webkit-filter 0.5s,
                background 0.5s,
                border-color 0.5s,
                color 0.5s,
                opacity 0.5s;
}

#game-board-front {
    z-index: 1;
    background: $light-color;
    color: $dark-color;
    border: 2px solid $dark-color;
    opacity: 0.91;
    filter: none;
    transform: translate3d(0, 0, 1px);
    .flipped & {
        opacity: 1;
        filter: blur(1px);
    }

}
#game-board-back {
    z-index: -1;
    background: $dark-color;
    color: $light-color;
    border: 2px solid $light-color;
    opacity: 1;
    filter: blur(1px);
    transform: translate3d(0, 0, -1px);
    .flipped & {
        opacity: 0.91;
        filter: none;
    }
}

.tile {
    position: relative;
    float: left;
    box-sizing: border-box;
    text-align: center;
    // get rid of highlighting
    user-select: none;
    -webkit-touch-callout: none;
    line-height: 0 !important;
    &:before {
        display: block;
        width: 100%;
        line-height: 0 !important;
        margin: 0;
    }
}

#player {
    position: absolute;
    top: 2px; left: 2px;
    // margin: 2px 0 0 2px;
    transition: filter 0.5s,
                -webkit-filter 0.5s,
                transform 0.1s,
                color 0.5s;
    color: $dark-color;
    &:before {
        font-size: 140%;
        animation: reduce 1s;
    }
    &.flip {
        color: $light-color;
    }
    .peek & {
        transition: filter 0.5s,
                    -webkit-filter 0.5s,
                    transform 0.5s,
                    color 0.5s;
        filter: blur(1px);
        &.unflip {
            color: $light-color;
        }
        &.flip {
            color: $dark-color; 
        }
    }
    &.dead:before {
        transition: transform 0.5s;
        transform: rotate(90deg);
    }
    .win &:before {
        transition: transform 1s;
        transform: scale(0);
    }
}


/* =========================
   Tile Classes
   ========================= */


%wall {
    content: "";
    display: block;
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
}

// walls
.wall-right {
    #game-board-front &:after {
        @extend %wall;
        border-right: 2px solid $dark-color;
    }
    #game-board-back &:after {
        @extend %wall;
        border-right: 2px solid $light-color;
    }
}
.wall-bottom {
    #game-board-front &:after {
        @extend %wall;
        border-bottom: 2px solid $dark-color;
    }
    #game-board-back &:after {
        @extend %wall;
        border-bottom: 2px solid $light-color;
    }
}

.icon-key {
    transition: color 0.5s;
    color: #990;
    &:before {
        font-size: 80%;
    }
    .hasKey & {
        color: transparent;
    }
}

.icon-fire {
    color: #d30;
    &:before {
        font-size: 120%;
        animation: unflipX 0.5s,
                   fire 3s 0.5s infinite linear;
    }
    .flipX &:before {
        animation: flipX 0.5s,
                   fire-flipped 3s 0.5s infinite linear;
    }
}

.icon-space-ship {
    .win &:before {
        animation: fly-away 5s forwards;
    }
    &:before {
        position: relative;
        display: block;
        top: 4px;
        font-size: 120%;
        transform: rotate(-90deg);
    }
}

/* =========================
   Menu Classes
   ========================= */

.clickable:hover {
    cursor: pointer;
    user-select: none;
}

.navigation {
    position: relative;
    text-align: center;
    margin: 20px 0;
}

.nav-item {
    padding: 8px;
    color: $light-color;
    background: $background-color;
}

.controls {
    display: inline-block;
}
.arrow-keys {
    margin: 0 auto;
}

.arrow-keys-line {
    text-align: center;
}

.icon-arrow-up,
.icon-arrow-down,
.icon-arrow-left,
.icon-arrow-right,
.spacebar {
    display: inline-block;
    border-radius: 4px;
    box-sizing: border-box;
    border: 2px solid $light-color;
    &:before {
        display: inline-block;
        height: $arrow-key-size;
        font-size: 80%;
        line-height: $arrow-key-size;
    }
}

.icon-arrow-up,
.icon-arrow-down,
.icon-arrow-left,
.icon-arrow-right {
    margin: 2px;
    &:before {
        margin: 0;
        width: $arrow-key-size;
    }
}

.icon-arrow-left {
    margin-left: 0;
}
.icon-arrow-right {
    margin-right: 0;
}

.spacebar {
    margin-top: 10px;
    width: 100%;
    &:before {
        content: "spacebar";
    }
}
