* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%; /* เปลี่ยนเป็น 100% เพื่อรอรับค่าจาก JS */
    width: 100%;
    overflow: hidden; /* ห้าม scroll ที่ body หลัก */
    background-color: #f0f4f9;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Container หลักที่จะถูกย่อขยายตามคีย์บอร์ด */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%; /* เต็มพื้นที่ที่ Browser จัดให้ */
    width: 100%;
    position: relative;
}

.app-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e1e4e8;
    flex-shrink: 0;
    z-index: 10;
}

.logo {
    font-size: 1.2rem;
    font-weight: bold;
    background: linear-gradient(90deg, #4285F4, #D96570);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.75rem;
    color: #666;
    background: #eee;
    padding: 2px 8px;
    border-radius: 12px;
}

.chat-area {
    flex: 1;
    overflow-y: scroll; /* ใช้ scroll แทน auto เพื่อความลื่นไหลใน iOS */
    -webkit-overflow-scrolling: touch; /* ให้เลื่อนลื่นๆ บน iOS */
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
    animation: popIn 0.3s ease;
}

.user-message { flex-direction: row-reverse; }

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    flex-shrink: 0;
}

.ai-avatar { background: linear-gradient(135deg, #4285F4, #D96570); color: white; }
.user-avatar { background-color: #444746; color: white; }

.bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 80%;
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.user-message .bubble { background-color: #005cbb; color: white; border-radius: 18px 4px 18px 18px; }
.ai-message .bubble { background-color: white; color: #1f1f1f; border-radius: 4px 18px 18px 18px; }

.img-meme { max-width: 100%; height: auto; border-radius: 12px; margin-top: 8px; display: block; }

.input-area {
    background-color: white;
    padding: 10px 16px;
    flex-shrink: 0;
    border-top: 1px solid #e1e4e8;
    /* เอา env padding ออกชั่วคราวเพื่อให้ JS คำนวณแม่นยำกว่า */
    padding-bottom: 10px; 
}

.input-wrapper {
    display: flex;
    align-items: center;
    background-color: #f0f4f9;
    border-radius: 24px;
    padding: 6px 12px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within { border-color: #4285F4; background-color: white; }

input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px;
    font-size: 16px;
    outline: none;
    min-width: 0;
    color: #1f1f1f;
}

button {
    background: none;
    border: none;
    color: #4285F4;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Animations */
@keyframes popIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.glitch-text { animation: shake 0.2s infinite; color: #D96570 !important; font-family: 'Courier New', monospace; font-weight: bold; }
@keyframes shake { 0% { transform: translate(1px, 1px); } 50% { transform: translate(-1px, -2px); } 100% { transform: translate(1px, -1px); } }
.typing { font-style: italic; color: #888; font-size: 0.85rem; }

