:root {
    /* Monochrome palette */
    --color-black: #000000;
    --color-gray-500: #788688; /* Used for secondary text */
    --color-gray-200: #EEEEEE; /* Used for borders */
    --color-gray-100: #F5F5F5; /* Used for backgrounds */
    --color-white: #FFFFFF;
    
    /* Common values */
    --border-radius-sm: 6px;
    --border-radius-round: 50%;
    --transition-speed: 0.2s ease;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Base styles */
html, body {
    /* Use min-height instead of fixed height for better iOS keyboard handling */
    min-height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-size: 18px;
    line-height: 28px;
    font-weight: 400;
    letter-spacing: -0.01em; /* -1% letter spacing */
    background-color: var(--color-white);
    color: var(--color-black);
    -webkit-font-smoothing: antialiased;
    margin: 0;
    width: 100%;
    overflow-x: hidden;
    /* Prevent iOS from auto-zooming on input fields */
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 40px 20px;
    box-sizing: border-box;
    width: 100%;
}

/* Header */
.header {
    margin-bottom: 64px;
}

.header h1 {
    font-size: 18px;
    line-height: 28px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--color-black);
}

.header h1 span {
    color: var(--color-gray-500);
    font-weight: 400;
}

/* Chat layout */
.chat-container {
    position: relative;
}

/* Avatar connector (animation line between avatars) */
.avatar-connector {
    position: absolute;
    left: 20px;
    top: 40px;
    width: 1px;
    height: 100%;
    background: linear-gradient(to bottom, #EEF0F0, #E3DBFD);
    z-index: 1;
    overflow: hidden;
}

/* Mode-specific connector backgrounds */
body[data-mode="erudeeritud"] .avatar-connector {
    background: linear-gradient(to bottom, #EEF0F0, #A6E5CF);
}

.avatar-connector::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom, 
        transparent, 
        transparent 20%, 
        rgba(94, 93, 126, 0.7) 40%,
        rgba(94, 93, 126, 0.7) 60%, 
        transparent 80%, 
        transparent
    );
    opacity: 0;
    transform: translateY(-100%);
    z-index: 2;
    transition: opacity 0.3s ease;
}

/* Mode-specific animation colors */
body[data-mode="tavaline"] .avatar-connector::after {
    background: linear-gradient(
        to bottom, 
        transparent, 
        transparent 20%, 
        rgba(94, 93, 126, 0.5) 35%,
        rgba(227, 219, 253, 0.7) 65%,
        transparent 80%, 
        transparent
    );
}

body[data-mode="erudeeritud"] .avatar-connector::after {
    background: linear-gradient(
        to bottom, 
        transparent, 
        transparent 20%, 
        rgba(94, 93, 126, 0.5) 35%,
        rgba(166, 229, 207, 0.7) 65%,
        transparent 80%, 
        transparent
    );
}

.avatar-connector.animating::after {
    opacity: 1;
    animation: flow-down 1.5s ease-in-out infinite; 
}

/* Chat bubbles layout */
.chat-input, .chat-response {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    position: relative;
    z-index: 2;
}

/* Avatar common styles */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-round);
    flex-shrink: 0;
    position: relative;
    z-index: 3; /* Higher than the connector */
}

/* Avatar containers */
.avatar-wrapper, .avatar-user-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
}

/* Focus indicator for user avatar */
.avatar-focus-indicator {
    position: absolute;
    top: -2px;
    left: -2px;
    width: 44px;
    height: 44px;
    border-radius: var(--border-radius-round);
    border: 2px solid var(--color-black);
    opacity: 0;
    transition: opacity var(--transition-speed);
    z-index: 4; /* Higher than avatar */
}

/* Avatar button for dropdown */
.avatar-button {
    position: relative;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    display: block;
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-round);
}

/* Avatar dropdown menu */
.avatar-dropdown-content {
    position: absolute;
    width: 160px;
    background-color: var(--color-white);
    border-radius: var(--border-radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    z-index: 100;
    border: 1px solid var(--color-gray-200);
    left: 0;
    transform-origin: top left;
    top: calc(100% + 4px); /* Default position below avatar */
    /* JavaScript will adjust position if needed */
}

/* Avatar dropdown options */
.avatar-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    outline: none;
    font-size: 16px;
}

.avatar-option:focus,
.avatar-option:hover {
    outline: none;
    background-color: var(--color-gray-100);
}

/* Avatar option thumbnail */
.avatar-option-img {
    width: 32px;
    height: 32px;
    border-radius: var(--border-radius-round);
    margin-right: 8px;
}

/* Content wrapper */
.input-wrapper {
    flex-grow: 1;
    min-width: 0;
}

.content-area {
    padding: 16px 0;
    min-height: 40px; /* Matches avatar height */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Input area */
textarea {
    width: 100%;
    min-height: 28px;
    padding: 8px 0;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 18px;
    line-height: 28px;
    letter-spacing: -0.01em;
    resize: none;
    outline: none;
    overflow: hidden;
    display: block;
}

/* Placeholder styling - unified for all browsers */
textarea::placeholder {
    color: var(--color-gray-500) !important;
    opacity: 1; /* Fix for Firefox */
}

/* Browser-specific placeholder selectors */
textarea::-webkit-input-placeholder {
    color: var(--color-gray-500) !important;
}

textarea::-moz-placeholder {
    color: var(--color-gray-500) !important;
    opacity: 1;
}

textarea:-ms-input-placeholder {
    color: var(--color-gray-500) !important;
}

input::placeholder {
    color: var(--color-gray-500);
    opacity: 1;
}

/* Ensure consistent height when empty */
textarea:empty {
    height: auto;
}

/* Response area */
.response-content {
    padding: 8px 0;
    min-height: 24px;
    flex-grow: 1;
}

.response-placeholder {
    color: var(--color-gray-500);
}

/* Controls */
.controls {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
    justify-content: flex-end;
}

/* Prevent transitions on page load */
.no-transitions * {
    transition: none !important;
}

/* Button styles */
.translate-button,
.clear-button {
    flex: 0 0 auto;
    height: 40px;
    padding: 18px;
    border: none;
    border-radius: 9999px; /* Full corner radius */
    font-family: inherit;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity var(--transition-speed);
    text-align: center;
    box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.12);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Translate button */
.translate-button {
    width: 72px;
    background: linear-gradient(45deg, #180614, #5E5D7E);
    color: var(--color-white);
}

/* Clear button */
.clear-button {
    width: auto;
    background: #FAFAFB;
    color: #3D344C;
    opacity: 1;
}

.clear-button:hover:not(:disabled) {
    opacity: 1;
}

.clear-button:disabled {
    opacity: 0.4;
    cursor: default;
}

.translate-button:hover {
    opacity: 0.9;
}

.translate-button:disabled {
    opacity: 0.7;
    cursor: default;
}

/* Loading spinner */
.loading-spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--color-white);
    border-radius: var(--border-radius-round);
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

.translate-button:disabled .button-text {
    display: none;
}

/* Focus states - unified style */
.translate-button:focus-visible,
.clear-button:focus-visible,
.avatar-button:focus-visible {
    outline: 2px solid var(--color-black);
}

.avatar-button:focus-visible {
    border-radius: var(--border-radius-round);
}

/* Mobile adjustments */
@media (max-width: 520px) {
    .container {
        padding: 20px 16px;
    }
    
    .controls {
        flex-wrap: wrap;
    }
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes flow-down {
    0% {
        opacity: 1;
        transform: translateY(-100%);
    }
    100% {
        opacity: 1;
        transform: translateY(100%);
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}