/* ==========================================================================
   KUJAS — Ghost theme
   A mosaic portfolio theme: staggered project tiles, hover overlays,
   a fixed navigation menu and fixed page titles.
   --------------------------------------------------------------------------
   Structure:
   01. Variables & base
   02. Layout helpers (container)
   03. Buttons & links
   04. Navbar
   05. Fixed navigation
   06. Fixed page title (title bar)
   07. Main regions (home / titled pages)
   08. Mosaic grid & tiles (hover overlay)
   09. Text styles (display text, lead text)
   10. Post content (Ghost editor output)
   11. Pagination
   12. Footer
   13. Image fade-in
   14. Responsive overrides
   ========================================================================== */

/* --------------------------------------------------------------------------
   01. Variables & base
   -------------------------------------------------------------------------- */

:root {
    --bg: #ffffff;
    --fg: #000000;
    --radius: 4px;
    --gutter: 64px;
    --nav-height: 120px;
    --container-max: 1620px;
    --font: "Fira Sans", -apple-system, BlinkMacSystemFont,
        "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.4;
    color: var(--fg);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

main {
    flex: 1 0 auto;
}

img,
svg {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

a,
a:link,
a:visited,
a:active,
a:focus {
    color: var(--fg);
    text-decoration: none;
}

::selection {
    background: #000;
    color: #fff;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid #000;
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   02. Layout helpers
   -------------------------------------------------------------------------- */

.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 15px;
}

@media (max-width: 1399px) {
    :root { --container-max: 1440px; }
}
@media (max-width: 1199px) {
    :root { --container-max: 960px; --gutter: 32px; }
}
@media (max-width: 991px) {
    :root { --container-max: 720px; }
}
@media (max-width: 767px) {
    :root { --container-max: 540px; --gutter: 40px; }
}

/* --------------------------------------------------------------------------
   03. Buttons & links
   -------------------------------------------------------------------------- */

.btn {
    display: inline-block;
    font-family: var(--font);
    font-weight: 400;
    font-size: 26px;
    line-height: 1.2;
    color: var(--fg);
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.btn:hover,
.btn:focus-visible {
    opacity: 0.6;
    color: var(--fg);
}

/* Right-hand gap between grouped buttons/links */
.gap-right {
    margin-right: 1em;
}

.gap-right:last-child {
    margin-right: 0;
}

/* --------------------------------------------------------------------------
   04. Navbar
   -------------------------------------------------------------------------- */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: #fff;
    z-index: 1030;
    padding: 18px 0;
}

.navbar .container {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.navbar-brand {
    display: inline-block;
}

.navbar-brand img {
    width: 85px;
    height: auto;
}

.brand-text {
    display: inline-block;
    font-size: 24px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.1;
    padding-top: 4px;
}

/* --------------------------------------------------------------------------
   05. Fixed navigation
   -------------------------------------------------------------------------- */

/* Pinned navigation menu, fed by Ghost navigation settings */
.site-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

/* Nav items stay below the brand text size */
.site-nav .btn {
    font-size: 20px;
}

/* --------------------------------------------------------------------------
   06. Fixed page title
   -------------------------------------------------------------------------- */

.title-bar {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    z-index: 2;
}

.page-heading {
    padding-top: 1rem;
    margin-bottom: 3rem;
}

/* Big headline pinned over the scrolling content;
   white backing keeps it readable, no border */
.title-box {
    display: block;
    width: 100%;
    margin: 0;
    padding: 20px 0;
    background: #fff;
    font-family: var(--font);
    font-weight: 400;
    line-height: 1.05;
    hyphens: auto;
    overflow-wrap: break-word;
}

/* Full-width big page title */
.title-box--page {
    font-size: 63px;
}

/* Smaller inline title */
.title-box--compact {
    display: inline-block;
    width: auto;
    font-size: 42px;
    padding: 10px 0;
}

/* --------------------------------------------------------------------------
   07. Main regions
   -------------------------------------------------------------------------- */

/* Home: mosaic starts right below the navbar */
.main-home {
    margin-top: 3rem;
}

.main-home > .container {
    padding-top: 80px;
    padding-bottom: 60px;
}

/* Pages with a fixed title bar */
.main-titled {
    margin-top: 180px;
    padding-bottom: 160px;
}

.main-titled > .container {
    padding-top: 60px;
}

.content-area {
    position: relative;
    margin-top: 3rem;
}

/* --------------------------------------------------------------------------
   08. Mosaic grid & tiles
   -------------------------------------------------------------------------- */

.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--gutter);
    align-items: start;
}

.tile {
    grid-column: span 6;
}

/* Featured posts render bigger than the big tiles (tablet) */
.tile--featured {
    grid-column: span 8;
}

@media (max-width: 767px) {
    .tile {
        grid-column: 1 / -1;
    }
}

/* Repeating mosaic pattern on large screens — an organic, staggered flow:
   mostly two tiles per row, one row with three small tiles, never edge to
   edge. Column ranges:
   [2-7]+[9-11] | [1-4]+[6-10] | [2-4]+[6-8]+[10-12] | [4-7]
   The free columns around the tiles create the whitespace. */
@media (min-width: 992px) {
    .tile:nth-child(8n+1) { grid-column: 2 / span 6; }
    .tile:nth-child(8n+2) { grid-column: 9 / span 3; }
    .tile:nth-child(8n+3) { grid-column: 1 / span 4; }
    .tile:nth-child(8n+4) { grid-column: 6 / span 5; }
    .tile:nth-child(8n+5) { grid-column: 2 / span 3; }
    .tile:nth-child(8n+6) { grid-column: 6 / span 3; }
    .tile:nth-child(8n+7) { grid-column: 10 / span 3; }
    .tile:nth-child(8n)   { grid-column: 4 / span 4; }

    /* Clearly portrait feature images take up two grid rows
       (.tile--portrait is set by the theme JS from the aspect ratio) */
    .tile--portrait {
        grid-row: span 2;
    }

    /* Featured posts: ~20% bigger than the big tiles (span 7 vs span 6) */
    .tile.tile--featured {
        grid-column: 2 / span 7;
    }
}

.card {
    position: relative;
    margin: 0;
    border: 0;
    background: transparent;
}

.tile-link {
    display: block;
    color: inherit;
}

.tile img {
    width: 100%;
    height: auto;
    display: block;
}

/* Hover overlay on top of the tile image */
.tile-overlay {
    position: absolute;
    inset: 0;
    display: none;
    background-size: cover;
    background-position: center;
    background-color: #fff;
    cursor: pointer;
}

.card:hover .tile-overlay,
.card:focus-within .tile-overlay {
    display: block;
    animation: fadein 0.6s ease;
}

@keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Neutral wrapper so the overlay text can anchor to the corners */
.overlay-frame {
    width: 100%;
    height: 100%;
}

/* Fixed text sizes — independent of the tile width */
.tile-overlay .overlay-title,
.text-tile .overlay-title {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    font-size: 44px;
    line-height: 0.98;
    font-weight: 400;
    overflow-wrap: break-word;
}

.tile-overlay .overlay-subtitle,
.text-tile .overlay-subtitle {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    font-size: 18px;
    line-height: 1.15;
    overflow-wrap: break-word;
}

.tile-overlay .overlay-title,
.tile-overlay .overlay-subtitle {
    color: #fff;
    text-shadow: 0 1px 14px rgba(0, 0, 0, 0.55);
}

/* Typographic tile for posts without a feature image:
   all-caps title, the excerpt fades in on hover */
.tile--text .text-tile {
    position: relative;
    min-height: 320px;
    background: #f4f4f4;
    color: var(--fg);
}

.text-tile .overlay-title,
.text-tile .overlay-subtitle {
    color: inherit;
}

.text-tile .overlay-title {
    text-transform: uppercase;
    line-height: 1.05;
}

.text-tile .overlay-subtitle {
    opacity: 0;
    transition: opacity 0.4s ease;
}

.tile--text:hover .overlay-subtitle,
.tile--text:focus-within .overlay-subtitle {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   09. Text styles
   -------------------------------------------------------------------------- */

/* Big light display text (quotes, poems, 404 message) */
.display-text {
    font-size: clamp(30px, 4.6vw, 66px);
    line-height: 1.2;
    font-weight: 400;
    text-align: left;
    margin: 1.5em 0;
    hyphens: auto;
}

/* Larger lead text (empty states) */
.lead-text {
    font-size: 24px;
    line-height: 1.3;
    font-weight: 400;
}

/* --------------------------------------------------------------------------
   10. Post content (Ghost editor output)
   -------------------------------------------------------------------------- */

/* Featured image at the top of the post, before the content */
.feature-hero {
    margin: 0 0 var(--gutter);
}

.feature-hero img {
    width: 100%;
    height: auto;
    display: block;
    cursor: zoom-in;
}

.post-content {
    font-size: 17.5px;
}

.post-content > p,
.post-content > h1,
.post-content > h2,
.post-content > h3,
.post-content > h4,
.post-content > ul,
.post-content > ol,
.post-content > table,
.post-content > pre {
    max-width: 836px;
}

.post-content p {
    margin: 0 0 1.2em;
    line-height: 1.45;
    hyphens: auto;
}

/* Section heading inside a page: plain big headline */
.post-content h1 {
    display: block;
    max-width: 836px;
    margin: 2.5em 0 0.8em;
    font-size: 42px;
    font-weight: 400;
    line-height: 1.1;
}

.post-content h2 {
    margin: 2em 0 0.6em;
    font-size: 26px;
    font-weight: 500;
}

.post-content h3 {
    margin: 1.8em 0 0.5em;
    font-size: 20px;
    font-weight: 500;
}

.post-content strong {
    font-weight: 600;
}

.post-content a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.post-content a:hover {
    text-decoration: none;
}

/* Blockquotes render in the big display-text style */
.post-content blockquote {
    margin: 2em 0;
    padding: 0;
    border: 0;
    max-width: 100%;
    font-size: clamp(30px, 4.6vw, 66px);
    line-height: 1.15;
    font-weight: 400;
}

.post-content blockquote p {
    margin: 0;
    line-height: 1.15;
}

.post-content ul,
.post-content ol {
    margin: 0 0 1.2em;
    padding-left: 1.3em;
}

.post-content li {
    margin-bottom: 0.4em;
}

.post-content hr {
    border: 0;
    border-top: 1px solid #000;
    margin: 3em 0;
}

.post-content img {
    width: 100%;
    height: auto;
}

/* Figures: staggered widths like a project spread */
.post-content figure {
    margin: 0 0 var(--gutter);
}

.post-content figure.kg-image-card:not(.kg-width-wide):not(.kg-width-full) {
    width: 66%;
}

.post-content figure.kg-image-card:not(.kg-width-wide):not(.kg-width-full):nth-of-type(even) {
    margin-left: auto;
}

.post-content figure.kg-width-wide {
    width: 100%;
}

.post-content figure.kg-width-full {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    max-width: 100vw;
}

.post-content figcaption {
    max-width: 836px;
    padding-top: 8px;
    font-size: 14px;
}

/* Content images open in the lightbox */
.post-content .kg-image-card img,
.post-content .kg-gallery-card img {
    cursor: zoom-in;
}

/* Galleries */
.kg-gallery-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.kg-gallery-image {
    flex: 1 1 0;
    min-width: 0;
}

.kg-gallery-image img {
    width: 100%;
    height: auto;
}

/* Embeds & bookmarks */
.post-content .kg-embed-card {
    margin-bottom: var(--gutter);
}

.post-content iframe {
    width: 100%;
}

/* Portrait videos stay narrow so they don't grow absurdly tall
   (.embed-portrait is set by the theme JS from the video's size) */
.post-content figure.embed-portrait {
    max-width: min(480px, 100%);
    margin-left: auto;
    margin-right: auto;
}

.post-content figure.embed-portrait iframe,
.post-content figure.embed-portrait video {
    width: 100%;
    height: auto;
}

.kg-bookmark-card {
    background: #f4f4f4;
    border-radius: var(--radius);
    padding: 1em;
    max-width: 836px;
    margin-left: auto;
    margin-right: auto;
}

.kg-bookmark-title {
    font-size: 18px;
    font-weight: 500;
}

.kg-bookmark-description {
    font-size: 14px;
    color: #444;
}

.kg-bookmark-metadata {
    font-size: 12px;
    color: #666;
}

/* Code */
.post-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 90%;
    background: #f2f2f2;
    padding: 2px 6px;
    border-radius: 3px;
}

.post-content pre {
    padding: 1em;
    background: #f7f7f7;
    overflow-x: auto;
}

.post-content pre code {
    background: none;
    padding: 0;
}

/* Tables */
.post-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
}

