/*==============================
� Core Sudoku Game Styles
==============================*/
html {
    font-size: min(3dvw, 3dvh);
}

p, ul {
    font-size: 1rem;
}

h1 {
    font-size: 2rem;
}

h2, label {
    font-size: 1.5rem;
}

.selector-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* Stylize the labels for the selectors */
.selector-container label {
    background-color: #34495e;
    color: white;
    padding: 5px 15px;
    border-radius: 5px;
    text-transform: uppercase;
    font-size: 1rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    margin-bottom: 5px;
}

.config-selectors {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 15px; /* Add a consistent gap between each label/select group */
}

h3 {
    font-size: 1.25rem;
}

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100dvh;
    box-sizing: border-box;
    transition: background-color 0.5s ease;
}

main {
    width: 100%;
}

#background-image-container {
    position: fixed;
    opacity: .25;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    transition: opacity 0.5s ease-in-out;
    background-image: url('../assets/ActiveSudoku.png');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
}

body.connection-background #background-image-container {
    background-image: url('../assets/StageConnection.png');
    opacity: 0.25;
}

/* When in config mode, hide game-specific UI elements */
.game-container.config-active #number-pad,
.game-container.config-active #sudoku-grid-area, 
.game-container.config-active #game-controls > *:not(.toggle-switch-container) {
    display: none;
}

/* Hide the signaling area by default */
#signaling-area {
    display: none;
}

/* When in config mode, re-style the controls container to be a simple top bar */
.game-container.config-active #game-controls {
    order: 0; /* Ensure it's at the very top */
    flex-direction: row;
    justify-content: center;
    height: auto; /* Override the fixed height */
}

.hidden {
    display: none !important;
}

/* When in config mode, show the signaling area */
.game-container.config-active #signaling-area {
    display: block; /* Or 'flex', 'grid', etc., depending on its internal layout */
}

.blink {
    animation: blink-animation 1s steps(1) infinite;
}

@keyframes blink-animation {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: #add8e6;
    }
}

/* Overlays and Information areas */
#scan-overlay-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 3rem;
    font-weight: bold;
    padding: 20px 40px;
    border-radius: 10px;
    z-index: 1000;
    transition: opacity 0.3s ease-in-out;
    opacity: 1;
}

#scan-overlay-message.hidden {
    opacity: 0;
    pointer-events: none;
}

#timer-area {
    padding: 0px 20px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 3rem;
    border-radius: 5px;    
    z-index: 1; /* Lower the z-index */
    display: inline-block;
}

#p1-peer-id {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 3rem;
    font-weight: bold;
    padding: 20px 40px;
    border-radius: 10px;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
    display: inline-block;
}

/* Global Button and Input Styles */
button, select, .number-btn {
    background-color: #007bff;
    color: #fff;
    border: 2px solid #0056b3;
    padding: 10px 20px;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover, select:hover, .number-btn:hover {
    background-color: #0056b3;
    border-color: #004494;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
}

button:active, select:active, .number-btn:active {
    transform: translateY(0);
    box-shadow: 2px 4px rgba(0, 0, 0, 0.1);
}

button:disabled, select:disabled, .number-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* Align icon and text inside buttons */
.theme-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.button-row {
    display: flex;
    align-items: center;
    gap: 8px; /* Add a gap between the buttons */
}

/* New Puzzle Button Styles */
#new-puzzle-btn {
    position: relative;
    overflow: hidden;
    justify-content: center; /* Center the main content */
    /* Adjust padding to make room for the rotated text */
    padding: 10px 20px 10px 40px;
}

.button-content {
    display: flex;
    align-items: center;
    position: relative; /* Needed for z-index to apply */
    z-index: 2; /* Ensure this is on top */
    gap: 10px;
}

.icon {
    font-size: 1.2em; /* Make icon slightly larger than text */
    display: flex;
    align-items: center;
}

.text {
    flex-grow: 1;
    text-align: center;
}

