/**
 * SpeedSight Base Styles
 * Reset, normalization, and global base styles
 */

/* Box Sizing Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Document Setup */
html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body {
    font-family: var(--font-ui);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    position: relative;
}

/* iOS Safe Area Support */
body {
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* Disable Pull-to-Refresh on Mobile */
body {
    overscroll-behavior-y: contain;
}

/* Typography Base */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    color: var(--color-text-primary);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

h4 {
    font-size: var(--font-size-lg);
}

h5, h6 {
    font-size: var(--font-size-base);
}

p {
    margin-bottom: var(--space-md);
    color: var(--color-text-secondary);
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-accent-hover);
}

a:active {
    color: var(--color-accent-pressed);
}

/* Lists */
ul, ol {
    list-style: none;
}

/* Images */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Forms */
input, button, textarea, select {
    font: inherit;
    color: inherit;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Focus Styles */
:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Selection */
::selection {
    background-color: var(--color-accent);
    color: var(--color-text-inverse);
}

::-moz-selection {
    background-color: var(--color-accent);
    color: var(--color-text-inverse);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border-secondary);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

/* Firefox Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-secondary) var(--color-bg-secondary);
}

/* App Container */
.app-container {
    position: relative;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
}

/* Screen Base */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    background-color: var(--color-bg-primary);
    transform: translateX(100%);
    opacity: 0;
    transition: transform var(--transition-slow), opacity var(--transition-slow);
    z-index: var(--z-base);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.screen.active {
    position: relative;
    transform: translateX(0);
    opacity: 1;
    z-index: var(--z-base);
}

.screen.modal-screen {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--z-modal);
}

.screen.modal-screen.active {
    position: fixed;
}

/* Screen Header */
.screen-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border-primary);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.screen-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    flex: 1;
}

.back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: transparent;
    color: var(--color-text-primary);
    transition: background-color var(--transition-fast);
}

.back-button:hover {
    background-color: var(--color-bg-tertiary);
}

.back-button:active {
    background-color: var(--color-border-primary);
}

.back-button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Hidden Utility */
.hidden {
    display: none !important;
}

/* Visually Hidden (Accessible) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Loading State */
.loading {
    pointer-events: none;
    opacity: 0.6;
}

/* Disabled State */
.disabled {
    pointer-events: none;
    opacity: 0.4;
}

/* Text Utilities */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.text-uppercase {
    text-transform: uppercase;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-primary {
    color: var(--color-text-primary);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-tertiary {
    color: var(--color-text-tertiary);
}

.text-accent {
    color: var(--color-accent);
}

/* Responsive Utilities */
@media (max-width: 640px) {
    html {
        font-size: 14px;
    }
}

@media (min-width: 1024px) {
    html {
        font-size: 16px;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .screen-header {
        border-bottom-width: 2px;
    }
}

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

/* Print Styles */
@media print {
    .screen-header,
    .back-button,
    button {
        display: none;
    }
}

/* Dark Mode Specific Adjustments */
[data-theme="dark"] body {
    background-color: var(--color-bg-primary);
}

[data-theme="dark"] .screen {
    background-color: var(--color-bg-primary);
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .screen-header {
        padding: var(--space-sm) var(--space-md);
    }
}

/* PWA Display Mode */
@media all and (display-mode: standalone) {
    body {
        padding-top: max(var(--safe-area-top), 20px);
    }
}

/* Security: Disable text selection in sensitive areas */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Accessibility: Skip to Content Link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-accent);
    color: var(--color-text-inverse);
    padding: var(--space-sm) var(--space-md);
    z-index: var(--z-tooltip);
    transition: top var(--transition-base);
}

.skip-to-content:focus {
    top: 0;
}