.post-content td,
.post-content th {
    padding: 8px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

/* Author bio */
.author-bio {
    max-width: 836px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 3rem;
    font-size: 17.5px;
}

/* Lightbox for content images (opened by the theme JS) */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.97);
    cursor: zoom-out;
}

.lightbox.active {
    display: flex;
    animation: fadein 0.3s ease;
}

.lightbox img {
    max-width: calc(100vw - 80px);
    max-height: calc(100vh - 80px);
    width: auto;
    height: auto;
}

body.lightbox-open {
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   11. Pagination (auto-load trigger for older posts)
   -------------------------------------------------------------------------- */

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1em;
    margin: 3rem 0 5rem;
}

/* --------------------------------------------------------------------------
   12. Footer
   -------------------------------------------------------------------------- */

.footer {
    margin-top: auto;
    padding: 6rem 0 1.5rem;
    background: #fff;
}

.footer-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
}

.footer-col-contact {
    flex: 1 1 320px;
}

.footer-col-social {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
}

.footer-col-legal {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

/* Legal links fed by Ghost secondary navigation */
.footer-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.social-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-right: 2em;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    transition: opacity 0.2s ease;
}

.social-link:last-child {
    margin-right: 0;
}

.social-link:hover,
.social-link:focus-visible {
    opacity: 0.6;
    color: var(--fg);
}

