:root {
    --primary-pink: #FFB6C1;
    --deep-pink: #FF69B4;
    --soft-white: #FFF5F7;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --card-shadow: 0 15px 45px rgba(255, 105, 180, 0.12);
    --font-handwriting: 'Dancing Script', cursive;
    --font-main: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at top left, #FFF, #FFE4E1);
    font-family: var(--font-main);
    color: #4A4A4A;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    /* Respect hardware notches and home indicators */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top left, #FFF, #FFE4E1);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
}

.welcome-content {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 30px;
    border-radius: 35px;
    box-shadow: var(--card-shadow);
    max-width: 500px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 85vh;
}

.welcome-title {
    font-family: var(--font-handwriting);
    font-size: 2.5rem;
    color: var(--deep-pink);
    margin: 0;
}

.welcome-text-container {
    overflow-y: auto;
    text-align: left;
    padding-right: 10px;
    font-size: 1.1rem;
    line-height: 1.6;
    color: #555;
}

.welcome-text-container p {
    margin-bottom: 15px;
}

.welcome-text-container::-webkit-scrollbar {
    width: 4px;
}

.welcome-text-container::-webkit-scrollbar-thumb {
    background: var(--primary-pink);
    border-radius: 10px;
}

.primary-btn {
    background: var(--deep-pink);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 20px rgba(255, 105, 180, 0.3);
}

.primary-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 25px rgba(255, 105, 180, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: white;
    color: var(--deep-pink);
    border: 1px solid var(--primary-pink);
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.secondary-btn:hover {
    background: var(--soft-white);
    transform: translateY(-2px);
}

.secondary-btn.delete {
    color: #FF4444;
    border-color: #FFCCCC;
}

.secondary-btn.export {
    background: var(--soft-white);
    border-style: dashed;
}

.secondary-btn.sync {
    background: #24292e;
    color: white;
    border: none;
}

.secondary-btn.sync:hover {
    background: #2ea44f;
}

.hidden-trigger {
    position: fixed;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    z-index: 2000;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#editor-controls.hidden {
    display: none;
}

#editor-controls {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.card-input {
    width: 100%;
    min-height: 150px;
    border: 1px solid var(--primary-pink);
    border-radius: 20px;
    padding: 20px;
    font-family: var(--font-handwriting);
    font-size: 1.5rem;
    color: var(--deep-pink);
    resize: none;
    background: rgba(255, 255, 255, 0.5);
    margin: 20px 0;
}

.card-input:focus {
    outline: none;
    border-color: var(--deep-pink);
    background: white;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.export-area {
    font-family: monospace;
    font-size: 0.9rem;
    color: #333;
    white-space: pre;
    background: #f8f8f8;
}

.token-input {
    font-family: monospace;
    font-size: 1.1rem;
    min-height: 50px;
    margin: 10px 0;
}

.small-text {
    font-size: 0.8rem;
    color: #666;
    margin-top: 10px;
}

.small-text a {
    color: var(--deep-pink);
    text-decoration: none;
}

.small-text a:hover {
    text-decoration: underline;
}

.app-container {
    width: 100%;
    max-width: 400px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#card-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.card {
    perspective: 1500px;
    width: 90vw;
    max-width: 400px;
    aspect-ratio: 3/4;
    max-height: 70vh;
    /* Leave room for controls even on short screens */
    cursor: pointer;
    touch-action: manipulation;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-style: preserve-3d;
}

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

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: var(--card-shadow);
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    padding: 40px;
}

.card-front::after {
    content: '❤';
    font-size: 5rem;
    color: var(--deep-pink);
    opacity: 0.8;
}

.card-back {
    background: white;
    transform: rotateY(180deg);
}

.card-back p {
    font-family: var(--font-handwriting);
    font-size: 1.8rem;
    color: var(--deep-pink);
    line-height: 1.3;
    margin: 0;
}

.card-number {
    position: absolute;
    top: 30px;
    right: 30px;
    font-size: 1rem;
    color: var(--primary-pink);
    font-weight: 600;
}

/* Nav Controls */
.nav-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 40px 0;
}

.nav-btn {
    background: white;
    border: none;
    width: 60px;
    /* Improved touch target */
    height: 60px;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    color: var(--deep-pink);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover {
    background: var(--soft-white);
}

.nav-btn:active {
    transform: scale(0.9);
}

#card-index {
    font-size: 0.9rem;
    font-weight: 600;
    color: #AAA;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.card {
    animation: fadeIn 0.5s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%) rotate(5deg);
        opacity: 0;
    }

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

@keyframes slideInLeft {
    from {
        transform: translateX(-100%) rotate(-5deg);
        opacity: 0;
    }

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

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(-100%) rotate(-5deg);
        opacity: 0;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%) rotate(5deg);
        opacity: 0;
    }
}

.card.slide-in-right {
    animation: slideInRight 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.card.slide-in-left {
    animation: slideInLeft 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.card.slide-out-left {
    animation: slideOutLeft 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.card.slide-out-right {
    animation: slideOutRight 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

/* Floating Decorations */
.floating-hearts-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.floating-heart {
    position: absolute;
    color: var(--primary-pink);
    opacity: 0.3;
    font-size: 20px;
    animation: floatUp 15s linear infinite;
    bottom: -50px;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }

    10% {
        opacity: 0.3;
    }

    90% {
        opacity: 0.3;
    }

    100% {
        transform: translateY(-110vh) rotate(360deg);
        opacity: 0;
    }
}

@media (max-height: 600px) {
    .card {
        aspect-ratio: 1/1;
    }

    .card-back p {
        font-size: 1.4rem;
    }
}