* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4d7c0f;
    --primary-dark: #365314;
    --bg: #f4f7ed;
    --surface: #ffffff;
    --surface-light: #e9f0e0;
    --text: #1c1917;
    --text-muted: #57534e;
    --border: #d6d3d1;
    --success: #15803d;
    --error: #b91c1c;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 2rem 1rem;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-family: 'Courier New', Courier, monospace;
    font-size: 3rem;
    margin-bottom: 0.5rem;
    color: #2f3e2e;
    font-weight: 700;
    letter-spacing: -1px;
}

.subtitle {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-muted);
    font-size: 1.1rem;
    /* Slightly larger */
    letter-spacing: 0.5px;
    text-transform: none;
    transition: opacity 0.5s ease;
    /* For smooth name transition */
}

/* Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    background: transparent;
    padding: 0;
    border-bottom: 2px solid var(--border);
}

.tab {
    flex: 1;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: 0.2s;
}

.tab:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--primary);
}

.tab.active {
    background: transparent;
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Card Box */
.card-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 2.5rem;
    border: 1px solid var(--border);
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    gap: 1rem;
}

input {
    flex: 1;
    padding: 1rem;
    background: #fafaf9;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    transition: 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(77, 124, 15, 0.1);
}

input[type="number"] {
    width: 80px;
    flex: none;
}

.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(77, 124, 15, 0.3);
}

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

.btn-secondary {
    background: var(--surface-light);
    color: var(--primary-dark);
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #dce5d0;
    border-color: var(--primary);
}

/* Messages */
.message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    display: none;
    font-size: 0.9rem;
}

.message.show {
    display: block;
}

.message.success {
    color: #166534;
    background: #dcfce7;
    border: 1px solid #bbf7d0;
}

.message.error {
    color: #991b1b;
    background: #fee2e2;
    border: 1px solid #fecaca;
}

.loader {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* User Profile & Welcome */
.user-profile {
    position: absolute;
    top: 1.5rem;
    right: 2rem;
    z-index: 200;
}

.avatar-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: block;
    border-radius: 50%;
    transition: transform 0.2s;
}

.avatar-btn:hover {
    transform: scale(1.05);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: block;
}

.profile-dropdown {
    position: absolute;
    top: 120%;
    right: 0;
    width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 4px 6px rgba(0, 0, 0, 0.05);
    padding: 1rem;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    text-align: center;
    transform-origin: top right;
    animation: scaleIn 0.2s ease;
}

.profile-dropdown.active {
    display: flex;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.profile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border);
    width: 100%;
}

.sign-out-btn {
    background: transparent;
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
    font-weight: 500;
}

.sign-out-btn:hover {
    background: var(--error);
    color: white;
}

@media (max-width: 600px) {
    .user-profile {
        top: 1rem;
        right: 1rem;
    }

    .avatar {
        width: 40px;
        height: 40px;
    }
}

.controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Vert List */
.cards-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.list-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.list-card-item:hover {
    border-color: var(--primary);
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}

.list-card-preview {
    font-weight: 500;
    color: #292524;
    font-family: 'Georgia', serif;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90%;
}

.list-icon {
    color: var(--primary);
    font-size: 1.2rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(244, 247, 237, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content-wrapper {
    display: flex;
    align-items: center;
    gap: 3rem;
    width: 100%;
    max-width: 900px;
    justify-content: center;
}

.nav-arrow {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.modal-card {
    width: 550px;
    height: 380px;
    perspective: 1000px;
    cursor: pointer;
    /* IMPORTANT: Position relative for animation */
    position: relative;
}

.modal-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.modal-card.flipped .modal-card-inner {
    transform: rotateY(180deg);
}

.modal-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    color: var(--text);
}

.modal-front {
    background: #ffffff;
    font-family: 'Georgia', serif;
    font-size: 1.5rem;
    line-height: 1.5;
    color: #1c1917;
}

.modal-back {
    transform: rotateY(180deg);
    background: #fdfbf7;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 1.15rem;
    color: #44403c;
    line-height: 1.6;
}

.hint {
    margin-top: 2.5rem;
    font-size: 0.75rem;
    color: var(--primary);
    font-family: sans-serif;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.7;
}

.modal-close-icon {
    position: absolute;
    top: 2rem;
    right: 2rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    transition: 0.2s;
}

.modal-close-icon:hover {
    color: var(--error);
    transform: rotate(90deg);
}

.collapse-text-btn {
    margin-top: 3rem;
    background: white;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.8rem 2rem;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.collapse-text-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

/* --- CARD SWAP ANIMATIONS (New) --- */

/* Slide Out to Left */
@keyframes slideOutLeft {
    to {
        transform: translateX(-60px) scale(0.95);
        opacity: 0;
    }
}

/* Slide In from Right */
@keyframes slideInRight {
    from {
        transform: translateX(60px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

/* Slide Out to Right (for Previous button) */
@keyframes slideOutRight {
    to {
        transform: translateX(60px) scale(0.95);
        opacity: 0;
    }
}

/* Slide In from Left (for Previous button) */
@keyframes slideInLeft {
    from {
        transform: translateX(-60px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

/* Utility classes to trigger animations */
.anim-out-left {
    animation: slideOutLeft 0.25s forwards ease-in;
}

.anim-in-right {
    animation: slideInRight 0.25s forwards ease-out;
}

.anim-out-right {
    animation: slideOutRight 0.25s forwards ease-in;
}

.anim-in-left {
    animation: slideInLeft 0.25s forwards ease-out;
}

@media (max-width: 700px) {
    .modal-content-wrapper {
        gap: 1rem;
        flex-direction: column;
    }

    .modal-card {
        width: 90%;
        height: 350px;
    }

    .nav-arrow {
        width: 44px;
        height: 44px;
        margin: 0.5rem 0;
    }

    /* Responsive Input Group */
    .input-group {
        flex-direction: column;
    }

    .input-group .btn {
        width: 100%;
    }
}

/* App Loader */
.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.app-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-content .logo {
    font-family: 'Courier New', Courier, monospace;
    font-size: 2rem;
    color: #2f3e2e;
    font-weight: 700;
    margin-bottom: 1rem;
}

.loader-content .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* Links in Cards */
.card-link {
    color: var(--primary-dark);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
    transition: all 0.2s;
    position: relative;
    z-index: 2;
    /* Ensure clickable above card click area */
}

.card-link:hover {
    color: var(--primary);
    border-bottom-style: solid;
}

.detail-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.detail-link:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}