.social-icon {
    width: 34px;
    height: 34px;
}

/* Bottom meta row: copyright + powered by */
.footer-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5em 2em;
    margin-top: 4rem;
    padding-top: 1rem;
    font-size: 14px;
}

.footer-powered a {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --------------------------------------------------------------------------
   13. Image fade-in (JS adds .is-loaded)
   -------------------------------------------------------------------------- */

html.js img.lazyload,
html.js .post-content img {
    opacity: 0;
    transition: opacity 0.4s ease;
}

html.js img.lazyload.is-loaded,
html.js .post-content img.is-loaded {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   14. Responsive overrides
   -------------------------------------------------------------------------- */

@media (max-width: 1199px) {
    .btn {
        font-size: 20px;
    }

    .site-nav .btn {
        font-size: 17px;
    }

    .title-box--page {
        font-size: 53px;
    }

    .title-box--compact,
    .post-content h1 {
        font-size: 34px;
    }

    .lead-text {
        font-size: 20px;
    }

    /* tighter tile inset on narrow screens */
    .tile-overlay .overlay-title,
    .text-tile .overlay-title {
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .tile-overlay .overlay-subtitle,
    .text-tile .overlay-subtitle {
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
}

@media (max-width: 991px) {
    .title-box--page {
        font-size: 38px;
    }

    .title-box--compact,
    .post-content h1 {
        font-size: 27px;
    }

    .display-text {
        font-size: 38px;
    }
}

@media (max-width: 767px) {
    .site-nav .btn {
        font-size: 15px;
    }

    .brand-text {
        font-size: 20px;
    }

    .navbar-brand img {
        width: 70px;
    }

    .tile.tile--featured {
        grid-column: 1 / -1;
    }

    .title-bar {
        position: relative;
        top: auto;
        margin-top: 125px;
    }

    .main-titled {
        margin-top: 1.5rem;
        padding-bottom: 60px;
    }

    .main-home {
        margin-top: 0;
    }

    .main-home > .container {
        padding-top: 130px;
    }

    .page-heading {
        padding-top: 0;
        margin-bottom: 1.5rem;
    }

    .tile--text .text-tile {
        min-height: 260px;
    }

    .post-content figure.kg-image-card:not(.kg-width-wide):not(.kg-width-full) {
        width: 100%;
    }

    .footer {
        padding-top: 3rem;
    }

    .footer-col-legal,
    .footer-nav {
        justify-content: flex-start;
    }

    .footer-col-contact,
    .footer-col-legal {
        margin-bottom: 1.5rem;
    }

    .footer-col-social {
        margin-top: 1.5rem;
    }

    .footer-meta {
        margin-top: 2rem;
        flex-direction: column;
        gap: 0.25em;
    }
}
