/* iOS-Style Sinterklaas App */

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

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

:root {
    --ios-blue: #007AFF;
    --ios-red: #FF3B30;
    --ios-gray: #8E8E93;
    --ios-light-gray: #F2F2F7;
    --ios-separator: #C6C6C8;
    --background: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --card-background: #F2F2F7;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
    background: #FFFFFF;  /* White background */
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Main View */
.main-view {
    display: flex;
    flex-direction: row;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
}

/* Navigation Bar */
.nav-bar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    background: transparent;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.nav-bar.hidden {
    opacity: 0;
    pointer-events: none;
}

.nav-button {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

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

.nav-button:active {
    transform: scale(0.95);
}

/* Time Remaining Display */
.time-remaining {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(142, 142, 147, 0.3);
    backdrop-filter: blur(10px);
    display: flex;  /* Always flex */
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    transition: background 0.3s ease;
}

.time-remaining.hidden {  /* Use the same .hidden as other nav elements */
    display: none;
}

.time-remaining.warning {
    background: rgba(255, 149, 0, 0.5);
}

/* Phone Container (mobile aspect ratio) */
.phone-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 430px;
    width: 100%;
    height: calc(100vh - 40px);  /* Subtract top + bottom margin */
    height: calc(100dvh - 40px);
    margin: 0 auto;
    background: #000000;
}

/* Video Container */
.video-container {
    flex: 1;
    position: relative;
    background: #000000;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#avatar-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.video-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.video-placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.placeholder-content {
    text-align: center;
    color: var(--ios-gray);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.avatar-image {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.2);
}

.avatar-name {
    font-size: 24px;
    font-weight: 600;
    color: white;
    margin: 0;
    max-width: 300px;
    text-align: center;
    line-height: 1.3;
}  

/* Controls Area - now overlays at bottom */
.controls-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 20px 32px;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    z-index: 10;
}

.connect-button {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: #34C759; /* iOS green */
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(52, 199, 89, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0; /* ✅ ADD THIS - prevents stretching */
    min-width: 60px; /* ✅ ADD THIS - enforces minimum width */
    min-height: 60px; /* ✅ ADD THIS - enforces minimum height */
}

.connect-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(52, 199, 89, 0.5);
}

.connect-button:active:not(:disabled) {
    transform: scale(0.95);
}

.connect-button:disabled {
    background: var(--ios-gray);
    cursor: not-allowed;
    box-shadow: none;
}

.connect-button.connecting {
    background: var(--ios-gray);
    animation: pulse 1.5s ease-in-out infinite;
}

.connect-button.connected {
    background: var(--ios-red); /* Red when connected */
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
}

.connect-button.unavailable {
    background: #8E8E93;
    cursor: pointer;
}

.connect-button.unavailable:active {
    transform: scale(0.95);
}

.phone-icon {
    width: 32px;
    height: 32px;
    color: white;
    flex-shrink: 0;
}

/* Remove button text styling */
#button-text {
    display: none;
}

/* Pulse animation for connecting state */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

/* Mobile: slightly smaller button */
@media (max-width: 767px) {
    .connect-button {
        width: 56px;  /* ✅ Changed from 64px */
        height: 56px; /* ✅ Changed from 64px */
        min-width: 56px;
        min-height: 56px;
    }
    
    .phone-icon {
        width: 28px;
        height: 28px;
    }
}

/* Settings Button */
.settings-button {
    position: absolute;
    bottom: 90px;
    right: 20px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.settings-button:hover {
    background: rgba(0, 0, 0, 0.4);
    color: rgba(255, 255, 255, 1);
    transform: scale(1.05);
}

.settings-button:active {
    transform: scale(0.95);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

/* Modal Content */
.modal-content {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    background: var(--background);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow-x: hidden;
}

.modal-overlay.visible .modal-content {
    transform: translateY(0);
}

/* Modal Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--ios-separator);
}

.modal-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.done-button {
    background: none;
    border: none;
    color: var(--ios-blue);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
}

.done-button:hover {
    opacity: 0.7;
}

/* Modal Body */
.modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    width: 100%;
}

/* Kids Container */
.kids-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
    width: 100%;
}

/* Kid Card */
.kid-card {
    background: var(--card-background);
    border-radius: 12px;
    padding: 16px;
    position: relative;
    width: 100%;
    overflow-x: hidden;
}

.kid-card-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.remove-kid-btn {
    background: none;
    border: none;
    color: var(--ios-red);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-kid-btn:hover {
    opacity: 0.7;
}

.kid-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.form-field input[type="text"],
.form-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--ios-separator);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background: white;
    max-width: 100%;
    box-sizing: border-box;
}

