/* css */
body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background-color: rgb(31, 30, 30);
}

.red {
    color: red !important;
}

a {
    color: #fff;
    text-decoration: none;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 18px;
    position: absolute;
    left: 2%;
    top: 3%;
    transition: 0.3s;
}

a:hover {
    transform: scale(1.6);
    cursor: pointer;
    transform: scale(1.1);
}

#canvas {
    display: flex;
    flex: 1 1 auto; /* the space between the top and the bottom bars */
    min-height: 0;
    flex-direction: column;
    justify-content: center;
}
/* tiles in rows of pairs; the columns are set by video-grid.ts */
#video-grid {
    display: grid;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

video {
    height: 300px;
    /* width: 400px; */
    object-fit: cover;
}

#main {
    display: flex;
    height: 100vh;
    justify-content: space-between;
    flex-direction: column;
    background-color: rgb(31, 30, 30);
}

#buttons {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 1px 0;
    background-color: rgb(44, 43, 43);
    border-top: 1px solid rgba(248, 248, 248, 0.219);
}

#buttons div {
    padding: 10px 20px;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 18px;
    color: #fff;
    border-radius: 10px;
    border: 1px solid rgba(248, 248, 248, 0.219);
}

#buttons div:hover {
    cursor: pointer;
}

#buttons div:active {
    transform: scale(0.95);
}

#exit-btn {
    background-color: rgb(177, 14, 14);
}

#exit-btn:hover {
    background-color: rgb(197, 22, 22);
}

#videoOptions {
    display: flex;
    justify-content: space-around;
    border: none !important;
}

#videoOptions:active {
    transform: none !important;
}

#toggleVideo {
    background-color: rgb(58, 57, 57);
    margin: 0 5px 0;
}
#toggleVideo:hover {
    background-color: rgb(65, 64, 64);
}

#shareScreen {
    background-color: rgb(58, 57, 57);
    margin: 0 5px 0;
}

#shareScreen:hover {
    background-color: rgb(65, 64, 64);
}

#toggleAudio {
    background-color: rgb(58, 57, 57);
}

#toggleAudio:hover {
    background-color: rgb(65, 64, 64);
}

/* utility classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

#join-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 30px auto;
}

#join-btn button {
    padding: 14px 36px;
    font-size: 1.2rem;
    background-color: #2d8cff;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition:
        background-color 0.2s,
        transform 0.1s;
    outline: none;
}

#join-btn button:hover,
#join-btn button:focus {
    background-color: #1761b6;
    transform: translateY(-2px) scale(1.03);
}

#join-btn.vanish {
    display: none !important;
}

/* lobby */
.lobby {
    width: 100%;
    max-width: 520px;
    margin: 12vh auto 0;
    padding: 0 16px;
    box-sizing: border-box;
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}

.lobby h1 {
    font-size: 2rem;
    margin: 0 0 20px;
}

.lobby h2 {
    font-size: 1.1rem;
    margin: 40px 0 12px;
    color: rgba(255, 255, 255, 0.7);
}

/* the global `a` rule positions links absolutely; lobby links stay in the flow */
.lobby a {
    position: static;
    font-size: inherit;
}

.lobby a:hover {
    transform: none;
}

.lobby-create {
    display: inline-block;
    padding: 14px 36px;
    font-size: 1.2rem !important;
    background-color: #2d8cff;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.lobby-create:hover {
    background-color: #1761b6;
}

.lobby-rooms {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lobby-room {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    margin-bottom: 8px;
    background-color: rgb(44, 43, 43);
    border: 1px solid rgba(248, 248, 248, 0.219);
    border-radius: 8px;
}

.lobby-room-name {
    flex: 1;
    font-family: monospace;
    font-size: 1rem;
}

.lobby-room-count {
    color: rgba(255, 255, 255, 0.7);
}

.lobby-room-join {
    padding: 6px 16px;
    background-color: #2d8cff;
    border-radius: 6px;
}

.lobby-room-join:hover {
    background-color: #1761b6;
}

.lobby-room-full {
    padding: 6px 16px;
    color: rgba(255, 255, 255, 0.4);
}

.lobby-empty {
    color: rgba(255, 255, 255, 0.5);
}

/* nickname field on the call page */
#join-btn {
    gap: 12px;
}

