/* =========================================
   Blog: list (/blog) and post (/blog/<id>)
   The hero sits on the homepage sky (index.css, body.home-page); everything
   below it is on a solid page that slides up over the sky like a sheet.
   ========================================= */

.blog-page {
    --bl-ink: #061226;
    --bl-muted: #5B6478;
    --bl-line: #E3E8F0;
    --bl-sheet: #FAFDFF; /* the homepage off-white, so the footer and wordmark blend in */
    --bl-soft: #F3F6FA;
    --bl-blue: #387FD9;
    /* Post page columns: contents | post | author. They grow on wide screens. */
    --bp-cols: minmax(220px, 280px) minmax(0, 780px) minmax(260px, 340px);
    background-color: var(--bg); /* off-white the sky fades into */
    color: var(--bl-ink);
    font-family: 'Inter', 'Helvetica Neue', system-ui, sans-serif;
}

body.dark.blog-page {
    --bl-ink: #F2F4F7;
    --bl-muted: #9AA3B2;
    --bl-line: #2A2D33;
    --bl-sheet: #141414;
    --bl-soft: #202227;
    --bl-blue: #6DB0EC;
    background-color: #141414;
}

.blog-page .main-container {
    min-height: auto;
}

/* Zero specificity, so every rule below can set its own spacing */
:where(.blog-page) :where(h1, h2, h3, p, ol, ul) {
    margin: 0;
}

/* The closing band and footer continue the solid sheet */
.bl-closing {
    position: relative;
    z-index: 1;
    background: var(--bl-sheet);
}

.blog-page .site-footer {
    position: relative;
    z-index: 1;
    margin-top: 0;
    border-top-color: var(--bl-line);
    background: var(--bl-sheet);
}

/* ---- Hero on the sky (both pages): white text; small text is semibold so it
   still reads where the blue lightens lower down ---- */
.bl-hero,
.bp-hero {
    --hero-text: #FFFFFF;
    --hero-soft: rgba(255, 255, 255, 0.9);
    color: var(--hero-text);
    text-shadow: 0 1px 2px rgba(6, 18, 38, 0.18);
    position: relative;
    z-index: 1;
    max-width: 1680px;
    margin: 0 auto;
    padding: 150px 32px 64px;
}

.bl-hero h1 {
    font-size: clamp(44px, 7vw, 88px);
    font-weight: 800;
    letter-spacing: -0.045em;
    line-height: 1;
}

.bl-hero-sub {
    margin-top: 16px;
    max-width: 34em;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--hero-soft);
}

/* Search + topics */
.bl-tools {
    margin-top: 36px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px 28px;
}

.bl-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(100%, 400px);
    height: 52px;
    padding: 0 18px;
    border-radius: 16px;
    background: var(--bl-sheet);
    color: var(--bl-muted);
    box-shadow: 0 10px 30px -10px rgba(10, 40, 90, 0.35);
    text-shadow: none;
}

.bl-search:focus-within {
    outline: 3px solid var(--bl-ink);
    outline-offset: 2px;
}

.bl-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: none;
    font: inherit;
    font-size: 16px; /* 16px stops iOS zooming in */
    color: var(--bl-ink);
}

.bl-search input::placeholder {
    color: var(--bl-muted);
}

/* Category dropdown: same white pill as the search box, native <select> underneath */
.bl-select {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 52px;
    padding: 0 16px 0 18px;
    border-radius: 16px;
    background: var(--bl-sheet);
    color: var(--bl-muted);
    box-shadow: 0 10px 30px -10px rgba(10, 40, 90, 0.35);
    text-shadow: none;
}

.bl-select:focus-within {
    outline: 3px solid var(--bl-ink);
    outline-offset: 2px;
}

.bl-select select {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    outline: 0;
    background: none;
    padding-right: 26px;
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    color: var(--bl-ink);
    cursor: pointer;
}

.bl-select-chev {
    position: absolute;
    right: 14px;
    pointer-events: none;
}

/* ---- The solid sheet below the sky ---- */
.bl-page,
.bp-page {
    position: relative;
    z-index: 1;
    background: var(--bl-sheet);
    border-radius: 36px 36px 0 0;
    padding: 56px 0 96px;
}

.bl-wrap {
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 32px;
}

