/*
  Article Content Stylesheet
  Suggested Rails path: app/assets/stylesheets/content.css

  Scope:
  - Designed for Perron/Markdown-rendered article content inside:
      <div class="content-wrapper"><article>...</article></div>
  - Safe to load site-wide because most selectors are scoped to .content-wrapper article.
*/

.content-wrapper {
    --content-bg: #f7f8fb;
    --article-bg: #ffffff;
    --article-text: #172033;
    --article-muted: #5f6b7a;
    --article-soft: #eef2f7;
    --article-border: #dfe6ef;
    --article-link: #2458d3;
    --article-link-hover: #173fa1;
    --article-accent: #16a085;
    --article-accent-soft: #e8f8f4;
    --article-heading: #0f172a;
    --article-code-bg: #f4f6f8;
    --article-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);

    min-height: 100%;
    padding: clamp(1.25rem, 4vw, 4rem) clamp(1rem, 3vw, 2rem);
    color: var(--article-text);
}

.content-wrapper article {
    width: min(100%, 860px);
    margin: 0 auto;
    padding: clamp(1.5rem, 4vw, 4rem);
    background: var(--article-bg);
    border: 1px solid rgba(223, 230, 239, 0.85);
    border-radius: clamp(1rem, 2vw, 1.75rem);
    box-shadow: var(--article-shadow);
    font-family:
        Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    line-height: 1.78;
    letter-spacing: -0.006em;
}

.content-wrapper article>*:first-child {
    margin-top: 0;
}

.content-wrapper article>*:last-child {
    margin-bottom: 0;
}

/* Headings */

.content-wrapper article h1,
.content-wrapper article h2,
.content-wrapper article h3 {
    color: var(--article-heading);
    line-height: 1.14;
    letter-spacing: -0.035em;
    text-wrap: balance;
}

.content-wrapper article h1 {
    max-width: 25ch;
    margin: 0 0 1.25rem;
    font-size: clamp(2.25rem, 7vw, 1.6rem);
    font-weight: 850;
}

.content-wrapper article h1::after {
    content: "";
    display: block;
    width: 5rem;
    height: 0.34rem;
    margin-top: 1.35rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--article-link), var(--article-accent));
}

.content-wrapper article h2 {
    margin: clamp(3rem, 7vw, 5rem) 0 1rem;
    padding-top: clamp(1.35rem, 3vw, 2rem);
    border-top: 1px solid var(--article-border);
    font-size: clamp(1.75rem, 3.8vw, 1.2rem);
    font-weight: 800;
}

.content-wrapper article h3 {
    margin: clamp(2rem, 4vw, 3rem) 0 0.7rem;
    font-size: clamp(1.25rem, 2.4vw, 1rem);
    font-weight: 760;
}

.content-wrapper article h3::before {
    content: "";
    display: inline-block;
    width: 0.62rem;
    height: 0.62rem;
    margin-right: 0.55rem;
    border-radius: 50%;
    background: var(--article-accent);
    transform: translateY(-0.08rem);
}

/* Body copy */

.content-wrapper article p {
    margin: 1.05rem 0;
    color: var(--article-text);
}

.content-wrapper article h1+p {
    margin-top: 1.4rem;
    color: #ffffff;
    font-size: clamp(1.12rem, 1rem + 0.45vw, 1.38rem);
    line-height: 1.68;
}

.content-wrapper article strong {
    color: var(--article-heading);
    font-weight: 760;
}

.content-wrapper article em {
    color: var(--article-muted);
}

.content-wrapper article a {
    color: var(--article-link);
    font-weight: 650;
    text-decoration: none;
    text-decoration-thickness: 0.09em;
    text-underline-offset: 0.18em;
    background-image: linear-gradient(currentColor, currentColor);
    background-position: 0 100%;
    background-repeat: no-repeat;
    background-size: 100% 0.07em;
    transition:
        color 160ms ease,
        background-size 160ms ease,
        background-color 160ms ease;
}

.content-wrapper article a:hover,
.content-wrapper article a:focus-visible {
    color: var(--article-link-hover);
    background-size: 100% 0.15em;
}

.content-wrapper article a:focus-visible {
    outline: 3px solid rgba(36, 88, 211, 0.24);
    outline-offset: 0.22rem;
    border-radius: 0.22rem;
}

/* Lists */

.content-wrapper article ul,
.content-wrapper article ol {
    margin: 1.15rem 0 1.5rem;
    padding-left: 1.35rem;
}

.content-wrapper article li {
    margin: 0.55rem 0;
    padding-left: 0.18rem;
}

