:root {
    /* System Colors - Light Mode (Default) */
    --system-bg: #F5F5F7;
    --system-card: rgba(255, 255, 255, 0.7);
    --system-text: #1D1D1F;
    --system-text-muted: #86868B;
    --system-accent: #0071E3;
    --system-border: rgba(0, 0, 0, 0.1);

    /* SF Pro Font Stack */
    --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;

    /* Shadows & Materials */
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.04);
    --glass-blur: blur(20px);
    --radius-main: 22px;

    /* Metallic Gradient */
    --metallic-bg: linear-gradient(135deg, #E3E3E8 0%, #F5F5F7 100%);
}

[data-theme="dark"] {
    --system-bg: #000000;
    --system-card: rgba(28, 28, 30, 0.7);
    --system-text: #F5F5F7;
    --system-text-muted: #86868B;
    --system-accent: #0A84FF;
    --system-border: rgba(255, 255, 255, 0.1);
    --metallic-bg: linear-gradient(135deg, #1C1C1E 0%, #000000 100%);
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-main);
    background: var(--system-bg);
    color: var(--system-text);
    transition: background 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    height: 100dvh;
    display: flex;
    justify-content: center;
}

/* Modal Overlay */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.modal.active {
    display: flex;
}

.modal-content {
    max-width: 340px;
    width: 100%;
    text-align: center;
    animation: modal-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Background Gradients */
.bg-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--metallic-bg);
    z-index: -1;
    overflow: hidden;
}

.bg-mesh::after {
    content: '';
    position: absolute;
    top: -20%;
    right: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, var(--system-accent) 0%, transparent 70%);
    opacity: 0.1;
    filter: blur(80px);
}

.app-container {
    max-width: 600px;
    width: 100%;
    min-height: 100dvh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 0 auto;
}

@media (orientation: landscape) {
    .app-container {
        max-width: 900px;
    }
}

/* Header & Navigation */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding: 10px 0;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.theme-toggle {
    background: var(--system-card);
    border: 1px solid var(--system-border);
    backdrop-filter: var(--glass-blur);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

/* Screen Transitions */
.screen {
    display: none;
    flex-direction: column;
    gap: 32px;
    animation: apple-fade 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.screen.active {
    display: flex;
}

@keyframes apple-fade {
    from {
        opacity: 0;
        transform: scale(0.98) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

h1 {
    font-size: 2.8rem;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -1.2px;
}

p {
    color: var(--system-text-muted);
    font-size: 1.1rem;
    line-height: 1.4;
    font-weight: 400;
}

/* Apple Glassmorphism Cards */
.glass {
    background: var(--system-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--system-border);
    border-radius: var(--radius-main);
    padding: 28px;
    box-shadow: var(--shadow-soft);
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--system-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 20px;
}

/* Buttons */
button {
    font-family: inherit;
    font-weight: 600;
    padding: 18px 24px;
    border-radius: 16px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.05rem;
}

.btn-primary {
    background: var(--system-accent);
    color: #FFFFFF;
}

.btn-primary:active {
    transform: scale(0.96);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--system-card);
    color: var(--system-text);
    border: 1px solid var(--system-border);
}

/* Sensors Visualization (Apple Watch Style) */
.sensor-visualization {
    height: clamp(200px, 40vh, 320px);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

@media (orientation: landscape) {
    .screen {
        display: none;
        grid-template-columns: 1fr 1fr;
        gap: 32px;
        align-items: center;
    }

    .screen.active {
        display: grid;
    }

    h1 {
        grid-column: span 2;
        font-size: 2rem;
    }

    .glass {
        grid-column: span 1;
        height: 100%;
    }

    .btn-primary {
        grid-column: span 1;
    }

    #screen-live {
        grid-template-columns: 1.2fr 1fr;
    }

    .sensor-visualization {
        height: 70vh;
        margin-bottom: 0;
    }

    .live-data-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .guidance-text {
        grid-column: 2;
    }

    .action-bar-wrap {
        grid-column: 2;
    }
}

.compass-ring {
    width: clamp(150px, 30vh, 240px);
    height: clamp(150px, 30vh, 240px);
    border: 1px solid var(--system-border);
    border-radius: 50%;
    background: radial-gradient(circle, transparent 60%, var(--system-card) 100%);
    position: relative;
}

.direction-labels {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.direction-labels span {
    position: absolute;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--system-text-muted);
}

.dir-n {
    top: 15px;
}

.dir-e {
    right: 15px;
}

.dir-s {
    bottom: 15px;
    color: var(--system-accent) !important;
}

.dir-w {
    left: 15px;
}

.sun-target {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: #FFD60A;
    /* iOS Sun Yellow */
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(255, 214, 10, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transform-origin: center;
}

.phone-pointer {
    width: 3px;
    height: clamp(60px, 12vh, 100px);
    background: var(--system-accent);
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: top center;
    /* Anchor to center of ring */
    border-radius: 2px;
    box-shadow: 0 0 15px var(--system-accent);
    z-index: 10;
}

.phone-pointer::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -5px;
    width: 12px;
    height: 12px;
    background: var(--system-accent);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(0, 113, 227, 0.4);
}

.tilt-meter {
    position: absolute;
    right: -10px;
    height: 200px;
    width: 6px;
    background: var(--system-border);
    border-radius: 3px;
    overflow: hidden;
}

.tilt-level {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: var(--system-accent);
    transition: height 0.2s ease-out;
}

/* Guidance Text Styles */
.guidance-text {
    text-align: center;
    font-weight: 500;
    min-height: 24px;
    transition: color 0.3s ease;
}

.guidance-success {
    color: #34C759 !important;
}

.guidance-warning {
    color: #FF9500 !important;
}

.guidance-info {
    color: #8E8E93 !important;
}

/* Direction Arrow */
#direction-arrow {
    position: absolute;
    width: 40px;
    height: 40px;
    top: 50%;
    right: -50px;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    fill: var(--system-accent);
}

@keyframes pulse-arrow {

    0%,
    100% {
        opacity: 0.6;
        transform: translateY(-50%) scale(1);
    }

    50% {
        opacity: 1;
        transform: translateY(-50%) scale(1.2);
    }
}

#direction-arrow.pulse {
    animation: pulse-arrow 0.8s ease-in-out infinite;
}

/* Data Grid */
.live-data-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (orientation: landscape) {
    .live-data-grid {
        grid-template-columns: 1fr;
    }
}

.data-card {
    padding: 20px;
    text-align: center;
}

.data-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    display: block;
}

