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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background-color: #f8fafc;
    --card-background: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.tagline {
    opacity: 0.9;
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
}

/* Section Styles */
section {
    margin-bottom: 2rem;
}

section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Input Section */
.input-container {
    background: var(--card-background);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.input-container label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea::placeholder {
    color: var(--text-secondary);
}

/* Button Styles */
.button-group {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon {
    font-size: 1.1rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Results Section */
.results-section {
    animation: fadeIn 0.3s ease-out;
}

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

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
    .results-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Result Cards */
.result-card {
    background: var(--card-background);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.result-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Sentiment Display */
.sentiment-display {
    text-align: center;
    padding: 1rem 0;
}

.sentiment-emoji {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    animation: pulse 2s infinite;
}

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

.sentiment-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sentiment-score {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Sentiment Meter */
.sentiment-meter {
    margin-top: 1.5rem;
}

.meter-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.meter-bar {
    height: 12px;
    background: linear-gradient(to right, var(--danger-color), var(--warning-color), var(--success-color));
    border-radius: 6px;
    position: relative;
}

.meter-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease-out;
}

.meter-indicator {
    position: absolute;
    top: -4px;
    width: 20px;
    height: 20px;
    background: white;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    transform: translateX(-50%);
    transition: left 0.5s ease-out;
    box-shadow: var(--shadow-md);
}

/* Emotions Chart */
.emotions-chart {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.emotion-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.emotion-label {
    width: 80px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.emotion-bar-container {
    flex: 1;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.emotion-bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 0.5s ease-out;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0.5rem;
    min-width: 40px;
}

.emotion-bar-fill span {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Emotion Colors */
.emotion-joy { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.emotion-sadness { background: linear-gradient(90deg, #60a5fa, #3b82f6); }
.emotion-anger { background: linear-gradient(90deg, #f87171, #ef4444); }
.emotion-fear { background: linear-gradient(90deg, #a78bfa, #8b5cf6); }
.emotion-surprise { background: linear-gradient(90deg, #fb923c, #f97316); }
.emotion-disgust { background: linear-gradient(90deg, #4ade80, #22c55e); }
.emotion-trust { background: linear-gradient(90deg, #2dd4bf, #14b8a6); }
.emotion-anticipation { background: linear-gradient(90deg, #f472b6, #ec4899); }

/* Keywords Container */
.keywords-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.keyword-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    background: var(--background-color);
    border-radius: 9999px;
    font-size: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.keyword-tag:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-sm);
}

.keyword-positive {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.keyword-negative {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.keyword-neutral {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(100, 116, 139, 0.2);
}

/* Visualization */
.visualization {
    height: 200px;
    position: relative;
}

#emotion-canvas {
    width: 100%;
    height: 100%;
}

/* Feedback Section */
.feedback-card {
    background: var(--card-background);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    text-align: center;
}

.feedback-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.feedback-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.feedback-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--card-background);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.feedback-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
}

.feedback-btn.selected {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.feedback-message {
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
    border-radius: var(--radius-md);
    animation: fadeIn 0.3s ease-out;
}

.feedback-detail {
    margin-top: 1rem;
    text-align: left;
}

.feedback-detail label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.feedback-detail textarea {
    height: 80px;
    margin-bottom: 0.75rem;
}

/* History Section */
.history-container {
    background: var(--card-background);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
}

.history-empty {
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

.history-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item:hover {
    background: var(--background-color);
}

.history-item-text {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-sentiment {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

#clear-history-btn {
    margin-top: 1rem;
}

/* Footer */
.footer {
    background: var(--text-primary);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

.footer a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.footer a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Adjustments */
@media (max-width: 639px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .logo-container {
        flex-direction: column;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .emotion-label {
        width: 70px;
        font-size: 0.75rem;
    }

    .sentiment-emoji {
        font-size: 2.5rem;
    }
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-hover);
}
