/* ==========================================================================
   Share card dialog (partials/share-card-dialog.blade.php, hp-share-dialog.js).
   The card is drawn on the canvas in the size and style picked beside it;
   the dialog around it follows the page theme through the --hx-* tokens.
   Logical properties throughout, so Arabic pages mirror.
   ========================================================================== */

html.hp-sc-on { overflow: hidden; }

body.hp-ui .hp-sc {
    --hp-sc-h: min(calc(100dvh - 110px), 660px);
    position: fixed; inset: 0; z-index: 2147481000;
    display: grid; place-items: center; padding: 24px;
    color: var(--hx-ink); font-family: var(--hx-f-body);
}
body.hp-ui .hp-sc[hidden] { display: none; }

body.hp-ui .hp-sc-scrim {
    position: absolute; inset: 0;
    background: rgba(3, 12, 8, .7);
    opacity: 0; transition: opacity .26s ease;
}

body.hp-ui .hp-sc-panel {
    position: relative; display: grid; grid-template-columns: auto minmax(300px, 340px);
    max-width: 100%; max-height: calc(100dvh - 48px);
    background: var(--hx-surface); border: 1px solid var(--hx-line); border-radius: 30px;
    box-shadow: var(--hx-shadow-lg); overflow: hidden;
    opacity: 0; transform: translateY(16px) scale(.985);
    transition: opacity .28s var(--hx-ease), transform .34s var(--hx-ease);
}
body.hp-ui .hp-sc.is-open .hp-sc-scrim { opacity: 1; }
body.hp-ui .hp-sc.is-open .hp-sc-panel { opacity: 1; transform: none; }

/* ---------- The stage: the canvas on the library backdrop ---------- */
body.hp-ui .hp-sc-stage {
    position: relative; display: grid; place-items: center; padding: 30px;
    width: calc(var(--hp-sc-h) * .8 + 60px); min-height: calc(var(--hp-sc-h) + 60px);
    background:
        radial-gradient(120% 70% at 10% 0%, rgba(35, 107, 82, .42), transparent 62%),
        radial-gradient(90% 60% at 100% 100%, rgba(184, 137, 74, .14), transparent 70%),
        var(--hx-stage);
}
/* The canvas keeps its own shape (story, portrait or square) inside the same stage. */
body.hp-ui .hp-sc-canvas {
    display: block; width: auto; height: auto; max-width: 100%; max-height: var(--hp-sc-h);
    border-radius: 16px;
    box-shadow: 0 0 0 1px rgba(230, 201, 149, .3), 0 34px 70px -30px rgba(0, 0, 0, .95);
    transition: opacity .2s ease;
}
body.hp-ui .hp-sc-canvas.is-drawing { opacity: .3; }
body.hp-ui .hp-sc-wait {
    position: absolute; inset-inline: 30px; top: 50%; max-width: 32ch; margin: 0 auto; transform: translateY(-50%);
    text-align: center; font-size: .95rem; line-height: 1.6; letter-spacing: .01em; color: var(--hx-on-stage-2);
    pointer-events: none;
}
body.hp-ui .hp-sc-wait[hidden] { display: none; }

/* ---------- The side: title, sentence picker, actions ---------- */
body.hp-ui .hp-sc-side {
    display: flex; flex-direction: column; gap: 22px; min-width: 0;
    padding: 40px 30px 30px; overflow-y: auto;
}
body.hp-ui .hp-sc-head { display: grid; gap: 10px; padding-inline-end: 34px; }
body.hp-ui .hp-sc-eyebrow {
    margin: 0; font-size: .74rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
    color: var(--hx-quill-ink);
}
body.hp-ui .hp-sc-title {
    margin: 0; font-family: var(--hx-f-display); font-weight: 400;
    font-size: 2.05rem; line-height: 1.04; letter-spacing: -.01em; color: var(--hx-ink);
}
body.hp-ui .hp-sc-note { margin: 2px 0 0; font-size: .9rem; line-height: 1.55; color: var(--hx-ink-3); }

