body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    background-color: #1a1a1a;
    color: #f0f0f0;
    min-height: 100vh;
    width: 100vw; /* Make body full width */
    overflow: hidden; /* Hide scrollbars if content overflows */
    -webkit-user-select: none; /* Disable text selection for webkit browsers */
    -moz-user-select: none; /* Disable text selection for Firefox */
    -ms-user-select: none; /* Disable text selection for IE/Edge */
    user-select: none; /* Standard syntax for disabling text selection */
    overscroll-behavior-y: contain; /* Prevent pull-to-refresh */
}

h1 {
    display: none; /* Hidden */
}

.canvas-container {
    position: relative;
    display: flex; /* Use flex to center canvas */
    justify-content: center;
    align-items: center;
    width: 100vw; /* Make container full width of viewport */
    height: 100vh; /* Make container full height of viewport */
}

canvas {
    border: none;
    background-color: #000;
    cursor: pointer;
    touch-action: none; /* Prevents default touch behaviors like scrolling */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    width: 100%;
    height: 100%;
    max-height: 100%;
}

#settingsGear, #randomizeButton, #rotateButton, #shakeButton, #saveImageButton {
    position: absolute;
    color: #00bfff;
    cursor: pointer;
    text-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
    transition: transform 0.2s ease-in-out, color 0.2s ease-in-out;
    z-index: 10; /* Ensure it's above the canvas */
}

#settingsGear {
    position: absolute;
    font-size: 2.5em; /* Make it noticeable */
    color: #00bfff;
    cursor: pointer;
    text-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
    transition: transform 0.2s ease-in-out, color 0.2s ease-in-out;
    z-index: 10; /* Ensure it's above the canvas */
    top: 15px;
    right: 15px;
}

#rotateButton {
    position: absolute;
    font-size: 2.5em; /* Make it noticeable */
    color: #00bfff;
    cursor: pointer;
    text-shadow: 0 0 10px rgba(0, 191, 255, 0.7);
    transition: transform 0.2s ease-in-out, color 0.2s ease-in-out;
    z-index: 10; /* Ensure it's above the canvas */
    top: 15px;
    left: 15px;
}

#shakeButton {
    bottom: 35px;
    left: 15px;
    font-size: 2.8em;
}

#recordingIndicator {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    background-color: red;
    color: white;
    padding: 8px 15px;
    border-radius: 8px;
    font-weight: bold;
    font-family: monospace;
    z-index: 11;
    display: none;
    animation: pulse-rec 1.5s infinite;
    cursor: pointer;
    text-align: center;
    font-size: 1.2em;
}

#recordingIndicator .stop-text {
    font-size: 0.7em;
    font-weight: normal;
    display: block;
    margin-top: 4px;
    opacity: 0.9;
}

#saveImageButton {
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2em; /* Increased from 2.8em for better touch */
}

#saveImageButton img {
    display: block;
    width: 44px;
    height: 44px;
    filter: drop-shadow(0 0 5px rgba(0, 191, 255, 0.7));
}

#rotateButton.active {
    color: #ff4136; /* Red for 'on' state, as requested */
}

#rotationSliderContainer {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    background: rgba(42, 42, 42, 0.6);
    padding: 8px 15px;
    border-radius: 20px;
    pointer-events: none;
}

#rotationSliderContainer.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

#rotationSpeedSlider {
    -webkit-appearance: none;
    appearance: none;
    width: 150px;
    height: 6px;
    background: #555;
    outline: none;
    border-radius: 3px;
    margin: 0;
}

#rotationSpeedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #00bfff;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0, 191, 255, 0.7);
}

#rotationSpeedSlider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #00bfff;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0, 191, 255, 0.7);
}

#randomizeButton {
    bottom: 35px;
    right: 15px;
    font-size: 2.8em;
}

#settingsGear:hover {
    transform: rotate(30deg);
}

#rotateButton:hover {
    transform: scale(1.2);
}

#shakeButton:hover {
    transform: translateY(-5px);
}

#saveImageButton:hover {
    transform: translateX(-50%) scale(1.1);
}

#randomizeButton:hover {
    transform: rotate(-30deg);
}

.footer {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: #888;
    font-size: 0.8em;
    z-index: 5;
    text-align: center;
}

.footer a {
    color: #00bfff;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* Modal styles */
.modal {
    display: none; /* Changed from block to none */
    position: fixed; /* Stay in place */
    z-index: 100; /* 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.8); /* Black w/ opacity */
    padding: 20px;
    box-sizing: border-box; /* Include padding in width/height calculation */
}

.modal-content {
    background-color: #2a2a2a;
    margin: 5vh auto; /* Adjusted margin for better spacing */
    padding: 25px;
    border: 1px solid #00bfff;
    border-radius: 10px;
    width: 90%;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    position: relative;
    max-height: 90vh; /* Max height to allow scrolling if content overflows */
    overflow-y: auto; /* Enable vertical scrolling */
}

.modal-content h2 {
    color: #00bfff;
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
    text-shadow: 0 0 8px rgba(0, 191, 255, 0.7);
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: #fff;
    text-decoration: none;
    transform: scale(1.1);
}

#controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px 20px;
    padding: 15px; /* Added padding to controls div itself */
    border-radius: 10px; /* Kept border-radius for aesthetic */
    max-width: 100%; /* Adjust to fit modal content */
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

label {
    margin-bottom: 5px;
    font-size: 0.9em;
    color: #ccc;
}

input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background-color: #444;
    border: 2px solid #00bfff;
    border-radius: 5px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s;
}