/* ---- Post cards ---- */
.bl-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 40px 28px;
}

.bl-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
    border-radius: 24px;
    --spot-opacity: 0.12;
}

.bl-card[hidden] {
    display: none;
}

.bl-cover {
    position: relative;
    aspect-ratio: 40 / 21; /* the share card's shape (1200 x 630) */
    border-radius: 20px;
    overflow: hidden;
    background: #387FD9;
    color: #fff;
}

.bl-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bl-cover-title {
    position: absolute;
    left: 24px;
    right: 24px;
    bottom: 22px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.15;
    text-wrap: balance;
}

.bl-card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 4px 4px;
}

.bl-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    font-size: 14px;
    color: var(--bl-muted);
}

.bl-meta-tag {
    font-weight: 600;
    color: var(--bl-blue);
}

.bl-card-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.bl-card-title a {
    color: inherit;
    text-decoration: none;
}

/* The title link covers the whole card */
.bl-card-title a::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: 24px;
}

.bl-card-title a:focus-visible {
    outline: none;
}

.bl-card-title a:focus-visible::after {
    outline: 3px solid var(--bl-blue);
    outline-offset: 6px;
}

.bl-card:hover .bl-card-title a {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.bl-card-summary {
    font-size: 16px;
    line-height: 1.6;
    color: var(--bl-muted);
}

.bl-cover img,
.bl-cover-title {
    transition: transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.bl-card:hover .bl-cover-title,
.bl-card:hover .bl-cover img {
    transform: translateY(-4px);
}

/* Featured: the newest (or first matching) post, cover beside the text */
.bl-card--featured {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    align-items: center;
    gap: 48px;
}

.bl-card--featured .bl-cover {
    aspect-ratio: 40 / 21;
}

.bl-card--featured .bl-cover-title {
    left: 36px;
    right: 36px;
    bottom: 32px;
    font-size: clamp(26px, 3vw, 40px);
}

.bl-card--featured .bl-card-title {
    font-size: clamp(28px, 3.4vw, 44px);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.1;
}

.bl-card--featured .bl-card-summary {
    font-size: 18px;
}

.bl-read {
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--bl-ink);
    transition: gap 0.2s ease;
}

.bl-card:hover .bl-read {
    gap: 10px;
}

.bl-read .material-icons-round {
    font-size: 18px;
}

.bl-edit {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--bl-sheet);
    color: var(--bl-ink);
    text-decoration: none;
}

.bl-edit .material-icons-round {
    font-size: 17px;
}

.bl-none {
    padding: 48px 0;
    font-size: 17px;
    color: var(--bl-muted);
}

/* ---- Post page: hero, on the same columns as the post so its text lines up ---- */
.bp-hero {
    max-width: 1680px;
    padding-bottom: 72px;
    display: grid;
    grid-template-columns: var(--bp-cols);
    justify-content: space-between;
    column-gap: 64px;
}

/* The hero text runs across the post and right columns, so the title wraps less */
.bp-hero > * {
    grid-column: 2 / 4;
}

.bp-summary {
    max-width: 44em;
}

.bp-crumbs {
    display: flex;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--hero-soft);
}

.bp-crumbs a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.bp-crumbs a:hover {
    color: var(--hero-text);
}

.bp-title {
    margin-top: 20px;
    font-size: clamp(36px, 5.6vw, 64px);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.05;
    text-wrap: balance;
}

.bp-summary {
    margin-top: 20px;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--hero-soft);
}

.bp-byline {
    margin-top: 32px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--hero-soft);
}

.bp-byline img {
    width: 40px;
    height: auto;
}

.bp-byline p {
    display: flex;
    flex-wrap: wrap;
    gap: 0 8px;
}

.bp-byline a {
    color: inherit;
}

.bp-author {
    font-weight: 700;
    color: var(--hero-text) !important;
    text-decoration: none;
}

/* ---- Post page: three columns ---- */
.bp-layout {
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 32px;
    display: grid;
    grid-template-columns: var(--bp-cols);
    justify-content: space-between;
    gap: 64px;
}

.bp-sticky {
    position: sticky;
    top: 110px; /* below the pinned nav */
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bp-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--bl-ink);
}

.bp-label:not(:first-child) {
    margin-top: 18px;
}

