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

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

: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;
    font-variant-numeric: tabular-nums;
}

#clock span {
    background-color: transparent;
    display: inline-block;
    transition: opacity 0.3s ease;
    min-width: 1ch;
    text-align: center;
}

/* 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-content {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.controls-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.controls-center {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 16px;
}

.controls-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
}

/* Display dropdown */
.display-dropdown-wrap {
    position: relative;
}

.display-dropdown-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: rgba(10, 10, 10, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 12px 14px;
    min-width: 220px;
    z-index: 200;
    backdrop-filter: blur(12px);
}

.display-dropdown-panel.open {
    display: block;
}

.display-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
}

.display-option + .display-option {
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.display-option label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    min-width: 56px;
    font-family: 'Inter', sans-serif;
}

#controls .display-dropdown-panel select {
    flex: 1;
    padding: 5px 24px 5px 8px;
    font-size: 12px;
    min-width: 0;
}

.control-group,
.button-group {
    flex: 1 1 0px;
    /* Ensure equal width regardless of content */
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-group {
    justify-content: flex-start;
}

.button-group {
    justify-content: flex-end;
}

.theme-selector-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 20px;
    min-width: 150px;
}

/* Controls header — position: fixed guarantees it's never a flex participant */
#controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    transition: opacity 0.5s ease;
    z-index: 10;
    box-sizing: border-box;
}

/* Auto-hide controls after inactivity (JS adds/removes this class) */
#controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
}

/* Hover-reveal zone — only active when controls are hidden, so it doesn't swallow clicks when visible */
#controls::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    pointer-events: none;
}

#controls.controls-hidden::before {
    pointer-events: auto;
}

/* In fullscreen, always use auto-hide (CSS-only fallback) */
html:fullscreen #controls:not(.controls-hidden) {
    opacity: 1;
    pointer-events: auto;
}

/* Ensure theme selector is always visible and styled properly */
.theme-selector-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 20px;
    min-width: 150px;
}

/* Theme selector specific styling */
.theme-selector-container select {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    min-width: 120px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    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;
}

.theme-selector-container select:hover {
    background: rgba(255, 255, 255, 0.15);
}

.theme-selector-container select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

/* Controls styling - override general styles for better visibility */
#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;
}

/* Theme selector override in controls to ensure visibility */
#controls .theme-selector-container select {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    font-weight: 600;
}

#controls .theme-selector-container select:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Mobile menu specific theme selector */
#mobile-style-switcher {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    font-size: 14px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    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 12px center;
}

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

/* ================================================================
   Mobile: persistent bottom toolbar (replaces hamburger + sheet)
   ================================================================ */
@media (max-width: 1024px) {

    /* App sits between top of viewport and bottom toolbar */
    #app-container {
        justify-content: center;
        padding-top: 16px;
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    }

    /* Dock controls bar to the bottom */
    #controls {
        top: auto;
        bottom: 0;
        flex-direction: row;
        align-items: center;
        padding: 0 12px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        min-height: 56px;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        border-bottom: none;
        background: rgba(10, 10, 10, 0.94);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        overflow: visible;
    }

    /* Dim instead of slide when idle */
    #controls.controls-hidden {
        transform: none;
        opacity: 0.22;
        pointer-events: auto;
    }

    /* Hover-reveal strip not applicable on touch */
    #controls::before,
    #controls.controls-hidden::before {
        display: none !important;
    }

    /* Hamburger: gone */
    .menu-toggle {
        display: none !important;
    }

    /* Controls row always visible, compact single line */
    .controls-content {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        width: 100%;
        padding: 0;
        gap: 8px;
        animation: none;
    }

    /* Left: Display dropdown — don't grow */
    .controls-left {
        flex: 0 0 auto;
        gap: 0;
    }

    /* Center: Fullscreen */
    .controls-center {
        padding: 0 8px;
        flex: 0 0 auto;
    }

    /* Right: theme selector fills remaining space */
    .controls-right {
        flex: 1;
        min-width: 0;
    }

    .controls-right .theme-selector-container {
        width: 100%;
    }

    .controls-right select {
        width: 100%;
    }

    /* Compact sizes for the slim toolbar */
    #controls button,
    #controls select {
        padding: 6px 10px;
        font-size: 13px;
        min-height: 0;
        width: auto;
    }

    /* Display dropdown panel opens upward */
    .display-dropdown-panel {
        top: auto;
        bottom: calc(100% + 8px);
        left: 0;
    }

    /* Timer controls stack vertically on mobile */
    #exam-controls,
    #boxing-controls,
    #egg-controls,
    #pomodoro-controls,
    #worldcup-controls {
        flex-direction: column;
        width: calc(100vw - 32px);
        padding: 14px 16px;
        gap: 12px;
    }

    #exam-controls .timer-top-row,
    #egg-controls .timer-top-row,
    #pomodoro-controls .timer-top-row,
    #worldcup-controls .timer-top-row {
        flex-wrap: wrap;
        justify-content: center;
    }

    #exam-controls .timer-bottom-row,
    #egg-controls .timer-bottom-row,
    #pomodoro-controls .timer-bottom-row,
    #worldcup-controls .timer-bottom-row,
    .egg-bottom {
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
    }

    #exam-controls .timer-settings,
    #egg-controls .timer-settings,
    #pomodoro-controls .timer-settings {
        flex-wrap: wrap;
    }

    #exam-controls .timer-actions,
    #egg-controls .timer-actions,
    #pomodoro-controls .timer-actions,
    #worldcup-controls .timer-actions {
        justify-content: center;
    }

    #exam-controls input,
    #exam-controls select,
    #exam-controls button,
    #boxing-controls input,
    #boxing-controls select,
    #boxing-controls button,
    #egg-controls input,
    #egg-controls select,
    #egg-controls button,
    #pomodoro-controls input,
    #pomodoro-controls select,
    #pomodoro-controls button,
    #worldcup-controls input,
    #worldcup-controls select,
    #worldcup-controls button {
        min-height: 44px;
        font-size: 16px;
    }

    /* Boxing: stack status + settings + actions vertically */
    #boxing-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    #boxing-controls .timer-settings {
        flex-wrap: wrap;
    }

    #boxing-controls .timer-actions {
        display: flex;
        justify-content: center;
        gap: 8px;
    }

}

