:root {
    --ink: #1a1714;
    --ink-soft: #3a342e;
    --paper: #f3ebe0;
    --paper-deep: #e6d8c6;
    --accent: #0f5c4c;
    --accent-deep: #0a3f35;
    --line: rgba(26, 23, 20, 0.14);
    --danger: #8b2e2e;
    --shadow: 0 18px 40px rgba(26, 23, 20, 0.08);
    --radius: 4px;
    --font-ar: "IBM Plex Sans Arabic", Tahoma, sans-serif;
    --font-display: "Libre Baskerville", "IBM Plex Sans Arabic", serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-ar);
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, rgba(15, 92, 76, 0.08), transparent 36%),
        linear-gradient(160deg, #f7f0e6 0%, var(--paper) 45%, #ebe1d2 100%);
    line-height: 1.6;
}

.ink-wash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(
            -12deg,
            transparent,
            transparent 18px,
            rgba(26, 23, 20, 0.015) 18px,
            rgba(26, 23, 20, 0.015) 19px
        );
    opacity: 0.7;
    z-index: 0;
}

.stage {
    position: relative;
    z-index: 1;
    width: min(980px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 3.5rem 0 5rem;
}

.brand-hero {
    margin-bottom: 2.5rem;
    animation: rise 0.7s ease both;
}

.eyebrow {
    margin: 0 0 0.6rem;
    color: var(--accent-deep);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.35rem;
}

.topbar .eyebrow {
    margin: 0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--ink-soft);
    font-size: 0.92rem;
}

.logout-btn {
    padding: 0.45rem 0.75rem;
}

.auth-body {
    min-height: 100vh;
}

.auth-stage {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: min(440px, 100%);
    background: rgba(255, 252, 247, 0.86);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 2rem 1.5rem 1.6rem;
    animation: rise 0.65s ease both;
}

.auth-title {
    margin: 0.25rem 0 0;
    font-family: var(--font-display);
    font-size: clamp(2rem, 6vw, 2.6rem);
    line-height: 1.1;
}

.auth-lede {
    margin: 0.75rem 0 1.25rem;
    color: var(--ink-soft);
}

.auth-form {
    display: grid;
    gap: 0.45rem;
}

.auth-form label:not(.remember) {
    margin-top: 0.55rem;
    font-weight: 600;
}

.auth-form input[type="email"],
.auth-form input[type="password"] {
    width: 100%;
    border: 1px solid var(--line);
    background: #fffaf3;
    color: var(--ink);
    border-radius: var(--radius);
    padding: 0.8rem 0.9rem;
    font: inherit;
}

.auth-form input:focus {
    outline: 2px solid rgba(15, 92, 76, 0.35);
    border-color: var(--accent);
}

.remember {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0.7rem 0 0.35rem;
    color: var(--ink-soft);
    font-size: 0.92rem;
}

.auth-submit {
    width: 100%;
    margin-top: 0.4rem;
}

.auth-error {
    margin-bottom: 1rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid rgba(139, 46, 46, 0.25);
    background: rgba(139, 46, 46, 0.08);
    color: var(--danger);
    border-radius: var(--radius);
}

.brand-name {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(3rem, 8vw, 5.4rem);
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.lede {
    margin: 1rem 0 0;
    max-width: 34rem;
    color: var(--ink-soft);
    font-size: 1.08rem;
}

.workspace {
    display: grid;
    gap: 1.4rem;
    animation: rise 0.8s ease 0.08s both;
}

.key-panel,
.prompt-panel,
.dropzone,
.result {
    background: rgba(255, 252, 247, 0.78);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.key-panel,
.prompt-panel {
    padding: 1.1rem 1.2rem;
    border-radius: var(--radius);
}

.key-panel label,
.prompt-panel label {
    display: block;
    margin-bottom: 0.45rem;
    font-weight: 600;
}

.prompt-panel textarea {
    width: 100%;
    resize: vertical;
    min-height: 120px;
    border: 1px solid var(--line);
    background: #fffaf3;
    color: var(--ink);
    border-radius: var(--radius);
    padding: 0.85rem 0.95rem;
    font: inherit;
    line-height: 1.55;
}

.prompt-panel textarea:focus {
    outline: 2px solid rgba(15, 92, 76, 0.35);
    border-color: var(--accent);
}

.key-row {
    display: flex;
    gap: 0.6rem;
}

.key-row input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--line);
    background: #fffaf3;
    color: var(--ink);
    border-radius: var(--radius);
    padding: 0.75rem 0.9rem;
    font: inherit;
}

.key-row input:focus {
    outline: 2px solid rgba(15, 92, 76, 0.35);
    border-color: var(--accent);
}

.hint {
    margin: 0.55rem 0 0;
    color: var(--ink-soft);
    font-size: 0.86rem;
}

.uploads {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.dropzone {
    position: relative;
    min-height: 260px;
    border-radius: var(--radius);
    border-style: dashed;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--accent);
    background: rgba(15, 92, 76, 0.05);
    transform: translateY(-2px);
}

.dropzone-body {
    display: grid;
    place-content: center;
    gap: 0.35rem;
    min-height: 260px;
    padding: 1.4rem;
    text-align: center;
}

.drop-kicker {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    margin: 0 auto 0.4rem;
    border-radius: 999px;
    background: var(--paper-deep);
    color: var(--accent-deep);
    font-weight: 700;
}

.dropzone strong {
    font-size: 1.15rem;
}

.dropzone span:last-child {
    color: var(--ink-soft);
    font-size: 0.92rem;
}

.dropzone .preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fffaf3;
    padding: 0.8rem;
}

.dropzone.has-file .dropzone-body {
    opacity: 0;
}

.actions {
    display: grid;
    gap: 0.75rem;
    justify-items: start;
}

.primary,
.ghost {
    font: inherit;
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.primary {
    border: 0;
    background: var(--accent);
    color: #f7f3ec;
    padding: 0.9rem 1.4rem;
    font-weight: 600;
}

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

.primary:disabled {
    opacity: 0.55;
    cursor: wait;
    transform: none;
}

.ghost {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink-soft);
    padding: 0.75rem 0.9rem;
}

.status {
    min-height: 1.4rem;
    margin: 0;
    color: var(--ink-soft);
}

.status.is-error {
    color: var(--danger);
}

.status.is-loading {
    color: var(--accent-deep);
}

.result {
    margin-top: 1.8rem;
    padding: 1.2rem;
    border-radius: var(--radius);
    animation: rise 0.55s ease both;
}

.result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.result-head h2 {
    margin: 0;
    font-size: 1.25rem;
}

.result-frame {
    margin: 0;
    background:
        linear-gradient(45deg, #efe4d4 25%, transparent 25%),
        linear-gradient(-45deg, #efe4d4 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #efe4d4 75%),
        linear-gradient(-45deg, transparent 75%, #efe4d4 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
    background-color: #f7f0e6;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.result-frame img {
    display: block;
    width: 100%;
    max-height: 720px;
    object-fit: contain;
    background: transparent;
}

.analysis {
    margin-top: 1rem;
    color: var(--ink-soft);
}

.analysis pre {
    margin: 0.75rem 0 0;
    padding: 0.9rem;
    overflow: auto;
    background: #fffaf3;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
    direction: ltr;
    text-align: left;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 760px) {
    .stage {
        padding-top: 2.2rem;
    }

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

    .result-head {
        flex-direction: column;
        align-items: stretch;
    }

    .key-row {
        flex-direction: column;
    }
}
