@keyframes place-turn {
    0% {
        scale: 105%;
    }

    75% {
        scale: 130%;
    }

    100% {
        scale: 100%;
    }
}

@keyframes slide-in {
  from {
    translate: 100% 0;
    visibility: hidden;
  }

  to {
    translate: 0 0;
    visibility: visible;
  }
}

body {
    width: 100vw;
    /* height: 100%; */
    margin: 0;
    /* width: max-content; */
    background-color: hsl(180, 3%, 15%);
    font-family: Arial, Helvetica, sans-serif;
    color: hsl(0, 0%, 100%);

    --accent: hsl(94, 89%, 39%);
    --accent2: hsl(155, 100%, 20%);
    --accent3: hsl(155, 100%, 13%);
    --primary: hsl(0, 0%, 50%);
    --secondary: hsl(0, 0%, 20%);

    position: relative;
}

.hidden {
    display: none !important;
}

form {
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
}

button {
    border: 0;
    padding: 0.7em 1em;
    font-size: 1em;
}

.green-button {
    background-color: var(--accent);
    border-radius: 0.5vw;
    border: 0;
    color: hsl(0, 0%, 100%);
    padding: 0.7em 1em;
    font-size: 1em;
    font-weight: bold;
    transition: background-color 0.1s ease;
    min-width: 250px;
    margin: 0.5em 0;
}

.green-button:hover {
    background-color: var(--accent2);
    color: hsl(0, 0%, 70%);
}

.green-button:active {
    background-color: var(--accent3);
    color: hsl(0, 0%, 50%);
}

.green-button:disabled {
    background-color: var(--primary);
}

#username-container {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    flex-grow: 0;
}

.ready-mark {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    margin: 4px;
    background-color: var(--accent);
}

.not-ready-mark {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    margin: 4px;
    background-color: #ff004c;
}

.back-button {
    background-color: rgba(0, 0, 0, 0);
    background-image: url("resources/arrow_back.svg");
    background-repeat: no-repeat;
    background-position: center center;
    min-width: 50px;
    width: 50px;
    height: 50px;
    margin: 0;
}

.back-button:hover {
    background-color: var(--secondary);
}

.back-button:active {
    background-color: hsl(0, 0%, 30%);
}

.title-block {
    position: relative;
    width: 100%;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    padding: 1em 0;
}

.title-block .back-button {
    z-index: 1;
}

.title-block .title {
    position: absolute;
    text-align: center;
    font-size: 1.5em;
    width: 100%;
    margin: auto 0;
    z-index: 0;
}

input {
    background-color: var(--secondary);
    border: 1px solid var(--secondary);
    border-radius: 0.5vw;
    color: hsl(0, 0%, 100%);
    padding: 0.7em 1em;
    font-size: 1em;
    transition: border-color 0.2s ease;
    min-width: 250px;
    margin: 0.5em 0;
    transition: color 0.2s ease;
}

input:focus {
    border-color: var(--accent);
    outline: none;
}

input::placeholder {
    color: hsl(0, 0%, 60%);
    opacity: 1;
}

input:disabled {
    background-color: hsl(0, 0%, 40%);
    border-color: hsl(0, 0%, 70%);
}

input:invalid {
    border-color: hsl(0, 74%, 30%);
}

#sidebar {
    border-radius: 0.5vw;
    display: flex;
    flex-flow: column nowrap;
}

#top {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--accent);
}

#sidebar-container {
    display: flex;
    flex-flow: column nowrap;
    height: 100%;
    width: 100%;

    /* animation: slide-in 0.5s ease; */
    /* transition: display 0.2s ease; */
    transition: width 0.2s ease, margin-left 0.2s ease;
    overflow-x: hidden;
    overflow-y: auto;
}

.sidebar-screen {
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    margin: auto;
}

#register-welcome {
    font-size: 1.5em;
    font-weight: bold;
    text-align: center;
    width: 50%;
    margin-bottom: 1em;
}

