/* ==================== GPT CHAT PANEL ==================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
    width: 100%;
}

.app-wrapper .container {
    flex: 1;
    min-width: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease;
}

/* Desktop (>1200px): side-by-side, panel 380px */
.app-wrapper.panel-open .container {
    transform: translateX(-7%);
}

/* GPT Panel Toggle Button */
.gpt-panel-toggle {
    position: fixed;
    right: 20px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px var(--accent-glow), 0 4px 16px rgba(0,0,0,0.3);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.gpt-panel-toggle:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: 0 12px 40px var(--accent-glow), 0 8px 24px rgba(0,0,0,0.4);
}

.gpt-panel-toggle .toggle-icon {
    font-size: 1.8rem;
}

.gpt-panel-toggle .toggle-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    background: var(--error);
    color: white;
    border-radius: 11px;
    font-size: 0.75rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(255, 118, 117, 0.5);
}

.gpt-panel-toggle .toggle-badge.show {
    display: flex;
    animation: bounce 0.5s ease;
}

.app-wrapper.panel-open .gpt-panel-toggle {
    opacity: 0;
    pointer-events: none;
    transform: translateX(100px);
}

/* GPT Chat Panel */
.gpt-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0,0,0,0.2);
}

.app-wrapper.panel-open .gpt-chat-panel {
    transform: translateX(0);
}

.gpt-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.gpt-panel-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.gpt-panel-title .gpt-icon {
    font-size: 1.5rem;
}

.gpt-panel-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--option-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.gpt-panel-close:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

.gpt-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.gpt-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.gpt-welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.gpt-welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.gpt-welcome-message h3 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 1.2rem;
}

.gpt-welcome-message p {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Chat Message Bubbles */
.gpt-message {
    background: var(--glass-bg);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.gpt-message-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.gpt-message-question {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    flex: 1;
    margin-right: 12px;
}

.gpt-message-answers {
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.gpt-message-answers .user-ans {
    color: var(--error);
    font-weight: 600;
}

.gpt-message-answers .correct-ans {
    color: var(--success);
    font-weight: 600;
}

.gpt-message-content {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-primary);
    overflow-wrap: break-word;
    word-break: break-word;
}

.gpt-message-content .gpt-section {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
}

.gpt-message-content .gpt-section:last-child {
    margin-bottom: 0;
}

.gpt-message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 12px;
    text-align: right;
}

.gpt-message.loading {
    text-align: center;
    padding: 32px;
}

.gpt-message.loading .loading-spinner {
    margin: 0 auto 12px;
}

/* Panel Footer */
.gpt-panel-footer {
    padding: 16px 20px;
    background: var(--glass-bg);
    border-top: 1px solid var(--border);
}

.gpt-ask-current-btn {
    margin-bottom: 12px;
    padding: 14px 20px;
    font-size: 1rem;
}

.gpt-ask-current-btn .btn-icon {
    margin-right: 8px;
}

.gpt-ask-current-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gpt-panel-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    justify-content: center;
}

/* Question indicator in panel */
.gpt-current-question-indicator {
    background: var(--option-bg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    border-left: 4px solid var(--accent);
}

.gpt-current-question-indicator .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.gpt-current-question-indicator .question-preview {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Highlight animation for existing messages */
@keyframes highlight {
    0% { 
        box-shadow: 0 0 0 3px var(--accent);
        transform: scale(1.02);
    }
    100% { 
        box-shadow: none;
        transform: scale(1);
    }
}

/* Responsive — GPT panel (mobile handled in Panel Open section below) */
@media (max-width: 600px) {
    .gpt-panel-toggle {
        right: 16px;
        bottom: 16px;
        width: 56px;
        height: 56px;
    }
    
    .gpt-panel-toggle .toggle-icon {
        font-size: 1.5rem;
    }
}

/* Exam Size Selector */
.exam-size-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 24px 0;
}

.exam-size-option input[type="radio"] {
    display: none;
}

.exam-size-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px;
    background: var(--option-bg);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

@media (hover: hover) {
    .exam-size-card:hover {
        background: var(--option-hover);
        border-color: var(--accent);
        transform: translateY(-2px);
    }
}

.exam-size-option input[type="radio"]:checked + .exam-size-card {
    background: var(--accent-glow);
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.exam-size-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.exam-size-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.exam-size-count {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 600;
}

.exam-size-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Distribution Info */
.exam-distribution-info {
    background: var(--option-bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 24px;
}

.exam-distribution-info h4 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.distribution-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
    gap: 8px;
}

.distribution-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.distribution-item .cat-name {
    color: var(--text-secondary);
    font-size: 0.8rem;
    flex: 1;
}

.distribution-item .cat-count {
    color: var(--accent);
    font-weight: 600;
    margin-left: 8px;
}

/* Exam History */
.exam-history-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.exam-history-section h4 {
    margin-bottom: 12px;
    color: var(--text-primary);
}

.exam-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.exam-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--accent);
}