.rotated-text {
  position: absolute;
  left: -25px; /* Position on the left */
  top: 50%;
  transform: translateY(-50%) rotate(-45deg); /* Rotate in the opposite direction */
  font-weight: bold;
  color: rgba(0, 0, 0, 0.6); /* More transparent black text */
  background-color: rgba(255, 255, 0, 0.5); /* More transparent yellow background */
  padding: 2px 20px; /* Adjust padding */
  z-index: 1; /* Ensure this is behind the main content */
}

/* Toggle Switch Styles */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-switch-label {
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    color: #34495e; /* Match the label style */
}

.toggle-switch {
    position: relative;
    width: 60px;
    height: 34px;
    -webkit-appearance: none;
    appearance: none;
    background: #ccc;
    outline: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-switch:checked {
    background: #007bff;
}

.toggle-switch::before {
    content: '';
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    top: 4px;
    left: 4px;
    background: white;
    transition: 0.3s;
}

.toggle-switch:checked::before {
    transform: translateX(26px);
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    min-width: 200px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
}

select option {
    font-size: 1rem;
}

textarea {
    width: 100%;
    height: 100px;
}

.host-id-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

#generate-new-id-btn {
    margin-top: 5px;
}

/* Video Background */
.video-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100dvw;
    height: 100dvh;
    overflow: hidden;
    z-index: -1;
}

.video-foreground {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
}

.video-foreground iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Common Sudoku and Number Pad Styles */
.number-btn {
    flex: 1 0 18%;
    padding: 1dvw;
    font-size: 2rem;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s ease-in-out;
}

.number-btn:hover {
    transform: scale(1.1);
}

.grid-cell {
    width: 100%;
    height: 100%;
    border: 1px solid black;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    cursor: pointer;
    transition: background-color 0.3s;
    font-size: 2rem;
}

.grid-cell {
    position: relative; /* Needed for absolute positioning of children */
}

.cell-value {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    z-index: 2; /* Ensure it's above the scratchpad */
}

.scratch-pad {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    z-index: 1;
}

.scratch-pad-digit {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.6rem;
    visibility: hidden; /* Digits are hidden by default */
}

.subgrid-border-right {
    border-right: 5px solid black;
}

.subgrid-border-bottom {
    border-bottom: 5px solid black;
}

/* Base Styles for Themed Elements */
.preloaded-cell {
    font-weight: bold;
    cursor: default;
}

.highlight-cell {
    background-color: #e0e0e0;
}

.active-cell {
    border: 2px solid red;
}

.invalid-cell {
    background-color: #ff0000;
}

.pencil-active {
    background-color: #0056b3 !important;
    color: white !important;
}

.solved-puzzle {
    background-color: lightgreen;
}

/* ------------------------------------------ */
/* Media Queries for Responsive Design */
/* ------------------------------------------ */

/* Portrait and narrow screens */
@media (orientation: portrait) {
    main {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .game-container {
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        gap: 2dvh;
    }

    /* This section now contains the grid and number pad */
    #sudoku-grid-area {
        display: flex;
        order: 2; /* Place after number pad */
        flex-direction: column;
        align-items: center;
        gap: 2dvh;
    }

    /* Controls are now a direct child of game-container */
    #game-controls {
        display: flex;
        order: 3; /* Place at the bottom */
        flex-direction: column;
        align-items: flex-start;
        gap: 1dvh;
    }

    #number-pad {
        display: grid;
        order: 1; /* Place at the top */
        grid-template-columns: repeat(5, 1fr); /* 5 columns for 2 rows */
        gap: 2dvw;
        margin: 1dvh auto;
        width: 90dvw;
    }

    #puzzle-area {
        width: 90dvw;
        max-height: 90dvw;
    }

    #sudoku-grid {
        width: 100%;
        height: 100%;
        display: grid;
        grid-template-columns: repeat(9, 1fr);
        grid-template-rows: repeat(9, 1fr);
        border: 3px solid black;
        margin: 0 auto;
        aspect-ratio: 1 / 1;
    }

    .button-row {
        width: 100%;
    }

    .number-btn {
        width: 100%;
        height: auto;
    }

    #instructions {
        font-size: 2rem;
    }

    .grid-cell {
        font-size: 2rem;
        background-color: rgba(255, 255, 255, .75);
    }
}

