1
0
mirror of https://github.com/danog/2048.git synced 2024-11-30 04:19:06 +01:00
2048/style/main.scss

550 lines
10 KiB
SCSS
Raw Permalink Normal View History

2014-03-05 16:33:31 +01:00
@import "helpers";
2014-03-05 15:38:29 +01:00
@import "fonts/clear-sans.css";
2014-03-05 16:07:40 +01:00
$field-width: 500px;
$grid-spacing: 15px;
$grid-row-cells: 4;
$tile-size: ($field-width - $grid-spacing * ($grid-row-cells + 1)) / $grid-row-cells;
$tile-border-radius: 3px;
$mobile-threshold: $field-width + 20px;
2014-03-05 17:34:04 +01:00
$text-color: #776E65;
$bright-text-color: #f9f6f2;
2014-03-05 17:34:04 +01:00
2014-03-05 16:07:40 +01:00
$tile-color: #eee4da;
2014-03-05 16:33:31 +01:00
$tile-gold-color: #edc22e;
2014-03-05 17:34:04 +01:00
$tile-gold-glow-color: lighten($tile-gold-color, 15%);
2014-03-05 16:07:40 +01:00
$game-container-margin-top: 40px;
2014-03-09 23:03:13 +01:00
$game-container-background: #bbada0;
2014-03-09 14:32:30 +01:00
$transition-speed: 100ms;
2014-03-05 15:38:29 +01:00
html, body {
margin: 0;
padding: 0;
background: #faf8ef;
2014-03-05 17:34:04 +01:00
color: $text-color;
2014-03-05 15:38:29 +01:00
font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
font-size: 18px;
2014-03-05 15:38:29 +01:00
}
2014-03-05 16:07:40 +01:00
body {
margin: 80px 0;
}
.heading {
@include clearfix;
2014-03-09 23:03:13 +01:00
}
h1.title {
2014-03-05 15:38:29 +01:00
font-size: 80px;
font-weight: bold;
2014-03-05 16:07:40 +01:00
margin: 0;
2014-03-09 23:03:13 +01:00
display: block;
float: left;
}
2014-03-09 23:24:17 +01:00
@include keyframes(move-up) {
0% {
top: 25px;
opacity: 1;
}
100% {
top: -50px;
opacity: 0;
}
}
.scores-container {
float: right;
2014-03-12 12:55:40 +01:00
text-align: right;
}
.score-container, .best-container {
2014-03-09 23:03:13 +01:00
$height: 25px;
position: relative;
display: inline-block;
2014-03-09 23:03:13 +01:00
background: $game-container-background;
2014-03-09 23:59:53 +01:00
padding: 15px 25px;
2014-03-09 23:03:13 +01:00
font-size: $height;
height: $height;
line-height: $height + 22px;
font-weight: bold;
border-radius: 3px;
color: white;
margin-top: 8px;
text-align: center;
2014-03-09 23:03:13 +01:00
&:after {
position: absolute;
width: 100%;
top: 10px;
left: 0;
text-transform: uppercase;
font-size: 13px;
line-height: 13px;
text-align: center;
color: $tile-color;
}
2014-03-09 23:24:17 +01:00
.score-addition {
position: absolute;
right: 30px;
color: red;
font-size: $height;
line-height: $height;
font-weight: bold;
color: rgba($text-color, .9);
z-index: 100;
@include animation(move-up 600ms ease-in);
@include animation-fill-mode(both);
}
2014-03-05 15:38:29 +01:00
}
.score-container:after {
content: "Score";
}
.best-container:after {
content: "Best"
}
p {
margin-top: 0;
margin-bottom: 10px;
line-height: 1.65;
}
a {
color: $text-color;
font-weight: bold;
text-decoration: underline;
2014-03-10 11:31:10 +01:00
cursor: pointer;
}
strong {
&.important {
text-transform: uppercase;
}
}
hr {
border: none;
border-bottom: 1px solid lighten($text-color, 40%);
margin-top: 20px;
margin-bottom: 30px;
}
2014-03-05 15:38:29 +01:00
.container {
2014-03-05 16:07:40 +01:00
width: $field-width;
2014-03-05 15:38:29 +01:00
margin: 0 auto;
}
2014-03-05 16:07:40 +01:00
2014-03-09 23:03:13 +01:00
@include keyframes(fade-in) {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
2014-03-11 15:18:20 +01:00
// Styles for buttons
@mixin button {
display: inline-block;
background: darken($game-container-background, 20%);
border-radius: 3px;
padding: 0 20px;
text-decoration: none;
color: $bright-text-color;
height: 40px;
line-height: 42px;
}
2014-03-10 21:31:41 +01:00
// Game field mixin used to render CSS at different width
@mixin game-field {
.game-container {
margin-top: $game-container-margin-top;
2014-03-10 21:31:41 +01:00
position: relative;
padding: $grid-spacing;
cursor: default;
-webkit-touch-callout: none;
2014-03-23 20:17:22 +01:00
-ms-touch-callout: none;
2014-03-10 21:31:41 +01:00
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
2014-03-10 21:31:41 +01:00
2014-03-23 20:17:22 +01:00
-ms-touch-action: none;
2014-03-23 20:21:58 +01:00
touch-action: none;
2014-03-23 20:17:22 +01:00
2014-03-10 21:31:41 +01:00
background: $game-container-background;
border-radius: $tile-border-radius * 2;
width: $field-width;
height: $field-width;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
.game-message {
display: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba($tile-color, .5);
z-index: 100;
text-align: center;
p {
font-size: 60px;
font-weight: bold;
height: 60px;
line-height: 60px;
margin-top: 222px;
// height: $field-width;
// line-height: $field-width;
}
2014-03-09 23:03:13 +01:00
2014-03-10 21:31:41 +01:00
.lower {
display: block;
margin-top: 59px;
}
2014-03-10 11:31:10 +01:00
2014-03-10 21:31:41 +01:00
a {
2014-03-11 15:18:20 +01:00
@include button;
2014-03-10 21:31:41 +01:00
margin-left: 9px;
// margin-top: 59px;
&.keep-playing-button {
display: none;
}
2014-03-10 21:31:41 +01:00
}
2014-03-10 11:31:10 +01:00
2014-03-10 21:31:41 +01:00
@include animation(fade-in 800ms ease $transition-speed * 12);
@include animation-fill-mode(both);
2014-03-10 11:31:10 +01:00
2014-03-10 21:31:41 +01:00
&.game-won {
background: rgba($tile-gold-color, .5);
color: $bright-text-color;
a.keep-playing-button {
display: inline-block;
}
2014-03-10 21:31:41 +01:00
}
2014-03-09 23:43:56 +01:00
2014-03-10 21:31:41 +01:00
&.game-won, &.game-over {
display: block;
}
}
2014-03-10 21:31:41 +01:00
}
2014-03-10 21:31:41 +01:00
.grid-container {
position: absolute;
z-index: 1;
}
2014-03-09 23:43:56 +01:00
2014-03-10 21:31:41 +01:00
.grid-row {
margin-bottom: $grid-spacing;
2014-03-09 23:03:13 +01:00
2014-03-10 21:31:41 +01:00
&:last-child {
margin-bottom: 0;
2014-03-10 11:31:10 +01:00
}
2014-03-10 21:31:41 +01:00
&:after {
content: "";
2014-03-10 11:31:10 +01:00
display: block;
2014-03-10 21:31:41 +01:00
clear: both;
2014-03-10 11:31:10 +01:00
}
2014-03-09 23:03:13 +01:00
}
2014-03-05 16:07:40 +01:00
2014-03-10 21:31:41 +01:00
.grid-cell {
width: $tile-size;
height: $tile-size;
margin-right: $grid-spacing;
float: left;
2014-03-05 16:07:40 +01:00
2014-03-10 21:31:41 +01:00
border-radius: $tile-border-radius;
2014-03-05 16:07:40 +01:00
2014-03-10 21:31:41 +01:00
background: rgba($tile-color, .35);
2014-03-05 16:07:40 +01:00
2014-03-10 21:31:41 +01:00
&:last-child {
margin-right: 0;
}
2014-03-05 16:07:40 +01:00
}
2014-03-10 21:31:41 +01:00
.tile-container {
position: absolute;
z-index: 2;
}
2014-03-05 16:07:40 +01:00
2014-03-10 21:31:41 +01:00
.tile {
&, .tile-inner {
width: ceil($tile-size);
height: ceil($tile-size);
2014-11-25 23:21:39 +01:00
line-height: ceil($tile-size);
}
2014-03-10 21:31:41 +01:00
// Build position classes
@for $x from 1 through $grid-row-cells {
@for $y from 1 through $grid-row-cells {
&.tile-position-#{$x}-#{$y} {
$xPos: floor(($tile-size + $grid-spacing) * ($x - 1));
$yPos: floor(($tile-size + $grid-spacing) * ($y - 1));
@include transform(translate($xPos, $yPos));
2014-03-10 21:31:41 +01:00
}
}
}
2014-03-05 16:07:40 +01:00
}
}
2014-03-10 21:31:41 +01:00
// End of game-field mixin
@include game-field;
2014-03-05 16:07:40 +01:00
.tile {
position: absolute; // Makes transforms relative to the top-left corner
2014-03-05 16:07:40 +01:00
.tile-inner {
border-radius: $tile-border-radius;
2014-03-05 16:07:40 +01:00
background: $tile-color;
text-align: center;
font-weight: bold;
z-index: 10;
font-size: 55px;
}
2014-03-10 21:31:41 +01:00
// Movement transition
2014-03-09 14:32:30 +01:00
@include transition($transition-speed ease-in-out);
2014-03-12 15:40:49 +01:00
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
transition-property: transform;
2014-03-05 16:33:31 +01:00
$base: 2;
$exponent: 1;
$limit: 11;
// Colors for all 11 states, false = no special color
$special-colors: false false, // 2
false false, // 4
#f78e48 true, // 8
#fc5e2e true, // 16
#ff3333 true, // 32
#ff0000 true, // 64
false true, // 128
false true, // 256
false true, // 512
false true, // 1024
false true; // 2048
// Build tile colors
2014-03-05 16:33:31 +01:00
@while $exponent <= $limit {
$power: pow($base, $exponent);
2014-03-05 17:34:04 +01:00
&.tile-#{$power} .tile-inner {
// Calculate base background color
$gold-percent: ($exponent - 1) / ($limit - 1) * 100;
$mixed-background: mix($tile-gold-color, $tile-color, $gold-percent);
2014-03-05 17:34:04 +01:00
$nth-color: nth($special-colors, $exponent);
2014-03-05 17:34:04 +01:00
$special-background: nth($nth-color, 1);
$bright-color: nth($nth-color, 2);
2014-03-05 16:33:31 +01:00
@if $special-background {
$mixed-background: mix($special-background, $mixed-background, 55%);
}
@if $bright-color {
color: $bright-text-color;
}
// Set background
background: $mixed-background;
2014-03-05 17:34:04 +01:00
// Add glow
$glow-opacity: max($exponent - 4, 0) / ($limit - 4);
2014-03-09 23:03:13 +01:00
@if not $special-background {
box-shadow: 0 0 30px 10px rgba($tile-gold-glow-color, $glow-opacity / 1.8),
inset 0 0 0 1px rgba(white, $glow-opacity / 3);
}
2014-03-05 17:34:04 +01:00
// Adjust font size for bigger numbers
2014-03-05 16:33:31 +01:00
@if $power >= 100 and $power < 1000 {
font-size: 45px;
2014-03-10 21:31:41 +01:00
// Media queries placed here to avoid carrying over the rest of the logic
@include smaller($mobile-threshold) {
2014-03-10 21:31:41 +01:00
font-size: 25px;
}
2014-03-05 16:33:31 +01:00
} @else if $power >= 1000 {
font-size: 35px;
2014-03-10 21:31:41 +01:00
@include smaller($mobile-threshold) {
2014-03-10 21:31:41 +01:00
font-size: 15px;
}
2014-03-05 16:33:31 +01:00
}
}
$exponent: $exponent + 1;
}
2014-03-14 13:50:49 +01:00
// Super tiles (above 2048)
&.tile-super .tile-inner {
color: $bright-text-color;
background: mix(#333, $tile-gold-color, 95%);
font-size: 30px;
@include smaller($mobile-threshold) {
2014-03-14 13:50:49 +01:00
font-size: 10px;
}
}
2014-03-05 16:07:40 +01:00
}
2014-03-09 14:32:30 +01:00
@include keyframes(appear) {
0% {
opacity: 0;
@include transform(scale(0));
2014-03-09 14:32:30 +01:00
}
100% {
opacity: 1;
@include transform(scale(1));
2014-03-09 14:32:30 +01:00
}
}
.tile-new .tile-inner {
2014-03-09 14:32:30 +01:00
@include animation(appear 200ms ease $transition-speed);
2014-03-12 15:40:49 +01:00
@include animation-fill-mode(backwards);
2014-03-09 14:32:30 +01:00
}
2014-03-09 20:03:04 +01:00
@include keyframes(pop) {
0% {
@include transform(scale(0));
2014-03-09 23:03:13 +01:00
}
50% {
@include transform(scale(1.2));
2014-03-09 20:03:04 +01:00
}
100% {
@include transform(scale(1));
2014-03-09 20:03:04 +01:00
}
}
.tile-merged .tile-inner {
2014-03-09 20:03:04 +01:00
z-index: 20;
@include animation(pop 200ms ease $transition-speed);
2014-03-12 15:40:49 +01:00
@include animation-fill-mode(backwards);
2014-03-09 20:03:04 +01:00
}
.above-game {
@include clearfix;
}
.game-intro {
float: left;
line-height: 42px;
margin-bottom: 0;
}
.restart-button {
@include button;
display: block;
text-align: center;
float: right;
}
2014-03-05 16:07:40 +01:00
.game-explanation {
margin-top: 50px;
}
2014-03-10 21:31:41 +01:00
@include smaller($mobile-threshold) {
2014-03-10 21:31:41 +01:00
// Redefine variables for smaller screens
$field-width: 280px;
$grid-spacing: 10px;
$grid-row-cells: 4;
$tile-size: ($field-width - $grid-spacing * ($grid-row-cells + 1)) / $grid-row-cells;
$tile-border-radius: 3px;
2014-03-22 17:31:55 +01:00
$game-container-margin-top: 17px;
2014-03-10 21:31:41 +01:00
html, body {
font-size: 15px;
}
body {
margin: 20px 0;
padding: 0 20px;
}
h1.title {
2014-03-12 12:55:40 +01:00
font-size: 27px;
margin-top: 15px;
2014-03-10 21:31:41 +01:00
}
.container {
width: $field-width;
margin: 0 auto;
}
2014-03-12 12:55:40 +01:00
.score-container, .best-container {
2014-03-10 21:31:41 +01:00
margin-top: 0;
2014-03-12 12:55:40 +01:00
padding: 15px 10px;
min-width: 40px;
2014-03-10 21:31:41 +01:00
}
.heading {
margin-bottom: 10px;
}
// Show intro and restart button side by side
.game-intro {
width: 55%;
display: block;
box-sizing: border-box;
line-height: 1.65;
}
.restart-button {
width: 42%;
padding: 0;
display: block;
box-sizing: border-box;
margin-top: 2px;
}
2014-03-10 21:31:41 +01:00
// Render the game field at the right width
@include game-field;
// Rest of the font-size adjustments in the tile class
.tile .tile-inner {
2014-03-10 21:31:41 +01:00
font-size: 35px;
}
.game-message {
p {
font-size: 30px !important;
height: 30px !important;
line-height: 30px !important;
margin-top: 90px !important;
}
.lower {
margin-top: 30px !important;
}
}
}