/* General Resets and Font Setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Aptos', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121212; /* Very dark grey - almost black */
    color: #e0e0e0; /* Light grey text for body */
    user-select: none;
}

/* Main Application Container */
#app-container {
    width: calc(100% - 10px);
    height: calc(100% - 10px);
    max-width: 500px;
    margin: 5px auto;
    display: flex;
    flex-direction: column;
    border: 2px solid #333; /* Darker border */
    border-radius: 20px;
    background-color: #1e1e1e; /* Dark background for container */
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    overflow: hidden;
    padding: 5px; /* Padding to ensure children don't touch edge visually */
}

/* Player Clock Areas */
.player-clock {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border-radius: 15px;
    transition: background-color 0.3s ease, opacity 0.3s ease, transform 0.1s ease-out;
    color: white;
    position: relative;
    border: 2px solid transparent; /* For smooth animation transitions of border/shadow */
}

#player1-clock {
    background-color: #005f99; /* Darker, richer blue */
    margin-bottom: 5px; /* Space between this and controls */
}
#player1-clock.active-turn {
    background-color: #004c7a; /* Even darker blue for active */
    animation: pulse-glow-blue 1.3s infinite ease-in-out;
}
#player1-clock.inactive-turn {
    background-color: #0072b3; /* Slightly lighter blue for inactive */
    opacity: 0.65;
}

#player2-clock {
    background-color: #b32d2d; /* Darker, richer red */
    margin-top: 5px; /* Space between this and controls */
}
#player2-clock.active-turn {
    background-color: #8c2424; /* Even darker red for active */
    animation: pulse-glow-red 1.3s infinite ease-in-out;
}
#player2-clock.inactive-turn {
    background-color: #cc3737; /* Slightly lighter red for inactive */
    opacity: 0.65;
}

/* Glowing-Vibrating Border Animations */
@keyframes pulse-glow-blue {
    0% { box-shadow: 0 0 8px rgba(0, 150, 255, 0.6), 0 0 4px rgba(100, 200, 255, 0.5); transform: scale(1); }
    50% { box-shadow: 0 0 18px rgba(0, 150, 255, 0.9), 0 0 8px rgba(100, 200, 255, 0.8); transform: scale(1.005); }
    100% { box-shadow: 0 0 8px rgba(0, 150, 255, 0.6), 0 0 4px rgba(100, 200, 255, 0.5); transform: scale(1); }
}

@keyframes pulse-glow-red {
    0% { box-shadow: 0 0 8px rgba(255, 80, 80, 0.6), 0 0 4px rgba(255, 150, 150, 0.5); transform: scale(1); }
    50% { box-shadow: 0 0 18px rgba(255, 80, 80, 0.9), 0 0 8px rgba(255, 150, 150, 0.8); transform: scale(1.005); }
    100% { box-shadow: 0 0 8px rgba(255, 80, 80, 0.6), 0 0 4px rgba(255, 150, 150, 0.5); transform: scale(1); }
}

.player-clock.game-over-loser {
    background-color: #404040 !important; /* Dim grey for loser */
    opacity: 0.5 !important;
    animation: none !important; /* Stop glowing animation */
    box-shadow: none !important;
}
.player-clock.game-over-loser .time-display {
    color: #ff4d4d !important; /* Bright Red for 00:00 on dark */
}

/* Time Display */
.time-display {
    font-family: 'Aptos', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: bold;
    font-size: clamp(4em, 18vw, 7em);
    text-shadow: 2px 2px 5px rgba(0,0,0,0.7); /* Stronger shadow for light text on dark/colored bg */
    transition: color 0.3s ease;
}

/* Time orientation flipped */
#player1-clock .time-display {
    transform: rotate(180deg);
}
#player2-clock .time-display {
    transform: rotate(0deg); /* Explicitly set to normal */
}

.time-display.low-time {
    color: #ffcc00; /* Bright Yellow for warning */
    animation: pulse-warning-dark-theme 1.2s infinite ease-in-out;
}