#nickname {
    padding: 13px 16px;
    font-size: 1.1rem;
    border: 1px solid rgba(248, 248, 248, 0.3);
    border-radius: 8px;
    background-color: rgb(44, 43, 43);
    color: #fff;
    outline: none;
}

#nickname:focus {
    border-color: #2d8cff;
}

/* a video tile: the video with its owner's nickname in the corner */
.video-tile {
    position: relative;
    display: inline-flex;
}

.video-label {
    position: absolute;
    left: 8px;
    bottom: 8px;
    padding: 2px 8px;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 14px;
    pointer-events: none;
}

/* game: the bar above the call buttons (status, announcements, buttons) */
#game-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 20px;
    padding: 8px 16px;
    background-color: rgb(38, 37, 37);
    border-top: 1px solid rgba(248, 248, 248, 0.219);
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 18px;
}

#game-status {
    font-variant-numeric: tabular-nums; /* the countdown doesn't wobble */
}

#game-announcement {
    font-weight: bold;
    color: #ffd54f;
}

#game-info {
    color: rgba(255, 255, 255, 0.75);
    font-size: 15px;
}

#start-game,
#skip-vote {
    padding: 8px 18px;
    font-size: 16px;
    color: #fff;
    background-color: #2e7d32;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#start-game:disabled {
    background-color: rgb(58, 57, 57);
    color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
}

/* game: votes, notes and action buttons on a tile (top right) */
.tile-extras {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    max-width: 70%;
}

.tile-votes,
.tile-note {
    padding: 2px 8px;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 13px;
    text-align: right;
}

.tile-actions {
    display: flex;
    gap: 6px;
}

/* action buttons (and Skip vote) in the acting player's role color */
.action-btn,
#skip-vote {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}
.action-btn:hover,
#skip-vote:hover {
    filter: brightness(1.15);
}
[data-color='mafia'] {
    background-color: #d32f2f;
}
[data-color='doctor'] {
    background-color: #2e7d32;
}
[data-color='detective'] {
    background-color: #1976d2;
}
[data-color='citizen'] {
    background-color: #757575;
}

/* players without video (yet): a dark stand-in tile */
.video-tile.placeholder video {
    background-color: rgb(20, 20, 20);
}

/* game: role colors on video tiles (drawn inside the tile, so the layout doesn't shift) */
.video-tile[data-role] video {
    outline: 5px solid transparent;
    outline-offset: -5px;
}
.video-tile[data-role='mafia'] video {
    outline-color: #d32f2f;
}
.video-tile[data-role='doctor'] video {
    outline-color: #2e7d32;
}
.video-tile[data-role='detective'] video {
    outline-color: #1976d2;
}
.video-tile[data-role='citizen'] video {
    outline-color: #9e9e9e;
}

.video-tile[data-role='mafia'] .video-label {
    background-color: rgba(211, 47, 47, 0.85);
}
.video-tile[data-role='doctor'] .video-label {
    background-color: rgba(46, 125, 50, 0.85);
}
.video-tile[data-role='detective'] .video-label {
    background-color: rgba(25, 118, 210, 0.85);
}
.video-tile[data-role='citizen'] .video-label {
    background-color: rgba(97, 97, 97, 0.85);
}

/* game: dead players are dimmed */
.video-tile.dead video {
    filter: grayscale(1) brightness(0.85); /* the dead, as seen by the dead at night */
}

/* game: the gunshot (morning kill) */
.video-tile video {
    transition: filter 0.8s ease; /* the fade to grey/dark after the shot */
}

.gunshot-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

.gunshot-canvas.fade-out {
    opacity: 0;
}

.video-tile.gunshot-hit {
    animation: gunshot-shake 0.35s ease-out;
}

/* the muzzle flash: a white layer that fades out at once */
.video-tile.gunshot-hit::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: #fff;
    pointer-events: none;
    animation: gunshot-flash 0.15s ease-out forwards;
}

@keyframes gunshot-flash {
    from {
        opacity: 0.95;
    }
    to {
        opacity: 0;
    }
}

@keyframes gunshot-shake {
    0% {
        transform: translate(0, 0);
    }
    20% {
        transform: translate(-7px, 3px);
    }
    40% {
        transform: translate(6px, -4px);
    }
    60% {
        transform: translate(-4px, 2px);
    }
    80% {
        transform: translate(2px, -1px);
    }
    100% {
        transform: translate(0, 0);
    }
}