/* ---------- Size and style ---------- */
body.hp-ui .hp-sc-looks { display: grid; gap: 18px; }
body.hp-ui .hp-sc-pick { min-width: 0; margin: 0; padding: 0; border: 0; }
body.hp-ui .hp-sc-pick-label {
    padding: 0; margin: 0 0 9px; font-size: .74rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
    color: var(--hx-ink-3);
}
body.hp-ui .hp-sc-sizes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
body.hp-ui .hp-sc-styles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
body.hp-ui .hp-sc-opt {
    position: relative; display: grid; justify-items: center; align-content: center; gap: 7px;
    min-height: 74px; padding: 10px 4px 8px; border-radius: 14px;
    border: 1px solid var(--hx-line); background: var(--hx-surface);
    color: var(--hx-ink-2); cursor: pointer; text-align: center;
    transition: border-color .18s ease, background-color .18s ease, color .18s ease;
}
body.hp-ui .hp-sc-opt[hidden] { display: none; }
body.hp-ui .hp-sc-opt input {
    position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
}
body.hp-ui .hp-sc-opt:hover { border-color: var(--hx-line-2); color: var(--hx-ink); }
body.hp-ui .hp-sc-opt:has(input:checked) {
    border-color: var(--hx-quill); background: var(--hx-surface-2); color: var(--hx-ink);
    box-shadow: inset 0 0 0 1px var(--hx-quill);
}
body.hp-ui .hp-sc-opt:has(input:focus-visible) { outline: 2px solid var(--hx-focus); outline-offset: 2px; }
body.hp-ui .hp-sc-opt-name { font-size: .8rem; font-weight: 600; line-height: 1.2; }
html[lang="ar"] body.hp-ui .hp-sc-opt-name { font-size: .78rem; }

/* The size: its outline, in proportion (9:16, 4:5, 1:1). */
body.hp-ui .hp-sc-opt-shape {
    display: block; width: 18px; height: 22.5px; border-radius: 3px;
    border: 1.5px solid currentColor; opacity: .7;
}
body.hp-ui .hp-sc-opt-shape.is-story { width: 14px; height: 25px; }
body.hp-ui .hp-sc-opt-shape.is-square { width: 21px; height: 21px; }
body.hp-ui .hp-sc-opt:has(input:checked) .hp-sc-opt-shape { border-color: var(--hx-quill); background: color-mix(in srgb, var(--hx-quill) 22%, transparent); opacity: 1; }
body.hp-ui .hp-sc-pick-note { margin: 8px 0 0; font-size: .8rem; line-height: 1.45; color: var(--hx-ink-3); font-variant-numeric: tabular-nums; }