@keyframes pulse-warning-dark-theme {
    0% { transform: scale(1) rotate(0); opacity: 1; } /* Keep existing rotate for P1 */
    50% { transform: scale(1.03) rotate(0); opacity: 0.85; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
/* Specific adjustments for rotated element */
#player1-clock .time-display.low-time {
    animation: pulse-warning-dark-theme-rotated 1.2s infinite ease-in-out;
}
@keyframes pulse-warning-dark-theme-rotated {
    0% { transform: scale(1) rotate(180deg); opacity: 1; }
    50% { transform: scale(1.03) rotate(180deg); opacity: 0.85; }
    100% { transform: scale(1) rotate(180deg); opacity: 1; }
}


/* Controls Area */
#controls-container {
    display: flex;
    flex-direction: column; /* Stack title and buttons */
    justify-content: center;
    align-items: center;
    padding: 10px 8px; /* Less padding if title takes space */
    background-color: #2a2a2a; /* Slightly different dark shade */
    border-top: 1px solid #383838;
    border-bottom: 1px solid #383838;
    flex-shrink: 0;
    border-radius: 10px; /* Rounded corners for the controls panel itself */
}

#controls-container h1 {
    font-family: 'Gabriela', serif;
    font-size: clamp(1.8em, 6vw, 2.4em);
    color: #f0f0f0; /* Light cream white */
    text-shadow: 0 0 6px rgba(0, 200, 200, 0.6), 1px 1px 2px rgba(0,0,0,0.4);
    margin-bottom: 12px;
    text-align: center;
}

#control-buttons-wrapper {
    display: flex;
    justify-content: space-around;
    width: 100%;
}

#controls-container button {
    padding: 10px clamp(8px, 2.5vw, 12px);
    font-family: 'Aptos', 'Segoe UI', sans-serif;
    font-size: clamp(0.75em, 2.2vw, 0.9em);
    border: 1px solid black;
    border-radius: 8px;
    cursor: pointer;
    background-color: #4a5459; /* Medium dark grey-blue */
    color: #e0e0e0; /* Light text */
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.1s ease;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
    font-weight: bold;
    flex-grow: 1; /* Make buttons take available space */
    margin: 0 3px; /* Small gap between buttons */
}
#controls-container button:first-child { margin-left: 0;}
#controls-container button:last-child { margin-right: 0;}


#controls-container button:hover {
    background-color: #5a6469; /* Lighter on hover */
}

#controls-container button:active {
    transform: translateY(3px); /* Slightly less push */
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

#pause-btn.paused-state {
    background-color: #2a7e3f; /* Darker Green */
}
#pause-btn.paused-state:hover {
    background-color: #389450; /* Lighter Dark Green on hover */
}

/* Modal Styles - Dark Theme */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.75); /* Darker overlay */
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #2c2c3a; /* Dark background for modal */
    padding: 25px;
    border: 1px solid #444;
    width: 85%;
    max-width: 320px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 6px 25px rgba(0,0,0,0.5);
    color: #d0d0d0; /* Light text */
}

.modal-content h2 {
    font-family: 'Gabriela', serif;
    margin-bottom: 10px;
    color: #e5e5e5; /* Brighter text for modal title */
    font-size: 1.8em;
}
.modal-content p {
    font-size: 0.9em;
    color: #b0b0b0; /* Softer light text */
    margin-bottom: 20px;
}

.modal-content label {
    display: block;
    margin-top: 12px;
    font-family: 'Aptos', 'Segoe UI', sans-serif;
    color: #c0c0c0;
    font-weight: bold;
    font-size: 1em;
}

.modal-content input[type="number"] {
    width: 80px;
    padding: 10px;
    margin-top: 5px;
    margin-bottom: 15px;
    border: 1px solid #555;
    background-color: #1e1e2f; /* Darker input background */
    color: #e0e0e0; /* Light text in input */
    border-radius: 8px;
    text-align: center;
    font-family: 'Aptos', 'Segoe UI', sans-serif;
    font-size: 1.2em;
    -moz-appearance: textfield;
}
.modal-content input[type="number"]::-webkit-outer-spin-button,
.modal-content input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.modal-buttons {
    margin-top: 25px;
    display: flex;
    justify-content: space-around;
}

.modal-buttons button {
    padding: 12px 20px;
    font-family: 'Aptos', 'Segoe UI', sans-serif;
    font-size: 1em;
    border: 1px solid black;
    border-radius: 8px;
    cursor: pointer;
    color: #e0e0e0;
    transition: background-color 0.2s ease, transform 0.1s ease;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.3);
    font-weight: bold;
}
.modal-buttons button:active {
    transform: translateY(3px);
}

#modal-save-btn {
    background-color: #389450; /* Green */
}
#modal-save-btn:hover {
    background-color: #42a85c; /* Lighter Green */
}

#modal-cancel-btn {
    background-color: #5a6469; /* Grey */
}
#modal-cancel-btn:hover {
    background-color: #6b767c; /* Lighter Grey */
}