/* =====================================================================
   Site Base — shared layout & components for the main site.
   Colour themes (coastal-dawn, autumn-harbor, rosewood-vintage,
   steampunk-metal) only set the CSS variables below; everything
   structural lives here so all themes stay responsive.
   ===================================================================== */

:root {
    /* Defaults (overridden by the active theme file) */
    --bg:            #f4f5f7;
    --surface:       #ffffff;
    --surface-2:     #e6e9ee;
    --text:          #1f2933;
    --muted:         #52606d;
    --heading:       #1f2933;
    --link:          #2f5d8a;
    --border:        #cfd6de;
    --header-bg:     #2f3a48;
    --header-text:   #ffffff;
    --nav-hover:     #b9cbe0;
    --accent:        #3f5f82;
    --accent-hover:  #2e4763;
    --accent-text:   #ffffff;

    --font-body:     system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-heading:  var(--font-body);
    --font-reading:  Georgia, "Iowan Old Style", "Palatino Linotype", serif;

    --radius:        10px;
    --shadow:        0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .08);
    --shadow-hover:  0 2px 4px rgba(0, 0, 0, .08), 0 10px 28px rgba(0, 0, 0, .14);
    --content-width: 1100px;
    --reading-width: 72ch;
    --gutter:        clamp(16px, 4vw, 32px);
}

/* === Reset-ish === */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    transition: background-color .25s, color .25s;
}

img, video, iframe { max-width: 100%; }
img { height: auto; }

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3, h4 {
    font-family: var(--font-heading);
    color: var(--heading);
    line-height: 1.25;
    margin: 0 0 .5em;
}
h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.8rem); }
h3 { font-size: 1.2rem; }

p { margin: 0 0 1em; }

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* === Header & Navigation === */
header.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--header-bg);
    color: var(--header-text);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}

.header-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 10px var(--gutter);
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    color: var(--header-text);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .02em;
    text-decoration: none;
    margin-right: auto;
    white-space: nowrap;
}
.brand:hover { color: var(--nav-hover); }

.navbar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.navbar a {
    color: var(--header-text);
    text-decoration: none;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background-color .2s, color .2s;
}
.navbar a:hover { color: var(--nav-hover); background: rgba(255, 255, 255, .08); }
.navbar a[aria-current="page"] {
    background: rgba(255, 255, 255, .14);
    color: var(--header-text);
}

.theme-btn {
    margin-left: 8px;
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    color: var(--header-text);
    background: transparent;
    border: 1.5px solid currentColor;
    transition: color .2s, background-color .2s;
}
.theme-btn:hover { color: var(--nav-hover); }

.nav-toggle {
    display: none;
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--header-text);
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, .35);
    cursor: pointer;
}

@media (max-width: 760px) {
    .header-inner { flex-wrap: wrap; }
    .nav-toggle { display: block; }
    .navbar {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        padding: 6px 0 4px;
        border-top: 1px solid rgba(255, 255, 255, .15);
    }
    .site-header.nav-open .navbar { display: flex; }
    .navbar a { padding: 10px 12px; }
    .theme-btn { margin: 8px 0 4px; align-self: flex-start; }
}

/* === Main Content === */
main {
    flex: 1;
    width: 100%;
    max-width: var(--content-width);
    margin: 0 auto;
    padding: clamp(20px, 4vw, 40px) var(--gutter) 48px;
}

.page-header { margin-bottom: 28px; }
.page-header p,
.lead {
    font-size: 1.1rem;
    color: var(--muted);
    max-width: 60ch;
}

.eyebrow {
    margin: 0 0 .35em;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}

/* === Footer === */
footer {
    background: var(--header-bg);
    color: var(--header-text);
    text-align: center;
    padding: 18px var(--gutter);
    font-size: .9rem;
}
footer p { margin: 0; opacity: .9; }

/* === Utilities (kept for existing markup) === */
.center-text {
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.bg-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: #fff;
    padding: 20px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    font: inherit;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .2s, transform .1s, box-shadow .2s;
}
.btn:hover {
    color: var(--accent-text);
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.btn:active { transform: translateY(0); }

.btn-outline {
    background: transparent;
    color: var(--accent);
    box-shadow: inset 0 0 0 2px var(--accent);
}
.btn-outline:hover { background: var(--accent); }

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}
@media (max-width: 480px) {
    .btn-row .btn { flex: 1 1 100%; }
}

/* === Card === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(18px, 4vw, 36px);
    margin: 0 0 24px;
}
.card > :last-child { margin-bottom: 0; }
.card h2 { margin-top: 0; }

.card figure,
figure {
    margin: 0 0 24px;
    text-align: center;
}
figure img {
    display: block;
    margin: 0 auto;
    border-radius: 6px;
}
figcaption {
    margin-top: 8px;
    font-size: .9rem;
    color: var(--muted);
}

/* Readable long-form text */
.prose { max-width: var(--reading-width); }
.prose p { font-size: 1.05rem; }