/* the victim's own screen */
.killed-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.8);
    color: #d32f2f;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 3rem;
    letter-spacing: 0.05em;
    pointer-events: none;
    animation: killed-overlay 2.8s ease forwards;
}

@keyframes killed-overlay {
    0% {
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .video-tile.gunshot-hit {
        animation: none;
    }
    .video-tile.gunshot-hit::after {
        display: none;
    }
}

/* game: full-screen messages (dawn, the night's result, the winner) */
.screen-message {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 3rem;
    text-align: center;
    letter-spacing: 0.04em;
    pointer-events: none;
    animation: screen-message-in 0.8s ease forwards;
}

.screen-message[data-tone='dawn'] {
    color: #ffd54f;
    font-style: italic;
}
.screen-message[data-tone='dusk'] {
    color: #9fa8da;
    font-style: italic;
}
.screen-message[data-tone='verdict'] {
    color: #ffb74d;
}
.screen-message[data-tone='night'] {
    color: #9fa8da;
    font-style: italic;
}
/* the detective's result */
.screen-message[data-tone='check-mafia'] {
    color: #ef5350;
    font-weight: bold;
}
.screen-message[data-tone='check-clear'] {
    color: #64b5f6;
    font-weight: bold;
}
.screen-message[data-tone='death'],
.screen-message[data-tone='mafia'] {
    color: #ef5350;
}
.screen-message[data-tone='attempt'] {
    color: #81c784;
}
.screen-message[data-tone='citizens'] {
    color: #64b5f6;
}

/* the winner: shown, then fades away so the revealed roles can be seen */
.screen-message.fade-out {
    animation: screen-message-fade 6s ease forwards;
}

@keyframes screen-message-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes screen-message-fade {
    0% {
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        visibility: hidden;
    }
}

/* game: tiles you get nothing from (fade to black), e.g. dead players for the living */
.video-tile.blackout video {
    filter: brightness(0);
}

/* game: the big label across a black or frozen tile ("Dead", "Sleeping") */
.tile-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    pointer-events: none;
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.tile-center-name {
    font-size: 18px;
}

.tile-center-state {
    font-size: 30px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.video-tile.dead .tile-center-state {
    color: #ef5350;
}

/* game: the "VOTED OUT" stamp */
.voted-out-stamp {
    position: absolute;
    top: 50%;
    left: 50%;
    padding: 6px 18px;
    border: 5px solid #d32f2f;
    border-radius: 8px;
    color: #d32f2f;
    background-color: rgba(255, 255, 255, 0.12);
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 34px;
    font-weight: bold;
    letter-spacing: 0.1em;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(-50%, -50%) rotate(-12deg);
    animation: stamp-slam 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
    transition: opacity 0.8s ease;
}

.voted-out-stamp.fade-out {
    opacity: 0;
}

@keyframes stamp-slam {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) rotate(-12deg) scale(2.6);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) rotate(-12deg) scale(1);
    }
}

.video-tile.stamp-hit {
    animation: stamp-shake 0.3s ease-out;
}

@keyframes stamp-shake {
    0% {
        transform: translate(0, 0);
    }
    30% {
        transform: translate(0, 5px);
    }
    60% {
        transform: translate(0, -2px);
    }
    100% {
        transform: translate(0, 0);
    }
}

/* game: the dead, at night */
.dead-banner {
    position: fixed;
    top: 16px;
    left: 50%;
    z-index: 80;
    transform: translateX(-50%);
    padding: 6px 16px;
    border-radius: 999px;
    background-color: rgba(30, 30, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.85);
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 15px;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .voted-out-stamp {
        animation: none;
    }
    .video-tile.stamp-hit {
        animation: none;
    }
}

/* lobby: creating a room */
.lobby-create-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.lobby-create-form button {
    border: none;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
}

.lobby-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

#create-password,
#room-password {
    padding: 12px 16px;
    font-size: 1rem;
    border: 1px solid rgba(248, 248, 248, 0.3);
    border-radius: 8px;
    background-color: rgb(44, 43, 43);
    color: #fff;
    outline: none;
}

#create-password:focus,
#room-password:focus {
    border-color: #2d8cff;
}

.lobby-error {
    margin: 0;
    color: #ef5350;
}

/* lobby: the title */
.title-accent {
    color: #e53935;
}

/* the Rules button (top right, on every page) and its window */
/* top right: Rules (and Back to lobby on the room page) */
.top-actions {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 95; /* above the full-screen game messages: always reachable */
    display: flex;
    gap: 8px;
}