.data-card .label {
    font-size: 0.8rem;
    color: var(--system-text-muted);
    margin-top: 4px;
}

/* Results */
.main-stat {
    text-align: center;
}

#res-efficiency {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: -3px;
    color: var(--system-text);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--system-border);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-item label {
    font-weight: 500;
}

.stat-item span {
    font-weight: 700;
    color: var(--system-accent);
}

footer {
    margin-top: auto;
    text-align: center;
    padding: 40px 0 20px;
    font-size: 0.85rem;
    color: var(--system-text-muted);
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-date {
    font-size: 0.85rem;
    color: var(--system-text-muted);
}

.history-score {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--system-accent);
}

.history-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.85rem;
    color: var(--system-text-muted);
}

.btn-delete {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-delete:hover {
    opacity: 1;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--system-border);
    color: var(--system-text);
}

#sensor-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    background: var(--system-border);
}

#sensor-status.active {
    background: rgba(48, 209, 88, 0.1);
    color: #30D158;
}
/* Leadmagnet Form Styles */
.blurred {
    filter: blur(4px);
    pointer-events: none;
    user-select: none;
}

.leadmagnet-box {
    margin-top: 20px;
    padding: 24px;
    text-align: center;
}

.leadmagnet-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.leadmagnet-box h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.leadmagnet-box > p {
    font-size: 0.9rem;
    color: var(--system-text-muted);
    margin-bottom: 20px;
}

.form-section {
    margin-bottom: 20px;
    text-align: left;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-group {
    flex: 1;
    margin-bottom: 14px;
}

.form-group.flex-1 { flex: 1; }
.form-group.flex-3 { flex: 3; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--system-text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--system-border);
    background: var(--system-card);
    color: var(--system-text);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--system-accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.form-group input.error {
    border-color: #FF3B30;
}

.consent-section {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    padding: 16px;
    margin-top: 20px;
    text-align: left;
}

.consent-group { margin-bottom: 14px; }
.consent-group:last-child { margin-bottom: 0; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
}

.checkbox-label input[type=checkbox] {
    position: absolute;
    opacity: 0;
}

.checkmark {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border: 2px solid var(--system-border);
    border-radius: 6px;
    background: var(--system-card);
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-label input:checked + .checkmark {
    background: var(--system-accent);
    border-color: var(--system-accent);
}

.checkbox-label input:checked + .checkmark::after {
    content: '\2713';
    color: white;
    font-weight: bold;
}

.checkmark.error { border-color: #FF3B30; }

.consent-text {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--system-text-muted);
}

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

.form-error {
    background: rgba(255, 59, 48, 0.1);
    border: 1px solid #FF3B30;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 16px;
    color: #FF3B30;
    text-align: center;
}

.btn-loading { display: inline-flex; align-items: center; gap: 8px; }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.privacy-note {
    font-size: 0.8rem;
    color: var(--system-text-muted);
    margin-top: 16px;
    text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 480px) {
    .form-row { flex-direction: column; gap: 0; }
}