/* Landscape and wider screens */
@media (orientation: landscape) {
    main {
        display: flex;
        align-items: center;
        justify-content: space-evenly;
    }

    .game-container {
        display: flex;
        flex-direction: row;
        justify-content: center; /* Center the items with gaps */
        align-items: center;
        width: 100dvw;
        gap: 1dvw; /* Add space between the main sections */
        padding: 0 1dvw; /* Adds a small padding on the sides */
        box-sizing: border-box;
    }

    #game-controls {
        display: flex;
        order: 3; /* Right side */
        flex-direction: column;
        height: 95dvh;
        justify-content: flex-start; /* Align items to the top */
        gap: 15px; /* Add vertical spacing between controls */
    }

    #game-controls .theme-button {
        width: auto; /* Prevent buttons from stretching */
        align-self: flex-start; /* Align them to the left of the column */    
    }

    #sudoku-grid-area {
        display: flex; order: 2; /* Center */
        flex-direction: row;
        align-items: flex-start;
        gap: 1dvw;
        justify-content: center;
    }

    #number-pad {
        display: grid;
        order: 1; /* Left side */
        grid-template-columns: repeat(2, 1fr); /* 2 columns */
        gap: 1dvh;
        align-content: center;
        width: 15dvw; /* Adjust width for better scaling */
    }

    .number-btn {
        width: 100%;
        height: auto;
    }

    #puzzle-area {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 90dvh;
        width: 60dvw;
    }

    #sudoku-grid {
        width: 100%;
        height: 100%;
        display: grid;
        grid-template-columns: repeat(9, 1fr);
        grid-template-rows: repeat(9, 1fr);
        border: 3px solid black;
    }

    #instructions {
        font-size: 2rem;
    }

    .grid-cell {
        font-size: 2rem;
        background-color: rgba(255, 255, 255, .75);
    }
}

/*==============================
 Resolution-specific Tweaks
==============================*/

/* For landscape screens around 1366px wide */
@media (orientation: landscape) and (max-width: 1400px) {
    #puzzle-area {
        height: 80dvh;
        width: 50dvw;
    }
}

/* For portrait screens around 1024px wide */
@media (orientation: portrait) and (min-width: 1000px) {
    #puzzle-area {
        height: 55dvh;
        width: 70dvw;
    }
}

/*==============================
� Default Theme
==============================*/
body.default {
    background-color: #E0DEDF;
    color: #2F2F2F;
}

body.default #sudoku-grid {
    border-color: #2F2F2F;
}

body.default .grid-cell {
    border-color: #4A4549;
    background-color: rgba(255, 255, 255, .75);
}

body.default .preloaded-cell {
    background-color: #AFAFAF;
    color: black;
}

body.default .highlight-cell {
    background-color: #007bff;
    color: #2F2F2F;
}

body.default .active-cell {
    background-color: #0056b3;
    color: #E0DEDF;
}

body.default .invalid-cell {
    background-color: #DC143C;
    color: #FFFFFF;
}

body.default .solved-puzzle {
    background-color: #3CB371;
    color: #E0DEDF;
}

/* Themed buttons and dropdowns */
body.default button,
body.default .number-btn,
body.default #empty-btn,
body.default select {
    background-color: #007bff;
    color: #E0DEDF;
    border-color: #5C4B2E;
}

body.default button:hover,
body.default .number-btn:hover,
body.default #empty-btn:hover,
body.default select:hover {
    background-color: #0056b3;
    border-color: #004494;
    color: #FFFFFF;
}

/* Red 'X' button for this theme */
body.default #empty-btn {
    background-color: #dc3545;
}

body.default #empty-btn:hover {
    background-color: #c82333;
}


/*==============================
� Banished Theme
==============================*/
body.banished {
    background-color: #262125;
    color: #E0DEDF;
}

body.banished #sudoku-grid {
    border-color: #8C2F2F;
}

body.banished .grid-cell {
    border-color: #4A4549;
    background-color: rgba(38, 33, 37, .75);
}

body.banished .preloaded-cell {
    background-color: #6B686A;
    color: #262125;
}

body.banished .highlight-cell {
    background-color: #A3A0A2;
    color: #262125;
}