#register-screen form {
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    margin-top: 0.5em;
}

#lobby-screen {
    flex: 1;
    /* width: 90%; */
    align-items: start;
    margin: 0;
    padding: 10px;
    align-items: stretch;
}

#lobby-title-block {
    position: relative;
    width: 100%;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    justify-content: space-between;
    padding: 1em 0;
}

#lobby-title-block .back-button {
    z-index: 1;
}

#lobby-title-block #lobby-info {
    position: absolute;
    text-align: center;
    font-weight: bold;
    font-size: 1.5em;
    width: 100%;
    margin: auto 0;
    z-index: 0;

    display: flex;
    flex-flow: column nowrap;
    justify-content: center;
    align-items: center;
}

#lobby-title-block #lobby-code-block {
    font-weight: normal;
    font-size: 0.6em;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 5px;
}

#lobby-title-block #lobby-code {
    font-weight: bold;
}

#lobby-code-copy-button {
    background-image: url(resources/copy.svg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 1.2em 1.2em;
    background-color: transparent;
    
    width: 1.2em;
    height: 1.2em;
    padding: 3px;
    border-radius: 5px;
    display: inline-block;
}

#lobby-code-copy-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#lobby-screen .player-list {
    display: flex;
    flex-flow: column nowrap;
    border: 1px solid var(--secondary);
    border-radius: 10px;
    padding: 0 0;
    margin: 10px 2px;
    background-color: hsl(180, 3%, 12%);
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 70px;
}

#lobby-start-game-button {
    margin: 10px 2px;
}

#lobby-screen .player-list > ul {
    position: relative;
    margin: 0;
    padding: 5px 10px;
    border-bottom: 1px solid var(--secondary);
    color: white;
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    justify-content: space-between;
}

#lobby-screen .player-list > ul > .name {
    display: flex;
    flex-flow: row wrap;
    align-items: center;
    gap: 5px;
}

#lobby-screen .player-list > ul > .name > .name-code {
    color: hsl(0, 0%, 50%);
}

#lobby-screen .player-list > ul .disconnected-icon {
    width: 1em;
    height: 1em;
}

#lobby-screen .player-list > ul .ready-status {
    color: var(--accent);
    font-size: 0.9em;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 10px;
}

#lobby-screen .player-list > ul .not-ready-status {
    color: #ff245b;
    font-size: 0.9em;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 10px;
}

#lobby-screen .player-list > ul .unassigned-status {
    color: hsl(0, 0%, 40%);
    font-size: 0.9em;
}

#lobby-screen .player-list > ul .disconnected-status {
    color: hsl(46, 100%, 59%);
    font-size: 0.9em;
}

#lobby-screen .player-list > ul:first-child {
    padding-top: 10px;
}

#lobby-screen .player-list > ul:last-child {
    padding-bottom: 10px;
}

#lobby-screen #lobby-participants {
    overflow-y: hidden;
}

#lobby-screen #lobby-participants > ul:last-child {
    border-bottom: none;
}

#lobby-screen .player-list > ul:nth-child(odd) {
    background-color: hsl(180, 3%, 11%);
}

#lobby-screen .player-list > ul:nth-child(even) {
    background-color: hsl(180, 3%, 12%);
}

#lobby-spectators {
    flex: 1;
}

.error-message {
    color: hsl(0, 79%, 35%)
}

#game-field {
    /* margin: 1vw; */
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    justify-content: center;
    max-width: 85vw;
    max-height: 85vh;
}

#field {
    width: fit-content;
    border-radius: 0.5vw;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-flow: row wrap;
}

.small-field {
    width: 33%;
    height: 33%;
    margin: auto;
    background-color: hsl(0, 0%, 20%);
    border-radius: 0.2vw;
    display: flex;
    flex-flow: row wrap;
}

.cell {
    width: 32%;
    height: 32%;
    margin: auto;
    background-color: hsl(0, 0%, 50%, 85%);
    border-radius: 0.2vw;
    transition: background-color 0.02s ease;
}

