@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');

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

body {
    font-family: 'Cinzel', serif;
    background: url('../maze/parchment.jpg') center/cover no-repeat fixed;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    color: #000;
    touch-action: none; /* Prevent default gestures */
}

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

body {
    font-family: 'Cinzel', serif;
    background: url('../maze/parchment.jpg') center/cover no-repeat fixed;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    color: #000;
    touch-action: none; /* Prevent default gestures */
}

body.dark-mode {
    background: url('../maze/dark-stone.jpg') center/cover no-repeat fixed;
    color: #fff;
}

body.dark-mode::before {
    display: none;
}

#gameContainer {
    background: url('../maze/solutions/placeholder.jpg') right 40% no-repeat fixed;
    background-size: cover;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    padding: 20px;
    min-width: calc(60vw); /* Width accounts for settingsBox (300px + 40px margins) */
	width: calc(80vw);
    max-width: calc(2000px);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    border: 2px solid #8B4513;
    transition: width 0.3s ease, max-width 0.3s ease, margin-left 0.3s ease;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
    margin-bottom: 20px;
    z-index: 2; /* Higher than titleContainer */
}

#gameContainer.settings-hidden {
    width: 90vw; /* Full width when settingsBox is hidden */
    max-width: 1200px;
    margin-left: auto; /* Center in full viewport */
    margin-right: auto;
}

body.dark-mode #gameContainer {
    border: 2px solid #000;
}

body.dark-mode #mazeCanvas {
    border: 3px solid #000;
}

#opacityInputDiv {
    margin-bottom: 20px;
}

#junctionsInputDiv {
    margin-bottom: 20px;
}


body.dark-mode #gameContainer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    z-index: 0;
    border-radius: 15px;
}

#titleContainer {
    text-align: center;
    background: rgba(255, 255, 255, 0.7);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    position: relative;
    z-index: 1; /* Lowest z-index for title */
}

body.dark-mode #titleContainer {
    background: rgba(0, 0, 0, 0.7);
}

#mainTitle {
    font-size: 3rem;
    margin: 10px 0 5px;
}

#subTitle {
    font-size: 1.8rem;
    font-style: italic;
    margin: 5px 0;
}

#dateString, #mazeCode, #promptText {
    font-size: 1.0rem;
    margin: 5px 0;
}

#promptText {
    font-size: 1.2rem;
    color: #222;
}

#dateString, #mazeCode {
    color: #666;
}

body.dark-mode #dateString, #mazeCode {
    color: #AAA;
}

body.dark-mode #promptText {
    color: #ccc;
}

#mazeContainer {
    overflow: auto;
    max-height: calc(100vh - 200px);
    width: fit-content;
    position: relative;
    z-index: 3; /* Higher than gameContainer and titleContainer */
}

#mazeCanvas {
    display: block;
    border: 5px solid #8B4513;
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
    background: transparent;
    transition: background-color 0.3s;
    touch-action: none; /* Prevent default touch behaviors */
}

body.dark-mode #mazeCanvas {
    border: 5px solid #555;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.2));
}

#zoomMessage {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 20;
    display: none;
}

#zoomMessage.show {
    display: block;
}

#openSettings {
    position: fixed;
    top: 10px; /* Slightly closer to edge for mobile */
    right: 10px;
    background: #f0f0f0;
    color: #000; /* Changed to black for visibility */
    border: none;
    border-radius: 50%;
    width: 48px; /* Slightly larger for touch targets */
    height: 48px;
    font-size: 1.4rem; /* Larger icon for visibility */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
    z-index: 9; /* Below settingsBox */
    touch-action: manipulation; /* Ensure touch events work */
}

#openSettings.hidden {
    display: none !important; /* Corrected typo and added !important for specificity */
}

#openSettings:hover {
    background: #45a049;
}

.dark-mode #openSettings {
    background: #303030;
    color: #fff; /* Ensure visibility in dark mode */
}

.dark-mode #openSettings:hover {
    background: #45a049;
}

#hideSettings {
    background: #4CAF50;
    color: #fff;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.3s;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    align-self: flex-end;
}

