/* Base Styles */
body {
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background-color 1s ease;
}

body.day-mode { 
    background: linear-gradient(to bottom right, #a7f3d0, #bfdbfe); 
}

body.night-mode { 
    background: linear-gradient(to bottom right, #1a202c, #4a5568); 
}

/* Container */
.container {
    background-color: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    max-width: 900px;
    width: 100%;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Speech Bubble */
.speech-bubble {
    position: relative;
    background-color: #fef08a;
    border-radius: 15px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 1.1rem;
    color: #333;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    width: 0; 
    height: 0;
    border-style: solid;
    border-width: 15px 15px 0 0;
    border-color: #fef08a transparent transparent transparent;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
}

.speech-bubble p {
    margin: 0;
    width: 100%;
}

/* Animal Icon */
.emoji-icon {
    font-size: 80px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid #f97316;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    background-color: #ffe0b2;
}

/* Animal Container */
.animal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 45%;
}

/* Dialogue Area */
.dialogue-area {
    display: flex;
    justify-content: space-around;
    width: 100%;
    flex-wrap: wrap;
    gap: 20px;
}

/* Clickable Animal */
.clickable-animal {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.clickable-animal:hover { 
    transform: scale(1.05); 
}

/* Drop Zone */
.drop-zone {
    width: 150px;
    height: 150px;
    border: 3px dashed #9ca3af;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    color: #6b7280;
    background-color: #f3f4f6;
    transition: border-color 0.3s ease, background-color 0.3s ease;
    position: relative;
    overflow: hidden;
}

.drop-zone.drag-over {
    border-color: #4ade80;
    background-color: #d1fae5;
}

.drop-zone .selected-animal-display {
    position: absolute;
    top: 0; 
    left: 0;
    width: 100%; 
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #ffe0b2;
    border-radius: 12px;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.1);
}

.drop-zone .selected-animal-display .emoji-icon {
    font-size: 80px;
    width: auto; 
    height: auto;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.drop-zone .selected-animal-display .animal-name-small {
    font-size: 0.9rem;
    font-weight: bold;
    color: #333;
    margin-top: 5px;
}

/* Animal Draggable */
.animal-draggable {
    background-color: #60a5fa;
    color: white;
    padding: 10px 15px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: bold;
    cursor: grab;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.animal-draggable:hover {
    background-color: #3b82f6;
    transform: translateY(-2px);
}

.animal-draggable:active {
    cursor: grabbing;
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Mode Button */
.mode-button {
    background-color: #f97316;
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border: none;
}

.mode-button:hover {
    background-color: #ea580c;
    transform: translateY(-2px);
}

.mode-button.active {
    background-color: #1a202c;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* Chat Input Area */
.chat-input-area {
    display: flex;
    width: 100%;
    gap: 10px;
}

.chat-input-area input {
    flex-grow: 1;
    padding: 12px 18px;
    border: 2px solid #e5e7eb;
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s ease;
}

.chat-input-area input:focus { 
    border-color: #f97316; 
}

.chat-input-area button {
    background-color: #f97316;
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border: none;
}

.chat-input-area button:hover {
    background-color: #ea580c;
    transform: translateY(-2px);
}

.chat-input-area button:disabled {
    background-color: #d1d5db;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Loading Spinner */
.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top: 4px solid #f97316;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Streaming Cursor */
.streaming-cursor {
    animation: blink 1s infinite;
    color: #f97316;
    font-weight: bold;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Selection Areas */
.selection-area, .mode-select-area {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
    flex-wrap: wrap;
}

/* Fact Box */
.fact-box {
    background-color: #f9fafb;
    border-left: 4px solid #f97316;
    padding: 15px;
    border-radius: 8px;
    text-align: left;
    width: 100%;
}

.fact-box strong { 
    color: #f97316; 
}

/* Profile Screen */
#animal-profile-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
    padding: 20px;
    max-width: 600px;
    width: 100%;
    background-color: #fff;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

#animal-profile-screen h2 {
    font-size: 2.5rem;
    font-weight: bold;
    color: #1f2937;
}

#animal-profile-screen p {
    font-size: 1.1rem;
    color: #4b5563;
    line-height: 1.6;
}

/* Message Styles */
.message {
    margin-bottom: 10px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
}

.message.user {
    background-color: #e0f2fe;
    margin-left: 20px;
    align-self: flex-end;
}

.message.animal {
    background-color: #f0f9ff;
    margin-right: 20px;
    align-self: flex-start;
}

.message.keeper {
    background-color: #f0fdf4;
    border-left: 4px solid #22c55e;
    margin: 10px 0;
}

/* Conversation History Improvements */
#conversation-history {
    overflow-y: auto;
    height: 300px;
    background-color: #fafafa;
    padding: 16px;
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 16px;
    width: 100%;
    font-size: 0.95rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f7fafc;
}

#conversation-history::-webkit-scrollbar {
    width: 6px;
}

#conversation-history::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 3px;
}

#conversation-history::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

#conversation-history::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
        align-items: flex-start;
    }
    
    .container { 
        padding: 20px 15px;
        margin: 0;
        min-height: 100vh;
        border-radius: 15px;
        gap: 15px;
    }
    
    h1 {
        font-size: 2rem !important;
        margin-bottom: 1rem !important;
    }
    
    h1 span:last-child {
        font-size: 1.2rem !important;
    }
    
    #initial-prompt {
        font-size: 1.3rem !important;
        margin-bottom: 1rem !important;
    }
    
    /* 会話履歴エリアの最適化 */
    #conversation-history-container {
        width: 100%;
        margin: 0;
    }
    
    #conversation-history {
        height: 250px;
        font-size: 0.9rem;
        padding: 12px;
        margin-bottom: 12px;
    }
    
    /* チャット入力エリアの最適化 */
    #chat-input-area {
        width: 100%;
        margin: 0;
    }
    
    #chat-input-area .flex {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    #user-input {
        font-size: 16px; /* iOS Safari zoom prevention */
        padding: 12px 16px;
        border-radius: 20px;
        width: 100%;
        margin-bottom: 8px;
    }
    
    #send-button, #keeper-button {
        padding: 10px 16px;
        font-size: 0.9rem;
        border-radius: 20px;
        flex: 1;
        min-width: 120px;
    }
    
    /* 動物会話エリアの縦型レイアウト */
    .dialogue-area { 
        flex-direction: column; 
        align-items: center;
        gap: 30px;
        width: 100%;
    }
    
    .animal-container { 
        width: 100%;
        max-width: 320px;
    }
    
    .speech-bubble {
        font-size: 1rem;
        min-height: 100px;
        padding: 16px;
        margin-bottom: 15px;
        max-width: 100%;
        text-align: left;
        line-height: 1.6;
    }
    
    .emoji-icon { 
        width: 80px; 
        height: 80px; 
        font-size: 50px;
        border-width: 3px;
    }
    
    .clickable-animal p {
        font-size: 1rem;
        margin-top: 8px;
    }
    
    /* 動物選択エリアの最適化 */
    .selection-area { 
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }
    
    .animal-draggable { 
        width: 100%;
        max-width: 280px;
        justify-content: center;
        padding: 12px 20px;
        font-size: 1.1rem;
        margin: 0 auto;
    }
    
    /* ドロップゾーンの最適化 */
    .drop-zone-container {
        flex-direction: row;
        gap: 20px;
        justify-content: center;
        margin: 20px 0;
    }
    
    .drop-zone { 
        width: 130px; 
        height: 130px;
        font-size: 0.8rem;
    }
    
    .drop-zone .selected-animal-display .emoji-icon {
        font-size: 60px;
    }
    
    .drop-zone .selected-animal-display .animal-name-small {
        font-size: 0.8rem;
    }
    
    /* メッセージスタイルの最適化 */
    .message {
        padding: 10px 14px;
        margin: 6px 0;
        font-size: 0.9rem;
        border-radius: 10px;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
    
    .message.user {
        background-color: #dbeafe;
        align-self: flex-end;
    }
    
    .message.animal {
        background-color: #f0f9ff;
        align-self: flex-start;
    }
    
    .message.keeper {
        background-color: #f0fdf4;
        border-left: 3px solid #22c55e;
    }
    
    /* プロフィール画面の最適化 */
    #animal-profile-screen {
        padding: 20px 15px;
        gap: 15px;
        border-radius: 15px;
    }
    
    #animal-profile-screen h2 {
        font-size: 2rem;
    }
    
    #animal-profile-screen p {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    #animal-profile-screen .emoji-icon {
        width: 100px;
        height: 100px;
        font-size: 60px;
    }
    
    .mode-button {
        width: 100%;
        max-width: 280px;
        margin: 0 auto;
        padding: 12px 20px;
        font-size: 1rem;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .container {
        padding: 15px 10px;
    }
    
    h1 {
        font-size: 1.7rem !important;
    }
    
    h1 span:last-child {
        font-size: 1rem !important;
    }
    
    #conversation-history {
        height: 220px;
        font-size: 0.85rem;
        padding: 10px;
    }
    
    .speech-bubble {
        font-size: 0.9rem;
        min-height: 90px;
        padding: 14px;
    }
    
    .drop-zone-container {
        gap: 15px;
    }
    
    .drop-zone {
        width: 110px;
        height: 110px;
    }
    
    .drop-zone .selected-animal-display .emoji-icon {
        font-size: 50px;
    }
    
    .animal-draggable {
        padding: 10px 16px;
        font-size: 1rem;
    }
    
    #send-button, #keeper-button {
        padding: 10px 14px;
        font-size: 0.85rem;
        min-width: 100px;
    }
}