.cell img {
    max-width: 100%;
    max-height: 100%;
    margin: auto;
}

.cell[data-turn="First"] {
    background-image: url("/resources/cross.svg");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center center;
    background-origin: content-box;
    animation: place-turn 0.2s ease;
}

.cell[data-turn="Second"] {
    background-image: url("/resources/circle.svg");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center center;
    background-origin: content-box;
    animation: place-turn 0.2s ease;
}

.playable-field .cell[data-turn="Empty"]:hover {
    background-color: hsl(0, 2%, 45%, 90%);
}

.small-field[data-result="FirstWon"] {
    background-color: hsl(0, 100%, 20%);
}

.small-field[data-result="SecondWon"] {
    background-color: hsl(239, 100%, 20%);
}

.small-field[data-result="Draw"] {
    background-color: hsl(310, 100%, 20%);
}

.small-field:not([data-result="NotDecided"]) .cell {
    opacity: 0.5;
}

.active-field {
    background-color: hsl(165, 83%, 35%);
}

#game-status {
    font-size: 1.5em;
    font-weight: bold;
}

#game-status .first-name {
    color: hsl(7, 74%, 52%)
}

#game-status .second-name {
    color: hsl(216, 76%, 56%)
}

#menu-joined-lobby {
    display: flex;
    flex-flow: column nowrap;
    justify-content: space-between;
    min-height: 220px;
    min-width: min(400px, 20vw);
    max-width: 450px;
    width: fit-content;
    background-color: hsl(180, 3%, 12%);
    border: 1px solid var(--secondary);
    border-radius: 0.5vw;
    color: white;
    padding: 10px 20px;
}

#menu-joined-lobby-header {
    width: 100%;
    padding: 7px 0;
    border-bottom: 2px solid var(--secondary);
    color: hsl(0, 0%, 80%);
    font-size: 1em;
}

#menu-joined-lobby-status-bar {
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;

    font-size: 1em;
    color: hsl(0, 0%, 60%);
}

#menu-joined-lobby-info {
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    align-items: end;
}

#menu-joined-lobby-id {
    display: flex;
    flex-flow: column nowrap;
}

#menu-joined-lobby-name {
    font-size: 1.6em;
    color: hsl(0, 0%, 80%);
}

#menu-joined-lobby-code {
    font-size: 1em;
    color: hsl(0, 0%, 50%);
}

#menu-joined-lobby-player-count-bar {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 5px;
}

#menu-joined-lobby-player-icon {
    background-image: url(resources/user.svg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    width: 1.2em;
    height: 1.2em;
    display: inline-block;
}

#menu-joined-lobby-buttons {
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-end;
    gap: 20px;
    padding-right: 5px;
}

#menu-joined-lobby-join-button {
    padding: 0 1em;
    min-width: auto;
}

#menu-joined-lobby-leave-button {
    color: hsl(340, 55%, 35%);
    background-color: transparent;
    min-width: auto;
}

#menu-joined-lobby-leave-button:hover {
    color: hsl(338, 49%, 72%);
}

