@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300&display=swap');

/* ==================== Theme ==================== */

/* Override bulma font color, it's dark by default */
body, p, table, table th, table td, .title, .navbar-item, div, .button, .navbar-burger span {
    color: rgb(248, 242, 242);
}

a, a:visited, a:hover {
    color: rgb(248, 242, 242);
}

.help {
    color: rgba(248, 242, 242, 0.7);
}

.navbar-item, .button {
    color: rgb(248, 242, 242) !important;
}

/* Auth buttons in navbar */
#auth-status .button {
    background-color: #416c86 !important;
    color: white !important;
    border: none !important;
}

#auth-status .button:hover {
    background-color: #355a70 !important;
}

html, body {
    font-family: 'Kanit', sans-serif;
    /* By default (on mobile) the background should all be the same color for simplicity */
    background: #2A2537;
}

code {
    background: initial;
    display: block;
    margin: 1rem;
}

a {
    text-decoration: underline;
}

.fatal.error {
    color: #e63131 !important;
}

.header a {
    text-decoration: none;
}

.my-navbar-menu, .navbar-item {
    background: #2A2537 !important;
}

.navbar-item:hover {
    background: #1D1A26 !important;
}

.bt-panel > .title {
    text-align: center;
}

/* Button colors */
.controls-subpanel button#try-again {
    background: #624344;
}

.controls-subpanel button#again {
    background: #434b62;
}

.controls-subpanel button#hard {
    background: #b7881a;
}

.controls-subpanel button#good {
    background: #2e680d;
}

.controls-subpanel button#easy {
    background: #269326;
}

cg-container {
    width: 100% !important;
    height: 100% !important;
}

cg-board {
    /* The chess board color */
    background-color: #bfcfdd;
}

/* Coordinates alignment and colors */
.cg-wrap coords {
    font-size: 8pt;
    font-weight: bold;
}

.cg-wrap coords.files {
    /* Override chessground default coord positioning */
    bottom: 0;
    left: 0;
    text-align: left;
    left: 0.2rem;
    text-transform: lowercase;
}

.cg-wrap coords.ranks {
    /* Override chessground default coord positioning */
    top: 0;
    right: 0.3rem;
    left: auto;
    width: auto;
}

.cg-wrap coords.ranks coord {
    /* Override chessground default coord positioning */
    transform: unset;
}

/* Light square colors */
.cg-wrap.orientation-white coords.ranks coord:nth-child(2n + 1),
.cg-wrap.orientation-white coords.files coord:nth-child(2n),
.cg-wrap.orientation-black coords.ranks coord:nth-child(2n),
.cg-wrap.orientation-black coords.files coord:nth-child(2n + 1) {
  color: rgba(72, 72, 72, 0.8);
}

/* Dark square colors */
.cg-wrap.orientation-black coords.ranks coord:nth-child(2n + 1),
.cg-wrap.orientation-black coords.files coord:nth-child(2n),
.cg-wrap.orientation-white coords.ranks coord:nth-child(2n),
.cg-wrap.orientation-white coords.files coord:nth-child(2n + 1) {
    color: white;
}

/* ==================== Mobile layout ==================== */
.title {
    /* Override bulma's titles having a big margin on the bottom. It's more consistent if our
     * paragraphs/other elements have a margin instead. */
    margin-bottom: 0 !important;
}

/* Bulma's default titles are a bit big so we adjust them too */
.title.is-2 {
    font-size: 2.2rem;
}

.title.is-3 {
    font-size: 1.8rem;
}

.title.is-4 {
    font-size: 1.5rem;
}

.header {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 0;
    min-height: 60px;
    white-space: nowrap;
}

.header .title {
    font-size: 2rem;
}

.section#main-section {
    flex-grow: 1;
}

.footer {
    display: none;
}

.section {
    padding: 0;
}

#site-name-container {
    flex-grow: 1;
}

#site-name-container .title {
    /* We don't want the link to take up the whole width or it can be clicked by accident. */
    display: inline-block;
}

/* Navbar */
.navbar {
    min-height: 0;
}

.navbar {
    position: relative;
}

.my-navbar-menu {
    display: none;
}

.my-navbar-menu.is-active {
    display: initial;
}

.navbar #nav-menu {
    position: absolute;
    right: 0;
    border: solid 1px #1D1A26;
    border-radius: 6px;
}

.navbar-burger {
    display: block !important;
    position: absolute;
    right: 0.5rem;
    top: 0.5rem;
    user-select: none;
}

.navbar-item {
    display: block !important;
    padding: 0.5rem 3rem;
    text-decoration: none;
    font-weight: bold;
    text-align: center;
}

/* Index page */
#stats-panel {
    gap: 1.5rem;
}

.stats-panel {
    display: flex;
    flex-direction: column;
    flex-grow: 0;
    position: relative;
    text-align: center;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.stats-panel .button-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 1rem;
}

