:root {
    --green-50: #ecfdf5;
    --green-100: #d1fae5;
    --green-500: #10b981;
    --green-600: #059669;
    --green-700: #047857;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --font-sans: "Inter", "Noto Sans Ethiopic", system-ui, -apple-system, sans-serif;
    --font-ethiopic: "Noto Sans Ethiopic", "Inter", system-ui, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--gray-800);
    background:
        radial-gradient(circle at top right, rgba(16, 185, 129, 0.08), transparent 28%),
        linear-gradient(180deg, var(--gray-50) 0%, var(--white) 40%, var(--gray-50) 100%);
    -webkit-font-smoothing: antialiased;
}

html[lang="am"] body {
    font-family: var(--font-ethiopic);
}

img,
svg {
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 16px 16px 32px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 12px;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--green-600), var(--green-500));
    color: var(--white);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    box-shadow: 0 8px 20px rgba(5, 150, 105, 0.25);
}

.brand-icon svg {
    width: 22px;
    height: 22px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-text strong {
    font-size: 1rem;
    color: var(--gray-900);
    line-height: 1.2;
}

.brand-text span {
    font-size: 0.78rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--gray-200);
    background: var(--white);
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.lang-switch svg {
    width: 18px;
    height: 18px;
    color: var(--green-600);
}

.lang-switch:hover {
    border-color: var(--green-500);
    color: var(--green-700);
    box-shadow: var(--shadow-sm);
}

.main-content {
    margin-top: 24px;
}

.hero {
    text-align: center;
    padding: 12px 8px 28px;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--green-50);
    color: var(--green-700);
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--green-100);
}

.hero h1 {
    margin: 16px 0 10px;
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    line-height: 1.15;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}

.hero p {
    margin: 0 auto;
    max-width: 620px;
    color: var(--gray-500);
    font-size: clamp(0.95rem, 2.5vw, 1.05rem);
    line-height: 1.6;
}

.workspace {
    display: grid;
    gap: 20px;
}

.panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--gray-900);
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--green-50);
    color: var(--green-700);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green-500);
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

.qr-input {
    width: 100%;
    min-height: 120px;
    padding: 16px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-50);
    color: var(--gray-800);
    resize: vertical;
    line-height: 1.6;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    margin-bottom: 16px;
    background: var(--gray-100);
    border-radius: 12px;
}

.mode-btn {
    min-height: 42px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.is-active {
    background: var(--white);
    color: var(--green-700);
    box-shadow: var(--shadow-sm);
}

.mode-panel.hidden {
    display: none;
}

.vcard-intro {
    margin-top: 0;
}

.vcard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0 16px;
}

.file-btn {
    cursor: pointer;
}

.vcard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.vcard-grid .option-field.full {
    grid-column: 1 / -1;
}

.text-input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--white);
    padding: 8px 12px;
    color: var(--gray-800);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-input:focus,
.vcard-note:focus {
    outline: none;
    border-color: var(--green-500);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12);
}

.vcard-note {
    min-height: 72px;
}

.qr-input:focus {
    outline: none;
    border-color: var(--green-500);
    background: var(--white);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12);
}

.input-hint,
.char-count,
.scan-hint {
    margin: 10px 0 0;
    font-size: 0.82rem;
    color: var(--gray-500);
}

.char-count {
    font-weight: 600;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.option-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--gray-600);
}

.select-input,
.color-input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: var(--white);
    padding: 8px 10px;
}

.color-input {
    padding: 4px;
    cursor: pointer;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.92rem;
    transition: all 0.2s ease;
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--green-600), var(--green-500));
    color: var(--white);
    box-shadow: 0 8px 20px rgba(5, 150, 105, 0.25);
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(5, 150, 105, 0.3);
}

