/*
 * mattsin.nu (Mattsin's Domains) – samma formspråk som mattsin.se (glaspaneler över himmel och äng,
 * rubrikflik, sidfotspiller) med ljust, mörkt och systemtema. Alla färger är semantiska
 * variabler; samma värden används i apparnas inställningar (se docs/mattsin-nu.md).
 *
 * Tema: inget data-theme = systemets inställning. data-theme="light"/"dark" sätts av
 * nu-theme.js när besökaren valt själv.
 */

:root {
    color-scheme: light;

    --background: #4f8fd6;
    --foreground: #0f1a26;
    --surface: rgba(255, 255, 255, .66);
    --surface-secondary: rgba(255, 255, 255, .86);
    --surface-edge: rgba(255, 255, 255, .85);
    --primary: #1f4f8a;
    --on-primary: #fff;
    --secondary: #2f7a3a;
    --border: rgba(15, 26, 38, .16);
    --muted: #3a4654;
    --link: #123e73;
    --focus: #0b3d91;
    --shadow: 0 2px 12px rgba(0, 40, 90, .14);
    /* Egna foton (se docs/ASSET_LICENSES.md). Mindre varianter för smala skärmar längre ner. */
    --bg-light: image-set(url("../img/nu-bg-light-2560.webp") type("image/webp"), url("../img/nu-bg-light-2560.jpg") type("image/jpeg"));
    --bg-dark: image-set(url("../img/nu-bg-dark-2560.webp") type("image/webp"), url("../img/nu-bg-dark-2560.jpg") type("image/jpeg"));
    --bg-image: var(--bg-light);
    --bg-position: 72% 100%;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --s1: .25rem;
    --s2: .5rem;
    --s3: .75rem;
    --s4: 1rem;
    --s5: 1.5rem;
    --s6: 2rem;
    --radius: 14px;
}

/* Mörka värden: både för systemets mörka läge (om besökaren inte valt ljust) och för eget val. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --background: #0d1a33;
        --foreground: #e6edf5;
        --surface: rgba(12, 21, 38, .68);
        --surface-secondary: rgba(36, 52, 80, .85);
        --surface-edge: rgba(255, 255, 255, .14);
        --primary: #8fbcf0;
        --on-primary: #0b1630;
        --secondary: #7cc98a;
        --border: rgba(255, 255, 255, .16);
        --muted: #aab7c6;
        --link: #a9cdf7;
        --focus: #9cc7ff;
        --shadow: 0 2px 14px rgba(0, 0, 0, .35);
        --bg-image: var(--bg-dark);
        --bg-position: 60% 100%;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --background: #0d1a33;
    --foreground: #e6edf5;
    --surface: rgba(12, 21, 38, .68);
    --surface-secondary: rgba(36, 52, 80, .85);
    --surface-edge: rgba(255, 255, 255, .14);
    --primary: #8fbcf0;
    --on-primary: #0b1630;
    --secondary: #7cc98a;
    --border: rgba(255, 255, 255, .16);
    --muted: #aab7c6;
    --link: #a9cdf7;
    --focus: #9cc7ff;
    --shadow: 0 2px 14px rgba(0, 0, 0, .35);
    --bg-image: var(--bg-dark);
    --bg-position: 60% 100%;
}

@media (max-width: 900px) {
    :root {
        --bg-light: image-set(url("../img/nu-bg-light-1600.webp") type("image/webp"), url("../img/nu-bg-light-1600.jpg") type("image/jpeg"));
        --bg-dark: image-set(url("../img/nu-bg-dark-1600.webp") type("image/webp"), url("../img/nu-bg-dark-1600.jpg") type("image/jpeg"));
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--foreground);
    background: var(--background);
}

/* ------------------------------------------------------------------ Bakgrund */

.bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--background) var(--bg-image) no-repeat var(--bg-position) / cover;
}

/* ------------------------------------------------------------------ Glas */

