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

:root {
    --primary-color: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary-color: #a78bfa;
    --accent-color: #06b6d4;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #fbbf24;
    --bg-color: #0a0118;
    --surface-color: #1a0b2e;
    --surface-light: #2d1b4e;
    --text-color: #e9d5ff;
    --text-muted: #a78bfa;
    --border-color: #4c1d95;
    --shadow: 0 10px 40px rgba(139, 92, 246, 0.3);
    --glow: 0 0 20px rgba(139, 92, 246, 0.5);
}

html {
    height: 100%;
    background: var(--bg-color);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, var(--bg-color) 0%, #1a0b2e 50%, #0a0118 100%);
    background-attachment: fixed;
    background-color: var(--bg-color); /* 기본 배경색 추가 */
    color: var(--text-color);
    min-height: 100vh;
    min-height: 100dvh; /* 모바일 동적 뷰포트 */
    line-height: 1.6;
    position: relative;
    direction: ltr; /* 전역 텍스트 방향 설정 */
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(167, 139, 250, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body > * {
    position: relative;
    z-index: 1;
}

/* Main Page Styles */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
}

.hero-section {
    text-align: center;
    margin-bottom: 60px;
    animation: fadeInUp 0.6s ease-out;
}

.lock-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: pulse 2s infinite, glow 3s infinite alternate;
    filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.6));
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes glow {
    0% { filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.6)); }
    100% { filter: drop-shadow(0 0 30px rgba(167, 139, 250, 0.8)); }
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(139, 92, 246, 0.5);
    animation: gradientShift 5s ease infinite;
    background-size: 200% auto;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% center; }
    50% { background-position: 100% center; }
}

.tagline {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

.action-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 60px;
    animation: fadeInUp 0.6s ease-out 0.2s both;
}

.card {
    background: var(--surface-color);
    border-radius: 16px;
    padding: 30px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--glow);
    transform: translateY(-2px);
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

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

input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #ffffff;
    font-size: 1rem;
    margin-bottom: 15px;
    transition: all 0.3s;
    font-family: inherit;
    font-weight: 400;
}

input[type="text"]::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(45, 27, 78, 0.8);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
    color: #ffffff;
}

.btn {
    width: 100%;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.input-row .btn {
    width: auto;
    min-width: 70px;
    padding: 12px 16px;
    font-size: 0.95rem;
    flex-shrink: 0;
    height: 48px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #7c3aed;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(139, 92, 246, 0.4);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.divider {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.divider span {
    background: var(--surface-color);
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
    animation: fadeInUp 0.6s ease-out 0.4s both;
}

.feature {
    background: var(--surface-color);
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: transform 0.3s;
}

.feature:hover {
    transform: translateY(-5px);
}


.feature h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.feature p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.info-section {
    text-align: center;
    animation: fadeInUp 0.6s ease-out 0.6s both;
}

.warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--warning-color);
    padding: 15px;
    border-radius: 8px;
    color: var(--warning-color);
    font-size: 0.9rem;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Room Styles */
.room-page {
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh; /* 모바일 동적 뷰포트 높이 */
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 모바일 동적 뷰포트 높이 */
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-color); /* 배경색을 bg-color로 변경하여 흰색 제거 */
    position: relative;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.room-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.room-info h2 {
    font-size: 1.3rem;
}

.status {
    font-size: 0.85rem;
    padding: 4px 12px;
    border-radius: 12px;
    background: var(--surface-light);
}

.status.connected {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.status.connecting {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning-color);
}

.user-count {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
}

.input-row .btn-icon {
    width: 44px;
    height: 48px;
    min-width: 44px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    padding-bottom: 180px; /* 하단 입력창 높이 + 여유 공간 확보 */
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* 모바일 스크롤 최적화 */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    /* 배경색 확실히 채우기 */
    background: var(--bg-color);
}

