/* Base styles */
html,
body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

:root {
    --clock-scale: clamp(4rem, 12vw, 10rem);
    --date-scale: clamp(1.5rem, 3.5vw, 3.75rem);

    /* Default dark mode colors */
    --bg-color: #0a0a0a;
    --text-color: #ffffff;
    --control-bg: rgba(255, 255, 255, 0.1);
    --control-border: rgba(255, 255, 255, 0.2);
    --control-hover: rgba(255, 255, 255, 0.2);
}

/* Main app container */
#app-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    position: relative;
}

/* Clock display */
#clock {
    font-size: var(--clock-scale);
    font-weight: bold;
    letter-spacing: 0.02em;
    transition: font-family 0.3s, text-shadow 0.3s, color 0.3s;
    background-color: transparent;
    line-height: 1;
    display: inline-block;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
    position: relative;
    z-index: 1;
}

#clock span {
    background-color: transparent;
    display: inline-block;
    transition: opacity 0.3s ease;
}

/* Date display */
#date-display {
    font-size: var(--date-scale);
    font-weight: normal;
    margin-top: 0.5rem;
    letter-spacing: 0.02em;
    transition: font-family 0.3s, text-shadow 0.3s, opacity 0.3s;
    opacity: 0;
    background-color: transparent;
    position: relative;
    z-index: 1;
}

#date-display.visible {
    opacity: 1;
}

/* Controls header */
#controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background-color: transparent;
    transition: opacity 0.3s ease;
    z-index: 10;
}

#controls .control-group,
#controls .button-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Hide controls in fullscreen, show on hover at top */
html:fullscreen #controls {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

html:fullscreen #controls::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    pointer-events: auto;
}

html:fullscreen #controls:hover {
    opacity: 1;
    pointer-events: auto;
}

/* Buttons and select styling */
#controls select,
#controls button {
    padding: 8px 16px;
    border-radius: 6px;
    background-color: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    cursor: pointer;
    outline: none;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

#controls select {
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

#controls select:hover,
#controls button:hover {
    background-color: var(--control-hover);
    border-color: rgba(255, 255, 255, 0.4);
}

#controls select:focus,
#controls button:focus {
    border-color: rgba(255, 255, 255, 0.5);
}

#controls select option {
    background-color: #1a1a1a;
    color: #fff;
}

/* Canvas elements */
#starwars-canvas,
#rain-canvas {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Show canvases for respective themes */
#app-container.theme-starwars-dark #starwars-canvas,
#app-container.theme-starwars-light #starwars-canvas {
    display: block;
}

#app-container.theme-rain-dark #rain-canvas,
#app-container.theme-rain-light #rain-canvas {
    display: block;
}

/* Pacman character */
.pacman-character {
    position: absolute;
    width: var(--pacman-size, 60px);
    height: var(--pacman-size, 60px);
    background: #ffff00;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.pacman-character.pacman-run {
    opacity: 1;
    animation: pacman-chomp 0.25s linear infinite;
}

@keyframes pacman-chomp {
    0% {
        clip-path: polygon(50% 50%, 100% 35%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 65%);
    }

    50% {
        clip-path: polygon(50% 50%, 100% 50%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 50%);
    }

    100% {
        clip-path: polygon(50% 50%, 100% 35%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 65%);
    }
}

/* Eaten digit animation */
#clock span {
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

#clock span.pacman-eaten {
    opacity: 0;
    transform: scale(0.3);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    position: relative;
}

/* Clock display */
#clock {
    font-size: var(--clock-scale);
    font-weight: bold;
    letter-spacing: 0.02em;
    transition: font-family 0.3s, text-shadow 0.3s, color 0.3s;
    background-color: transparent;
    line-height: 1;
    display: inline-block;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
    position: relative;
    z-index: 1;
}

#clock span {
    background-color: transparent;
    display: inline-block;
    transition: opacity 0.3s ease;
}

/* Date display */
#date-display {
    font-size: var(--date-scale);
    font-weight: normal;
    margin-top: 0.5rem;
    letter-spacing: 0.02em;
    transition: font-family 0.3s, text-shadow 0.3s, opacity 0.3s;
    opacity: 0;
    background-color: transparent;
    position: relative;
    z-index: 1;
}

#date-display.visible {
    opacity: 1;
}

/* Controls header */
#controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    background-color: transparent;
    transition: opacity 0.3s ease;
    z-index: 10;
}

