1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/assets/css/_board.scss

209 lines
4.4 KiB
SCSS

:root {
--board-size: 90vmin;
}
@media (min-aspect-ratio: 10/11) {
:root {
--board-size: 80vmin;
}
}
@mixin move-indicator {
border-radius: 50%;
content: "";
display: block;
height: 2%;
position: absolute;
right: 2%;
width: 2%;
}
.board {
background: lighten($black-square-color, 7%);
border-collapse: unset;
border-radius: 2.8%;
border-spacing: 1px;
box-shadow: 0 (var(--board-size) / 200) (var(--board-size) / 40) $board-shadow-color;
color: $white-square-color;
height: var(--board-size);
padding: calc(var(--board-size) / 20);
position: relative;
width: var(--board-size);
&.white-to-move::before {
@include move-indicator;
background: $white;
}
&.black-to-move::before {
@include move-indicator;
background: $black;
}
&.player-is-white.white-to-move::before,
&.player-is-black.black-to-move::before {
bottom: 2%;
}
&.player-is-white.black-to-move::before,
&.player-is-black.white-to-move::before {
top: 2%;
}
.board-rank-labels,
.board-file-labels {
display: none;
}
&.player-is-white {
.board-rank-labels {
display: flex;
flex-direction: column-reverse;
}
.board-file-labels {
display: flex;
flex-direction: row;
}
}
&.player-is-black {
.board-rank-labels {
display: flex;
flex-direction: column;
}
.board-file-labels {
display: flex;
flex-direction: row-reverse;
}
}
}
.board-rank-labels {
display: flex;
height: 90%;
left: 0;
position: absolute;
width: 5%;
}
.board-file-labels {
display: flex;
height: 5%;
position: absolute;
top: 0;
width: 90%;
}
.board-game-state {
bottom: 0;
color: white;
height: 5%;
position: absolute;
width: 90%;
}
.board-label {
align-items: center;
display: flex;
flex-grow: 1;
font-size: calc(var(--board-size) / 40);
justify-content: center;
}
.board-body {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
height: 100%;
width: 100%;
}
%black-square {
background-color: $black-square-color;
&.selected {
background-color: mix($black-square-color, $selected-square-color, 60%);
box-shadow: inset 0 0 0 calc(var(--board-size) / 400) $selected-outline-color;
}
&.available {
background-color: mix($black-square-color, $available-square-color, 80%);
box-shadow: inset 0 0 0 calc(var(--board-size) / 400) $available-outline-color;
}
}
%white-square {
background-color: $white-square-color;
&.selected {
background-color: mix($white-square-color, $selected-square-color, 60%);
box-shadow: inset 0 0 0 calc(var(--board-size) / 400) $selected-outline-color;
}
&.available {
background-color: mix($white-square-color, $available-square-color, 80%);
box-shadow: inset 0 0 0 calc(var(--board-size) / 400) $available-outline-color;
}
}
.board-square {
background-position: center;
background-repeat: no-repeat;
background-size: 100%;
border-radius: 2%;
margin: 0.5px;
// This is to ensure the squares can be clicked on in PhantomJS
// TODO: Figure out why we need this
min-height: 20px;
min-width: 20px;
@include odd-between(1, 8) { @extend %white-square; }
@include even-between(1, 8) { @extend %black-square; }
@include odd-between(9, 16) { @extend %black-square; }
@include even-between(9, 16) { @extend %white-square; }
@include odd-between(17, 24) { @extend %white-square; }
@include even-between(17, 24) { @extend %black-square; }
@include odd-between(25, 32) { @extend %black-square; }
@include even-between(25, 32) { @extend %white-square; }
@include odd-between(33, 40) { @extend %white-square; }
@include even-between(33, 40) { @extend %black-square; }
@include odd-between(41, 48) { @extend %black-square; }
@include even-between(41, 48) { @extend %white-square; }
@include odd-between(49, 56) { @extend %white-square; }
@include even-between(49, 56) { @extend %black-square; }
@include odd-between(57, 64) { @extend %black-square; }
@include even-between(57, 64) { @extend %white-square; }
@each $colour in $colours {
@each $piece in $pieces {
&.#{$colour}.#{$piece} {
background-image: url(/images/#{$piece}_#{$colour}.svg);
}
}
}
}
@media (min-width: 480px) {
.board-body {
grid-gap: 1px;
}
}
@media (min-width: 768px) {
.board-body {
grid-gap: 2px;
}
}