.stats-panel .stats {
    margin: auto;
}

.stats-panel .stats > caption {
    font-size: 24pt;
    margin-bottom: 1rem;
}

.stats-panel .stats > tbody > tr > th {
    text-align: left;
}

.stats-panel .stats > tbody > tr > td {
    text-align: right;
    min-width: 4rem;
}

.stats-panel a.button {
    background: #416c86;
    text-decoration: none;
    width: 7rem;
}

.stats-panel .bt-loader {
    position: absolute;
    width: 10rem;
    height: 10rem;
    top: calc(50% - 5rem);
    right: calc(50% - 5rem);
    background-image: url('./images/loader.svg');
    background-size: cover;
}

.analysis-link {
    margin: 0 1rem;
}

/* Puzzle page */
#main-container {
    margin: 0 auto;
    max-width: 1000px;
}

.chessground {
    aspect-ratio: 1;
}

#board-container {
    position: relative;
    padding: 0;
    overflow: clip;
}

#promotion-ui {
    /* The promotion ui should completely cover the board, but be disabled by default */
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;

    /* Semi-transparent overlay background that indicates the board is disabled */
    background: rgba(0.0, 0.0, 0.0, 0.5);

    /* Center the promotion pieces panel horizontally and vertically */
    display: flex;
    justify-content: center;
    align-items: center;
}

.promotion-pieces {
    display: flex;

    width: 12rem;
    height: 12rem;
    gap: 0.5rem;

    /* This smaller box containing only the promotion pieces is also a flex box so the pieces can be
     * shown in rows */
    flex-wrap: wrap;
}

.promotion-piece {
    padding: 0;

    /* Take up 50% of the width of the box so we get two rows, but leave a little space for the gap
     * between items */
    flex: 45%;

    /* Make sure the buttons still always remain square */
    aspect-ratio: 1;

    background-size: cover;
    border-radius: 6px;
}

.promotion-piece[data-color="w"][data-piece="q"] {
    background-image: url('./images/pieces/white-queen.svg');
}

.promotion-piece[data-color="w"][data-piece="r"] {
    background-image: url('./images/pieces/white-rook.svg');
}

.promotion-piece[data-color="w"][data-piece="n"] {
    background-image: url('./images/pieces/white-knight.svg');
}

.promotion-piece[data-color="w"][data-piece="b"] {
    background-image: url('./images/pieces/white-bishop.svg');
}

.promotion-piece[data-color="b"][data-piece="q"] {
    background-image: url('./images/pieces/black-queen.svg');
}

.promotion-piece[data-color="b"][data-piece="r"] {
    background-image: url('./images/pieces/black-rook.svg');
}

.promotion-piece[data-color="b"][data-piece="n"] {
    background-image: url('./images/pieces/black-knight.svg');
}

.promotion-piece[data-color="b"][data-piece="b"] {
    background-image: url('./images/pieces/black-bishop.svg');
}

.columns {
    margin: 0;
}

.column {
    padding: 0;
}

#puzzle-interface .stats {
    margin: 0 auto;
    text-align: center;
}

#puzzle-interface .stats th {
    padding-right: 1rem;
    white-space: nowrap;
}

/* Sidebars (e.g. on the puzzle interface) */
.sidebar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
}

/* These should take up 50% of the width in the collapsed mobile view,
 * for the case where they're both visible they should push the move indicator
 * to the next row. */
#puzzle-info, #card-details {
    flex-basis: 50%;
}

/* Put the themes at the end and 100% width on mobile */
#puzzle-themes {
    order: 999;
    flex-basis: 100%;
}

#move-controls {
    padding: 0;
    display: flex;
    flex-basis: 100%;
    justify-content: center;
    gap: 1rem;
}

/* Move controls */
#move-controls a {
    fill: white;
    display: flex;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
}

#move-controls a:active {
    fill: grey;
}

#move-controls a[disabled] {
    pointer-events: none;
    font-weight: unset;
    cursor: unset;
    fill: grey;
}

#move-controls a svg {
    pointer-events: none;
    width: 20px;
    height: 20px;
}

/* Move indicators */
.to-move-piece {
    width: 45px;
    height: 45px;
    margin: 0 auto;
    background-size: cover;
}

.to-move-piece[data-color="w"] {
    background-image: url('./images/pieces/white-queen.svg');
}

.to-move-piece[data-color="b"] {
    background-image: url('./images/pieces/black-queen.svg');
}

/* The sidebar panels that show up on success failure etc. They should all be hidden until needed. */
.controls-subpanel {
    text-align: center;
    margin-top: 1rem;
    /* If these are ever visible on mobile they should take up 100% of the width */
    flex-basis: 100%;
}

.sidebar .bt-panel {
    text-align: center;
}

.button-container {
    display: flex;
}

.button-container > div {
    display: flex;
    justify-content: space-around;
}