.glass {
    background: var(--surface);
    border: 1px solid var(--surface-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .glass {
        -webkit-backdrop-filter: blur(6px) saturate(1.15);
        backdrop-filter: blur(6px) saturate(1.15);
    }
}

/* ------------------------------------------------------------------ Grundlayout (mobil) */

.shell {
    display: flex;
    flex-direction: column;
    gap: var(--s4);
    max-width: 62rem;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: var(--s4);
}

.skip-link {
    position: absolute;
    left: var(--s4);
    top: -100px;
    z-index: 10;
    padding: var(--s2) var(--s4);
    color: var(--foreground);
    background: var(--surface-secondary);
    font-weight: 700;
    border-radius: 8px;
}

.skip-link:focus { top: var(--s4); }

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

.visually-hidden-sm {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ------------------------------------------------------------------ Sidhuvud */

.site-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: var(--s2) var(--s4);
    padding: var(--s2) var(--s3);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    min-height: 44px;
    color: var(--foreground);
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
}

.brand img { border-radius: 8px; }

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--s2);
}

.site-nav { grid-column: 1 / -1; }

.site-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 var(--s3);
    color: var(--foreground);
    font-weight: 600;
    text-decoration: none;
    border-radius: 999px;
}

.site-nav a:hover { background: var(--surface-secondary); }

.site-nav a[aria-current="page"] {
    background: var(--surface-secondary);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

/* Temaväljare – segmenterad kontroll, samma som "Theme" i apparnas inställningar. */
.theme-switch {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}

.theme-switch[hidden] { display: none; }

.theme-switch button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 36px;
    padding: 0;
    color: var(--foreground);
    background: transparent;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.theme-switch button:hover { background: var(--surface-secondary); }

.theme-switch button[aria-pressed="true"] {
    color: var(--on-primary);
    background: var(--primary);
}

.theme-switch svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Språkväljare – visas först när fler språk är aktiverade (NuLayout::LANGUAGES). */
.language {
    display: inline-flex;
    gap: var(--s1);
}

.language a {
    padding: var(--s1) var(--s2);
    color: var(--foreground);
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 999px;
}

.language a[aria-current="true"] { background: var(--surface-secondary); }

/* ------------------------------------------------------------------ Innehåll */

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--s4);
    min-width: 0;
}

.content:focus { outline: none; }

/* Rubrikflik ovanpå första panelen, som på mattsin.se. */
.tab {
    align-self: flex-start;
    max-width: 100%;
    margin: var(--s2) 0 calc(-1 * var(--s4) - 1px) var(--s4);
    padding: var(--s2) var(--s4);
    font-size: 1.35rem;
    line-height: 1.3;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
    position: relative;
    z-index: 1;
}

.panel {
    padding: var(--s4);
    overflow-wrap: anywhere;
}

.panel > :last-child { margin-bottom: 0; }

h2 {
    margin: 0 0 var(--s3);
    font-size: 1.2rem;
    line-height: 1.3;
}

.prose h2:not(:first-child) { margin-top: var(--s5); }

p, ul, dl { margin: 0 0 var(--s3); }

.prose ul { padding-left: 1.25rem; }
.prose li + li { margin-top: var(--s2); }

a {
    color: var(--link);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover { text-decoration-thickness: 2px; }

.lead {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.35;
}

.hero .lead { font-size: 1.5rem; }

.muted { color: var(--muted); }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: var(--s2) var(--s5);
    color: var(--on-primary);
    background: var(--primary);
    font-weight: 700;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 999px;
}

.button:hover { filter: brightness(1.1); }

.button.secondary {
    color: var(--foreground);
    background: var(--surface-secondary);
    border-color: var(--border);
}

.badge {
    display: inline-block;
    margin: 0;
    padding: 0 var(--s2);
    color: var(--foreground);
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    border-radius: 999px;
}

/* ------------------------------------------------------------------ Rader (som en inställningslista) */

