/* CSS Reset & Variables */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --accent:         #2C5F63;
    --accent-hover:   #1C4145;
    --accent-tint:    #E7F0F0;

    --surface:        #FFFFFF;
    --background:     #F2F2F7;
    --border:         #D2D2D7;

    --text:           #1D1D1F;
    --text-secondary: #6E6E73;
    --text-tertiary:  #8E8E93;

    --success: #34C759;
    --warning: #FF9500;
    --error:   #FF3B30;
    --star:    #FFD60A;

    --radius:      8px;
    --radius-card: 12px;
    --transition:  150ms ease;
}

/* Base Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3 {
    font-weight: 500;
    letter-spacing: -0.01em;
}

h1 {
    letter-spacing: -0.02em;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 0.5px solid var(--border);
}

.header h1 {
    font-size: 1.75rem;
    color: var(--text);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info span {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding-right: 12px;
    border-right: 0.5px solid var(--border);
}

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

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 32px;
    border: 0.5px solid var(--border);
}

.login-card {
    max-width: 400px;
    margin: 60px auto;
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    margin-bottom: 24px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 95, 99, 0.15);
}

.form-group input::placeholder {
    color: var(--text-tertiary);
}

/* Select inputs */
.select-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236E6E73' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

.select-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 95, 99, 0.15);
}

/* Settings form */
.settings-form {
    margin-top: 24px;
}

.settings-form .form-group {
    margin-bottom: 24px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

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

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

.btn-primary:active {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    border: 0.5px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    font-size: 0.875rem;
}

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

.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0;
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.btn-link:hover {
    color: var(--accent);
}

.btn-full {
    width: 100%;
}

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

/* Lists Container */
.lists-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--background);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    border: 0.5px solid transparent;
}

.list-item:hover {
    background: var(--surface);
    border-color: var(--accent);
}

.list-item-name {
    font-weight: 500;
    font-size: 1rem;
}

.list-item-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.list-item-arrow {
    color: var(--text-secondary);
    font-size: 1.25rem;
}

/* Flashcards Info */
.flashcards-info {
    margin: 24px 0;
}

.flashcards-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--background);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    border: 0.5px solid var(--border);
}

.stat-number {
    font-size: 2rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Export Options */
.export-options {
    border-top: 0.5px solid var(--border);
    padding-top: 24px;
}

.option-group {
    margin-bottom: 20px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

.option-hint {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 6px;
    margin-left: 30px;
}

/* Progress */
.progress-container {
    margin-top: 20px;
}

.progress-bar {
    height: 6px;
    background: var(--background);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 300ms ease;
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 12px;
}

/* Messages */
.error-message {
    background: rgba(255, 59, 48, 0.08);
    color: var(--error);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-top: 16px;
}

.success-message {
    background: rgba(52, 199, 89, 0.08);
    color: var(--success);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-top: 16px;
}

/* Loading */
.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

.loading::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* Flashcard Preview */
.flashcard-preview {
    margin-top: 16px;
}

.flashcard-preview-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.preview-card {
    background: var(--background);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
    border: 0.5px solid var(--border);
}

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

.preview-card-front {
    border-left: 2px solid var(--accent);
    padding-left: 12px;
}

.preview-card-back {
    border-left: 2px solid var(--success);
    padding-left: 12px;
}

.preview-word {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--accent);
}

.preview-sentence {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 4px;
}

.preview-sentence b,
.preview-translation b {
    color: var(--accent);
    font-weight: 500;
    font-style: normal;
}

.preview-translation {
    font-size: 1.125rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 32px;
    max-width: 480px;
    width: 100%;
    border: 0.5px solid var(--border);
    animation: modalSlideIn 200ms ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-content h2 {
    margin-bottom: 24px;
}

.modal-section {
    margin-bottom: 24px;
}

.modal-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--background);
    border-radius: var(--radius);
    cursor: pointer;
    border: 0.5px solid transparent;
    transition: all var(--transition);
}

.radio-label:hover {
    border-color: var(--accent);
}

.radio-label input[type="radio"] {
    display: none;
}

.radio-custom {
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
    position: relative;
    transition: all var(--transition);
}

.radio-label input[type="radio"]:checked + .radio-custom {
    border-color: var(--accent);
    background: var(--accent);
}

.radio-label input[type="radio"]:checked + .radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

.radio-label input[type="radio"]:checked ~ .radio-text strong {
    color: var(--accent);
}

.radio-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.radio-text strong {
    font-weight: 500;
    transition: color var(--transition);
}

.radio-text small {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-actions .btn {
    flex: 1;
}

/* Small button */
.btn-small {
    padding: 8px 16px;
    font-size: 0.875rem;
}

/* Input field */
.input-field {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface);
    color: var(--text);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 95, 99, 0.15);
}

.input-field::placeholder {
    color: var(--text-tertiary);
}

.input-field:disabled {
    background-color: var(--background);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* Textarea field */
.textarea-field {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface);
    color: var(--text);
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
    min-height: 60px;
}

.textarea-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 95, 99, 0.15);
}

.textarea-field::placeholder {
    color: var(--text-tertiary);
}