.welcome-message {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.welcome-message .lock-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.welcome-message .small {
    font-size: 0.85rem;
    margin-top: 8px;
}

.btn-generate-qr {
    margin-top: 30px;
    padding: 16px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.btn-generate-qr:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.btn-generate-qr:active {
    transform: translateY(-1px);
}

.message {
    display: flex;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
    transition: all 0.5s ease;
    direction: ltr; /* 명시적으로 왼쪽에서 오른쪽으로 텍스트 방향 설정 */
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.mine {
    justify-content: flex-end; /* row-reverse 대신 flex-end 사용 */
}

.message-content {
    max-width: 70%;
    background: rgba(45, 27, 78, 0.8);
    padding: 14px 18px;
    border-radius: 16px;
    word-wrap: break-word;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    direction: ltr;
    text-align: left;
}

.message-content:has(.message-image) {
    max-width: 80%;
    padding: 8px;
}

.message.mine .message-content {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.message.mine .message-text {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.message.theirs .message-text {
    color: #e9d5ff;
}

.message-text {
    margin-bottom: 5px;
    direction: ltr;
    text-align: left;
    unicode-bidi: embed;
    font-size: 1rem;
    line-height: 1.5;
    color: #ffffff;
    font-weight: 400;
    word-break: break-word;
}

.message-image {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    object-fit: contain;
    display: block;
    background: rgba(0, 0, 0, 0.2);
}

.message-image:hover {
    opacity: 0.9;
    transform: scale(1.02);
    transition: all 0.2s;
}

.message-video {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
    border-radius: 12px;
    margin-bottom: 8px;
    display: block;
    background: rgba(0, 0, 0, 0.3);
}

.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.message.mine .message-meta {
    color: rgba(255, 255, 255, 0.85);
}

.message.theirs .message-meta {
    color: rgba(167, 139, 250, 0.7);
}

.delete-timer {
    color: var(--warning-color);
    font-weight: 600;
    animation: timerPulse 1s ease-in-out infinite;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(251, 191, 36, 0.15);
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.95); }
}

.system-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 8px;
    background: rgba(148, 163, 184, 0.1);
    border-radius: 8px;
    margin: 10px auto;
    max-width: 300px;
}

.input-container {
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom)); /* 아이폰 하단 안전 영역 대응 */
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    /* 모바일에서 고정 위치 */
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.timer-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.timer-selector label {
    color: var(--text-muted);
}

.timer-selector select {
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-row input[type="text"] {
    flex: 1;
    flex-grow: 1;
    flex-shrink: 1;
    margin-bottom: 0;
    font-size: 1.1rem;
    color: #ffffff !important;
    background: rgba(26, 11, 46, 0.95);
    padding: 14px 18px;
    line-height: 1.5;
    font-weight: 500;
    border: 2px solid var(--border-color);
    height: 48px;
    min-width: 0;
    /* 모바일 브라우저 기본 동작 제거 */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* 브라우저 자동완성 제안 숨기기 */
    -webkit-autofill: none;
    /* iOS Safari 자동완성 제거 */
    -webkit-text-size-adjust: 100%;
    /* 모바일에서 키보드 올라오도록 보장 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.input-row input[type="text"]::placeholder {
    color: rgba(167, 139, 250, 0.4);
    opacity: 1;
    font-weight: 300;
}

.input-row input[type="text"]:focus {
    background: rgba(26, 11, 46, 1);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3), 0 0 20px rgba(139, 92, 246, 0.2);
    color: #ffffff !important;
    outline: none;
}

.input-row input[type="text"]:not(:placeholder-shown) {
    font-weight: 500;
    color: #ffffff !important;
    background: rgba(26, 11, 46, 1);
}

/* Modal */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--surface-color);
    padding: 30px;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.close-modal {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover {
    color: var(--text-color);
}

#qrcode {
    margin: 20px 0;
    display: flex;
    justify-content: center;
}

.room-url {
    background: var(--surface-light);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 15px;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    animation: fadeInUp 0.5s ease-out;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 15px;
}

.countdown {
    font-size: 1.2rem;
    color: var(--warning-color);
    margin: 20px 0;
}

/* Responsive */
@media (max-width: 768px) {
    .action-section {
        grid-template-columns: 1fr;
    }
    
    .divider {
        transform: rotate(90deg);
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .message-content:has(.message-image) {
        max-width: 90%;
    }
    
    .message-image {
        max-height: 300px;
    }
    
    /* 아이폰 하단 입력창 대응 */
    .room-page {
        height: 100dvh;
        height: -webkit-fill-available; /* Safari 대응 */
    }
    
    .chat-container {
        height: 100dvh;
        height: -webkit-fill-available; /* Safari 대응 */
    }
    
    .messages-container {
        padding-bottom: 200px; /* 모바일에서 더 많은 여유 공간 (입력창 + 키보드 대응) */
    }
    
    .input-container {
        padding-bottom: max(20px, env(safe-area-inset-bottom) + 10px);
        position: sticky;
        bottom: 0;
        z-index: 100;
    }
    
    /* 모바일에서 입력창 주변 브라우저 UI 숨기기 */
    .input-row input[type="text"] {
        /* iOS Safari 자동완성 제안 숨기기 */
        -webkit-appearance: none;
        appearance: none;
        /* 모바일 브라우저 기본 스타일 제거 */
        border-radius: 8px;
    }
    
    /* 모바일 브라우저의 자동완성 드롭다운 숨기기 */
    .input-row input[type="text"]::-webkit-contacts-auto-fill-button,
    .input-row input[type="text"]::-webkit-credentials-auto-fill-button {
        visibility: hidden;
        display: none !important;
        pointer-events: none;
        position: absolute;
        right: 0;
    }
    
    /* 모바일에서 입력창 포커스 시 나타나는 브라우저 UI 숨기기 */
    .input-row input[type="text"]:focus {
        /* iOS Safari 자동완성 제안 숨기기 */
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* 모바일에서 하단 여백 제거 */
    .room-page {
        background: var(--bg-color);
    }
    
    body.room-page {
        background: var(--bg-color);
        overflow: hidden;
    }
}

/* Scrollbar */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--surface-color);
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

