#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; 
}

#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 {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 10px;
}

body.dark-mode .accordion-header {
    color: #fff;
}

#appearanceToggle {
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: #333;
    transition: color 0.3s;
}

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

#appearanceToggle:hover {
    color: #4CAF50;
}

#appearanceControls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

#appearanceControls.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none; /* Prevent interaction with hidden controls */
}

#appearanceControls:not(.collapsed) {
    max-height: 500px; /* Adjust based on content height */
    opacity: 1;
}

#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="moveBoardMode"],
label[for="darkMode"],
label[for="showArrowKeys"],
label[for="showResizeThumb"] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    font-size: 1rem;
}

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 {
    width: 100%;
    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, #shareInstagramButton {
    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;
}

#shareInstagramButton {
	display: none !important; 
}

body.dark-mode #copyLinkButton,
body.dark-mode #shareXButton,
body.dark-mode #shareFacebookButton,
body.dark-mode #shareInstagramButton {
    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: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: #4CAF50;
    cursor: se-resize;
    border-radius: 5px;
    z-index: 15;
    touch-action: none; /* Prevent default touch behaviors */
}

#resizeThumb.hidden {
    display: none;
}