.textarea-field:disabled {
    background-color: var(--background);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* Settings divider */
.settings-divider {
    height: 0.5px;
    background: var(--border);
    margin: 24px 0;
}

/* Warning message */
.warning-message {
    background: rgba(255, 149, 0, 0.08);
    color: #C47000;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.warning-message .btn-link {
    margin-bottom: 0;
    color: #C47000;
    font-weight: 600;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--background);
    padding: 4px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    border: 0.5px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    background: transparent;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    background: var(--surface);
    color: var(--accent);
}

/* Tab content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Form row (side by side) */
.form-row {
    display: flex;
    gap: 16px;
}

.form-group-half {
    flex: 1;
}

/* Generate results */
.generate-results {
    margin-top: 24px;
    border-top: 0.5px solid var(--border);
    padding-top: 24px;
}

.results-header {
    margin-bottom: 16px;
}

.results-header h3 {
    font-size: 1.125rem;
    margin-bottom: 4px;
}

.results-summary {
    font-size: 0.875rem;
    color: var(--success);
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Result item (flashcard) */
.result-item {
    background: var(--background);
    border-radius: var(--radius);
    padding: 16px;
    border: 0.5px solid var(--border);
    border-left: 2px solid var(--accent);
}

.result-item-word {
    font-size: 1rem;
    font-weight: 500;
    color: var(--accent);
    margin-bottom: 8px;
}

.result-item-sentence {
    font-size: 0.9375rem;
    margin-bottom: 4px;
}

.result-item-sentence b,
.result-item-translation b {
    color: var(--accent);
    font-weight: 500;
}

.result-item-translation {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
}

.result-item-audio {
    margin-top: 8px;
}

/* Play button */
.play-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--accent);
}

.play-btn:hover {
    border-color: var(--accent);
    background: var(--accent-tint);
}

.play-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Modal small */
.modal-small {
    max-width: 360px;
}

/* Option hint without margin-left (for settings) */
.settings-form .option-hint {
    margin-left: 0;
}

/* Danger button */
.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #D02020;
}

/* List Details Header */
.list-details-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.list-details-header .btn-link {
    margin-bottom: 0;
}

.list-details-actions {
    display: flex;
    gap: 8px;
}

/* Search box */
.search-box {
    margin-bottom: 20px;
}

/* Table container */
.table-container {
    overflow-x: auto;
    margin-top: 16px;
    width: 100%;
    max-width: 100%;
}

/* Flashcards table */
.flashcards-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
    table-layout: fixed;
}

.flashcards-table th,
.flashcards-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 0.5px solid var(--border);
}

.flashcards-table th {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--background);
    cursor: pointer;
    user-select: none;
}

.flashcards-table th:hover {
    color: var(--accent);
}

.flashcards-table th.sorted {
    color: var(--accent);
}

.flashcards-table th .sort-icon {
    margin-left: 4px;
    opacity: 0.5;
}

.flashcards-table th.sorted .sort-icon {
    opacity: 1;
}

.flashcards-table tbody tr {
    transition: background var(--transition);
}

.flashcards-table tbody tr:hover {
    background: var(--background);
}

.flashcards-table .word-cell {
    width: 9%;
    font-weight: 500;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flashcards-table .base-word-cell {
    width: 11%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flashcards-table .sentence-cell {
    width: 28%;
    white-space: normal;
    word-break: break-word;
}

.flashcards-table .sentence-cell b,
.flashcards-table .translation-cell b {
    color: var(--accent);
    font-weight: 500;
}

.flashcards-table .translation-cell {
    width: 28%;
    white-space: normal;
    word-break: break-word;
    color: var(--text-secondary);
    font-style: italic;
}

.flashcards-table .audio-cell {
    width: 12%;
    text-align: center;
    white-space: nowrap;
}

.flashcards-table .actions-cell {
    width: 12%;
    text-align: center;
    white-space: nowrap;
}

/* Delete button in table */
.delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 1rem;
    background: transparent;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.delete-btn:hover {
    background: rgba(255, 59, 48, 0.08);
    border-color: var(--error);
    color: var(--error);
}

.edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    margin-right: 4px;
    color: var(--text-secondary);
}

.edit-btn:hover {
    background: var(--accent-tint);
    border-color: var(--accent);
    color: var(--accent);
}

/* Delete modal message */
.delete-modal-message {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* Empty state button */
.empty-state .btn {
    margin-top: 16px;
}

/* Responsive */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }

    .card {
        padding: 24px;
    }

    .header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .flashcards-stats {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .user-info {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Custom Prompt Examples */
.custom-examples {
    background: var(--background);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 0.5px solid var(--border);
}

.custom-examples-title {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.custom-examples-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.example-chip {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.8125rem;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text);
    font-family: inherit;
    line-height: 1.4;
}

.example-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-tint);
}

/* Custom prompt button row */
.custom-btn-row {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.custom-generate-btn {
    flex: 1;
}

/* Auth switch link (login ↔ signup) */
.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    margin-left: 4px;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Field-level error (signup validation) */
.field-error {
    color: var(--error);
    font-size: 0.8125rem;
    margin-top: 4px;
}

/* Excel Export Toast Animation */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}
