@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Light Mode Variables */
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-glow: rgba(79, 70, 229, 0.4);

    --bg-base: #f8fafc;
    --bg-mesh-1: #e0e7ff;
    --bg-mesh-2: #fae8ff;
    --bg-mesh-3: #fef08a;

    --surface: #ffffff;
    --surface-border: rgba(255, 255, 255, 0.5);

    --text-main: #1e293b;
    --text-muted: #64748b;

    --input-bg: #f1f5f9;
    --input-border: #e2e8f0;
    --input-focus: #4F46E5;
    --input-text: #0f172a;

    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #b91c1c;

    --card-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.08);
    --btn-shadow: 0 4px 14px 0 rgba(79, 70, 229, 0.39);

    --border-radius-lg: 24px;
    --border-radius-md: 14px;
    --border-radius-sm: 8px;

    --glass-blur: blur(20px);
}

body.dark-mode {
    /* Dark Mode Variables */
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-glow: rgba(129, 140, 248, 0.4);

    --bg-base: #020617;
    --bg-mesh-1: #1e1b4b;
    --bg-mesh-2: #312e81;
    --bg-mesh-3: #4c1d95;

    --surface: rgba(15, 23, 42, 0.7);
    --surface-border: rgba(255, 255, 255, 0.05);

    --text-main: #f8fafc;
    --text-muted: #cbd5e1;

    --input-bg: rgba(30, 41, 59, 0.5);
    --input-border: #334155;
    --input-focus: #818cf8;
    --input-text: #f1f5f9;

    --success-bg: rgba(20, 83, 45, 0.3);
    --success-text: #86efac;
    --error-bg: rgba(127, 29, 29, 0.3);
    --error-text: #fca5a5;

    --card-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    --btn-shadow: 0 4px 20px 0 rgba(99, 102, 241, 0.3);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 24px;
    position: relative;
    overflow-x: hidden;
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Beautiful Animated Background Mesh */
body::before,
body::after,
.bg-blob {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.6;
    transition: background-color 1s ease;
    animation: float 20s infinite alternate ease-in-out;
}

body::before {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, var(--bg-mesh-1), transparent 70%);
}

body::after {
    bottom: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--bg-mesh-2), transparent 70%);
    animation-delay: -5s;
}

.bg-blob {
    top: 30%;
    left: 40%;
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, var(--bg-mesh-3), transparent 70%);
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    50% {
        transform: translate(10%, 10%) scale(1.1);
    }

    100% {
        transform: translate(-5%, 15%) scale(0.9);
    }
}

/* App Container (Glassmorphism) */
.app-container {
    width: 100%;
    max-width: 560px;
    background: var(--surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--surface-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    position: relative;
    z-index: 10;
    animation: scaleUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes scaleUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

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

/* Header & Switch */
.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 32px 32px 0 32px;
}

.header-wrapper h1 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    background: linear-gradient(135deg, var(--text-main), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.theme-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mensaje-modo {
    display: none;
    /* Hide text, keep switch clean */
}

/* Toggle Switch Customization */
.theme-switch {
    display: inline-block;
    height: 32px;
    width: 56px;
    position: relative;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    transition: 0.4s;
    border-radius: 32px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 2;
}

input:checked+.slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.slider .icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    z-index: 1;
    transition: opacity 0.3s;
}

.slider .moon {
    right: 8px;
    opacity: 1;
}

.slider .sun {
    left: 8px;
    opacity: 0;
    color: #f59e0b;
}

input:checked+.slider .moon {
    opacity: 0;
}

input:checked+.slider .sun {
    opacity: 1;
}


/* Main Content area */
.main-content {
    padding: 24px 32px 32px 32px;
}

.source-link-main {
    margin-bottom: 24px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.source-link-main a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.source-link-main a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Forms & Inputs */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-md);
    font-size: 1rem;
    color: var(--input-text);
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
    outline: none;
}

.form-group select {
    appearance: none;
    /* Custom simple arrow for select */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2rem;
    padding-right: 2.5rem;
}

body.dark-mode .form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23cbd5e1'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background-color: var(--surface);
}

/* Primary Button */
.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 16px;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    box-shadow: var(--btn-shadow);
    transition: all 0.3s ease;
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px 0 var(--primary-glow);
}

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

/* Results Area */
.resultado-area {
    margin-top: 24px;
    min-height: 20px;
    /* Keep layout stable */
    transition: all 0.3s ease;
}

.resultado-area:empty {
    display: none;
}

.resultado-area p {
    padding: 18px;
    border-radius: var(--border-radius-md);
    text-align: center;
    font-size: 1rem;
    line-height: 1.5;
    animation: fadeIn 0.4s ease forwards;
}

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

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

.resultado-area p.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid rgba(22, 101, 52, 0.1);
}

.resultado-area p.success strong {
    font-weight: 700;
    font-size: 1.2rem;
    display: block;
    margin-top: 4px;
}

.resultado-area p.info {
    background-color: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--input-border);
}

.resultado-area p.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid rgba(185, 28, 28, 0.1);
}

/* Copy Button */
.copy-button-container {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    animation: fadeIn 0.5s ease forwards;
}

.copy-button-enhanced {
    background-color: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--input-border);
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.copy-button-enhanced:hover {
    background-color: var(--input-bg);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.copy-button-enhanced svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Copy Popup Toast */
.copy-popup {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translate(-50%, 20px) scale(0.9);
    background-color: var(--text-main);
    color: var(--bg-base);
    padding: 12px 24px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.copy-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0) scale(1);
}

.copy-popup.error {
    background-color: #ef4444;
}

/* History Area */
.history-container {
    margin-top: 32px;
    border-top: 1px solid var(--input-border);
    padding-top: 24px;
    animation: fadeIn 0.5s ease forwards;
}

.history-container h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-weight: 600;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.history-item:hover {
    border-color: var(--primary);
    background-color: var(--surface);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-text {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.history-copy-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-copy-btn:hover {
    background-color: var(--primary-glow);
    color: var(--primary);
    transform: scale(1.1);
}

.history-copy-btn svg {
    fill: currentColor;
    width: 16px;
    height: 16px;
}

/* Loading overlay */
.loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--surface-border), 0.5);
    /* using a hack basically a backdrop */
    backdrop-filter: blur(4px);
    border-radius: var(--border-radius-lg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 50;
    color: var(--primary);
    font-weight: 600;
    animation: fadeIn 0.2s ease forwards;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--primary-glow);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .app-container {
        border-radius: 20px;
    }

    .main-content {
        padding: 24px;
    }

    .header-wrapper {
        padding: 24px 24px 0 24px;
    }
}