.button-container button  {
    display: block;
    min-height: 4rem;
    width: 90%;
    padding: 0 !important;
    overflow: hidden;
}

.button-container button > .main-text {
    font-weight: bold;
}

.button-container button > .sub-text {
    font-size: 0.8em;
}

a.puzzle-link-button {
    user-select: none;
}

/* About page - these might apply to other pages too, but I thought I'd try them here first */
#about h2 {
    margin-bottom: 0;
}

#about p {
    margin: 0.5em;
}

#about ul {
    max-width: 90%;
    margin: 0 auto;
}

#about ul li {
    list-style: square;
    margin: 0.5rem auto;
}

.chart-panel {
    display: flex;
    flex-direction: column;
    /* It needs this or the graphs get wider when you make the screen less wide but don't go back
     * to normal after you resize it again. I'm not 100% sure why this works but I'm guessing it
     * just stops the flex item from growing when the graph resizes and forces the graph to stay
     * about the same size. */
    overflow: hidden;
}

.chart-panel .title {
    margin-bottom: 0;
}

.chart-container {
    flex-grow: 1;
    min-height: 15rem;
    padding: 0 0.5rem;
}

.chart-buttons {
    text-align: right;
}

.chart-button {
    display: inline;
    margin-left: auto;
    margin-right: 1rem;
    text-decoration: none;
    user-select: none;
}

.chart-button.inactive {
    font-weight: bold;
    cursor: unset;
    pointer-events: none;
}

/* History page */
#puzzle-history-container {
    display: grid;
    grid-template-columns: repeat(2, minmax(0px, 300px));
    grid-gap: 1rem;
    justify-content: center;
}

.puzzle-history-board {
    aspect-ratio: 1;
}

.puzzle-history-info {
    /* Align table vertically within container */
    display: flex;
    align-items: center;
}

.puzzle-history-info th {
    padding-right: 1rem;
}

.puzzle-history-info td {
    padding-right: 1rem;
    min-width: 4rem;
}

/* These get a bit weird at smaller sizes */
.puzzle-history-board-container coords {
    display: none;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-around;
    padding: 0.5rem;
}

.pagination a {
    font-weight: bold;
    text-decoration: none;
    user-select: none;
}

a[disabled] {
    font-weight: unset;
    cursor: unset;
    color: grey !important;
    pointer-events: none;
}

/* ==================== Desktop layout ==================== */
@media only screen and (min-width: 768px) {
    /* On desktop the main background color and panel background color should be different */
    body, .footer {
        background: #352F44;
    }

    .bt-panel {
        /* Foreground panel color */
        background: #2A2537;
        border-radius: 6px;
    }

    /* Header */
    .header {
        margin-top: 1rem;
    }

    .header .title {
        font-size: 3rem;
    }

    /* Footer */
    .footer {
        display: inherit;
        padding: 0;
        overflow: hidden;
    }

    #ferris-container {
        display: inline-block;
        margin: 0 auto;
        width: 100px;
    }

    #ferris-container:hover {
        transform: rotate(5deg);
    }

    #main-container {
        padding-left: 1rem;
        padding-right: 1rem;
        /* Fill screen, so that the footer sticks to the bottom */
        min-height: 100vh;
    }

    #main-section {
        padding-top: 1rem;
        padding-bottom: 0;
    }

    .column {
        /* The default padding on columns makes it hard to align threm when they're nested */
        padding: 0;
    }

    /* Custom interface stuff */

    /* The mini panels e.g. the one around the puzzle board, or around each panel in the sidebar */
    .bt-panel {
        padding: 0.5rem;
        margin: 0.5rem;
    }

    /* Stats page, we want the stats panels to be in rows of two on desktop */
    #stats-columns {
        flex-wrap: wrap;    
        justify-content: center;
    }

    .sidebar {
        justify-content: initial;
    }

    .sidebar .bt-panel {
        flex-grow: 0;
    }

    .grow {
        flex-grow: 1;
    }

    .stats-panel {
        flex-basis: calc(50% - 1rem);
    }

    /* Puzzle interface */
    #puzzle-interface {
        padding-bottom: 0;
    }

    .sidebar {
        flex-direction: column;
        flex-wrap: nowrap;
    }

    #puzzle-info, #card-details, #move-controls {
        flex-basis: 0;
    }

    #puzzle-themes {
        order: unset;
        flex-basis: 0;
    }

    .move-indicator {
        /* On desktop this one shouldn't grow at all */
        flex: initial;
        flex-grow: 0;
    }

    .to-move-piece {
        width: 100px;
        height: 100px;
    }

    .controls-subpanel {
        /* The visible controls panel should take up the rest of the space instead */
        flex: initial;
    }

    .controls-subpanel .button-container {
        margin-top: 1rem;
        margin-left: 0.25rem;
        margin-right: 0.25rem;
    }

    .controls-subpanel .button-container:last-of-type {
        margin-bottom: 1rem;
    }
}