/* The style: a small swatch of each card. */
body.hp-ui .hp-sc-swatch {
    position: relative; display: block; width: 30px; height: 36px; border-radius: 6px; overflow: hidden;
    box-shadow: 0 0 0 1px rgba(20, 35, 28, .18), 0 6px 14px -8px rgba(0, 0, 0, .5);
}
body.hp-ui .hp-sc-swatch::after { content: ""; position: absolute; }
body.hp-ui .hp-sc-swatch.is-library { background: radial-gradient(120% 80% at 20% 10%, #1f684d, transparent 70%), #06100b; }
body.hp-ui .hp-sc-swatch.is-library::after { inset: 4px; border: 1px solid rgba(230, 201, 149, .45); border-radius: 4px; }
body.hp-ui .hp-sc-swatch.is-paper { background: #f5eddc; }
body.hp-ui .hp-sc-swatch.is-paper::after {
    top: 5px; inset-inline-end: 4px; width: 12px; height: 12px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fbe6b2, #c68b3e 55%, #5f3610);
}
body.hp-ui .hp-sc-swatch.is-night { background: linear-gradient(#11392b, #071d15); }
body.hp-ui .hp-sc-swatch.is-night::after { inset: 3px; border: 1px solid rgba(232, 203, 147, .75); }
body.hp-ui .hp-sc-swatch.is-quote { background: #fbf8f2; }
body.hp-ui .hp-sc-swatch.is-quote::after {
    content: "A"; top: 3px; inset-inline-start: 4px;
    font: 400 22px/1 var(--hx-f-display); color: #9a6b2b;
}
html[data-hp-theme="dark"] body.hp-ui .hp-sc-swatch { box-shadow: 0 0 0 1px rgba(244, 236, 221, .22), 0 6px 14px -8px rgba(0, 0, 0, .8); }

body.hp-ui .hp-sc-cycle {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding-block: 16px; border-block: 1px solid var(--hx-line);
}
body.hp-ui .hp-sc-cycle[hidden] { display: none; }
body.hp-ui .hp-sc-count { margin: 0; font-size: .84rem; font-variant-numeric: tabular-nums; color: var(--hx-ink-3); }

body.hp-ui .hp-sc-actions { display: grid; gap: 10px; margin-top: auto; }

body.hp-ui .hp-sc-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 48px; padding: 0 20px; border-radius: 999px;
    border: 1px solid var(--hx-line-2); background: var(--hx-surface-2); color: var(--hx-ink);
    font: 700 .95rem/1 var(--hx-f-body); cursor: pointer;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .18s var(--hx-ease);
}
body.hp-ui .hp-sc-btn[hidden] { display: none; }
body.hp-ui .hp-sc-btn:hover:not(:disabled) { border-color: var(--hx-quill); }
body.hp-ui .hp-sc-btn:active:not(:disabled) { transform: translateY(1px); }
body.hp-ui .hp-sc-btn:disabled { opacity: .5; cursor: not-allowed; }
body.hp-ui .hp-sc-btn-primary { background: var(--hx-btn); border-color: var(--hx-btn); color: #fff; }
body.hp-ui .hp-sc-btn-primary:hover:not(:disabled) { background: var(--hx-royal-hover); border-color: var(--hx-royal-hover); }
body.hp-ui .hp-sc-btn-quiet { min-height: 44px; padding: 0 16px; background: transparent; }
body.hp-ui .hp-sc-btn:focus-visible,
body.hp-ui .hp-sc-close:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 3px; }
body.hp-ui .hp-sc-i { width: 18px; height: 18px; flex: none; }

body.hp-ui .hp-sc-status { min-height: 1.5em; margin: -6px 0 0; font-size: .86rem; line-height: 1.5; color: var(--hx-ink-3); }
body.hp-ui .hp-sc-status.is-ok { color: var(--hx-ok); }
body.hp-ui .hp-sc-status.is-error { color: var(--hx-danger); }

body.hp-ui .hp-sc-close {
    position: absolute; top: 14px; inset-inline-end: 14px;
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--hx-ink-2);
    cursor: pointer; transition: background-color .18s ease, color .18s ease;
}
body.hp-ui .hp-sc-close:hover { background: var(--hx-surface-2); color: var(--hx-ink); }

/* Arabic: the display face does not take letter-spacing (it breaks the joins). */
html[lang="ar"] body.hp-ui :is(.hp-sc-eyebrow, .hp-sc-title) { letter-spacing: 0; }
html[lang="ar"] body.hp-ui .hp-sc-title { line-height: 1.3; }

/* ---------- Phones: a sheet from the bottom ---------- */
@media (max-width: 760px) {
    body.hp-ui .hp-sc { --hp-sc-h: max(220px, min(calc(100dvh - 430px), 560px)); padding: 0; place-items: end stretch; }
    body.hp-ui .hp-sc-panel {
        grid-template-columns: minmax(0, 1fr); width: 100%; max-height: 100dvh;
        border-radius: 26px 26px 0 0; border-inline: 0; border-bottom: 0; overflow-y: auto;
        transform: translateY(32px);
    }
    body.hp-ui .hp-sc-stage { width: auto; min-height: calc(var(--hp-sc-h) + 38px); padding: 20px 20px 18px; }
    body.hp-ui .hp-sc-canvas { border-radius: 12px; }
    body.hp-ui .hp-sc-looks { gap: 12px; }
    body.hp-ui .hp-sc-opt { min-height: 64px; padding-block: 8px 6px; gap: 5px; }
    body.hp-ui .hp-sc-side { gap: 14px; padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); overflow: visible; }
    body.hp-ui .hp-sc-head { padding-inline-end: 0; gap: 6px; }
    body.hp-ui .hp-sc-title { font-size: 1.55rem; }
    body.hp-ui .hp-sc-note { font-size: .84rem; }
    body.hp-ui .hp-sc-cycle { padding-block: 10px; }
    body.hp-ui .hp-sc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
    body.hp-ui .hp-sc-actions .hp-sc-btn { flex: 1 1 140px; padding: 0 10px; font-size: .88rem; gap: 7px; }
    body.hp-ui .hp-sc-actions .hp-sc-btn-primary { flex-basis: 100%; }
    body.hp-ui .hp-sc-close {
        top: 10px; inset-inline-end: 10px; color: var(--hx-on-stage);
        background: rgba(4, 23, 15, .55); border-color: rgba(230, 201, 149, .24);
    }
    body.hp-ui .hp-sc-close:hover { background: rgba(4, 23, 15, .8); color: var(--hx-on-stage); }
    body.hp-ui .hp-sc-close:focus-visible { outline-color: var(--hx-focus-on-stage); }
}

@media (prefers-reduced-motion: reduce) {
    body.hp-ui :is(.hp-sc-scrim, .hp-sc-panel, .hp-sc-canvas, .hp-sc-btn, .hp-sc-close, .hp-sc-opt) { transition: none; }
    body.hp-ui .hp-sc-panel { transform: none; }
}
