/* Track Split Calculator - Mobile-First Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007AFF;
    --success-color: #34C759;
    --danger-color: #FF3B30;
    --warning-color: #FF9500;
    --bg-color: #000000;
    --surface-color: #1C1C1E;
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --border-color: #38383A;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    touch-action: manipulation;
    position: fixed;
    width: 100%;
    height: 100%;
    
    /* Full-screen mobile optimizations */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* Headers */
.app-header, .race-header, .results-header {
    padding: .25rem;
    padding-top: 1rem; /* Reduced padding for iOS status bar - half of previous */
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
}

.app-header h1 .version {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-left: 0.5rem;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.0625rem;
    line-height: 1.2;
}

.app-credit {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.credit-link {
    color: var(--primary-color);
    text-decoration: none;
}

.credit-link:hover {
    text-decoration: underline;
}

.usage-stats {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.usage-count {
    color: var(--text-secondary);
    font-weight: normal;
}

.race-header {
    padding: 0.75rem 1rem 0;
    padding-top: 1.5rem; /* Reduced padding for iOS status bar - half of previous */
    background-color: var(--surface-color);
    border-bottom: none;
    flex-shrink: 0;
}

.race-title-main {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-bottom: 0.5rem;
}

.race-title-main h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
}

.reset-button-small, .undo-button-small {
    position: absolute;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.reset-button-small {
    right: 0;
}

.undo-button-small {
    left: 0;
}

.reset-button-small:active, .undo-button-small:active {
    color: var(--primary-color);
}

.undo-button-small:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.undo-button-small:disabled:active {
    color: var(--text-secondary);
}

.header-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0;
}

.results-header {
    text-align: center;
}

.results-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Configuration Screen */
.config-form {
    padding: 1.5rem;
    padding-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.select-input {
    width: 100%;
    padding: 0.875rem;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.time-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-input {
    flex: 1;
    padding: 0.875rem;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1.25rem;
    text-align: center;
    font-weight: 600;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.time-separator {
    font-size: 1.5rem;
    font-weight: 700;
}

.start-button {
    width: calc(100% - 3rem);
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    margin: 1rem 1.5rem 1.5rem;
    -webkit-tap-highlight-color: transparent;
}

.start-button:active {
    opacity: 0.8;
}

/* Split Preview */
.split-preview {
    padding: 0 1.5rem 1rem;
    display: none;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.split-preview.visible {
    display: flex;
}

.split-preview h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.preview-table-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-color);
    -webkit-overflow-scrolling: touch;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
}

.preview-table thead {
    position: sticky;
    top: 0;
    background-color: var(--surface-color);
    z-index: 10;
}

.preview-table th {
    padding: 0.75rem 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
}

.preview-table td {
    padding: 0.75rem 0.5rem;
    text-align: center;
    font-size: 0.9375rem;
    border-bottom: 1px solid var(--border-color);
}

.preview-table tr:last-child td {
    border-bottom: none;
}

/* Race Screen */
.race-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
}

/* Dashboard - Three Line Layout */
.dashboard {
    padding: 0.75rem 1rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.dashboard-static {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.dashboard-dynamic {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.dashboard-feedback {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.dash-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    flex: 1;
}

.dash-label {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 0.125rem;
    text-align: center;
}

.dash-value-large {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-align: center;
}

.dash-value {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-align: center;
}

/* Status coloring for dashboard values */
.dash-value-large.fast, .dash-value.fast {
    color: var(--success-color);
}

.dash-value-large.slow, .dash-value.slow {
    color: var(--danger-color);
}

.dash-value-large.on-pace, .dash-value.on-pace {
    color: var(--primary-color);
}

/* Last Lap Feedback Line */
.last-lap-feedback {
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    text-align: center;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease;
}

.feedback-text {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.25px;
}

.last-lap-feedback.fast {
    background-color: var(--success-color);
}

.last-lap-feedback.slow {
    background-color: var(--danger-color);
}

.last-lap-feedback.on-pace {
    background-color: var(--primary-color);
}

.last-lap-feedback.fast .feedback-text,
.last-lap-feedback.slow .feedback-text,
.last-lap-feedback.on-pace .feedback-text {
    color: white;
}

/* Lap Table */
.lap-table-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.lap-table {
    width: 100%;
    border-collapse: collapse;
}

.lap-table thead {
    position: sticky;
    top: 0;
    background-color: var(--surface-color);
    z-index: 10;
}

.lap-table th {
    padding: 0.75rem 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
}

.lap-table td {
    padding: 0.875rem 0.5rem;
    text-align: center;
    font-size: 0.9375rem;
    border-bottom: 1px solid var(--border-color);
}

.lap-table tr.current-lap {
    background-color: rgba(0, 122, 255, 0.1);
}

.lap-table tr.completed-lap {
    opacity: 0.7;
}

.lap-table .diff-positive {
    color: var(--danger-color);
    font-weight: 700;
}

.lap-table .diff-negative {
    color: var(--success-color);
    font-weight: 700;
}

.lap-table .diff-zero {
    color: var(--text-secondary);
}

.lap-table tr.fastest-lap {
    background-color: rgba(52, 199, 89, 0.15);
}

.lap-table tr.slowest-lap {
    background-color: rgba(255, 59, 48, 0.15);
}



/* Split Button - 20% of screen height */
.split-button-container {
    flex-shrink: 0;
    height: 20vh;
    min-height: 120px;
    max-height: 200px;
    background-color: var(--surface-color);
    border-top: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.split-button {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color), #0051D5);
    border: none;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
    transition: transform 0.1s;
}

.split-button:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.split-button-text {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    letter-spacing: 2px;
}

.split-button-lap {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 0.25rem;
}

/* Results Screen */
.results-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    -webkit-overflow-scrolling: touch;
}

/* Results Dashboard - Mirrors main screen dashboard layout */
.results-dashboard {
    margin-bottom: 1.5rem;
    background-color: var(--surface-color);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.results-dashboard-primary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.results-dashboard-secondary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.results-dashboard-tertiary {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.results-dashboard .dash-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    flex: 1;
}

.results-dashboard .dash-label {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
    text-align: center;
}

.results-dashboard .dash-value-large {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    text-align: center;
}

/* Color coding for results dashboard values */
.results-dashboard .dash-value-large.positive {
    color: var(--danger-color);
}

.results-dashboard .dash-value-large.negative {
    color: var(--success-color);
}



.results-table-container {
    margin-bottom: 1.5rem;
}

.results-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    padding-bottom: 2rem;
}

.action-button {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.share-button {
    background-color: var(--primary-color);
    color: white;
}

.new-race-button {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.action-button:active {
    opacity: 0.8;
}

/* Responsive Design */
@media (min-width: 768px) {
    .app-container {
        max-width: 480px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
}

/* Loading States */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* Mobile Optimization & Install Guidance */
.install-guidance {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.guidance-content {
    background: var(--surface-color);
    border-radius: 16px;
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    border: 2px solid var(--primary-color);
}

.guidance-content h3 {
    font-size: 1.375rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.guidance-content p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.guidance-content ol {
    text-align: left;
    margin: 1rem 0;
    padding-left: 1.5rem;
    color: var(--text-primary);
}

.guidance-content ol li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.share-icon {
    display: inline-block;
    font-size: 1.25rem;
    vertical-align: middle;
    margin: 0 0.25rem;
}

.guidance-benefit {
    background: rgba(0, 122, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    margin: 1rem 0;
    font-weight: 600;
    color: var(--primary-color) !important;
}

.guidance-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.install-button {
    flex: 2;
    padding: 0.875rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.install-button:active {
    opacity: 0.8;
}

.guidance-dismiss {
    flex: 1;
    padding: 0.875rem;
    background: var(--surface-color);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.guidance-dismiss:active {
    opacity: 0.7;
}

/* Fullscreen optimizations */
body.fullscreen-active {
    /* Additional fullscreen-specific styling */
    background: var(--bg-color);
}

/* Hide install guidance once installed */
@media (display-mode: standalone) {
    .install-guidance {
        display: none !important;
    }
}

/* Standalone web app optimizations */
@media (display-mode: standalone) {
    /* Headers get safe area padding in standalone mode */
    .app-header, .race-header, .results-header {
        padding-top: max(env(safe-area-inset-top), 1rem);
    }
    
    /* Split button gets safe area padding in standalone mode */
    .split-button-container {
        padding-bottom: max(env(safe-area-inset-bottom), 1rem);
    }
}