:root {
    /* Light Mode Variables */
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-color: #333;
    --header-color: #1c1e21;
    --status-bg: #e7f3ff;
    --status-text: #1877f2;
    --border-color: #dddfe2;
    --button-primary: #1877f2;
    --button-hover: #166fe5;
    --panel-bg: #f7f8fa;
    --result-bg: #f7f7f7;
    --speed-good: #4CAF50;
    --speed-alert: #f44336;
}

body.dark-mode {
    /* Dark Mode Overrides */
    --bg-color: #1c1e21;
    --card-bg: #242526;
    --text-color: #e4e6eb;
    --header-color: #f0f2f5;
    --status-bg: #3a3b3c;
    --status-text: #81b4f4;
    --border-color: #3e4042;
    --button-primary: #81b4f4;
    --button-hover: #6a95cc;
    --panel-bg: #3a3b3c;
    --result-bg: #242526;
    --speed-good: #6dd684;
    --speed-alert: #ff6e6e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    transition: background-color 0.5s;
}

.hidden {
    display: none !important;
}

.container {
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 600px;
    width: 100%;
    transition: background-color 0.5s, box-shadow 0.5s;
}

h1 {
    color: var(--header-color);
    margin-bottom: 20px;
}

p {
    color: var(--text-color);
    line-height: 1.5;
}

/* --- Controls & Buttons --- */
.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

#data-source-section, #tracking-section {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

button {
    background-color: var(--button-primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
    flex-grow: 1; /* For controls grid */
}

button:hover:not(:disabled) {
    background-color: var(--button-hover);
}

button:disabled {
    background-color: var(--border-color);
    color: var(--text-color);
    cursor: not-allowed;
}

.stop-button {
    background-color: #e02c2c;
}
.stop-button:hover {
    background-color: #c02424;
}
.exit-button {
    background-color: #555;
}
.exit-button:hover {
    background-color: #333;
}

/* --- Status and Results --- */
#status {
    padding: 15px;
    border-radius: 6px;
    background-color: var(--status-bg);
    color: var(--status-text);
    font-weight: 500;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

#result-list {
    margin-top: 30px;
    text-align: left;
}

.result-header {
    font-size: 1.1em;
    font-weight: bold;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 5px;
    color: var(--header-color);
}

.result-item {
    background-color: var(--result-bg);
    color: var(--text-color);
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-item .road-info {
    font-size: 0.9em;
}

.result-item .speed-value {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--speed-good);
    margin-left: 15px;
}

.no-result {
    color: #888;
    font-style: italic;
    text-align: center;
}


/* --- Dashboard Grid - Responsive Layout --- */

.dashboard-grid {
    display: flex;
    flex-direction: column; /* Default: Stacked (for portrait mobile) */
    gap: 20px;
    margin-bottom: 20px;
}

.dashboard-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: var(--panel-bg);
    padding: 15px;
    border-radius: 10px;
    flex: 1; /* Allows panels to grow in landscape */
}

.panel-header {
    color: var(--header-color);
    margin-bottom: 10px;
}

/* Speed Display Styling */
.speed-display-wrapper {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    border: 4px solid var(--border-color);
    transition: border-color 0.3s;
}

.actual-speed {
    border-color: var(--speed-good); /* Default good color */
}

.actual-speed.alert {
    border-color: var(--speed-alert); /* Alert color */
}

.speed-display-wrapper div {
    line-height: 1;
}

#current-velocity-display, #current-speed-display {
    font-size: 40px;
    color: var(--text-color);
}

.mph-label {
    font-size: 12px;
    color: #888;
    margin-top: 5px;
}


/* --- Media Query for Landscape/Desktop (Side-by-Side) --- */
@media screen and (min-width: 500px) and (orientation: landscape), screen and (min-width: 700px) {
    .dashboard-grid.main-grid {
        flex-direction: row; /* Side-by-side on wider screens */
        justify-content: space-around;
    }
    .dashboard-grid.main-grid .speed-display-wrapper {
        width: 150px;
        height: 150px;
    }
    .dashboard-grid.main-grid #current-velocity-display, 
    .dashboard-grid.main-grid #current-speed-display {
        font-size: 60px;
    }
}

/* --- Fullscreen Mode Styling --- */

#fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--card-bg); /* Use card background for consistency */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.fullscreen-grid {
    flex-direction: column; /* Always stacked in portrait fullscreen */
    width: 90%;
    max-width: 800px;
    gap: 40px;
}

/* Fullscreen Media Query for Landscape */
@media screen and (min-width: 700px) and (orientation: landscape) {
    .fullscreen-grid {
        flex-direction: row; /* Side-by-side in landscape fullscreen */
        width: 90%;
        height: 80vh;
        gap: 5%;
    }
}

/* Adjust size for fullscreen mode */
.fullscreen-grid .speed-display-wrapper {
    width: 250px;
    height: 250px;
    margin: 10px 0;
}
.fullscreen-grid #fs-current-velocity-display, 
.fullscreen-grid #fs-current-speed-display {
    font-size: 100px;
}
.fullscreen-grid .panel-header {
    font-size: 1.5em;
}
.fullscreen-grid .mph-label {
    font-size: 20px;
}

#exitFullscreenBtn {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 10px 20px;
    width: auto;
}