body.banished .active-cell {
    background-color: #C22D2D;
    color: #FFFFFF;
}

body.banished .invalid-cell {
    background-color: #FF0000;
    color: #FFFFFF;
}

body.banished .solved-puzzle {
    background-color: #5C4B2E;
    color: #E0DEDF;
}

/* Themed buttons and dropdowns */
body.banished button,
body.banished .number-btn,
body.banished #empty-btn,
body.banished select {
    background-color: #8C2F2F;
    color: #E0DEDF;
    border-color: #5C4B2E;
}

body.banished button:hover,
body.banished .number-btn:hover,
body.banished #empty-btn:hover,
body.banished select:hover {
    background-color: #C22D2D;
    border-color: #8C2F2F;
    color: #FFFFFF;
}

/* Transparent red 'X' button for this theme */
body.banished #empty-btn {
    background-color: rgba(220, 53, 69, 0.6); /* Transparent red */
}

body.banished #empty-btn:hover {
    background-color: rgba(200, 35, 51, 0.8);
}

/*==============================
� UNSC Theme
==============================*/
body.unsc {
    background-color: #1A1A1A;
    color: #CDCFCC;
}

body.unsc #sudoku-grid {
    border-color: #2D6A4F;
}

body.unsc .grid-cell {
    border-color: #1D3A2F;
    background-color: rgba(26, 26, 26, .75);
}

body.unsc .preloaded-cell {
    background-color: #4C4A45;
    color: #CDCFCC;
}

body.unsc .highlight-cell {
    background-color: #EFB82A;
    color: #1D3A2F;
}

body.unsc .active-cell {
    background-color: #3D6B51;
    color: #CDCFCC;
}

body.unsc .invalid-cell {
    background-color: #B53835;
}

body.unsc .solved-puzzle {
    background-color: #00A0C0;
    color: #1A1A1A;
}

/* Themed buttons and dropdowns */
body.unsc button,
body.unsc .number-btn,
body.unsc #empty-btn,
body.unsc select {
    background-color: #3D6B51;
    color: #CDCFCC;
    border-color: #2D6A4F;
}

body.unsc button:hover,
body.unsc .number-btn:hover,
body.unsc #empty-btn:hover,
body.unsc select:hover {
    background-color: #EFB82A;
    color: #1A1A1A;
    border-color: #EFB82A;
}

/* Red 'X' button for this theme */
body.unsc #empty-btn {
    background-color: #dc3545;
}

body.unsc #empty-btn:hover {
    background-color: #c82333;
}

/*==============================
� Forerunner Theme
==============================*/
body.forerunner {
    background-color: #1A2A3A;
    color: #C0D0E0;
}

body.forerunner #sudoku-grid {
    border-color: #4A6A8A;
}

body.forerunner .grid-cell {
    border-color: #3A5A7A;
    background-color: rgba(26, 42, 58, .75);
}

body.forerunner .preloaded-cell {
    background-color: #2A4A6A;
    color: #F0F8FF;
}

body.forerunner .highlight-cell {
    background-color: #6A8AA0;
    color: #1A2A3A;
}

body.forerunner .active-cell {
    background-color: #00A0C0;
    color: #1A2A3A;
}

body.forerunner .invalid-cell {
    background-color: #CC3333;
    color: #F0F8FF;
}

body.forerunner .solved-puzzle {
    background-color: #208060;
    color: #F0F8FF;
}

/* Themed buttons and dropdowns */
body.forerunner button,
body.forerunner .number-btn,
body.forerunner #empty-btn,
body.forerunner select {
    background-color: #4A6A8A;
    color: #C0D0E0;
    border-color: #3A5A7A;
}

body.forerunner button:hover,
body.forerunner .number-btn:hover,
body.forerunner #empty-btn:hover,
body.forerunner select:hover {
    background-color: #00A0C0;
    color: #1A2A3A;
    border-color: #00A0C0;
}

/* Red 'X' button for this theme */
body.forerunner #empty-btn {
    background-color: #dc3545;
}

body.forerunner #empty-btn:hover {
    background-color: #c82333;
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%; /* Could be more or less, depending on screen size */
    border-radius: 8px;
}