/* Mobile Menu - Bottom Sheet */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    z-index: 999;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 85vh;
    overflow-y: auto;
}

.mobile-menu.active {
    transform: translateY(0);
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    background: var(--bg-color);
}

.mobile-menu-header span {
    font-size: 18px;
    font-weight: 600;
}

.mobile-menu-header button {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
}

.mobile-menu-content {
    padding: 20px;
}

.mobile-menu-content .control-section {
    margin-bottom: 24px;
}

.mobile-menu-content .control-section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 12px;
}

.mobile-menu-content .control-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.mobile-menu-content button {
    flex: 1 1 calc(50% - 4px);
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    font-size: 14px;
    cursor: pointer;
}

.mobile-menu-content button:hover,
.mobile-menu-content button:focus {
    background: var(--control-hover);
}

.mobile-menu-content select {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    font-size: 14px;
}

.mobile-section {
    margin-bottom: 20px;
}

.mobile-section label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 8px;
}

.mobile-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.mobile-display-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.mobile-select-item label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 6px;
}

.mobile-select-item select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text-color);
    border: 1px solid var(--control-border);
    font-size: 13px;
    appearance: none;
    -webkit-appearance: none;
    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 8px center;
}

/* Timer presets */
.timer-presets {
    display: flex;
    gap: 6px;
}

.preset-btn {
    padding: 6px 11px !important;
    border-radius: 6px !important;
    background: var(--control-bg) !important;
    border: 1px solid var(--control-border) !important;
    color: var(--text-color) !important;
    font-size: 12px !important;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.preset-btn:hover {
    background: var(--control-hover) !important;
}

.preset-btn.active {
    background: rgba(255, 255, 255, 0.25) !important;
    border-color: rgba(255, 255, 255, 0.5) !important;
}

/* Timer controls */
.timer-controls {
    background: rgba(20, 20, 20, 0.95);
    padding: 14px 18px;
    border-radius: 14px;
    width: 90vw;
    max-width: 840px;
    box-sizing: border-box;
}

/* Exam timer: two-row layout */
#exam-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#exam-controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

.timer-top-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.timer-top-row .timer-status {
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.65);
    letter-spacing: 0.02em;
}

.timer-bottom-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Boxing timer: single-row layout */
#boxing-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

#boxing-controls .timer-status {
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.65);
    letter-spacing: 0.02em;
}

#boxing-controls .timer-settings {
    display: flex;
    gap: 10px;
    flex: 1;
}

#boxing-controls .timer-actions {
    display: flex;
    gap: 8px;
}

#exam-controls .timer-settings {
    display: flex;
    gap: 10px;
    flex: 1;
}

.timer-settings .control-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.timer-settings label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.timer-settings input,
.timer-settings select {
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.timer-settings select {
    color: #a8c8e8;
}

#exam-controls .timer-actions,
#egg-controls .timer-actions,
#pomodoro-controls .timer-actions,
#worldcup-controls .timer-actions {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
}

/* Pomodoro timer layout */
#pomodoro-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#pomodoro-controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

/* Egg timer layout */
#egg-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#egg-controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

#egg-controls .timer-settings {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
}

.egg-bottom {
    justify-content: center;
}

.timer-actions button {
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

.primary-btn {
    background: #4CAF50;
    color: white;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.danger-btn {
    background: #f44336;
    color: white;
}

.tertiary-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: white;
}

/* Keyboard hint */
.keyboard-hint {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    display: none;
}

/* Control sections */
.control-section {
    margin-bottom: 16px;
    flex-shrink: 1;
    min-width: 0;
}


/* Fullscreen section never shrinks to invisibility */
.control-section-actions {
    flex-shrink: 0;
}

.control-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
}

.control-section-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-section-actions button {
    width: 100%;
    max-width: 200px;
}