* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    width: 100%;
    max-height: 100vh;
    overflow-y: auto;
}

.container {
    background-color: white;
    padding: 1rem;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 95vw;
    max-height: 95vh;
    overflow-y: auto;
}

.setup-container {
    text-align: center;
    width: 100%;
}

h1 {
    margin-bottom: 1rem;
    color: #333;
}

h2 {
    margin-bottom: 1rem;
    color: #444;
    font-size: 1.2rem;
}

.piece-selection {
    margin-bottom: 2rem;
    width: 100%;
}

.piece-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
    width: 100%;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.piece-option {
    width: 60px;
    height: 60px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
}

.piece-option:hover {
    border-color: #4CAF50;
    transform: scale(1.05);
}

.piece-option.selected {
    border-color: #4CAF50;
    background-color: #e8f5e9;
}

.piece-option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.piece-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    border: none;
    border-radius: 5px;
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background-color: #45a049;
}

.join-game {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

input {
    padding: 0.8rem;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    flex-grow: 1;
}

.hidden {
    display: none;
}

.game-info {
    text-align: center;
    margin-bottom: 1rem;
    width: 100%;
}

#status {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

#error-message-display {
    color: #D8000C; /* Red text color */
    min-height: 24px; /* Reserve space to avoid layout shift */
    margin-bottom: 10px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#error-message-display.visible {
    opacity: 1;
}

.board-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#board {
    width: 100%;
    aspect-ratio: 734 / 429;
    position: relative;
    display: flex;
    background-image: url('/static/board.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

#left-border {
    width: calc(100% * 19 / 734);
    height: 100%;
    box-sizing: border-box;
}

#playable-width {
    width: calc(100% * 24 * 15 / 734);
    height: 100%;
    box-sizing: border-box;
}

#playable-top-border {
    width: 100%;
    height: calc(100% * 24 / 429);
    box-sizing: border-box;
}

#playable-area {
    position: relative;
    height: calc(100% * 24 * 15 / 429);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
}

#right-panel {
    width: calc(100% * 355 / 734);
    height: 100%;
    box-sizing: border-box;
}

#room-name-panel {
    width: 100%;
    height: calc(100% * 62 / 429);
    box-sizing: border-box;
}

#player-panel {
    width: 100%;
    height: calc(100% * 181 / 429);
    box-sizing: border-box;
}

#player-sprites-panel {
    width: 100%;
    height: calc(100% * 82 / 181);
    box-sizing: border-box;
    display: flex;
}

#player-sprites-left-fill-1 {
    width: calc(100% * 23 / 355);
    height: 100%;
    box-sizing: border-box;
}

#player-sprites-left-fill-2 {
    width: calc(100% * 32 / 355);
    height: 100%;
    box-sizing: border-box;
}

.player-sprite {
    width: calc(100% * 68 / 355);
    height: 100%;
    box-sizing: border-box;
}

.player-sprite img {
    height: 100%;
    width: 100%;
    object-fit: cover;
    overflow: visible;
}

#player-sprite-image-1 {
    transform: scaleX(-1);
}

#player-name-tag-padding {
    height: calc(100% * 5 / 181);
    width: 100%;
    box-sizing: border-box;
}

#player-name-tag-panel {
    height: calc(100% * 16 / 181);
    width: 100%;
    display: flex;
    box-sizing: border-box;
}

#player-name-tag-left-fill-1 {
    height: 100%;
    width: calc(100% * 26 / 355);
    box-sizing: border-box;
}

#player-name-tag-left-fill-2 {
    height: 100%;
    width: calc(100% * 11 / 355);
    box-sizing: border-box;
}

.player-name-tag {
    height: 100%;
    width: calc(100% * 75 / 355);
    box-sizing: border-box;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-name-tag label {
    font-family: Arial, sans-serif;
    font-size: 0.7rem;
    color: #333;
    width: 100%;
    text-align: center;
    display: block;
    pointer-events: none;
    user-select: none;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

#start-button-panel {
    width: 100%;
    height: calc(100% * 29 / 429);
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

#start-button-left-fill {
    width: calc(100% * 246 / 355);
    height: 100%;
    box-sizing: border-box;
}

#start-button {
    width: calc(100% * 96 / 355);
    height: 100%;
    box-sizing: border-box;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

#start-button:disabled {
    cursor: not-allowed;
}

#start-button-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

#chat-panel {
    width: 100%;
    height: calc(100% * 131 / 429);
    box-sizing: border-box;
}

#control-buttons-panel {
    width: 100%;
    height: calc(100% * 18 / 429);
    display: flex;
    box-sizing: border-box;
}

#control-buttons-left-fill-1 {
    width: calc(100% * 31 / 355);
    height: 100%;
    box-sizing: border-box;
}

#forfeit-button {
    width: calc(100% * 43 / 355);
    height: 100%;
    box-sizing: border-box;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
}

#forfeit-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#forfeit-button:disabled {
    cursor: not-allowed;
}

#control-buttons-left-fill-2 {
    width: calc(100% * 5 / 355);
    height: 100%;
    box-sizing: border-box;
}

#draw-button {
    width: calc(100% * 43 / 355);
    height: 100%;
    box-sizing: border-box;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
}

#draw-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#draw-button:disabled {
    cursor: not-allowed;
}

#control-buttons-left-fill-3 {
    width: calc(100% * 5 / 355);
    height: 100%;
    box-sizing: border-box;
}

#redo-button {
    width: calc(100% * 43 / 355);
    height: 100%;
    box-sizing: border-box;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
}

#redo-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#redo-button:disabled {
    cursor: not-allowed;
}

#control-buttons-left-fill-4 {
    width: calc(100% * 130 / 355);
    height: 100%;
    box-sizing: border-box;
}

#exit-button {
    width: calc(100% * 43 / 355);
    height: 100%;
    box-sizing: border-box;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
}

#exit-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cell {
    cursor: pointer;
    z-index: 1;
}

.cell.flash-error {
    animation: flash-red 0.8s ease-out;
}

.cell:hover {
    background-color: rgba(0, 255, 0, 0.2);
}

#pieces-container {
    display: contents;
}

.piece {
    pointer-events: none;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5%;
}

@keyframes blink {
    50% {
        opacity: 0.5;
    }
}

.piece.blinking {
    animation: blink 1s infinite;
}

.piece img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.piece.black {
    background-color: #000;
}

.piece.white {
    background-color: #fff;
    border: 1px solid #000;
}

@keyframes flash-red {
    50% { background-color: rgba(255, 0, 0, 0.3); }
}

.name-input {
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.name-input label {
    font-family: Arial, sans-serif;
    font-size: 1rem;
    margin-bottom: 0.3rem;
}

.name-input input {
    width: 100%;
    font-family: Arial, sans-serif;
}

/* Redo request overlay */
.redo-request-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.redo-request-overlay.hidden {
    display: none;
}

.redo-request-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    max-width: 300px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.redo-request-content p {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: #333;
}

.redo-request-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.redo-button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background-color 0.2s;
}

.redo-button.accept {
    background-color: #4CAF50;
    color: white;
}

.redo-button.accept:hover {
    background-color: #45a049;
}

.redo-button.decline {
    background-color: #f44336;
    color: white;
}

.redo-button.decline:hover {
    background-color: #da190b;
}

/* Win/Lose/Draw overlay */
.win-lose-draw-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 2000;
}

.win-lose-draw-overlay img {
    max-width: none;
    max-height: none;
    width: auto;
    height: auto;
    object-fit: contain;
}