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

:root {
    --primary: #007AFF;
    --primary-dark: #0056CC;
    --success: #34C759;
    --warning: #FF9500;
    --danger: #FF3B30;
    --background: #F2F2F7;
    --surface: #FFFFFF;
    --text: #1C1C1E;
    --text-secondary: #8E8E93;
    --border: #C6C6C8;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    -webkit-user-select: none;
    user-select: none;
    padding-bottom: env(safe-area-inset-bottom);
}

#app {
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Connection Banner */
.connection-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
}

.connection-banner.connected .status-indicator {
    background: var(--success);
}

.connection-banner.connecting .status-indicator {
    background: var(--warning);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.banner-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 16px;
    background: var(--primary);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.banner-btn:active {
    background: var(--primary-dark);
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 8px;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
}

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 100px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* Form Sections */
.form-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.form-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h3 {
    margin-bottom: 0;
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.form-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.form-row:first-child {
    padding-top: 0;
}

.form-row label {
    font-size: 16px;
}

/* Select */
select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--background);
    min-width: 80px;
}

/* Button Group */
.button-group {
    display: flex;
    gap: 8px;
}

.par-btn, .format-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
}

.par-btn.active, .format-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Stepper */
.stepper {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stepper-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stepper-btn:active {
    background: var(--background);
}

/* Toggle */
.toggle {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    border-radius: 31px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px var(--shadow);
}

.toggle input:checked + .toggle-slider {
    background-color: var(--success);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* Small Button */
.small-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 16px;
    background: var(--primary);
    color: white;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

/* Hazard Row */
.hazard-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
}

.hazard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hazard-inputs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hazard-input {
    flex: 1;
    min-width: 80px;
}

.hazard-input label {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.hazard-input input, .hazard-input select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.remove-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    font-size: 16px;
    cursor: pointer;
}

/* Distance Controls */
.distance-control {
    margin-bottom: 20px;
}

.distance-control label {
    display: block;
    margin-bottom: 8px;
    font-size: 16px;
}

.distance-control input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    -webkit-appearance: none;
}

.distance-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

/* Green Preview */
.green-preview {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

.green-shape {
    width: 120px;
    height: 160px;
    background: linear-gradient(135deg, #228B22 0%, #32CD32 50%, #228B22 100%);
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    position: relative;
    box-shadow: 0 4px 8px var(--shadow);
}

.distance-marker {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
}

.distance-marker.front {
    background: #FF6B6B;
    bottom: 20%;
}

.distance-marker.center {
    background: #FFD93D;
    bottom: 50%;
}

.distance-marker.back {
    background: #6BCB77;
    bottom: 80%;
}

/* Preset Buttons */
.preset-buttons {
    display: flex;
    gap: 8px;
}

.preset-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
}

.preset-btn:active {
    background: var(--background);
}

/* Player Row */
.player-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.player-name-input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
}

.player-scores {
    display: flex;
    gap: 8px;
}

.player-score-input {
    flex: 1;
}

.player-score-input label {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.player-score-input input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    text-align: center;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
}

/* Send Button */
.send-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
}

.send-btn:active {
    background: var(--primary-dark);
}

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

/* Progress Bar */
.progress-container {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 70vh;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 18px;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--background);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* Device List */
.device-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.device-row:active {
    background: var(--background);
}

.device-info {
    display: flex;
    flex-direction: column;
}

.device-name {
    font-weight: 500;
}

.device-rssi {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Scanning Indicator */
.scanning {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Buttons */
.primary-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

.danger-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--danger);
    color: white;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay-content {
    background: var(--surface);
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    min-width: 200px;
}

.overlay-content .spinner {
    margin: 0 auto 16px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--text);
    color: white;
    border-radius: 24px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 400;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

/* Responsive */
@media (max-width: 380px) {
    .tab-btn {
        font-size: 12px;
        padding: 10px 4px;
    }

    .hazard-inputs {
        flex-direction: column;
    }

    .hazard-input {
        min-width: 100%;
    }
}