#hideSettings:hover {
    background: #45a049;
}

#settingsBox {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px; /* Default width */
    max-width: 90vw; /* Prevent overflow on small screens */
    height: 100%;
    background: #fff;
    border-left: 2px solid #ccc;
    padding: 15px; /* Slightly reduce padding for mobile */
    z-index: 10; /* Higher than openSettings */
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    touch-action: auto; /* Allow scrolling inside settings box */
}

#settingsBox:not(.hidden) {
    transform: translateX(0);
}

body.dark-mode #settingsBox {
    background: #444;
    border-left: 2px solid #666;
    color: #fff;
}

#settingsBox hr {
    border: none;
    border-top: 1px solid #8B4513;
    margin: 10px 0;
    opacity: 0.7;
}

body.dark-mode #settingsBox hr {
    border-top: 1px solid #666;
}

#puzzleIdContainer::before {
    content: 'Maze Selection';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #puzzleIdContainer::before {
    color: #fff;
}

#appearanceContainer::before {
    content: 'Appearance';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #appearanceContainer::before {
    color: #fff;
}

#showSolution::before {
    content: 'Gameplay';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #showSolution::before {
    color: #fff;
}

#zoomButtons::before {
    content: 'Zoom';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #zoomButtons::before {
    color: #fff;
}

#shareButtons::before {
    content: 'Share';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #shareButtons::before {
    color: #fff;
}

#buyBookContainer::before {
    content: 'A Mazing Book';
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
    display: block;
}

body.dark-mode #buyBookContainer::before {
    color: #fff;
}

label[for="showSolution"],
label[for="darkMode"],
label[for="showArrowKeys"],
label[for="showResizeThumb"] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    font-size: 1rem;
}

/* Specific styling for Show Solution to make it stand out */
label[for="showSolution"] {
    font-weight: 700; /* Bold text */
    color: #7B1FA2; /* Deep purple in light mode */
    background: rgba(123, 31, 162, 0.1); /* Subtle purple background */
    padding: 5px 10px; /* Slight padding for background visibility */
    border-radius: 5px; /* Rounded corners for elegance */
    transition: background 0.3s, color 0.3s; /* Smooth hover transition */
}

label[for="showSolution"]:hover {
    background: rgba(123, 31, 162, 0.2); /* Slightly darker background on hover */
    color: #4A148C; /* Darker purple on hover */
}

body.dark-mode label[for="showSolution"] {
    color: #E1BEE7; /* Lighter purple in dark mode for contrast */
    background: rgba(225, 190, 231, 0.2); /* Subtle purple background in dark mode */
}

body.dark-mode label[for="showSolution"]:hover {
    background: rgba(225, 190, 231, 0.3); /* Slightly darker background on hover */
    color: #F3E5F5; /* Even lighter purple on hover */
}

#maxJunctionsInputSpan {
    display: none;
}

label[for="maxJunctionsInput"] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    font-size: 1rem;
}

input[type="checkbox"] {
    display: none;
}

input[type="checkbox"] + span.slider {
    position: relative;
    width: 40px;
    height: 20px;
    background: #ccc;
    border-radius: 20px;
    transition: background 0.3s;
}

input[type="checkbox"] + span.slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

input[type="checkbox"]:checked + span.slider {
    background: #4CAF50;
}

input[type="checkbox"]:checked + span.slider::before {
    transform: translateX(20px);
}

#puzzleIdContainer {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

#puzzleIdInput {
    text-transform: uppercase;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1rem;
    font-family: 'Cinzel', serif;
    width: 100px;
}

#goButton {
    padding: 8px 12px;
}

#randomPuzzleButton, #resetButton, #loadMazeButton {
    width: 100%;
    margin-top: 5px;
    padding: 7px;
}

#mazeDate, #difficulty {
    margin-top: 5px;
    padding: 7px;
}

#zoomButtons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 0px;
}

#zoomInButton, #zoomOutButton, #zoomResetButton {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#shareButtons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 0px;
}

#shareButtons button {
    width: 40px;
    height: 40px;
    background: #2196F3;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#shareButtons button:hover {
    background: #1976D2;
}

