/* ==========================================================================
   Image Converter — page shell
   The Rust/WASM app owns everything inside <canvas>; this stylesheet only
   lays out the shell around it (app area + responsive advertisement rail).
   ========================================================================== */

:root {
    --bg: #0b0f17;
    --bg-elevated: #111725;
    --border: #1f2937;
    --text: #e5e9f0;
    --text-muted: #8b97ad;
    --accent: #4f8cff;

    --ad-rail-width: 336px;
    --ad-banner-height: 132px;
    --gap: 16px;
    --stack-breakpoint: 1100px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    margin: 0;
    background: var(--bg);
    background-image:
        radial-gradient(1100px 620px at 12% -8%, rgba(79, 140, 255, 0.16), transparent 62%),
        radial-gradient(900px 520px at 96% 4%, rgba(168, 85, 247, 0.12), transparent 58%);
    background-attachment: fixed;
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--ad-rail-width);
    gap: var(--gap);
    height: 100dvh;
    padding: var(--gap);
    padding-left: max(var(--gap), env(safe-area-inset-left));
    padding-right: max(var(--gap), env(safe-area-inset-right));
}

/* `min-*: 0` keeps grid children from being forced open by their content,
   which is what lets the canvas actually shrink with the viewport. */
.layout__app,
.layout__ads {
    min-width: 0;
    min-height: 0;
}

/* ── Application stage ──────────────────────────────────────────────────── */

.stage {
    position: relative;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--bg-elevated);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.stage__canvas {
    display: block;
    width: 100%;
    height: 100%;
    /* The app draws its own focus affordances. */
    outline: none;
    touch-action: none;
    /* Scrolling inside the app must not bounce the page behind it. */
    overscroll-behavior: none;
}

/* ── Loader / fallback overlays ─────────────────────────────────────────── */

.loader,
.fallback {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 32px;
    text-align: center;
    background: var(--bg-elevated);
}

.loader[hidden],
.fallback[hidden] {
    display: none;
}

.loader__spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255, 255, 255, 0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .loader__spinner {
        animation-duration: 3s;
    }
}

.loader__text {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}

.fallback__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.fallback__text {
    margin: 0;
    max-width: 46ch;
    color: var(--text-muted);
    line-height: 1.6;
}

.fallback__detail {
    max-width: 100%;
    max-height: 34%;
    margin: 0;
    padding: 12px 14px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: left;
    white-space: pre-wrap;
}

.fallback__detail:empty {
    display: none;
}

/* ── Advertisement rail ─────────────────────────────────────────────────── */

.ad-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    border: 1px dashed var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.02);
}

.ad-slot__label {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    opacity: 0.55;
}

/* ── Responsive: rail moves below the app on narrow viewports ───────────── */

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) var(--ad-banner-height);
    }
}

@media (max-width: 600px) {
    :root {
        --gap: 10px;
        --ad-banner-height: 108px;
    }

    .stage,
    .ad-slot {
        border-radius: 14px;
    }
}

/* Short viewports (e.g. landscape phones): the ad must not eat the app. */
@media (max-width: 1100px) and (max-height: 560px) {
    .layout {
        grid-template-rows: minmax(0, 1fr) 72px;
    }
}

/* ── Below the fold: the description, the FAQ, the footer ───────────────── */

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 8px var(--gap) 56px;
}

.prose {
    color: var(--text-muted);
    font-size: 0.98rem;
    line-height: 1.7;
}

.prose h2 {
    margin: 44px 0 14px;
    color: var(--text);
    font-size: 1.32rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.prose h2:first-child {
    margin-top: 8px;
}

.prose h3 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 0.98rem;
    font-weight: 600;
}

.prose p {
    margin: 0 0 14px;
    max-width: 72ch;
}

.prose strong {
    color: var(--text);
    font-weight: 600;
}

.prose a {
    color: var(--accent);
    text-decoration-color: rgba(79, 140, 255, 0.4);
    text-underline-offset: 3px;
}

.prose a:hover,
.footer a:hover {
    text-decoration-color: currentColor;
}

/* ── Feature cards ──────────────────────────────────────────────────────── */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--gap);
    margin: 20px 0 8px;
}

.card {
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-elevated);
}

.card p {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.65;
}

/* ── Steps and questions ────────────────────────────────────────────────── */

.steps {
    margin: 0;
    padding-left: 1.2em;
    max-width: 72ch;
}

.steps li {
    margin-bottom: 8px;
}

.faq {
    margin: 0;
    max-width: 72ch;
}

.faq dt {
    margin-top: 22px;
    color: var(--text);
    font-weight: 600;
}

.faq dd {
    margin: 6px 0 0;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.footer {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.86rem;
}

.footer p {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.footer a {
    color: var(--text-muted);
    text-decoration-color: rgba(139, 151, 173, 0.4);
    text-underline-offset: 3px;
}

/* Visible to assistive technology and to crawlers, not to the eye. The app
   draws the same words inside the canvas; this is the version a screen reader
   and a search engine can actually read. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