.bp-toc {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-left: 2px solid var(--bl-line);
}

.bp-toc a {
    display: block;
    margin-left: -2px;
    padding: 6px 0 6px 14px;
    border-left: 2px solid transparent;
    font-size: 14px;
    line-height: 1.4;
    color: var(--bl-muted);
    text-decoration: none;
}

.bp-toc .lvl-3 a {
    padding-left: 28px;
}

.bp-toc a:hover {
    color: var(--bl-ink);
}

.bp-toc a.on {
    color: var(--bl-ink);
    font-weight: 600;
    border-left-color: var(--bl-blue);
}

.bp-share {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bp-share :is(a, button) {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 14px;
    color: var(--bl-muted);
    text-decoration: none;
    cursor: pointer;
}

.bp-share :is(a, button):hover {
    color: var(--bl-ink);
}

.bp-share .material-icons-round {
    font-size: 17px;
}

.bp-copy.done span:last-child {
    font-size: 0;
}

.bp-copy.done span:last-child::after {
    content: "Copied";
    font-size: 14px;
    color: var(--bl-ink);
}

[data-lang="ja"] .bp-copy.done span:last-child::after {
    content: "コピーしました";
}

/* ---- The post itself: plain, readable type ---- */
.bp-cover {
    width: 100%;
    border-radius: 20px;
    margin-bottom: 40px;
}

.bp-toc-mobile {
    display: none;
}

.bp-prose {
    font-size: 18px;
    line-height: 1.75;
    color: var(--bl-ink);
}

.bp-prose > * + * {
    margin-top: 1.15em;
}

.bp-prose :is(h2, h3) {
    scroll-margin-top: 110px; /* clears the pinned nav when a contents link is used */
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.bp-prose h2 {
    margin-top: 2em;
    font-size: 28px;
    font-weight: 800;
}

.bp-prose h3 {
    margin-top: 1.6em;
    font-size: 22px;
    font-weight: 700;
}

.bp-prose :is(ul, ol) {
    padding-left: 1.4em;
}

.bp-prose ul {
    list-style: disc;
}

.bp-prose ol {
    list-style: decimal;
}

.bp-prose li + li {
    margin-top: 0.4em;
}

.bp-prose a {
    color: var(--bl-blue);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.bp-prose strong {
    font-weight: 700;
}

.bp-prose blockquote {
    margin-left: 0;
    padding-left: 20px;
    border-left: 3px solid var(--bl-blue);
    color: var(--bl-muted);
}

.bp-prose img {
    max-width: 100%;
    border-radius: 14px;
}

.bp-prose code {
    font-family: 'SF Mono', ui-monospace, monospace;
    font-size: 0.88em;
    padding: 0.15em 0.35em;
    border-radius: 6px;
    background: var(--bl-soft);
}

.bp-prose pre {
    padding: 20px 22px;
    border-radius: 14px;
    overflow-x: auto;
    background: #0E1726;
    color: #E2E8F0;
    font-size: 15px;
}

.bp-prose pre code {
    padding: 0;
    background: none;
}

/* "Key takeaways" list at the top of a post */
.bp-prose .takeaways {
    padding: 20px 24px;
    border-radius: 16px;
    background: var(--bl-soft);
    font-size: 17px;
}

.bp-prose .takeaways > p:first-child {
    font-weight: 700;
}

.bp-prose .takeaways ul {
    margin-top: 8px;
}

/* Tables scroll sideways on phones instead of squashing */
.bp-prose .table-wrap {
    overflow-x: auto;
}

.bp-prose table {
    width: 100%;
    border-collapse: collapse;
    font-size: 16px;
    line-height: 1.5;
}

.bp-prose :is(th, td) {
    padding: 10px 14px 10px 0;
    border-bottom: 1px solid var(--bl-line);
    text-align: left;
    vertical-align: top;
}

.bp-prose th {
    font-weight: 700;
}

.bp-prose figcaption,
.bp-prose .caption {
    margin-top: 8px;
    font-size: 14px;
    color: var(--bl-muted);
}

.bp-prose hr {
    border: 0;
    border-top: 1px solid var(--bl-line);
    margin: 2.5em 0;
}

.bp-tags {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--bl-line);
    font-size: 15px;
    color: var(--bl-muted);
}

.bp-tags span {
    font-weight: 600;
    color: var(--bl-ink);
}

/* Older / newer post */
.bp-pager {
    margin-top: 32px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.bp-pager a {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px 22px;
    border-radius: 18px;
    background: var(--bl-soft);
    color: var(--bl-ink);
    text-decoration: none;
}

.bp-pager a:hover strong {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.bp-pager span {
    font-size: 14px;
    color: var(--bl-muted);
}

.bp-pager strong {
    font-size: 17px;
    line-height: 1.3;
}

.bp-pager-next {
    grid-column: 2;
    text-align: right;
}

/* ---- Right column: author ---- */
.bp-author-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 22px;
    border-radius: 20px;
    background: var(--bl-soft);
    font-size: 15px;
    line-height: 1.55;
    color: var(--bl-muted);
}

.bp-author-card img {
    width: 48px;
    height: auto;
}

.bp-author-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--bl-ink);
}

.bp-author-links {
    display: flex;
    gap: 16px;
}

.bp-author-links a {
    font-weight: 600;
    color: var(--bl-ink);
    text-underline-offset: 3px;
}

/* More posts under the post */
.bp-more {
    max-width: 1680px;
    margin: 96px auto 0;
    padding: 56px 32px 0;
    border-top: 1px solid var(--bl-line);
}

.bp-more h2 {
    margin-bottom: 32px;
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

/* Very wide screens: four cards a row */
@media (min-width: 1500px) {
    .bl-grid:not(.bl-grid--more) {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ---- Narrower screens ---- */
@media (max-width: 1180px) {
    /* Contents move into a fold above the post; share sits above it as a row */
    .bp-layout,
    .bp-hero {
        grid-template-columns: minmax(0, 1fr) 270px;
        gap: 32px 48px;
    }

    .bp-hero {
        row-gap: 0;
    }

    .bp-hero > * {
        grid-column: 1;
    }

    .bp-left {
        grid-column: 1 / -1;
    }

    .bp-left .bp-sticky {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .bp-left :is(.bp-toc, .bp-label) {
        display: none;
    }

    .bp-share {
        flex-direction: row;
        gap: 4px 20px;
    }

    .bp-toc-mobile {
        display: block;
        margin-bottom: 32px;
        padding: 16px 20px;
        border-radius: 16px;
        background: var(--bl-soft);
    }

    .bp-toc-mobile summary {
        font-size: 15px;
        font-weight: 700;
        cursor: pointer;
    }

    .bp-toc-mobile .bp-toc {
        margin-top: 12px;
    }

    .bl-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .bp-layout,
    .bp-hero {
        grid-template-columns: minmax(0, 1fr);
    }

    .bp-right .bp-sticky {
        position: static;
    }

    .bl-card--featured {
        grid-template-columns: minmax(0, 1fr);
        gap: 20px;
    }
}

@media (max-width: 640px) {
    .bl-hero,
    .bp-hero {
        padding: 120px 20px 48px;
    }

    .bl-hero-sub,
    .bp-summary {
        font-size: 17px;
    }

    .bl-search,
    .bl-select {
        width: 100%;
    }

    .bl-select select {
        flex: 1;
    }

    .bl-page,
    .bp-page {
        border-radius: 28px 28px 0 0;
        padding: 36px 0 72px;
    }

    .bl-wrap,
    .bp-layout {
        padding: 0 20px;
    }

    .bl-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 36px;
    }

    .bp-prose {
        font-size: 17px;
    }

    .bp-pager {
        grid-template-columns: 1fr;
    }

    .bp-pager-next {
        grid-column: auto;
    }

    .bp-more {
        margin-top: 64px;
        padding: 40px 20px 0;
    }
}

/* Contents links glide to their section instead of jumping */
@media (prefers-reduced-motion: no-preference) {
    html:has(body.blog-post-page) {
        scroll-behavior: smooth;
    }
}

/* Japanese titles break between phrases, not mid-word (html lang="ja" on /jp pages) */
:lang(ja) :is(.bp-title, .bl-hero h1, .bl-card-title, .bl-cover-title, .bp-prose h2, .bp-prose h3) {
    word-break: auto-phrase;
}