input[type="checkbox"]:checked {
    background-color: #00bfff;
}

#rainbow:checked {
    background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
}

#rainbowContainer:checked {
    background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
}

#rainbowTrails:checked {
    background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
}

#customTrailColor {
    border-color: #00bfff; /* Blue border for custom trail color */
}

#customTrailColor:checked {
    background-color: #00bfff;
}

#deviceOrientation {
    border-color: #9b59b6; /* A purple border */
}

#deviceOrientation:checked {
    background-color: #9b59b6;
}

#deviceOrientation:checked::after {
    content: '📱';
    font-size: 14px;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#shakeToShuffle {
    border-color: #f0ad4e; /* An orange border */
}

#shakeToShuffle:checked {
    background-color: #f0ad4e;
}

#shakeToShuffle:checked::after {
    content: '🔀'; /* Shuffle icon */
    font-size: 14px;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

input[type="checkbox"]:checked::after {
    content: '✔';
    font-size: 16px;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 120px; /* Reduced width to prevent overflow */
    height: 8px;
    background: #444;
    outline: none;
    border-radius: 5px;
    transition: opacity 0.2s;
}

/* Specific styling for the new 'Color on Hit' checkbox if needed for distinction */
#colorOnHit {
    border-color: #ffd700; /* Gold-ish color for a distinctive look */
}

#colorOnHit:checked {
    background-color: #ffd700;
}

#starryNight {
    border-color: #f0f0f0; /* White-ish border */
}

#starryNight:checked {
    background-color: #4c3a8c; /* Deep purple */
}

#backgroundEffect {
    width: 140px; /* Give it enough space for text */
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #00bfff;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #00bfff;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0, 191, 255, 0.7);
}

select, button {
    background-color: #333;
    color: #fff;
    border: 1px solid #00bfff;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s, box-shadow 0.3s;
}

#defaultSettingsButton {
    display: block; /* Make it a block element to control margins */
    margin: 0 auto 20px; /* Center horizontally and add margin below */
    border-color: #5bc0de;
}

#defaultSettingsButton:hover {
    background-color: #5bc0de;
    box-shadow: 0 0 10px #5bc0de;
}

select:hover, button:hover {
    background-color: #00bfff;
    box-shadow: 0 0 10px #00bfff;
}

.instructions {
    display: none; /* Hidden */
}

#lastNoteDisplay {
    display: none; /* Hidden */
}

#deleteMode {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background-color: #444;
    border: 2px solid #ff4136;
    border-radius: 5px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s;
}

#deleteMode:checked {
    background-color: #ff4136;
}

#deleteMode:checked::after {
    content: '🗑';
    font-size: 16px;
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#freezeButton.active {
    background-color: #f0ad4e;
    box-shadow: 0 0 10px #f0ad4e;
    border-color: #eea236;
}

/* Style for color input */
input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 40px; /* Make it a square */
    height: 25px;
    border: 2px solid #00bfff;
    border-radius: 5px;
    background-color: #444; /* Default background */
    cursor: pointer;
    padding: 0;
    overflow: hidden; /* Hide the default color picker border */
    transition: border-color 0.3s;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
}

input[type="color"]::-moz-color-swatch-wrapper {
    border: none;
    padding: 0;
}

input[type="color"]::-moz-color-swatch {
    border: none;
}

input[type="text"]#noteBox {
    width: 120px; /* Reduced width of notebox */
    background-color: #333;
    border: 1px solid #00bfff;
    color: #fff;
    padding: 5px;
    border-radius: 5px;
}

/* Start Screen Styles */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease-out;
}

.start-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-content {
    text-align: center;
    color: #fff;
}

.app-title {
    display: block !important; /* Override the hidden h1 */
    font-size: 3em;
    font-weight: 300;
    margin-bottom: 2rem;
    background: linear-gradient(45deg, #00bfff, #ff6b6b, #4ecdc4, #45b7d1);
    background-size: 400% 400%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 4s ease-in-out infinite;
}

.app-subtitle {
    font-size: 1.2em;
    color: #ccc;
    margin-top: -1.5rem; /* Pull it closer to the title */
    margin-bottom: 2rem;
    font-weight: 200;
}

.start-button {
    background: transparent;
    border: 3px solid #00bfff;
    color: #00bfff;
    font-size: 1.5em;
    font-weight: 300;
    padding: 1rem 3rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(0, 191, 255, 0.3);
}

.start-button:hover {
    background: #00bfff;
    color: #000;
    box-shadow: 0 0 30px rgba(0, 191, 255, 0.6);
    transform: scale(1.05);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(0, 191, 255, 0.3);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 40px rgba(0, 191, 255, 0.6);
    }
}

@keyframes gradientShift {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

@keyframes pulse-rec {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.7);
        transform: translateX(-50%) scale(1);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 0, 0, 0);
        transform: translateX(-50%) scale(1.05);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 0, 0, 0);
        transform: translateX(-50%) scale(1);
    }
}

@media (max-width: 768px) {
    .modal-content {
        padding: 20px;
    }
    #controls {
        gap: 12px 15px; /* Reduce gap on smaller screens */
    }
}

@media (max-width: 480px) {
    .modal-content {
        margin: 2vh auto; /* Further reduce margin for small screens */
        padding: 15px;
    }
    #controls {
        gap: 10px 10px; /* Further reduce gap */
        padding: 10px;
    }
    label {
        font-size: 0.8em;
    }
    input[type="range"] {
        width: 100px; /* Even smaller range slider */
    }
    select, button {
        padding: 6px 10px;
        font-size: 0.9em;
    }
}