:root {
    --bg-color: #0f172a;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    /* Blue-500 */
    --accent-glow: rgba(59, 130, 246, 0.5);
    --user-msg-bg: #2563eb;
    --ai-msg-bg: rgba(30, 41, 59, 0.8);
    --font-main: 'Inter', 'Noto Sans JP', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    font-family: var(--font-main);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    /* Prevent body scroll if creating a full app feel */
}

/* Dynamic Background */
/* ... (unchanged blocks) ... */
/* App Container */
.app-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: var(--app-height, 100%);
    /* Use JS-calculated height for perfect mobile fit */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}

/* Evaluation Button */
.eval-btn {
    padding: 0.4rem 1rem;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: 'Noto Sans JP', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.eval-btn:disabled {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
}

.eval-btn:not(:disabled) {
    background: #eab308;
    color: #1a1a2e;
    box-shadow: 0 0 12px rgba(234, 179, 8, 0.4);
    animation: evalPulse 2s ease-in-out infinite;
}

.eval-btn:not(:disabled):hover {
    background: #ca8a04;
    transform: scale(1.05);
}

@keyframes evalPulse {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(234, 179, 8, 0.3);
    }

    50% {
        box-shadow: 0 0 18px rgba(234, 179, 8, 0.6);
    }
}

/* ... (unchanged blocks) ... */
/* Input Area */
.input-area {
    padding: 1.2rem;
    padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
    padding-bottom: calc(1.2rem + constant(safe-area-inset-bottom));
    /* iOS < 11.2 fallback */
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Dynamic Background */
.background-globes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.globe {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
}

.globe-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #4f46e5, #0f172a);
    top: -100px;
    left: -100px;
    animation: moveGlobe 20s infinite alternate ease-in-out;
}

.globe-2 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #0ea5e9, #0f172a);
    bottom: -150px;
    right: -150px;
    animation: moveGlobe 25s infinite alternate-reverse ease-in-out;
}

@keyframes moveGlobe {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(50px, 50px);
    }

    100% {
        transform: translate(50px, 50px);
    }
}

/* Start Overlay */
.start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-content {
    text-align: center;
    color: white;
    cursor: pointer;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
    transition: transform 0.3s ease;
}

.start-content:active {
    transform: scale(0.95);
}

.start-content:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.15);
}

.start-content i {
    font-size: 4rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
    display: block;
}

.start-content p {
    font-size: 1.2rem;
    font-weight: 600;
}

/* App Container */
.app-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Use fixed positioning with all 4 corners to fill available space */
    width: 100%;
    height: auto;
    /* Remove explicit height to let browser handle layout */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

/* Header */
.app-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(5px);
    background: rgba(14, 165, 233, 0.15);
    /* Light Blue Tint */
}

/* Header Controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.level-select {
    background: #ffffff;
    /* White background */
    border: 1px solid var(--glass-border);
    color: #000000;
    /* Black text */
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
}

.level-select:focus {
    border-color: var(--accent-color);
}

.level-select option {
    background: #ffffff;
    color: #000000;
}



.app-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #22c55e;
    box-shadow: 0 0 5px #22c55e;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

/* Scrollbar styling */
.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.message .text {
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
    word-break: break-word;
}

.message.ai .text {
    background: var(--ai-msg-bg);
    border-top-left-radius: 2px;
    border: 1px solid var(--glass-border);
    /* IMPORTANT: Prevent unnecessary whitespace indentation */
    white-space: normal;
}

.message.user .text {
    background: var(--user-msg-bg);
    border-top-right-radius: 2px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    white-space: pre-wrap;
    /* User input might have intentional breaks */
}

/* Input Area */
.input-area {
    padding: 1.2rem;
    padding-bottom: calc(3rem + env(safe-area-inset-bottom));
    /* Increased base padding significantly + safe area */
    padding-bottom: calc(3rem + constant(safe-area-inset-bottom));
    /* Older iOS fallback */
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    align-items: center;
    background: rgba(14, 165, 233, 0.15);
    /* Ensure background covers padding */
}

.glass-panel-inner {
    background: rgba(14, 165, 233, 0.15);
    /* Light Blue Tint for input area */
    backdrop-filter: blur(15px);
}

.voice-controls {
    flex-shrink: 0;
}

.control-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: #eab308;
    /* Yellow-500 default */
    color: #ffffff;
    /* White icon */
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    box-shadow: 0 0 10px rgba(234, 179, 8, 0.5);
}

.control-btn:hover {
    background: #ca8a04;
    /* Darker yellow on hover */
}

.control-btn.listening {
    background: #ef4444;
    /* Red for listening */
    box-shadow: 0 0 15px #ef4444;
}

.control-btn.listening .pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

.text-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.text-input-wrapper input {
    width: 100%;
    padding: 0.8rem 3rem 0.8rem 1.2rem;
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    background: #ffffff;
    /* White background */
    color: #000000;
    /* Black text */
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.text-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: #ffffff;
}

.send-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s ease;
}

.send-btn:hover {
    transform: translateY(-50%) scale(1.1);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .app-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }

    .chat-area {
        padding: 1rem;
    }

    .message {
        max-width: 85%;
    }

    .desktop-only-text {
        display: none;
    }

    /* PREVENT ZOOM ON INPUT FOCUS (iOS) */
    .level-select,
    .text-input-wrapper input {
        font-size: 16px !important;
        /* Minimum size to prevent zoom */
    }

    /* Prevent double-tap zoom on buttons */
    button,
    .control-btn,
    .send-btn {
        touch-action: manipulation;
    }
}