#copyLinkButton, #shareXButton, #shareFacebookButton {
    color: #fff;
    background-color: #333;
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin: 5px;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    transition: color 0.3s, background-color 0.3s;
}

body.dark-mode #copyLinkButton,
body.dark-mode #shareXButton,
body.dark-mode #shareFacebookButton {
    color: #333;
    background-color: #ddd;
}

#buyBookContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
}

#bookImageLink {
    display: block;
    cursor: pointer;
}

#bookImage {
    max-width: 200px;
    border-radius: 5px;
}

#amazonRegionSelect {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
}

#buyBookButton {
    padding: 4px;
    background: orange;
    border-radius: 5px;
    font-size: 1.1em;
}

#buyBookButton:hover {
    background: darkorange;
    cursor: pointer;
}

#buyBookButton.glow {
    background: red;
}

@keyframes glow {
    0% { box-shadow: 0 0 5px orange; }
    50% { box-shadow: 0 0 20px orange; }
    100% { box-shadow: 0 0 5px orange; }
}

#arrowKeys {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    padding: 10px;
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    gap: 5px;
    z-index: 20;
}

#arrowKeys.hidden {
    display: none;
}

#arrowUpButton { grid-area: up; }
#arrowLeftButton { grid-area: left; }
#arrowDownButton { grid-area: down; }
#arrowRightButton { grid-area: right; }

#arrowKeys button {
    width: 40px;
    height: 40px;
    background: #666;
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    touch-action: manipulation; /* Prevent default touch behaviors */
    cursor: pointer;
}

#arrowKeys button:hover,
#arrowKeys button:active {
    background: #555;
}

#resizeThumb {
    position: absolute;
    bottom: 0px;
    right: 0px; 
    width: 20px;
    height: 20px;
    background: #4CAF50;
    cursor: se-resize;
    border-radius: 5px;
    z-index: 15;
    touch-action: none;
    display: flex; /* Enable flexbox to center the arrow */
    align-items: center;
    justify-content: center;
}

#resizeThumb::before {
    content: '↘'; /* Unicode for bottom-right diagonal arrow */
    color: #fff; /* White arrow for contrast against green background */
    font-size: 12px; /* Adjust size to fit within 20x20px */
    line-height: 20px; /* Center vertically */
    text-align: center; /* Center horizontally */
}

#resizeThumb.hidden {
    display: none;
}
body.dark-mode #resizeThumb {
    background: #388E3C; /* Slightly darker green for dark mode */
}

body.dark-mode #resizeThumb::before {
    color: #ddd; /* Slightly off-white for dark mode */
}
#mazingAdventureLogo {
    position: absolute;
    top: 10px;
    left: 15px;
    z-index: 9;
}

#mazingAdventureLogo img {
    width: 64px;
    height: 64px;
}

@media (max-width: 700px) {
    #mainTitle { font-size: 2rem; }
    #subTitle { font-size: 1.2rem; }
    #dateString, #mazeCode, #promptText { font-size: 0.9rem; }
    #gameContainer {
        margin: 10px auto;
        width: 90vw;
        max-width: 1200px;
    }
    #gameContainer.settings-hidden {
        width: 90vw;
        max-width: 1200px;
    }
    #settingsBox {
        width: 90vw; /* Use most of the viewport width */
        padding: 10px;
    }
    #settingsBox.hidden {
        display: none; /* Hide completely on mobile */
    }
    body.dark-mode #settingsBox {
        border: 2px solid #666;
    }
    #arrowKeys { top: 10px; left: 10px; }
    #puzzleIdContainer::before, #appearanceContainer::before, #showSolution::before, #zoomButtons::before, #shareButtons::before, #buyBookContainer::before {
        font-size: 1rem;
    }
    label, button, #puzzleIdInput, #amazonRegionSelect {
        font-size: 0.9rem;
    }
    #puzzleIdInput {
        width: 80px;
    }
    #mazingAdventureLogo img {
        width: 32px;
        height: 32px;
    }
    #openSettings {
        top: 5px;
        right: 5px;
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
}