.form-field input[type="text"]:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--ios-blue);
}

.form-field textarea {
    resize: vertical;
    min-height: 80px;
}

/* Gender and Age Row */
.gender-age-row {
    display: flex;
    gap: 16px;
}

.gender-age-row > div {
    flex: 1;
}

/* Gender Picker */
.gender-picker {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    border: 1px solid var(--ios-separator);
}

.gender-option {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: white;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gender-option.selected {
    background: var(--ios-blue);
    color: white;
}

.gender-option:not(:last-child) {
    border-right: 1px solid var(--ios-separator);
}

/* Age Stepper */
.age-stepper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.age-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--ios-blue);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.age-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.age-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.age-btn:disabled {
    background: var(--ios-gray);
    cursor: not-allowed;
}

.age-display {
    font-size: 20px;
    font-weight: 600;
    min-width: 60px;
    text-align: center;
}

/* Add Kid Button */
.add-kid-button {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--ios-blue);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
}

.add-kid-button:hover {
    opacity: 0.7;
}

.add-kid-button.hidden {
    display: none;
}

/* Divider */
.divider {
    height: 1px;
    background: var(--ios-separator);
    margin: 24px 0;
}

/* Section */
.section h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Context Grid */
.context-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.context-option {
    padding: 12px 16px;
    border: 1px solid var(--ios-separator);
    border-radius: 20px;
    background: var(--card-background);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    word-wrap: break-word;
}

.context-option:hover {
    transform: scale(1.02);
}

.context-option.selected {
    background: var(--ios-blue);
    color: white;
    border-color: var(--ios-blue);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

/* Debug Panel (Hidden) */
.debug-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 300px;
    background: rgba(0, 0, 0, 0.95);
    color: #00ff00;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.debug-panel.hidden {
    transform: translateY(100%);
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.debug-header h3 {
    color: white;
    font-size: 14px;
}

.debug-controls {
    display: flex;
    gap: 8px;
}

.debug-btn {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 11px;
    cursor: pointer;
}

.debug-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.debug-log {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.log-entry {
    margin-bottom: 4px;
    padding: 4px;
    border-radius: 2px;
}

.log-entry.system {
    color: #00aaff;
}

.log-entry.error {
    color: #ff4444;
}

.log-entry.warning {
    color: #ffaa00;
}

.log-entry.success {
    color: #00ff00;
}

.timestamp {
    color: #888888;
    margin-right: 8px;
}

.message {
    color: #ffffff;
}

/* Mobile: Overlay nav on top of video */
@media (max-width: 767px) {
    .main-view {
        flex-direction: column;
    }
    
    .nav-bar {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        flex-direction: row;
        justify-content: space-between;
        padding: 12px 16px;
        z-index: 100;
    }
    
    .phone-container {
        max-width: 100%;
        margin: 0 auto;
        height: 100vh;
        height: 100dvh;
    }
}

/* Desktop: Sidebar nav */
@media (min-width: 768px) {
    .main-view {
        justify-content: center;
        align-items: center;
    }
    
    .nav-bar {
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
    }

    /* Wider container on desktop */
    .phone-container {
        max-width: 600px; /* Increased from 430px */
        height: calc(100vh - 80px);
        height: calc(100dvh - 80px);
    }
}

/* Responsive Design */
@media (min-width: 768px) {
    .modal-content {
        border-radius: 20px;
        margin: auto;
        max-height: 80vh;
    }
    
    .controls-area {
        padding: 30px 40px;
    }
    
    .context-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .modal-header h1 {
        font-size: 24px;
    }
    
    .gender-age-row {
        flex-direction: column;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .kid-card {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .context-grid {
        grid-template-columns: 1fr;
    }
    
    .context-option {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .modal-body {
        padding: 12px;
    }
}

/* Mobile viewport optimization */
@media (max-height: 700px) {
    .controls-area {
        padding: 12px 20px;
        gap: 8px;
    }
    
    .connect-button {
        height: 44px;
        font-size: 16px;
    }
}

/* Very small screens */
@media (max-height: 600px) {
    .controls-area {
        padding: 8px 20px;
    }
    
    .connect-button {
        height: 40px;
        font-size: 15px;
    }
}

/* Shared Auth Form Styles */
.auth-error {
    background: #ffebee;
    color: #c62828;
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #c62828;
    font-size: 15px;
}

.auth-form .form-field {
    margin-bottom: 20px;
}

.auth-form .form-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
    font-weight: 500;
    color: var(--dark-color);
}

.auth-form .form-field input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 16px;
    transition: var(--transition);
}

.auth-form .form-field input:focus {
    outline: none;
    border-color: var(--primary-color);
}