/* ==========================================================================
   Text Tools — the page shell.

   The Rust/WebAssembly application owns everything inside <canvas>; this
   stylesheet lays out the shell around it and the description below it. The
   three palettes match `ra-ui`'s exactly, so the canvas edge is invisible in
   every theme — a page that follows the system while the app does not is
   worse than one that ignores it.
   ========================================================================== */

:root {
    color-scheme: dark light;

    --bg: #0b0f17;
    --bg-elevated: #111725;
    --card: #182031;
    --border: #27334a;
    --text: #e5e9f0;
    --text-muted: #8b97ad;
    --accent: #4f8cff;
    --glow-a: rgba(79, 140, 255, 0.14);
    --glow-b: rgba(168, 85, 247, 0.10);
    --sunken: #0d131f;
    --shadow: rgba(0, 0, 0, 0.35);

    --ad-rail-width: 336px;
    --ad-banner-height: 132px;
    --gap: 16px;
}

/* The system's preference, but only while the visitor has not overruled it.
   `data-theme` is written by the application — and, before the first paint, by
   the small script in the page head that reads what it stored last time. */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]):not([data-theme="purple"]) {
        --bg: #eef1f7;
        --bg-elevated: #f4f6fa;
        --card: #ffffff;
        --border: #d5dbe6;
        --text: #161d2b;
        --text-muted: #5c687d;
        --accent: #1d5fd8;
        --sunken: #eceff5;
        --shadow: rgba(22, 29, 43, 0.10);
    }
}

/* An explicit choice wins in both directions. Every value here matches the
   palette of the same name in `ra-ui`, which is what makes the edge of the
   canvas invisible against the page it sits in. */
:root[data-theme="dark"] {
    color-scheme: dark;
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg: #eef1f7;
    --bg-elevated: #f4f6fa;
    --card: #ffffff;
    --border: #d5dbe6;
    --text: #161d2b;
    --text-muted: #5c687d;
    --accent: #1d5fd8;
    --sunken: #eceff5;
    --shadow: rgba(22, 29, 43, 0.10);
}

:root[data-theme="purple"] {
    color-scheme: dark;

    --bg: #2a0740;
    --bg-elevated: #380a4e;
    --card: #450c55;
    --border: #7f167f;
    --text: #ffeaf7;
    --text-muted: #e6a3c8;
    --accent: #ff4fa3;
    --sunken: #250630;
    --shadow: rgba(0, 0, 0, 0.45);
    --glow-a: rgba(255, 79, 163, 0.22);
    --glow-b: rgba(175, 1, 113, 0.20);
}

*,
*::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%, var(--glow-a), transparent 62%),
        radial-gradient(900px 520px at 96% 4%, var(--glow-b), 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 var(--shadow);
    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 and fallbacks ───────────────────────────────────────────────── */

.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(127, 127, 127, 0.22);
    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;
}

.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: var(--sunken);
    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(127, 127, 127, 0.04);
}

.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: the 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 (a phone held sideways): 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 tools, the questions ──────────── */

.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: color-mix(in srgb, var(--accent) 40%, transparent);
    text-underline-offset: 3px;
}

.prose a:hover,
.footer a:hover {
    text-decoration-color: currentColor;
}

/* ── Cards, steps, settings, questions ──────────────────────────────────── */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--gap);
    margin: 20px 0 8px;
}

.card {
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
}

.card p {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.6;
}

.card a {
    font-weight: 600;
}

.steps {
    margin: 0;
    padding-left: 1.2em;
    max-width: 72ch;
}

.steps li {
    margin-bottom: 8px;
}

.settings {
    margin: 0;
    max-width: 72ch;
}

.settings dt {
    margin-top: 16px;
    color: var(--text);
    font-weight: 600;
}

.settings dd {
    margin: 4px 0 0;
}

.faq {
    margin: 0;
    max-width: 72ch;
}

.faq dt {
    margin-top: 22px;
    color: var(--text);
    font-weight: 600;
}

.faq dd {
    margin: 6px 0 0;
}

.group-heading {
    margin: 34px 0 6px;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 600;
}

.crumbs {
    margin: 0 0 8px;
    font-size: 0.86rem;
}

/* ── 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: color-mix(in srgb, var(--text-muted) 40%, transparent);
    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;
}
