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

:root {
    --primary-blue: #1a365d;
    --primary-red: #c53030;
    --light-gray: #f8f9fa;
    --border-gray: #e8eaed;
    --text-dark: #202124;
    --text-gray: #5f6368;
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--light-gray);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 12px;
    padding-top: calc(12px + var(--safe-area-inset-top));
    padding-bottom: calc(12px + var(--safe-area-inset-bottom));
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    height: 100%;
}

header {
    text-align: center;
    color: var(--primary-blue);
    margin-bottom: 16px;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 4px;
    font-weight: 700;
    color: #8B0000;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-gray);
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start;
}

@media (min-width: 900px) {
    body {
        padding: 20px;
    }
    
    header {
        margin-bottom: 30px;
    }
    
    header h1 {
        font-size: 2.5rem;
        margin-bottom: 5px;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .main-content {
        grid-template-columns: 480px 1fr;
        gap: 24px;
    }
}

.orthy-container {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
    display: none;
}

@media (min-width: 900px) {
    .orthy-container {
        display: block;
        padding: 24px;
    }
}

.orthy {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 300px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 900px) {
    .orthy {
        height: 480px;
    }
}

.orthy-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.orthy.thinking .orthy-image {
    animation: think-bob 1s ease-in-out infinite;
}

.orthy.happy .orthy-image {
    animation: happy-bounce 0.5s ease;
}

.orthy.waving .orthy-image {
    animation: wave-wobble 0.5s ease-in-out 2;
}

@keyframes think-bob {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-2deg); }
    75% { transform: rotate(2deg); }
}

@keyframes happy-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes wave-wobble {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}

.speech-bubble {
    background: var(--light-gray);
    border-radius: 12px;
    padding: 14px;
    position: relative;
    border: 1px solid var(--border-gray);
}

.speech-bubble::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--border-gray);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid var(--light-gray);
}

#orthy-speech {
    color: var(--text-dark);
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 900px) {
    .chat-section {
        gap: 16px;
    }
}

.topics {
    background: white;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

@media (min-width: 900px) {
    .topics {
        padding: 16px 20px;
    }
}

.topics h3 {
    color: var(--text-dark);
    margin-bottom: 10px;
    font-size: 0.9rem;
    font-weight: 600;
}

@media (min-width: 900px) {
    .topics h3 {
        margin-bottom: 12px;
        font-size: 0.95rem;
    }
}

.topic-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

@media (min-width: 900px) {
    .topic-buttons {
        gap: 8px;
    }
}

.topic-btn {
    background: white;
    color: var(--primary-blue);
    border: 1px solid var(--border-gray);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

@media (min-width: 900px) {
    .topic-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }
}

.topic-btn:hover,
.topic-btn:active {
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
}

.knowledge-info {
    background: white;
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
    border-left: 3px solid var(--primary-red);
}

@media (min-width: 900px) {
    .knowledge-info {
        padding: 12px 16px;
    }
}

.knowledge-info p {
    color: var(--text-gray);
    font-size: 0.8rem;
    margin: 0;
}

@media (min-width: 900px) {
    .knowledge-info p {
        font-size: 0.85rem;
    }
}

.chat-container {
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 320px);
    min-height: 300px;
    max-height: 500px;
}

@media (min-width: 900px) {
    .chat-container {
        padding: 16px;
        height: 420px;
        max-height: none;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 900px) {
    .chat-messages {
        gap: 12px;
    }
}

.message {
    display: flex;
    gap: 8px;
    max-width: 90%;
}

@media (min-width: 900px) {
    .message {
        gap: 10px;
        max-width: 85%;
    }
}

.bot-message {
    align-self: flex-start;
}

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

.message-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--light-gray);
}

@media (min-width: 900px) {
    .message-avatar {
        width: 120px;
        height: 120px;
        font-size: 2rem;
    }
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    padding: 8px 12px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 0.85rem;
}

@media (min-width: 900px) {
    .message-content {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
}

.bot-message .message-content {
    background: var(--light-gray);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
}

.user-message .message-content {
    background: var(--primary-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-input-container {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

@media (min-width: 900px) {
    .chat-input-container {
        gap: 10px;
        margin-top: 12px;
    }
}

#user-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border-gray);
    border-radius: 24px;
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
}

@media (min-width: 900px) {
    #user-input {
        padding: 12px 18px;
        font-size: 0.95rem;
    }
}

#user-input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(26, 54, 93, 0.1);
}

#send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--primary-blue);
    color: white;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

@media (min-width: 900px) {
    #send-btn {
        width: 46px;
        height: 46px;
        font-size: 1.1rem;
    }
}

#send-btn:hover,
#send-btn:active {
    background: #15294a;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.reset-btn {
    margin-top: 8px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border-gray);
    border-radius: 8px;
    color: var(--text-gray);
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.reset-btn:hover,
.reset-btn:active {
    border-color: var(--primary-red);
    color: var(--primary-red);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--primary-blue);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 1; }
}

@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
}

.typing-cursor {
    display: inline;
    animation: blink 0.7s infinite;
    color: var(--primary-blue);
    font-weight: bold;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.voice-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: white;
    color: var(--text-dark);
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    border: 2px solid var(--border-gray);
}

@media (min-width: 900px) {
    .voice-btn {
        width: 54px;
        height: 54px;
        font-size: 1.3rem;
    }
    .voice-icon {
        width: 42px;
        height: 42px;
    }
}

.voice-btn:hover {
    background: var(--border-gray);
}

.voice-btn.recording {
    background: var(--primary-red);
    border-color: var(--primary-red);
    animation: pulse-recording 1s infinite;
}

.voice-btn.recording span,
.voice-btn.recording .voice-icon {
    filter: brightness(0) invert(1);
}

.voice-icon {
    width: 38px;
    height: 38px;
    object-fit: contain;
}

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

.voice-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.speaker-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    margin-left: 8px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.speaker-btn:hover {
    opacity: 1;
}

.speaker-btn.speaking {
    opacity: 1;
    animation: pulse-speaking 0.5s infinite alternate;
}

@keyframes pulse-speaking {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.voice-not-supported {
    display: none;
}
