/* style.css */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    /* Dynamic properties (bg-color, color, font-family) set in index.php's <style> block */
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    height: 100vh; /* Try to contain within viewport height */
    overflow: hidden; /* Prevent body scrolling */
    padding: 10px; /* Small border around the entire page */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    width: 100%;
    max-width: 450px; /* Max width for a phone-like interface */
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around; /* Distribute space nicely */
    padding: 15px;
    overflow: hidden; /* Prevent internal overflow from scrolling body */
    background-color: rgba(0,0,0,0.1); /* Subtle inner container bg */
    border-radius: var(--border-radius-general);
}

.page-title {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
    font-weight: normal;
    margin-bottom: 15px;
    text-align: center;
    flex-shrink: 0;
}

.mode-switcher {
    display: flex;
    width: 100%;
    margin-bottom: 20px;
    border-radius: var(--border-radius-buttons);
    overflow: hidden; /* To make child buttons fit the radius */
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.mode-switcher button {
    flex-grow: 1;
    padding: 12px 5px;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
    font-weight: bold;
    border: none; /* Border is on the parent container */
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
    /* background-color and color set by PHP based on .active class */
}
.mode-switcher button:not(.active):hover {
    background-color: #3E5064; /* Slightly lighter than secondary for hover */
}
.mode-switcher button:first-child {
    border-top-left-radius: var(--border-radius-buttons);
    border-bottom-left-radius: var(--border-radius-buttons);
}
.mode-switcher button:last-child {
    border-top-right-radius: var(--border-radius-buttons);
    border-bottom-right-radius: var(--border-radius-buttons);
}


.timer-display-area {
    width: 100%;
    padding: clamp(15px, 5vw, 30px);
    margin-bottom: 20px;
    text-align: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    flex-shrink: 0;
    /* bg-color, color, font-family, border-radius set by PHP */
}

#time-display {
    font-size: clamp(2.5rem, 12vw, 4.5rem); /* Very large display text */
    font-weight: bold;
    letter-spacing: 2px; /* Common for digital displays */
    text-shadow: 0 0 5px rgba(255,255,255,0.2), 0 0 10px rgba(255,255,255,0.1);
}

.countdown-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
    padding: 10px;
    background-color: rgba(0,0,0,0.15);
    border-radius: var(--border-radius-general);
    flex-shrink: 0;
}

.countdown-inputs {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
}

.countdown-inputs input {
    width: clamp(50px, 18vw, 70px);
    height: clamp(40px, 12vw, 55px);
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    text-align: center;
    border: 1px solid #444;
    margin: 0 5px;
    /* bg-color, color, border-radius set by PHP */
    -moz-appearance: textfield; /* Remove spinners for Firefox */
}
.countdown-inputs input::-webkit-outer-spin-button,
.countdown-inputs input::-webkit-inner-spin-button {
    -webkit-appearance: none; /* Remove spinners for Chrome/Safari/Edge */
    margin: 0;
}
.countdown-inputs span { /* Colon separator */
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    font-weight: bold;
    color: var(--primary-text-color, #E0E0E0);
}

#set-countdown-btn {
    padding: 10px 20px;
    font-size: clamp(0.9rem, 3vw, 1rem);
}


.controls-area {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Default to 2x2 or similar */
    gap: 10px;
    width: 100%;
    margin-bottom: 15px;
    flex-shrink: 0;
}
/* Adjust grid for 3 buttons (Start/Stop, Lap, Reset) */
.controls-area.show-lap {
    grid-template-columns: repeat(2, 1fr); /* Keep as 2 for better button size */
}
.controls-area.show-lap #start-btn,
.controls-area.show-lap #stop-btn {
    grid-column: 1 / -1; /* Make Start/Stop span full width when Lap is visible */
}


.control-button {
    padding: clamp(15px, 4vw, 20px);
    font-size: clamp(1rem, 4.5vw, 1.3rem);
    font-weight: bold;
    border: 1px solid #000000; /* Thin black outline */
    cursor: pointer;
    border-radius: var(--border-radius-buttons);
    transition: background-color 0.2s ease, transform 0.15s ease-out, box-shadow 0.2s ease;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.4);
    /* background-color and color set by PHP based on .primary/.secondary */
}
.control-button:hover {
    filter: brightness(1.15); /* General hover effect */
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.control-button:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
    filter: brightness(0.95);
}
.control-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #555 !important; /* Ensure disabled state is clear */
    color: #aaa !important;
}

.lap-times-area {
    width: 100%;
    text-align: center;
    margin-top: auto; /* Push to bottom if space allows */
    flex-grow: 1; /* Allow it to take remaining space */
    display: flex; /* Use flex to manage inner scroll */
    flex-direction: column;
    min-height: 0; /* Important for flex child with overflow */
    flex-shrink: 1; /* Allow shrinking if needed */
}
.lap-times-area h2 {
    font-size: clamp(1.1rem, 4vw, 1.4rem);
    margin-bottom: 8px;
    color: var(--primary-text-color, #E0E0E0);
    flex-shrink: 0;
}

.lap-times-list {
    list-style: none;
    padding: 10px;
    overflow-y: auto; /* Scroll for laps */
    flex-grow: 1; /* Take available space within its flex parent */
    min-height: 50px; /* Ensure it has some height to show scrollbar if needed */
    /* bg-color, color, border-radius set by PHP */
}

.lap-times-list li {
    padding: 5px 0;
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
    border-bottom: 1px solid #333A4D; /* Subtle separator */
}
.lap-times-list li:last-child {
    border-bottom: none;
}
.lap-times-list li .lap-number {
    font-weight: bold;
    margin-right: 10px;
    color: var(--button-generic-bg, #5DADE2); /* Use an accent color */
}


/* Debug Indicator */
#debug-indicator {
    position: fixed;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    background-color: red;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 9px;
    z-index: 10001;
}

/* Blinking animation for countdown finished */
.timer-display-area.countdown-finished {
    animation: blinkBackground 0.7s infinite alternate;
}
@keyframes blinkBackground {
    from { box-shadow: inset 0 0 10px rgba(0,0,0,0.5), 0 0 10px var(--button-plus-bg, #2ECC71); }
    to { box-shadow: inset 0 0 10px rgba(0,0,0,0.5), 0 0 30px var(--button-plus-bg, #2ECC71); }
}


/* Responsive adjustments for very small heights if needed */
@media (max-height: 600px) {
    .app-container {
        justify-content: flex-start; /* Stack from top on short screens */
        padding: 10px;
    }
    .page-title {
        margin-bottom: 10px;
        font-size: clamp(1.5rem, 5vw, 2rem);
    }
    .timer-display-area {
        margin-bottom: 10px;
        padding: clamp(10px, 3vw, 20px);
    }
    #time-display {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }
    .controls-area { margin-bottom: 10px; }
    .mode-switcher { margin-bottom: 10px; }
    .lap-times-area h2 { font-size: 1rem; margin-bottom: 5px; }
}

/* style.css */