:root {
    --primary-bg: #1a1a1a;
    --secondary-bg: #333;
    --accent-color: #4CAF50;
    --error-color: #ff4444;
    --warning-color: #FFA500;
    --text-color: #ffffff;
    --vh: 1vh;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--primary-bg);
    color: var(--text-color);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    /* Remove overflow: hidden to allow scrolling */
    position: relative;
}

.app-container {
    height: 100vh; /* Fallback */
    height: calc(var(--vh, 1vh) * 100);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
}

/* Navigation Styles */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--primary-bg);
}

.nav-buttons {
    display: flex;
    gap: 0.8rem;
    align-items: center;
}

.icon-button {
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-color);
    text-decoration: none;
}

.icon-button:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.05);
}

.share-icon {
    width: 1.2rem;
    height: 1.2rem;
}

/* Share Options */
.share-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 1rem;
    background: var(--secondary-bg);
    border-radius: 0.8rem;
    padding: 0.5rem;
    margin-top: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    min-width: 180px;
}

.share-options.active {
    display: block;
}

.share-option {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    border-radius: 0.4rem;
    transition: background-color 0.2s;
}

.share-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    gap: 1rem;
}

/* Status Section */
.status-container {
    text-align: center;
}

.status {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

.instructions {
    color: var(--warning-color);
    font-size: 1rem;
}

/* Balance Indicator */
.balance-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.balance-indicator {
    width: min(280px, 70vw);
    height: min(280px, 70vw);
    border: 3px solid var(--accent-color);
    border-radius: 50%;
    position: relative;
    background: var(--secondary-bg);
}

.target-zones {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.target-zone {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.target-zone.perfect {
    width: 20%;
    height: 20%;
    background: rgba(76, 175, 80, 0.1);
}

.target-zone.good {
    width: 40%;
    height: 40%;
    background: rgba(76, 175, 80, 0.05);
}

.target-zone.okay {
    width: 60%;
    height: 60%;
    background: rgba(255, 165, 0, 0.05);
}

.cardinal-marks {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.mark {
    position: absolute;
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.3);
}

.mark.north { top: 5%; left: 50%; transform: translateX(-50%); }
.mark.south { bottom: 5%; left: 50%; transform: translateX(-50%); }
.mark.east { right: 5%; top: 50%; transform: translateY(-50%); }
.mark.west { left: 5%; top: 50%; transform: translateY(-50%); }

.balance-dot {
    width: 1rem;
    height: 1rem;
    background: var(--error-color);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.1s ease-out;
}

.balance-dot.centered {
    background: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
}

.timer {
    font-size: 2.5rem;
    font-family: monospace;
    font-weight: bold;
    min-height: 3rem;
}

/* Metrics */
.metrics {
    width: 100%;
    max-width: 400px;
    background: var(--secondary-bg);
    padding: 1rem;
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.metric-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.metric-value {
    font-family: monospace;
    font-weight: bold;
}

.metric-bar {
    height: 0.6rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.3rem;
    overflow: hidden;
}

.metric-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
}

/* Feedback Section */
.feedback-container {
    text-align: center;
    margin-top: auto;
}

.feedback {
    color: var(--accent-color);
    font-size: 1.1rem;
    margin-bottom: 1rem;
    min-height: 1.5rem;
}

.start-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.start-btn:disabled {
    background: #666;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.7;
}

/* Mobile Optimizations */
@media (max-height: 700px) {
    .balance-indicator {
        width: min(200px, 60vw);
        height: min(200px, 60vw);
    }

    .metrics {
        padding: 0.8rem;
    }

    .metric {
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.5rem;
        gap: 0.8rem;
    }

    .status {
        font-size: 1.2rem;
    }

    .instructions {
        font-size: 0.9rem;
    }

    .balance-indicator {
        width: min(240px, 80vw);
        height: min(240px, 80vw);
    }

    .timer {
        font-size: 2rem;
    }

    .metrics {
        padding: 0.8rem;
    }

    .metric-label {
        font-size: 0.8rem;
    }

    .feedback {
        font-size: 1rem;
    }

    .start-btn {
        padding: 0.7rem 1.8rem;
        font-size: 1rem;
    }
}

/* Portrait Mode Lock Warning */
.portrait-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-bg);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

@media (orientation: landscape) {
    .portrait-warning {
        display: flex;
    }
}

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

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .balance-dot {
        transition: none;
    }
    
    .start-btn:hover {
        transform: none;
    }
}

* {
    touch-action: pan-y pinch-zoom;
}

/* High Contrast Mode */
@media (prefers-contrast: more) {
    :root {
        --accent-color: #5CFF60;
        --error-color: #FF6666;
        --warning-color: #FFB84D;
    }
}