.content-wrapper article li::marker {
    color: var(--article-accent);
    font-weight: 800;
}

.content-wrapper article li p {
    margin: 0.45rem 0;
}

/* Tables
   Note: Markdown tables must be rendered as real <table> markup.
   Pipe-table text wrapped in <p> cannot be styled as a true table with CSS alone.
*/

.content-wrapper article table {
    width: 100%;
    margin: 1.6rem 0 2rem;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border: 1px solid var(--article-border);
    border-radius: 1rem;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
    font-size: 0.95em;
    line-height: 1.45;
}

.content-wrapper article th,
.content-wrapper article td {
    padding: 0.9rem 1rem;
    vertical-align: top;
    border-bottom: 1px solid var(--article-border);
}

.content-wrapper article th {
    background: #f8fafc;
    color: var(--article-heading);
    font-weight: 760;
    text-align: left;
}

.content-wrapper article tr:last-child td {
    border-bottom: 0;
}

.content-wrapper article tbody tr:nth-child(even) td {
    background: #fbfdff;
}

.content-wrapper article tbody tr:hover td {
    background: var(--article-accent-soft);
}

/* Optional: wrap real tables on small screens */

.content-wrapper article .table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1.6rem 0 2rem;
    border-radius: 1rem;
}

.content-wrapper article .table-wrapper table {
    margin: 0;
    min-width: 680px;
}

/* Quotes, code, media */

.content-wrapper article blockquote {
    margin: 1.7rem 0;
    padding: 1rem 1.25rem 1rem 1.35rem;
    border-left: 0.35rem solid var(--article-accent);
    border-radius: 0 1rem 1rem 0;
    background: var(--article-accent-soft);
    color: #ffffff;
}

.content-wrapper article code {
    padding: 0.16rem 0.36rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.38rem;
    background: var(--article-code-bg);
    color: #9a3412;
    font-family:
        "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.88em;
}

.content-wrapper article pre {
    overflow-x: auto;
    margin: 1.5rem 0;
    padding: 1.15rem 1.25rem;
    border-radius: 1rem;
    background: #ffffff;
    color: #e2e8f0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
}

.content-wrapper article pre code {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font-size: 0.92rem;
}

.content-wrapper article img,
.content-wrapper article video,
.content-wrapper article iframe {
    max-width: 100%;
    border-radius: 1rem;
}

.content-wrapper article img {
    height: auto;
    margin: 1.4rem 0;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.10);
}

/* Horizontal rules and anchors */

.content-wrapper article hr {
    height: 1px;
    margin: 3rem 0;
    border: 0;
    background: linear-gradient(90deg, transparent, var(--article-border), transparent);
}

.content-wrapper article :target {
    scroll-margin-top: 2rem;
}

/* Sources section: keeps long URLs/lists tidy */

.content-wrapper article h2:last-of-type+ul,
.content-wrapper article h2:last-of-type+ol {
    padding: 1rem 1.2rem 1rem 2.25rem;
    border: 1px solid var(--article-border);
    border-radius: 1rem;
    background: #fbfdff;
    font-size: 0.96em;
}

.content-wrapper article h2:last-of-type+ul a,
.content-wrapper article h2:last-of-type+ol a {
    overflow-wrap: anywhere;
}

/* JSON-LD schema should never create visible spacing */

.content-wrapper article script[type="application/ld+json"] {
    display: none !important;
}

/* Responsive polish */

@media (max-width: 720px) {
    .content-wrapper {
        padding: 0;
        background: var(--article-bg);
    }

    .content-wrapper article {
        width: 100%;
        padding: 1.2rem;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .content-wrapper article h1 {
        max-width: none;
        font-size: clamp(2.15rem, 12vw, 3.2rem);
    }

    .content-wrapper article h2 {
        margin-top: 2.75rem;
    }

    .content-wrapper article table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .content-wrapper article th,
    .content-wrapper article td {
        padding: 0.75rem 0.85rem;
    }
}

/* Print */

@media print {
    .content-wrapper {
        padding: 0;
        background: #ffffff;
    }

    .content-wrapper article {
        width: 100%;
        padding: 0;
        border: 0;
        box-shadow: none;
        color: #ffffff;
    }

    .content-wrapper article a {
        color: #ffffff;
        background: none;
        text-decoration: underline;
    }

    .content-wrapper article h2 {
        break-after: avoid;
    }

    .content-wrapper article table,
    .content-wrapper article blockquote,
    .content-wrapper article pre {
        break-inside: avoid;
    }
}