:root {
    --ren-bg: #1e293b;
    --ren-accent: #334155;
    --ren-glow: #64748b;
    --student-bubble: rgba(255, 255, 255, 0.1);
    --ren-bubble: rgba(15, 23, 42, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-blue: #3b82f6;
}

body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    color: white;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#demo-container {
    width: 390px;
    height: 844px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 40px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    backdrop-filter: blur(20px);
    transform-origin: center;
}

/* Auto-scale for smaller screens */
@media (max-height: 900px) {
    #demo-container {
        transform: scale(0.85);
        margin: -60px 0;
    }
}
@media (max-height: 750px) {
    #demo-container {
        transform: scale(0.7);
        margin: -120px 0;
    }
}

.status-bar {
    height: 44px;
    padding: 0 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    opacity: 0.9;
}

.status-icons {
    display: flex;
    gap: 5px;
}

/* App Header */
.app-header {
    height: 60px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.back-button {
    font-size: 20px;
    margin-right: 15px;
    opacity: 0.7;
}

.coach-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

.coach-avatar {
    width: 40px;
    height: 40px;
    background: radial-gradient(circle at top left, #3b82f6, #1d4ed8);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 18px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
    overflow: hidden; /* Added to clip image */
}

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

.coach-name {
    font-size: 16px;
    font-weight: bold;
}

.coach-status {
    font-size: 11px;
    color: #4ade80;
    margin-top: 2px;
}

.header-icons {
    font-size: 20px;
    opacity: 0.5;
}

.chat-log {
    position: absolute;
    top: 104px; /* Status bar(44) + Header(60) */
    bottom: 80px; /* Bottom bar(80) */
    left: 0;
    right: 0;
    overflow-y: auto;
    padding: 20px 15px 80px 15px; /* Adjusted to be naturally above the bottom bar */
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 5;
}

.bubble {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    animation: fadeIn 0.5s ease-out forwards;
}

.student-bubble {
    align-self: flex-end;
    background: var(--student-bubble);
    border: 1px solid var(--glass-border);
    border-bottom-right-radius: 5px;
}

.ren-bubble {
    align-self: flex-start;
    background: var(--ren-bubble);
    border: 1px solid var(--accent-blue);
    border-bottom-left-radius: 5px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
    display: flex; /* Added for bubble content layout */
    align-items: flex-start;
}

.avatar-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-right: 10px;
    flex-shrink: 0;
    overflow: hidden;
    background: #1e293b;
}

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

.problem-photo {
    width: 100%;
    border-radius: 12px;
    margin-bottom: 5px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.scan-line {
    position: absolute;
    width: 100%;
    height: 2px;
    background: var(--accent-blue);
    box-shadow: 0 0 15px var(--accent-blue);
    top: 50px;
    left: 0;
    z-index: 10;
    animation: scan 2s linear infinite;
    display: none;
}

.voice-wave {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    height: 40px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 100; /* Higher than chat */
    pointer-events: none; /* Don't block clicking through to chat */
}

/* Bottom Bar */
.bottom-bar {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 80px;
    padding: 10px 15px 30px 15px;
    background: rgba(15, 23, 42, 0.9);
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.input-area {
    width: 100%;
    height: 44px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.4);
}

.send-icon {
    width: 30px;
    height: 30px;
    background: var(--accent-blue);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 12px;
    transform: rotate(90deg);
}

.wave-bar {
    width: 3px;
    height: 8px;
    background: var(--accent-blue);
    border-radius: 2px;
}

.wave-bar.active {
    animation: wave 1.2s ease-in-out infinite;
}

.textbook-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 280px;
    padding: 20px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--accent-blue);
    border-radius: 24px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
    z-index: 100;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.textbook-popup.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.textbook-img {
    width: 120px;
    height: 160px;
    object-fit: contain;
    margin-bottom: 15px;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));
}

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

@keyframes scan {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 32px; }
}

/* Custom Scrollbar */
.chat-log::-webkit-scrollbar { width: 4px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
