:root {
    --bg: #ffffff;
    --bg-soft: #f4f6f9;
    --text: #1d2433;
    --muted: #5d6779;
    --line: #e2e6ed;
    --primary: #1f5eff;
    --primary-dark: #1546c4;
    --radius: 10px;
    --shadow: 0 8px 24px rgba(20, 30, 60, .10);
    --max: 1120px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    display: flex; flex-direction: column; min-height: 100vh;
}
main { flex: 1; }
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
code { background: var(--bg-soft); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 20px; }
.section { padding: 48px 20px; }
.prose { max-width: 720px; }
.lead { font-size: 1.2rem; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: #fff; padding: 8px 14px; z-index: 100; border-radius: 6px; }
.skip-link:focus { left: 8px; }

/* ---------- Header & meny ---------- */
.site-header { background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 68px; }
.logo { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); display: flex; gap: .5em; align-items: center; }
.logo-mark { color: var(--primary); }

.menu, .submenu { list-style: none; margin: 0; padding: 0; }
.menu { display: flex; gap: 4px; }
.menu > li { position: relative; display: flex; align-items: center; }
.menu a { display: block; padding: 10px 14px; text-decoration: none; color: var(--text); border-radius: 8px; font-weight: 500; }
.menu a:hover, .menu a:focus-visible { background: var(--bg-soft); }
.menu > li.active > a { color: var(--primary); }
.menu > li.active > a::after { content: ""; display: block; height: 2px; background: var(--primary); margin-top: 2px; border-radius: 2px; }

.has-sub > a { padding-right: 4px; }
.sub-toggle { background: none; border: 0; cursor: pointer; padding: 10px 8px 10px 2px; color: var(--muted); font-size: .9rem; }
.submenu {
    position: absolute; top: 100%; left: 0; min-width: 220px;
    background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 6px;
    opacity: 0; visibility: hidden; transform: translateY(6px); transition: .15s ease;
}
.has-sub:hover .submenu, .has-sub:focus-within .submenu, .has-sub.open .submenu { opacity: 1; visibility: visible; transform: none; }
.submenu li.active a { color: var(--primary); background: var(--bg-soft); }

.nav-toggle { display: none; background: none; border: 0; width: 44px; height: 44px; cursor: pointer; position: relative; }
.bars, .bars::before, .bars::after { position: absolute; left: 11px; width: 22px; height: 2px; background: var(--text); content: ""; transition: .2s; }
.bars { top: 21px; }
.bars::before { top: -7px; left: 0; }
.bars::after { top: 7px; left: 0; }
.nav-open .bars { background: transparent; }
.nav-open .bars::before { top: 0; transform: rotate(45deg); }
.nav-open .bars::after { top: 0; transform: rotate(-45deg); }

@media (max-width: 800px) {
    .nav-toggle { display: block; }
    .main-nav {
        position: absolute; top: 100%; left: 0; right: 0; background: var(--bg);
        border-bottom: 1px solid var(--line); box-shadow: var(--shadow); display: none;
    }
    .nav-open .main-nav { display: block; }
    .menu { flex-direction: column; padding: 10px 20px 16px; }
    .menu > li { flex-wrap: wrap; }
    .menu > li > a { flex: 1; }
    .menu > li.active > a::after { display: none; }
    .sub-toggle { padding: 10px 14px; }
    .submenu { position: static; width: 100%; box-shadow: none; border: 0; padding: 0 0 0 14px; display: none; opacity: 1; visibility: visible; transform: none; }
    .has-sub:hover .submenu, .has-sub:focus-within .submenu { display: none; }
    .has-sub.open .submenu { display: block; }
}