.btn-outline {
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.btn-outline:hover {
    border-color: var(--green-500);
    color: var(--green-700);
}

.qr-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.qr-frame {
    position: relative;
    width: min(100%, 360px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, var(--gray-50), var(--white));
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border: 3px solid var(--green-600);
    z-index: 2;
}

.corner-tl { top: 18px; left: 18px; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.corner-tr { top: 18px; right: 18px; border-left: none; border-bottom: none; border-radius: 0 8px 0 0; }
.corner-bl { bottom: 18px; left: 18px; border-right: none; border-top: none; border-radius: 0 0 0 8px; }
.corner-br { bottom: 18px; right: 18px; border-left: none; border-top: none; border-radius: 0 0 8px 0; }

.scan-line {
    position: absolute;
    left: 12%;
    right: 12%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--green-500), transparent);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.6);
    animation: scan 2.8s ease-in-out infinite;
    z-index: 3;
    pointer-events: none;
}

@keyframes scan {
    0%, 100% { top: 18%; opacity: 0; }
    10% { opacity: 1; }
    50% { top: 82%; opacity: 1; }
    60% { opacity: 0; }
}

.qr-output {
    position: relative;
    z-index: 1;
    width: min(72%, 260px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
}

.qr-output img,
.qr-output canvas {
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
}

.qr-output.hidden {
    visibility: hidden;
    position: absolute;
    pointer-events: none;
}

.qr-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    color: var(--gray-500);
    z-index: 1;
}

.qr-empty.hidden {
    display: none;
}

.empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--green-50);
    color: var(--green-600);
    display: grid;
    place-items: center;
    margin-bottom: 12px;
}

.empty-icon svg {
    width: 28px;
    height: 28px;
}

.qr-empty strong {
    color: var(--gray-700);
    margin-bottom: 6px;
}

.qr-empty p {
    margin: 0;
    font-size: 0.88rem;
}

.features {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 24px;
}

.feature-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.feature-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--green-50);
    color: var(--green-600);
    display: grid;
    place-items: center;
    margin-bottom: 10px;
}

.feature-icon svg {
    width: 20px;
    height: 20px;
}

.feature-card h3 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    color: var(--gray-900);
}

.feature-card p {
    margin: 0;
    font-size: 0.84rem;
    color: var(--gray-500);
    line-height: 1.5;
}

.footer {
    margin-top: 28px;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.84rem;
}

.footer p {
    margin: 0;
}

.footer-sub {
    margin-top: 4px !important;
    color: var(--gray-400);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(120%);
    background: var(--gray-900);
    color: var(--white);
    padding: 12px 18px;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
    z-index: 100;
    max-width: calc(100% - 32px);
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

@media (min-width: 768px) {
    .app-shell {
        padding: 24px 24px 40px;
    }

    .workspace {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .panel-preview {
        position: sticky;
        top: 96px;
    }

    .features {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 767px) {
    .hero {
        padding: 4px 4px 12px;
        text-align: left;
    }

    .hero-badge {
        font-size: 0.7rem;
    }

    .hero h1 {
        margin: 8px 0 4px;
        font-size: 1.35rem;
    }

    .hero p {
        display: none;
    }

    .main-content {
        margin-top: 12px;
    }

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

    /* Preview first so realtime QR stays in view while typing */
    .panel-preview {
        order: 1;
    }

    .panel-input {
        order: 2;
    }

    .panel {
        padding: 14px;
    }

    .panel-preview .panel-header {
        flex-direction: row;
        align-items: center;
    }

    .panel-preview .panel-header .btn-primary {
        width: auto;
        min-height: 40px;
        padding: 0 12px;
        font-size: 0.85rem;
    }

    .qr-frame {
        width: min(100%, 280px);
    }

    .scan-hint {
        margin-top: 8px;
    }
}

@media (max-width: 640px) {
    .topbar {
        top: 0;
        border-radius: 0 0 var(--radius-md) var(--radius-md);
    }

    .app-shell {
        padding-left: 12px;
        padding-right: 12px;
        padding-top: 8px;
    }

    .brand-text span {
        display: none;
    }

    .panel-input .panel-header {
        flex-direction: column;
        align-items: stretch;
    }

    .options-grid {
        grid-template-columns: 1fr;
    }

    .vcard-grid {
        grid-template-columns: 1fr;
    }

    .vcard-actions .btn,
    .vcard-actions .file-btn {
        flex: 1;
        justify-content: center;
    }

    .action-row .btn {
        flex: 1;
    }

    .features {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scan-line,
    .live-dot {
        animation: none;
    }
}