/* the global `a` rule positions links absolutely; these sit in the group */
a.top-action {
    position: static;
    font-size: 15px;
}

a.top-action:hover {
    transform: none;
}

.top-action {
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    background-color: rgba(30, 30, 30, 0.85);
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 15px;
    cursor: pointer;
}

.top-action:hover {
    background-color: rgba(60, 60, 60, 0.9);
}

.rules {
    width: min(640px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 28px 32px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    background-color: rgb(28, 27, 27);
    color: rgba(255, 255, 255, 0.88);
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    box-sizing: border-box;
}

.rules::backdrop {
    background-color: rgba(0, 0, 0, 0.7);
}

.rules h2 {
    margin: 0 0 8px;
    color: #fff;
    font-size: 1.6rem;
}

.rules h3 {
    margin: 26px 0 8px;
    color: #fff;
    font-size: 1.15rem;
}

.rules h4 {
    margin: 0 0 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
}

.rules p,
.rules ol,
.rules ul {
    margin: 0 0 8px;
}

.rules ol,
.rules ul {
    padding-left: 22px;
}

.rules-intro {
    color: rgba(255, 255, 255, 0.75);
}

.rules-note {
    color: rgba(255, 255, 255, 0.55);
    font-size: 14px;
}

.rules-close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

.rules-close:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

.rules-roles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
    margin-bottom: 8px;
}

/* each role in its game color */
.rules-role {
    padding: 10px 14px;
    border-left: 4px solid;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.04);
}
.rules-role[data-role='mafia'] {
    border-color: #d32f2f;
}
.rules-role[data-role='doctor'] {
    border-color: #2e7d32;
}
.rules-role[data-role='detective'] {
    border-color: #1976d2;
}
.rules-role[data-role='citizen'] {
    border-color: #9e9e9e;
}

/* your own role, during a game */
.rules-you {
    display: none;
    padding: 1px 8px;
    border-radius: 999px;
    background-color: #fff;
    color: #121010;
    font-size: 12px;
}
.rules-role.mine {
    background-color: rgba(255, 255, 255, 0.1);
}
.rules-role.mine .rules-you {
    display: inline-block;
}

/* "Made by Nick Lukic", top left on every page */
.credit {
    position: absolute;
    left: 2%;
    top: 3%;
    z-index: 70;
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 16px;
}

/* the global `a` rule positions links absolutely; this one sits in the sentence */
.credit a {
    position: static;
    font-size: inherit;
    color: #fff;
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.35);
    text-underline-offset: 3px;
}

.credit a:hover {
    transform: none;
    text-decoration-color: #e53935;
}

/* the 404 page */
.not-found {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    text-align: center;
    color: #fff;
    font-family:
        'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}

/* the hat, tipped as if it had just been knocked off */
.not-found-hat {
    width: 180px;
    height: 180px;
    border-radius: 36px;
    transform: rotate(-12deg);
    filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.6));
    animation: hat-sway 4s ease-in-out infinite;
}

@keyframes hat-sway {
    0%,
    100% {
        transform: rotate(-12deg) translateY(0);
    }
    50% {
        transform: rotate(-8deg) translateY(-6px);
    }
}

.not-found-code {
    margin: 28px 0 4px;
    color: #e53935;
    font-size: 20px;
    letter-spacing: 0.4em;
}

.not-found h1 {
    margin: 0 0 12px;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.not-found-text {
    max-width: 420px;
    margin: 0 0 28px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 17px;
}

/* the global `a` rule positions links absolutely; this one sits in the page */
.not-found a.not-found-back {
    position: static;
    padding: 12px 30px;
    border-radius: 8px;
    background-color: #2d8cff;
    font-size: 1.1rem;
}

.not-found a.not-found-back:hover {
    transform: none;
    background-color: #1761b6;
}

@media (prefers-reduced-motion: reduce) {
    .not-found-hat {
        animation: none;
    }
}

/* the room page's top left: Back to lobby, then the credit beside it */
.top-left {
    position: fixed;
    top: 14px;
    left: 16px;
    z-index: 95; /* like the Rules button: above the full-screen game messages */
    display: flex;
    align-items: center;
    gap: 16px;
}

/* inside the group, the credit is placed by the group, not on its own */
.top-left .credit {
    position: static;
}