.rows {
    margin: 0 0 var(--s3);
    padding: 0;
    list-style: none;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.rows li + li { border-top: 1px solid var(--border); }

.row {
    display: flex;
    align-items: center;
    gap: var(--s3);
    min-height: 64px;
    padding: var(--s3);
    color: var(--foreground);
    font-weight: 400;
    text-decoration: none;
}

.row:hover { background: var(--surface); }
.row:hover .row-title { text-decoration: underline; }

.row-icon {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 12px;
}

.row-icon-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--on-primary);
    background: var(--primary);
    font-weight: 700;
    font-size: 1.3rem;
}

.row-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.row-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s1) var(--s2);
    font-weight: 700;
}
.row-sub { color: var(--muted); font-size: .92rem; line-height: 1.4; }

.row-chevron {
    flex: none;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: var(--muted);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.more { text-align: right; }

/* ------------------------------------------------------------------ Principer */

.principles {
    display: grid;
    gap: var(--s2);
    margin: 0 0 var(--s3);
    padding: 0;
    list-style: none;
}

.principles li {
    position: relative;
    padding: var(--s2) var(--s3) var(--s2) 2.4rem;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.prose .principles li + li { margin-top: 0; }

.principles li::before {
    content: "";
    position: absolute;
    left: .85rem;
    top: 1rem;
    width: .5rem;
    height: .85rem;
    border: solid var(--secondary);
    border-width: 0 3px 3px 0;
    transform: translateY(-25%) rotate(45deg);
}

/* ------------------------------------------------------------------ Appsida */

.app-header {
    display: grid;
    gap: var(--s4);
    align-items: start;
}

.app-icon {
    width: 96px;
    height: 96px;
    border-radius: 22px;
    box-shadow: var(--shadow);
}

/* Delad Onefold-bana: koden ska gå att läsa av och skriva in tecken för tecken. */
.puzzle-code code {
    display: inline-block;
    padding: var(--s2) var(--s3);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-secondary);
    font-size: 1.25rem;
    letter-spacing: .08em;
    overflow-wrap: anywhere;
    user-select: all;
}

.app-header .badge { margin-bottom: var(--s2); }

.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--s2) var(--s4);
}

.facts dt { font-weight: 700; }
.facts dd { margin: 0; }

.screenshots {
    display: flex;
    gap: var(--s3);
    margin: 0;
    padding: 0 0 var(--s2);
    list-style: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
}

.screenshots li { flex: none; scroll-snap-align: start; }

.screenshots img {
    display: block;
    width: auto;
    height: 420px;
    max-height: 70vh;
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* ------------------------------------------------------------------ Sidfot */

.site-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--s2);
    padding-bottom: var(--s2);
    text-align: center;
}

.site-footer p { margin: 0; }

.footer-links {
    display: flex;
    gap: var(--s2);
}

.pill {
    display: inline-block;
    padding: var(--s1) var(--s4);
    color: var(--foreground);
    font-size: .85rem;
    font-weight: 400;
    text-decoration: none;
    border-radius: 999px;
}

a.pill:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ 768px */

@media (min-width: 768px) {
    .shell { padding: var(--s6) var(--s6) var(--s5); gap: var(--s5); }

    .site-header {
        grid-template-columns: auto 1fr auto;
        padding: var(--s2) var(--s4);
    }

    .site-nav { grid-column: 2; grid-row: 1; justify-self: center; }
    .header-controls { grid-column: 3; }

    .content { gap: var(--s5); }
    .tab { margin-bottom: calc(-1 * var(--s5) - 1px); margin-left: var(--s5); }
    .panel { padding: var(--s5) var(--s6); }

    .app-header { grid-template-columns: auto 1fr; }
}

@media (min-width: 1024px) {
    .shell { padding-top: 6vh; }
    .hero .lead { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}


button.button { font: inherit; font-weight: 700; cursor: pointer; }

@media print {
    .bg, .site-header, .site-footer, .skip-link { display: none; }
    .glass { background: none; border: 0; box-shadow: none; }
}