/* ---------- Sidhuvud på undersidor ---------- */
.page-head { background: var(--bg-soft); border-bottom: 1px solid var(--line); padding: 28px 0 24px; }
.page-head h1 { margin: 0; font-size: 2rem; }
.breadcrumbs { font-size: .9rem; color: var(--muted); margin-bottom: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumbs a { color: var(--muted); }

/* ---------- Startsida ---------- */
.hero { background: linear-gradient(135deg, #eef3ff, #f8faff); padding: 80px 0 72px; border-bottom: 1px solid var(--line); }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); max-width: 16ch; }
.eyebrow { color: var(--primary); font-weight: 600; margin: 0 0 8px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

/* ---------- Komponenter ---------- */
.btn { display: inline-block; background: var(--primary); color: #fff; padding: 12px 22px; border-radius: 8px; text-decoration: none; font-weight: 600; border: 2px solid var(--primary); cursor: pointer; font-size: 1rem; }
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary); color: #fff; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.card { display: block; padding: 26px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); transition: .15s; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: transparent; }
.card h2 { font-size: 1.25rem; }
.card p { color: var(--muted); margin: 0 0 12px; }
.card-more { color: var(--primary); font-weight: 600; }

.checklist { list-style: none; padding: 0; }
.checklist li { padding-left: 1.8em; position: relative; margin-bottom: .5em; }
.checklist li::before { content: "✓"; position: absolute; left: 0; color: var(--primary); font-weight: 700; }

.team { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.team li { display: flex; flex-direction: column; align-items: flex-start; padding: 18px; background: var(--bg-soft); border-radius: var(--radius); }
.team span:last-child { color: var(--muted); font-size: .95rem; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; margin-bottom: 10px; }

/* ---------- Formulär ---------- */
.contact { display: grid; grid-template-columns: 1fr 1.2fr; gap: 48px; }
@media (max-width: 800px) { .contact { grid-template-columns: 1fr; } }
.form label { display: block; font-weight: 600; margin-bottom: 16px; }
.form input, .form select, .form textarea {
    display: block; width: 100%; margin-top: 6px; padding: 11px 12px; font: inherit; font-weight: 400;
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.err { display: block; color: #c62828; font-weight: 400; font-size: .9rem; margin-top: 4px; }
.hp { position: absolute; left: -9999px; }
.alert { padding: 14px 16px; border-radius: 8px; margin-bottom: 18px; }
.alert-success { background: #e7f6ec; color: #1b5e20; }
.alert-error { background: #fdecea; color: #b71c1c; }

.notfound { text-align: center; padding: 96px 20px; }
.notfound .big { font-size: 5rem; font-weight: 800; color: var(--primary); margin: 0; line-height: 1; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--bg-soft); color: var(--muted); font-size: .95rem; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding-top: 20px; padding-bottom: 20px; }
.footer-inner p { margin: 0; }
.footer-links { list-style: none; display: flex; gap: 18px; margin: 0; padding: 0; }
.footer-links a { color: var(--muted); }

/* ---------- Album ---------- */
.album-meta { color: var(--muted); margin-top: 0; }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.album-card { display: block; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--text); transition: .15s; }
.album-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.album-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.album-card-body { display: block; padding: 14px 16px; }
.album-card-body span { display: block; color: var(--muted); font-size: .9rem; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 45%), 1fr)); gap: 10px; margin-bottom: 32px; }
.gallery-item { position: relative; display: block; border-radius: 8px; overflow: hidden; background: var(--bg-soft); aspect-ratio: 1; }
.gallery-item img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.gallery-item:hover img { transform: scale(1.04); }
.gallery-item .play {
    position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%;
    background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; font-size: 1.3rem; padding-left: 4px;
}
.no-thumb { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* Bildvisare (bild och film). dvh = synlig höjd på mobil, utan adressfältet. */
.lightbox {
    width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
    margin: 0; padding: 0; border: 0; background: rgba(10,12,18,.95); color: #fff; overflow: hidden;
}
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: rgba(0,0,0,.6); }
.lb-stage { margin: 0; display: flex; flex-direction: column; align-items: center; }
.lb-media img, .lb-media video {
    display: block; width: auto; height: auto;
    max-width: calc(100vw - 120px);
    max-height: calc(100vh - 110px); max-height: calc(100dvh - 110px);
    border-radius: 4px; background: #000;
}
.lb-caption { margin-top: 10px; min-height: 1.6em; color: #d0d4dc; text-align: center; padding: 0 12px; }
.lb-count { position: absolute; top: 18px; left: 22px; color: #aab; font-size: .9rem; }
.lightbox button { position: absolute; z-index: 2; background: rgba(255,255,255,.12); border: 0; color: #fff; cursor: pointer; border-radius: 50%; width: 48px; height: 48px; font-size: 1.6rem; line-height: 1; }
.lightbox button:hover { background: rgba(255,255,255,.25); }
.lb-close { top: 12px; right: 14px; font-size: 1.2rem !important; }
.lb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 14px; top: 50%; transform: translateY(-50%); }

@media (max-width: 700px) {
    /* Mobil: full bredd, plats för stängknapp överst och pilar nederst */
    .lb-media img, .lb-media video {
        max-width: 100vw;
        max-height: calc(100vh - 170px); max-height: calc(100dvh - 170px);
        border-radius: 0;
    }
    .lb-prev, .lb-next { top: auto; bottom: 14px; transform: none; }
    .lb-prev { left: calc(50% - 60px); }
    .lb-next { right: calc(50% - 60px); }
}

/* Lichess-parti / studie.
   Bred iframe (> 450 px): bräde till vänster, drag till höger.
   Smal iframe (<= 450 px): Lichess lägger dragen under brädet och visaren blir
   exakt "bredden + ca 120 px" hög – resten blir en svart ruta. Därför sätts
   höjden efter iframens egen bredd (100cqw) via en container query. */
.lichess-embed { max-width: 760px; margin: 24px 0; container-type: inline-size; }
.lichess-embed iframe { display: block; width: 100%; aspect-ratio: 600 / 397; border: 0; border-radius: 8px; }

@container (max-width: 450px) {
    .lichess-embed iframe {
        aspect-ratio: auto;
        height: calc(100cqw + 122px);   /* bräde + knappar (48 px) + draglista (72 px) */
    }
}