.exam-history-item.high { border-left-color: var(--success); }
.exam-history-item.mid { border-left-color: var(--warning); }
.exam-history-item.low { border-left-color: var(--error); }

.exam-history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.exam-history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.exam-history-type {
    font-weight: 600;
    color: var(--text-primary);
}

.exam-history-stats {
    display: flex;
    align-items: center;
    gap: 16px;
}

.exam-history-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.exam-history-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .exam-size-selector {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .exam-size-card {
        flex-direction: row;
        justify-content: flex-start;
        gap: 16px;
        padding: 16px;
    }
    
    .exam-size-icon {
        margin-bottom: 0;
    }
    
    .distribution-preview {
        grid-template-columns: 1fr 1fr;
    }
    
    .exam-history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .exam-history-stats {
        width: 100%;
        justify-content: space-between;
    }
}

/* Responsive - Small screens */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .tabs {
        gap: 4px;
        padding: 6px;
        margin-bottom: 20px;
    }
    
    .tab {
        padding: 10px 14px;
        font-size: 0.8rem;
    }
    
    .results-summary {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }
    
    .result-stat {
        width: 100%;
        max-width: 200px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .gpt-modal {
        max-width: 95%;
        padding: 20px;
    }
    
    .gpt-answers {
        flex-direction: column;
        gap: 8px;
    }
    
    /* Quiz actions - even more compact on small phones */
    .quiz-actions .btn {
        font-size: 0.85rem;
        padding: 8px 12px;
        min-height: 38px;
    }
    
    /* Exam nav buttons */
    .exam-nav-buttons .btn {
        flex: 1;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    /* Quiz card: header/tabs hidden via quiz-active, only subtract container padding */
    #quiz-area.card,
    #exam-area.card,
    #challenge-game.card {
        max-height: calc(var(--app-height, 100vh) - 16px);
        padding: 8px 8px 0;
    }
    
    /* Smaller header on small phones */
    .header {
        padding: 10px 12px;
        margin-bottom: 10px;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    /* Tabs compact */
    .tabs {
        margin-bottom: 10px;
        padding: 4px;
        gap: 3px;
    }
    
    .tab {
        padding: 8px 10px;
        font-size: 0.78rem;
    }
    
    /* Container less padding */
    .container {
        padding: 6px;
    }
    
    /* Even more compact quiz elements */
    .quiz-header {
        padding: 6px 8px;
        margin-bottom: 4px;
    }
    
    .progress-bar {
        height: 3px;
        margin-bottom: 4px;
    }
    
    .question-text {
        font-size: 0.88rem;
        padding: 8px 10px;
        margin-bottom: 4px;
    }
    
    .options-container {
        gap: 5px;
        margin-top: 4px;
    }
    
    .option {
        padding: 8px 10px;
        min-height: 36px;
        gap: 6px;
    }
    
    .option-select-btn {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }
    
    .option .text {
        font-size: 0.85rem;
        padding-top: 1px;
    }
    
    .feedback {
        padding: 8px 10px;
        margin-top: 6px;
        margin-bottom: 2px;
    }
    
    .feedback.correct p,
    .feedback.wrong p {
        font-size: 0.85rem;
    }
    
    /* User info compact */
    .user-info {
        padding: 6px 12px;
        gap: 8px;
    }
    
    .user-info span {
        font-size: 0.85rem;
    }
    
    /* Flashcard */
    .flashcard {
        height: 220px;
        max-width: 100%;
    }
    
    .flashcard-word {
        font-size: 1.6rem;
    }
    
    .flashcard-meaning {
        font-size: 1.1rem;
    }
    
    .flashcard-nav {
        flex-direction: column;
    }
    
    .flashcard-nav .btn {
        width: 100%;
    }
    
    /* Questions list */
    .questions-list {
        max-height: 500px;
    }
    
    .question-item {
        padding: 14px;
    }
    
    .question-item .answers {
        flex-direction: column;
        gap: 6px;
    }
    
    /* Btn large */
    .btn-large {
        padding: 14px 28px;
        font-size: 1.05rem;
        width: 100%;
    }
    
    /* Stats actions */
    .stats-actions .btn {
        min-width: unset;
    }
    
    /* History filter */
    #historyFilter {
        min-width: unset;
        width: 100%;
    }
    
    /* Exam result actions */
    .exam-result-actions {
        flex-direction: column;
    }
    
    .exam-result-actions .btn {
        width: 100%;
    }
    
    /* Challenge result actions */
    .challenge-result-actions {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .challenge-result-actions .btn {
        width: 100%;
    }
    
    /* Lobby actions */
    .lobby-actions {
        flex-direction: column;
    }
    
    .lobby-actions .btn {
        width: 100%;
    }
    
    /* Room code card */
    .room-code-card-value {
        font-size: 1.8rem;
    }
}

