:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --chat-user-bg: #6366f1;
    --chat-user-text: #ffffff;
    --chat-bot-bg: #f1f5f9;
    --chat-bot-text: #1e293b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 600px;
    background: var(--card-bg);
    height: 100vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

/* Header */
header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--text-main);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: var(--bg-color);
    color: var(--primary-color);
}

/* Settings Panel */
#settings-panel {
    background: var(--bg-color);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.settings-card h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.hidden {
    display: none !important;
}

/* Main Area */
main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.search-section {
    margin-bottom: 2rem;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
}

#word-input {
    flex: 1;
    padding: 0.85rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1.1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

#word-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0 1.5rem;
    border-radius: 12px;
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.feedback {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    padding: 0.5rem;
    border-radius: 6px;
}

.feedback.error {
    background: #fef2f2;
    color: #ef4444;
}

.feedback.success {
    background: #f0fdf4;
    color: #22c55e;
}

/* Chat */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 85%;
    padding: 1rem;
    border-radius: 12px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-bottom-left-radius: 4px;
}

/* Markdown Styles for Bot Messages */
.message.bot h1,
.message.bot h2,
.message.bot h3,
.message.bot h4 {
    margin: 0.5em 0 0.3em 0;
    font-weight: 600;
}

.message.bot h1 {
    font-size: 1.3em;
}

.message.bot h2 {
    font-size: 1.2em;
}

.message.bot h3 {
    font-size: 1.1em;
}

.message.bot p {
    margin: 0.5em 0;
}

.message.bot ul,
.message.bot ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message.bot li {
    margin: 0.25em 0;
}

.message.bot code {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message.bot pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.message.bot pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message.bot blockquote {
    border-left: 3px solid var(--primary-color);
    margin: 0.5em 0;
    padding-left: 1em;
    color: var(--text-muted);
}

.message.bot table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

.message.bot th,
.message.bot td {
    border: 1px solid var(--border-color);
    padding: 0.5em;
    text-align: left;
}

.message.bot th {
    background: var(--bg-color);
    font-weight: 600;
}

.message.bot strong {
    font-weight: 600;
}

.message.bot em {
    font-style: italic;
}

.welcome-message {
    text-align: center;
    color: var(--text-muted);
    margin-top: 2rem;
}

/* Footer Input */
.input-area {
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

#chat-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.95rem;
}

#chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.send-btn {
    color: var(--primary-color);
    background: #e0e7ff;
}

.send-btn:hover {
    background: #c7d2fe;
}

/* Tabs */
.app-tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #e0e7ff;
    color: var(--primary-color);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Views */
.view-section {
    display: none;
    flex-direction: column;
    gap: 1.5rem;
    animation: fadeIn 0.3s ease;
}

.view-section.active {
    display: flex;
}

/* Import Styles */
.import-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 3rem 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary-color);
    background: #f8fafc;
}

.upload-icon {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.sub-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Group List Styles */
.groups-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.group-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.group-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: var(--primary-color);
}

.group-card h4 {
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.group-card span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Study View Header */
.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.group-actions {
    display: flex;
    gap: 0.5rem;
}

.small-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: white;
    cursor: pointer;
    transition: background 0.2s;
}

.small-btn:hover {
    background: #f1f5f9;
    border-color: var(--text-muted);
}

/* Quiz Styles */
.quiz-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    text-align: center;
}

.placeholder-text {
    color: var(--text-muted);
}

.flashcard {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.card-content {
    margin-bottom: 1.5rem;
}

.card-content .label {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.quiz-text {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.4;
}

.card-input {
    display: flex;
    gap: 0.5rem;
}

.card-input input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.quiz-controls {
    display: flex;
    gap: 1rem;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
}

.secondary-btn:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

/* ===========================================
   FLASHCARD VIEW STYLES
   =========================================== */

.flashcard-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.flashcard-header h3 {
    text-align: center;
    color: var(--text-main);
    font-weight: 600;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    background: var(--bg-color);
    padding: 0.35rem;
    border-radius: 10px;
}

.mode-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    color: var(--primary-color);
}

.mode-btn.active {
    background: var(--card-bg);
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Flashcard Container */
.flashcard-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}

/* Flip Card Styles */
.flip-card-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.flip-card {
    width: 100%;
    max-width: 320px;
    height: 200px;
    perspective: 1000px;
    cursor: pointer;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.flip-card-front {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

.flip-card-back {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    transform: rotateY(180deg);
}

.card-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.flip-card-front .card-label {
    color: rgba(255, 255, 255, 0.8);
}

.flip-card-back .card-label {
    color: var(--text-muted);
}

.card-word {
    font-size: 1.8rem;
    font-weight: 600;
    text-align: center;
}

.card-def {
    font-size: 1.1rem;
    text-align: center;
    color: var(--text-main);
    line-height: 1.5;
}

.flip-hint {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Browse Mode Styles */
.browse-mode {
    width: 100%;
}

.browse-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.browse-word {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.browse-def {
    font-size: 1.1rem;
    color: var(--text-main);
    line-height: 1.5;
}

/* Spell Mode Styles */
.spell-mode {
    width: 100%;
}

.spell-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.spell-card .card-label {
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.spell-def {
    font-size: 1.2rem;
    color: var(--text-main);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.spell-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.spell-input-wrapper input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.spell-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#spell-feedback {
    margin-top: 1rem;
}

/* Flashcard Controls */
.flashcard-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 1rem 0;
}

.control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.control-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.card-counter {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    min-width: 60px;
    text-align: center;
}

/* Progress Bar */
.flashcard-progress {
    padding: 0 1rem;
}

.progress-bar {
    height: 4px;
    background: var(--bg-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* Animation for card transitions */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-in-right {
    animation: slideInRight 0.3s ease;
}

.slide-in-left {
    animation: slideInLeft 0.3s ease;
}