/* =========================================
   1. Global Settings & Variables
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700&display=swap');

:root {
    --primary-pink: #FF8BA7;
    --soft-pink-bg: #FFF0F3;
    
    --chat-bg: #fff1f5;
    --chat-me-bubble: #ffc2d1;
    
    --bg-gray: #F4F5F7;
    --text-dark: #333333;
    --text-gray: #777777;
    --log-gray: #E9ECEF;
    --log-yellow: #FFF3CD;
    --log-pink: #F8D7DA;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Noto Sans KR', sans-serif; background-color: var(--bg-gray); color: var(--text-dark); height: 100vh; overflow: hidden; }
button { font-family: inherit; cursor: pointer; border: none; }

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* =========================================
   2. Setup Screen (START 화면)
   ========================================= */
#screen-setup {
    flex-direction: column; align-items: center; justify-content: center; background: var(--soft-pink-bg); padding: 40px;
}
.setup-container {
    background: white; padding: 30px 40px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); width: 100%; max-width: 800px; text-align: center;
}
.logo-title { font-size: 2rem; color: var(--primary-pink); margin-bottom: 30px; }
.logo-title .sub { font-size: 1rem; color: var(--text-gray); font-weight: 400; }

.input-group { display: flex; gap: 8px; margin-bottom: 20px; justify-content: center; align-items: center; flex-wrap: wrap; }
.input-group input, .input-group select { padding: 10px; border: 1px solid #ddd; border-radius: 8px; height: 44px; font-size: 0.9rem; }
.btn-add { background: var(--primary-pink); color: white; padding: 0 20px; border-radius: 8px; font-weight: bold; height: 44px; }

.gender-toggle { display: flex; background: #e9ecef; border-radius: 8px; padding: 4px; height: 44px; align-items: center; }
.gender-toggle input[type="radio"] { display: none; }
.gender-toggle label { cursor: pointer; padding: 6px 12px; border-radius: 6px; font-size: 0.9rem; color: #888; transition: all 0.2s; }
.gender-toggle input[type="radio"]:checked + label { background: white; color: var(--text-dark); box-shadow: 0 1px 3px rgba(0,0,0,0.1); font-weight: bold; }
#g-male:checked + label { color: #4dabf7; }
#g-female:checked + label { color: #ff8787; }

.avatar-selector { display: flex; align-items: center; gap: 5px; }
.current-emoji { width: 44px; height: 44px; background: white; border: 1px solid #ddd; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.refresh-btn { background: var(--bg-gray); width: 32px; height: 32px; border-radius: 50%; color: #666; font-size: 0.8rem; }

.participants-board { display: flex; gap: 20px; margin-bottom: 30px; min-height: 200px; max-height: 250px; }
.group-box { flex: 1; background: var(--bg-gray); border-radius: 12px; padding: 15px; overflow-y: auto; }
.group-box h3 { font-size: 1rem; margin-bottom: 10px; color: var(--text-gray); }

.user-card-mini { display: flex; align-items: center; background: white; padding: 10px; border-radius: 8px; margin-bottom: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.user-card-mini .info { flex: 1; text-align: left; }
.user-card-mini .name { font-weight: bold; font-size: 0.9rem; }
.gender-icon { font-size: 0.8rem; margin-left: 2px; }
.gender-icon.male { color: #4dabf7; }
.gender-icon.female { color: #ff8787; }
.user-card-mini .mbti { font-size: 0.8rem; color: #888; margin-left: 5px; }
.user-card-mini .btn-delete { color: #ff6b6b; font-size: 1.2rem; background: none; }

.btn-start-check {
    width: 100%; padding: 18px;
    background: var(--text-dark); color: white;
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: 800;  
    letter-spacing: 2px;
    transition: transform 0.1s;
}
.btn-start-check:active { transform: scale(0.98); }


/* =========================================
   3. Game Screen (Main)
   ========================================= */
#screen-game { flex-direction: row; }

/* Left Panel */
.panel-left { flex: 3; display: flex; flex-direction: column; background: white; height: 100%; border-right: 1px solid #ddd; min-width: 320px; }
.game-header { flex-shrink: 0; height: 50px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid #eee; background: #fafafa; }
.header-title { font-weight: bold; color: #555; font-size: 0.95rem; }
.scroll-content { flex: 1; overflow-y: auto; padding: 15px; background: #fff; }

.log-date-divider { text-align: center; font-weight: bold; margin: 20px 0; color: var(--primary-pink); font-size: 0.9rem; }
.log-item { display: flex; padding: 12px; border-radius: 8px; margin-bottom: 10px; border-left: 4px solid; background: #f9f9f9; font-size: 0.85rem; line-height: 1.4; }
.log-item.gray { border-color: #adb5bd; background: var(--log-gray); }
.log-item.yellow { border-color: #ffc107; background: var(--log-yellow); }
.log-item .time { width: 45px; font-weight: bold; color: #888; font-size: 0.75rem; flex-shrink: 0; }
.log-item .icon { font-size: 1.1rem; margin-right: 8px; min-width: 20px; }

.game-footer { flex-shrink: 0; background: white; border-top: 1px solid #eee; padding: 15px; display: flex; justify-content: space-between; align-items: center; }
.btn-main-action { background: var(--text-dark); color: white; padding: 8px 16px; border-radius: 6px; font-weight: bold; font-size: 0.9rem; }

/* Right Panel */
.panel-right { flex: 7; background: var(--bg-gray); padding: 20px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
.status-bar { display: flex; justify-content: space-around; background: white; padding: 15px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.widget-box { background: white; padding: 15px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.widget-box h4 { margin-bottom: 10px; font-size: 0.9rem; color: #555; }
.couple-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #f1f1f1; font-size: 0.9rem; }
.heart-score { color: var(--primary-pink); font-weight: bold; }
.participant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; }

.user-card-full { background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 5px rgba(0,0,0,0.05); text-align: center; padding-bottom: 15px; transition: transform 0.2s; }
.user-card-full:hover { transform: translateY(-3px); }
.card-header { background: #f1f3f5; padding: 20px 0; position: relative; }
.card-header .badge { position: absolute; top: 10px; right: 10px; font-size: 0.7rem; color: white; padding: 2px 6px; border-radius: 4px; }
.badge.group-a { background: #6c5ce7; }
.badge.group-b { background: #fd79a8; }
.card-body .name { font-weight: bold; margin-top: 10px; }
.card-body .name small { color: #888; font-weight: 400; font-size: 0.85rem; }
.card-body .mbti { color: #888; font-size: 0.85rem; margin-bottom: 10px; }
.btn-view-heart { background: var(--soft-pink-bg); color: var(--primary-pink); font-size: 0.8rem; padding: 6px 14px; border-radius: 15px; font-weight: 600; }

.avatar-emoji { width: 40px; height: 40px; background-color: #ffffff; border-radius: 15px; display: flex; align-items: center; justify-content: center; font-size: 24px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); flex-shrink: 0; margin-right: 10px; }
.avatar-emoji-lg { width: 70px; height: 70px; background-color: #ffffff; border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 40px; box-shadow: 0 4px 10px rgba(0,0,0,0.15); margin: 0 auto; border: 3px solid white; }


/* =========================================
   4. Chat Popup (Overlay) 
   ========================================= */
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(3px);
    
    display: none; 
    
    align-items: center; justify-content: center;
    z-index: 100;
}
.overlay.active {
    display: flex;
}

.chat-window {
    width: 380px; height: 620px;
    background: var(--chat-bg);
    border-radius: 25px;
    display: flex; flex-direction: column;
    overflow: hidden;
    box-shadow: 0 15px 40px rgba(255, 139, 167, 0.3);
    animation: popUp 0.4s ease-out;
}
@keyframes popUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.chat-header {
    background: rgba(255,255,255,0.95);
    padding: 18px; 
    display: flex; justify-content: center; 
    align-items: center;
    border-bottom: 1px solid rgba(255, 139, 167, 0.2);
}
.chat-header .room-name { font-weight: bold; font-size: 1rem; color: #555; }

.chat-body {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
}

.system-notice { text-align: center; margin: 10px 0; }
.system-notice span {
    background: rgba(255, 180, 200, 0.3);
    color: #d66; padding: 5px 14px; border-radius: 15px; font-size: 0.75rem; font-weight: 500;
}

.chat-row { display: flex; align-items: flex-start; max-width: 85%; }
.chat-row.other { align-self: flex-start; }
.chat-row.me { align-self: flex-end; justify-content: flex-end; }
.bubble-group { display: flex; flex-direction: column; }
.sender-name { font-size: 0.75rem; margin-bottom: 4px; color: #777; margin-left: 2px; }

.bubble {
    padding: 10px 14px; border-radius: 16px; font-size: 0.95rem; line-height: 1.5;
    box-shadow: 0 2px 4px rgba(100, 100, 100, 0.05); position: relative;
}
.chat-row.other .bubble { background: #ffffff; color: #444; border-top-left-radius: 4px; }
.chat-row.me .bubble { background: var(--chat-me-bubble); color: #333; border-top-right-radius: 4px; }

.chat-footer {
    background: white; padding: 15px; text-align: center;
}
.btn-chat-next {
    width: 100%; padding: 14px;
    background: var(--primary-pink); color: white;
    font-weight: bold; border-radius: 30px;
    font-size: 1rem;
    box-shadow: 0 4px 10px rgba(255, 139, 167, 0.4);
    transition: transform 0.2s;
}
.btn-chat-next:hover { transform: scale(1.02); }
.log-item {
  opacity: 1;
  transform: translateY(0);
}

.log-item.enter {
  opacity: 0;
  transform: translateY(10px);
}

.log-item.enter.show {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 260ms ease, transform 260ms ease;
}
.chat-row {
  opacity: 1;
  transform: translateY(0);
}

.chat-row.enter {
  opacity: 0;
  transform: translateY(10px);
}

.chat-row.enter.show {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 260ms ease, transform 260ms ease;
}
/* =========================================
   5. Mobile Responsive (모바일 최적화)
   ========================================= */
@media screen and (max-width: 768px) {

    /* --- 1. Global Layout Adjustment --- */
    body {
        height: 100%; 
        overflow: hidden; 
    }

    /* --- 2. Setup Screen (세로 배치) --- */
    #screen-setup {
        padding: 15px;
        overflow-y: auto; 
    }
    .setup-container {
        width: 100%;
        padding: 20px;
        margin-top: 20px;
    }
    .input-group {
        flex-direction: column; 
        align-items: stretch;
        gap: 12px;
    }
    .input-group select, 
    .input-group input, 
    .gender-toggle, 
    .btn-add {
        width: 100% !important; 
    }
    .avatar-selector {
        justify-content: center;
        margin: 10px 0;
    }
    .participants-board {
        flex-direction: column;
        height: auto;
        max-height: none;
        gap: 15px;
    }
    .group-box {
        max-height: 200px; 
    }

    .chat-window {
        width: 95%;
        height: 90%;
        border-radius: 15px;
    }
    
    #screen-game {
        flex-direction: column; 
        height: 100vh;
        position: relative;
    }

    .status-bar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 50; 
        border-radius: 0;
        border-bottom: 1px solid #ddd;
        padding: 10px;
        font-size: 0.8rem;
        height: 50px; 
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .panel-left {
        width: 100%;
        flex: none; 
        height: 50vh; 
        min-width: 0;
        border-right: none;
        border-bottom: 2px solid #ddd;
        margin-top: 50px; 
    }
    
    .game-header {
        display: none; 
       
    }
    
    .scroll-content {
        padding: 10px;
    }
    .log-item {
        padding: 8px;
        font-size: 0.8rem;
    }

    .game-footer {
        padding: 10px;
    }
    .action-info {
        font-size: 0.85rem;
    }
    .btn-main-action {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .panel-right {
        width: 100%;
        flex: 1;
        padding: 15px;
        border-left: none;
        background: var(--bg-gray);
        overflow-y: auto; 
    }

    .widget-box {
        margin-bottom: 15px;
        padding: 10px;
    }
    .widget-box h4 {
        font-size: 0.85rem;
        margin-bottom: 5px;
    }

    .participant-grid {
        grid-template-columns: repeat(2, 1fr); 
        gap: 10px;
        padding-bottom: 20px; 
    }
    
    .user-card-full {
        padding-bottom: 10px;
    }
    .avatar-emoji-lg {
        width: 50px;
        height: 50px;
        font-size: 30px;
    }
    .card-body .name {
        font-size: 0.9rem;
    }
    .card-body .mbti {
        font-size: 0.8rem;
    }
}