pre {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-wrap: break-word;
    font-family: var(--font-reading);
    font-size: 1.08rem;
    line-height: 1.75;
    tab-size: 4;
    margin: 0;
}

/* === Tile grid (hub, portfolio, gallery & story indexes) === */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 150px;
    padding: 22px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.tile:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent);
}
.tile-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--heading);
    line-height: 1.25;
}
.tile-desc { color: var(--muted); font-size: .95rem; }
.tile-cta {
    margin-top: auto;
    padding-top: 10px;
    font-weight: 700;
    font-size: .9rem;
    color: var(--link);
}

/* Image tiles: pass the image via style="--tile-img: url(...)" */
.tile-image {
    min-height: 220px;
    justify-content: flex-end;
    color: #fff;
    border: 0;
    background:
        linear-gradient(to top, rgba(0, 0, 0, .82) 0%, rgba(0, 0, 0, .25) 60%, rgba(0, 0, 0, .05) 100%),
        var(--tile-img) center / cover no-repeat,
        var(--header-bg);
}
.tile-image .tile-title { color: #fff; }
.tile-image .tile-desc  { color: rgba(255, 255, 255, .85); }
.tile-image .tile-cta   { color: #fff; }

/* === Page hero (project pages) === */
.page-hero {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: clamp(180px, 30vw, 300px);
    margin-bottom: 24px;
    padding: clamp(20px, 4vw, 40px);
    border-radius: var(--radius);
    color: #fff;
    background:
        linear-gradient(to top, rgba(0, 0, 0, .8) 0%, rgba(0, 0, 0, .2) 70%),
        var(--hero-img, none) center / cover no-repeat,
        var(--header-bg);
    box-shadow: var(--shadow);
}
.page-hero h1 { color: #fff; margin-bottom: .2em; }
.page-hero .subtitle { margin: 0; font-size: 1.15rem; opacity: .9; }

/* Tag list (languages & tools) */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.tags li {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
.tags-label {
    margin: 24px 0 8px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
}

/* === Gallery === */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: 16px;
    align-items: start;
    margin: 0 auto;
}
.gallery img {
    display: block;
    width: 100%;
    height: auto;          /* show artwork uncropped */
    border-radius: 8px;
    border: 4px solid var(--surface);
    box-shadow: var(--shadow);
    cursor: zoom-in;
    transition: transform .2s, box-shadow .2s;
}
.gallery img:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow-hover);
}
@media (max-width: 420px) {
    .gallery { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* Lightbox (created by main.js) */
.lightbox {
    padding: 0;
    border: 0;
    background: transparent;
    max-width: 95vw;
    max-height: 95vh;
}
.lightbox::backdrop { background: rgba(0, 0, 0, .85); }
.lightbox img {
    display: block;
    max-width: 95vw;
    max-height: 90vh;
    width: auto;
    border-radius: 6px;
}
.lightbox-close {
    position: fixed;
    top: 12px;
    right: 16px;
    font-size: 2rem;
    line-height: 1;
    color: #fff;
    background: none;
    border: 0;
    cursor: pointer;
}

/* === Stories === */
.story-header,
.story,
.story-nav {
    max-width: calc(var(--reading-width) + 80px);
    margin-left: auto;
    margin-right: auto;
}
.story-header { text-align: center; margin-bottom: 28px; }
.story-header h1 { margin-bottom: 0; }

.story figure img { max-width: 100%; }
@media (max-width: 700px) {
    /* Inline width="50%" scans are too small on phones */
    .story figure img { width: 100%; }
}

.story-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}
.story-nav a {
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    text-decoration: none;
    color: var(--accent);
    box-shadow: inset 0 0 0 2px var(--accent);
    transition: background-color .2s, color .2s;
}
.story-nav a:hover { background: var(--accent); color: var(--accent-text); }
/* Display order: previous | contents | next */
.story-nav .prev { order: 0; }
.story-nav .up   { order: 1; margin: 0 auto; }
.story-nav .next { order: 2; }

/* Story table of contents */
.toc {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: toc;
    display: grid;
    gap: 12px;
}
.toc li { counter-increment: toc; }
.toc a {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    transition: transform .2s, border-color .2s;
}
.toc a::before {
    content: counter(toc, decimal-leading-zero);
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 2.4em;
    height: 2.4em;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-size: .85rem;
    font-weight: 700;
}
.toc a:hover { transform: translateX(4px); border-color: var(--accent); }

/* === Section (hub) === */
.hero {
    text-align: center;
    padding: clamp(24px, 6vw, 56px) 0 clamp(24px, 4vw, 40px);
}
.hero p { margin-left: auto; margin-right: auto; }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