.player-menu-button {
    background-image: url(resources/dots.svg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 1em 1em;
    background-color: transparent;
    
    min-height: 0;
    min-width: 0;
    width: 0.5em;
    height: 1em;
    border-radius: 5px;
    display: block;
    padding: 0 5px;
    margin: 0;
}

.player-menu-button:hover {
    background-color: hsla(0, 0%, 100%, 0.185);
}

.player-menu-button:active {
    background-color: hsla(0, 0%, 100%, 0.5);
}

.player-menu {
    margin: 0;
    position: absolute;
    z-index: 2000;
    min-width: 80px;
    max-width: 120px;
    width: fit-content;
    height: fit-content;
    padding: 0;
    border: 1px solid hsl(0, 0%, 60%);
    border-radius: 5px;
    color: rgba(255, 255, 255, 1);
    background-color: var(--secondary);
    display: flex;
    flex-flow: column nowrap;
}

.player-menu ul {
    border-bottom: 1px solid hsl(0, 0%, 30%);
    padding: 10px 15px;
    margin: 0;
}

.player-menu ul:hover {
    background-color: var(--primary);
}

.player-menu:last-child {
    border-bottom: 0;
}

.player-menu .player-menu-kick {
    color: hsl(61, 100%, 77%);
}

.player-menu .player-menu-ban {
    color: hsl(0, 69%, 54%);
}

.close-area {
    width: 600px;
    height: 600px;
    z-index: 1999;
    position: absolute;
    display: hidden;
}

@media (orientation: landscape) {
    main {
        display: flex;
        flex-flow: row-reverse nowrap;
        justify-content: center;
        align-items: center;
        margin: auto;
        width: 100vw;
        height: 100vh;
        gap: 5vw;
    }

    #sidebar {
        width: 30vw;
        min-width: 30vw;
        height: 80vh;
    }

    #game-field {
        /*width: 60vw;
        height: 65vw;*/
        max-height: 70vh;
        min-height: min(70vh, 70vw);
    }

    #field {
        min-width: min(50vw, 80vh);
        max-width: 100%;
        aspect-ratio: 1/1;
        /* height: 60vw; */
    }

    #top {
        padding-bottom: 1vh;
    }

    #logo {
        width: 11vw;
    }

    #mobile-toggle-sidebar {
        display: none;
    }

    #user-name {
        font-weight: bold;
        font-size: 1.8em;
    }

    #user-code {
        font-size: 1em;
        color: hsl(0, 0%, 60%)
    }
}

@media (orientation: portrait) {
    main {
        display: flex;
        flex-flow: column nowrap;
        justify-content: center;
        align-items: center;
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
        /* gap: 2vh; */
    }

    #sidebar {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 10vh;
    }

    #sidebar-container {
        background-color: hsl(180, 3%, 15%);

        z-index: 999;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 82vh;
        max-width: 100vw;
        padding-top: 10vh;
        padding-bottom: 8vh;
    }

    #game-field {
        width: 95vw;
        height: 100%;
        justify-content: center;
    }

    #field {
        width: 95vw;
        height: 95vw;
        justify-content: center;
    }

    #sidebar #top {
        flex-flow: row-reverse nowrap;
        justify-content: space-between;
        background-color: hsl(180, 3%, 15%);
        z-index: 1000;
        position: absolute;
        top: 0;
        width: 100vw;
        /* padding: 2vh 1vw 1vh 4vw; */
    }
    
    #logo {
        flex: 0;
        width: 12vw;
        min-width: 120px;
        margin-top: 2vh;
        margin-bottom: 1vh;
    }

    #username-container {
        flex: 1;
        flex-wrap: wrap;
        margin-top: 2vh;
        margin-left: 4vw;
    }

    #user-name {
        font-weight: bold;
        font-size: 1.3em;
    }

    #user-code {
        font-size: 1em;
        color: hsl(0, 0%, 60%)
    }

    #mobile-toggle-sidebar {
        margin-left: 4vw;
        min-width: 40px;
        min-height: 40px;
        flex: 1;
        /*height: 100%; */
        display: flex;
        flex-flow: row-reverse nowrap;
        justify-content: end;
    }

    #toggle-sidebar-button {
        width: 40px;
        margin: 0;
        padding: 0;
        background-color: transparent;

        background-image: url(resources/hamburger.svg);
        background-repeat: no-repeat;
        background-position: center center;
        background-size: 60% 60%;
        background-color: transparent;
    }

    #toggle-sidebar-button:hover {
        background-color: hsla(0, 0%, 100%, 0.2);
    }

    #toggle-sidebar-button:active {
        background-color: hsla(0, 0%, 100%, 0.1);
    }

    #menu-joined-lobby {
        min-width: min(400px, 60vw);
    }
}