#controls .control-group,
#controls .button-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Hide controls in fullscreen, show on hover at top */
html:fullscreen #controls {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

html:fullscreen #controls::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    pointer-events: auto;
}

html:fullscreen #controls:hover {
    opacity: 1;
    pointer-events: auto;
}

/* Buttons and select styling */
#controls select,
#controls button {
    padding: 8px 16px;
    border-radius: 6px;
    background-color: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    cursor: pointer;
    outline: none;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

#controls select {
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

#controls select:hover,
#controls button:hover {
    background-color: var(--control-hover);
    border-color: rgba(255, 255, 255, 0.4);
}

#controls select:focus,
#controls button:focus {
    border-color: rgba(255, 255, 255, 0.5);
}

#controls select option {
    background-color: #1a1a1a;
    color: #fff;
}

/* Canvas elements */
#starwars-canvas,
#rain-canvas {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Show canvases for respective themes */
#app-container.theme-starwars-dark #starwars-canvas,
#app-container.theme-starwars-light #starwars-canvas {
    display: block;
}

#app-container.theme-rain-dark #rain-canvas,
#app-container.theme-rain-light #rain-canvas {
    display: block;
}

/* Pacman character */
.pacman-character {
    position: absolute;
    width: var(--pacman-size, 60px);
    height: var(--pacman-size, 60px);
    background: #ffff00;
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}

.pacman-character.pacman-run {
    opacity: 1;
    animation: pacman-chomp 0.25s linear infinite;
}

@keyframes pacman-chomp {
    0% {
        clip-path: polygon(50% 50%, 100% 35%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 65%);
    }

    50% {
        clip-path: polygon(50% 50%, 100% 50%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 50%);
    }

    100% {
        clip-path: polygon(50% 50%, 100% 35%, 100% 0%, 0% 0%, 0% 100%, 100% 100%, 100% 65%);
    }
}

/* Eaten digit animation */
#clock span {
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

#clock span.pacman-eaten {
    opacity: 0;
    transform: scale(0.3);
}

/* Menu Toggle (Hamburger) */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 30px;
    height: 21px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 20;
}

.menu-toggle .bar {
    width: 100%;
    height: 3px;
    background-color: var(--text-color);
    border-radius: 3px;
    transition: all 0.3s ease;
}

/* Controls Content Wrapper */
.controls-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: 100%;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #app-container {
        justify-content: space-between;
        padding-bottom: 20px;
    }

    #controls {
        position: fixed;
        /* Fixed header on mobile */
        top: 0;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: flex-start;
        /* Align toggle to left */
        padding: 16px;
        gap: 0;
        background-color: rgba(0, 0, 0, 0.8);
        /* Darker background for contrast */
        backdrop-filter: blur(10px);
        width: 100%;
        box-sizing: border-box;
        z-index: 100;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .menu-toggle {
        display: flex;
    }

    /* Hamburger Animation */
    .menu-toggle.active .bar:nth-child(1) {
        transform: translateY(9px) rotate(45deg);
    }

    .menu-toggle.active .bar:nth-child(2) {
        opacity: 0;
    }

    .menu-toggle.active .bar:nth-child(3) {
        transform: translateY(-9px) rotate(-45deg);
    }

    .controls-content {
        display: none;
        flex-direction: column;
        width: 100%;
        padding-top: 20px;
        gap: 16px;
        animation: slideDown 0.3s ease forwards;
    }

    .controls-content.active {
        display: flex;
    }

    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    #controls .control-group,
    #controls .button-group {
        justify-content: center;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        /* 2 columns for better layout */
        gap: 10px;
    }

    #controls select,
    #controls button {
        padding: 12px;
        font-size: 14px;
        width: 100%;
        text-align: center;
        min-height: 44px;
    }

    /* Clock adjustments */
    #clock {
        margin-top: auto;
        margin-bottom: auto;
    }

    /* Exam controls specific mobile styles */
    #exam-controls {
        flex-direction: column;
        width: 90%;
        max-width: 400px;
        gap: 12px;
        background-color: rgba(20, 20, 20, 0.9);
        padding: 20px;
        border-radius: 16px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        position: relative;
        bottom: auto;
        top: auto;
        margin-top: 20px;
        z-index: 50;
    }

    #exam-controls input,
    #exam-controls select,
    #exam-controls button {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }

    /* Adjust clock size for mobile */
    :root {
        --clock-scale: 15vw;
        --date-scale: 5vw;
    }
}