:root {
    --paper: #efeae3;
    --ink: #1c1917;
    --muted: #5e584f;
    --line: #e6dfd4;
    --rule: #ddd4c8;
    --accent: #8c3a2f;
    --slip: #fffcf8;
    --panel: #ffffff;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans: "Segoe UI", "Avenir Next", sans-serif;
    color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    display: flex;
    flex-direction: column;
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.6;
}

body.admin { font-family: var(--sans); }

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

a { color: var(--accent); }

button, input, textarea { font: inherit; color: inherit; }

button, .text-link, .quiet {
    min-height: 44px;
}

button {
    border: 0;
    background: var(--ink);
    color: #f7f3ee;
    border-radius: 2px;
    padding: 0 1.15rem;
    letter-spacing: 0.02em;
    cursor: pointer;
}

.quiet {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--ink);
}

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

.skip {
    position: absolute;
    left: 0.75rem;
    top: -4rem;
    z-index: 5;
    background: var(--ink);
    color: var(--paper);
    padding: 0.6rem 0.9rem;
    text-decoration: none;
}

.skip:focus { top: 0.75rem; }

.mast {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: calc(0.95rem + env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0.95rem max(1.25rem, env(safe-area-inset-left));
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(28, 25, 23, 0.03);
}

.mast::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
}

.brand { color: inherit; text-decoration: none; }

.logo, .brand h1, .brand-mark {
    margin: 0;
    font-family: var(--sans);
    font-size: clamp(1.05rem, 2.4vw, 1.35rem);
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.logo-link {
    color: inherit;
    text-decoration: none;
}

.mast-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.admin-nav {
    display: flex;
    gap: 0.85rem;
    font-family: var(--sans);
    font-size: 0.92rem;
}

.admin-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: inherit;
    text-decoration: none;
}

.admin-nav a[aria-current="page"] { color: var(--accent); }

.mast time, .colophon, .hint, .lede, small {
    color: var(--muted);
}

.mast time { font-family: var(--sans); font-size: 0.86rem; }

main { display: block; }

article, .manage {
    width: min(76rem, calc(100% - 2rem));
    margin: 0 auto;
    padding: clamp(1.6rem, 4vw, 3rem) 0 calc(3.5rem + env(safe-area-inset-bottom));
}

h1, h2, .hero-title { font-family: var(--serif); }

h2 {
    font-weight: 560;
    font-size: clamp(1.7rem, 3vw, 2.15rem);
    line-height: 1.12;
    letter-spacing: -0.03em;
    margin: 0 0 1rem;
}

.hero-title {
    font-weight: 560;
    font-size: clamp(2.5rem, 6vw, 4rem);
    line-height: 0.98;
    letter-spacing: -0.04em;
    max-width: 14ch;
    margin: 0 0 1.1rem;
}

.hero-title::after {
    content: "";
    display: block;
    width: 3.25rem;
    height: 3px;
    margin-top: 0.85rem;
    background: var(--accent);
}

.prose { font-family: var(--serif); }

.prose {
    max-width: 40rem;
    font-size: clamp(1.05rem, 2.4vw, 1.2rem);
    line-height: 1.7;
}

.prose p, .closing p { margin: 0 0 1.05em; }

.prose h3, .prose h4 {
    font-weight: 560;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 1.7em 0 0.45em;
}

.prose h3 { font-size: 1.55rem; }

.prose h4 { font-size: 1.25rem; }

.prose blockquote {
    margin: 1.4em 0;
    padding-left: 1rem;
    border-left: 2px solid var(--accent);
    color: var(--muted);
    font-style: italic;
}

.prose ul, .prose ol { margin: 0 0 1.1em; padding-left: 1.2rem; }

.prose a { text-underline-offset: 0.16em; }

.prose img,
.editor img {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    margin: 1rem auto;
    object-fit: contain;
    object-position: center center;
}

.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }

.frames {
    display: grid;
    grid-template-columns: repeat(2, 250px);
    gap: 14px;
    justify-content: start;
    margin: 2.4rem 0 0;
}

.frame {
    position: relative;
    display: block;
    width: 250px;
    height: 250px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid #c8bfb2;
    border-radius: 2px;
    background: #f6f3ee;
    box-shadow: 0 10px 28px rgba(28, 25, 23, 0.06);
    color: inherit;
    cursor: zoom-in;
}

.frame img {
    position: absolute;
    inset: 8px;
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    max-width: none;
    max-height: none;
    object-fit: contain;
    object-position: center center;
    display: block;
}

.lightbox:not([open]) {
    display: none;
}

.lightbox {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.lightbox::backdrop {
    background: rgba(18, 16, 14, 0.72);
    backdrop-filter: blur(8px);
}

.lightbox-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: min(92vw, 960px);
    max-height: calc(100vh - 2rem);
    margin: 0;
    padding: 2.75rem 0.9rem 0.9rem;
    background: var(--panel);
    border: 1px solid #e4ddd2;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.lightbox-close {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    z-index: 1;
    min-height: 40px;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--rule);
}

.lightbox img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(86vw, 900px);
    max-height: calc(100vh - 8.5rem);
    margin: 0 auto;
    object-fit: contain;
    object-position: center center;
    background: #f6f3ee;
    border: 1px solid #e7e0d6;
}

.lightbox-caption {
    margin: 0.75rem 0 0;
    font-family: var(--sans);
    font-size: 0.92rem;
    color: var(--muted);
}

.closing {
    max-width: 38rem;
    margin-top: 2.4rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--line);
    font-size: clamp(1.2rem, 2.6vw, 1.45rem);
    line-height: 1.45;
}

.colophon {
    width: 100%;
    flex-shrink: 0;
    margin-top: auto;
    padding: 1.35rem max(1.1rem, env(safe-area-inset-right)) calc(1.15rem + env(safe-area-inset-bottom)) max(1.1rem, env(safe-area-inset-left));
    background: #1c1917;
    color: #d8d0c6;
    font-family: var(--sans);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-align: center;
}

.colophon p { margin: 0; color: inherit; text-align: center; }

.journal {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}

.journal h2 {
    font-size: clamp(1.55rem, 3vw, 2rem);
    margin-bottom: 1rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.crumbs {
    width: min(76rem, calc(100% - 2.5rem));
    margin: 0 auto;
    padding: 0.85rem 0 0;
}

.crumbs ol {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.82rem;
}

.crumbs a, .crumbs span {
    color: var(--muted);
    text-decoration: none;
}

.crumbs [aria-current="page"] {
    color: var(--ink);
    font-weight: 650;
}

.crumbs li + li::before {
    content: "→";
    margin: 0 0.45rem;
    color: var(--accent);
}

.cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    align-items: start;
}

.card {
    min-width: 0;
    min-height: 0;
    align-self: start;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 8px 22px rgba(28, 25, 23, 0.05);
}

.card-link {
    display: grid;
    grid-template-columns: 2.75rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: center;
    min-height: 44px;
    padding: 0.55rem;
    color: inherit;
    text-decoration: none;
}

.card-frame {
    position: relative;
    display: block;
    width: 2.75rem;
    height: 2.75rem;
    overflow: hidden;
    border: 1px solid #d9d0c4;
    background: #f6f3ee;
}

.card-frame img {
    position: absolute;
    inset: 4px;
    width: calc(100% - 8px);
    height: calc(100% - 8px);
    max-width: none;
    object-fit: contain;
    object-position: center center;
    display: block;
}

.card h3 {
    margin: 0;
    font-family: var(--serif);
    font-size: clamp(0.92rem, 2.4vw, 1.12rem);
    line-height: 1.25;
    letter-spacing: -0.02em;
    font-weight: 560;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card p {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
}

.facts {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0.65rem 0 0;
    border-top: 1px solid var(--rule);
    display: grid;
    gap: 0.4rem;
}

.facts li {
    display: grid;
    grid-template-columns: 18px 6.4rem minmax(0, 1fr);
    gap: 0.4rem;
    align-items: center;
    font-size: 0.82rem;
    color: var(--ink);
}

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

.facts strong { font-weight: 650; }

.icon { display: block; color: var(--accent); }

.archive h1 {
    margin: 0 0 0.45rem;
    font-size: clamp(2.2rem, 5vw, 3.2rem);
    letter-spacing: -0.04em;
    line-height: 1;
}

.facts-page { max-width: 28rem; margin-top: 0.2rem; }

.post-thumb {
    width: 4.5rem;
    height: 4.5rem;
    max-width: 4.5rem;
    padding: 4px;
    border: 1px solid #d9d0c4;
    aspect-ratio: auto;
    object-fit: contain;
    object-position: center center;
    display: block;
    background: #f6f3ee;
}

.views {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.55rem 0 0;
    font-family: var(--sans);
    font-size: 0.82rem;
    color: var(--accent);
}

.card .views {
    margin-top: 0.35rem;
    font-size: 0.75rem;
}

.post-thumb { margin: 0 0 1.1rem; }

.post-page h1 {
    margin: 0 0 0.7rem;
    font-family: var(--serif);
    font-weight: 560;
    font-size: clamp(2.1rem, 5vw, 3.3rem);
    line-height: 1.05;
    letter-spacing: -0.035em;
    max-width: 18ch;
}

.post-page time {
    display: block;
    margin-bottom: 1.2rem;
    font-family: var(--sans);
    font-size: 0.86rem;
    color: var(--muted);
}

.post-page .lede { margin: 1rem 0 1.4rem; max-width: 40rem; }

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.section-head h2 {
    font-family: var(--serif);
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    max-width: none;
}

.post-admin {
    list-style: none;
    margin: 1rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.8rem;
}

.post-admin li {
    display: grid;
    gap: 0.35rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--rule);
}

.post-admin a {
    color: inherit;
    font-size: 1.15rem;
}

.post-admin .meta {
    font-family: var(--sans);
    font-size: 0.86rem;
    color: var(--muted);
    word-break: break-word;
}

.post-admin form { margin: 0; }

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin: 1rem 0 1.4rem;
}

.stat-card {
    padding: 0.8rem;
    border: 1px solid var(--rule);
    background: var(--slip);
}

.stat-card span,
.stat-card strong { display: block; }

.stat-card span {
    font-family: var(--sans);
    font-size: 0.82rem;
    color: var(--muted);
}

.stat-card strong {
    font-size: 1.7rem;
    font-weight: 560;
    letter-spacing: -0.03em;
}

.stat-split {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.stat-split h3,
.manage h3 {
    margin: 0 0 0.4rem;
    font-size: 1.05rem;
    font-weight: 560;
}

.stat-bars {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stat-bars li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--rule);
    font-family: var(--sans);
    font-size: 0.9rem;
}

.table-wrap { overflow-x: auto; }

.visit-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--sans);
    font-size: 0.84rem;
}

.visit-table th,
.visit-table td {
    text-align: left;
    padding: 0.55rem 0.45rem;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
    white-space: nowrap;
}

@media (min-width: 800px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
    .stat-split { grid-template-columns: 1fr 1fr; }
}

.gate {
    width: min(32rem, calc(100% - 2rem));
    margin: 0 auto;
    padding: calc(4.5rem + env(safe-area-inset-top)) 0 calc(2rem + env(safe-area-inset-bottom));
    display: grid;
    gap: 0.8rem;
    align-content: start;
}

.gate h1 {
    margin: 0;
    font-family: var(--serif);
    font-size: clamp(2.6rem, 8vw, 4.2rem);
    font-weight: 520;
    letter-spacing: -0.04em;
    line-height: 0.95;
}

.lede, .hint, .banner, .status { margin: 0; }

.stack, .slot { display: grid; gap: 0.75rem; }

.stack > label, .slot label, .pair label { display: grid; gap: 0.35rem; }

.pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.8rem;
    align-items: end;
}

input[type="color"] {
    width: 4.75rem;
    padding: 0.3rem;
}

label span, legend {
    font-family: var(--sans);
    font-size: 0.92rem;
}

input, textarea, .editor {
    width: 100%;
    border: 1px solid var(--rule);
    background: var(--slip);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
    min-height: 44px;
}

textarea, .editor { min-height: 16rem; resize: vertical; }

.editor {
    font-family: var(--serif);
    line-height: 1.65;
    min-height: 18rem;
}

.editor-line {
    min-height: 3.2rem;
    font-size: 1.15rem;
}

.source {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.writer { border: 0; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.tools { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.tools button {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--rule);
    min-width: 44px;
    padding: 0 0.75rem;
}

fieldset { border: 0; margin: 0.4rem 0 0; padding: 0; }

legend { margin-bottom: 0.35rem; }

.slots {
    display: grid;
    gap: 0.8rem;
}

.slot {
    padding: 0.8rem;
    border: 1px solid var(--rule);
    border-radius: 16px;
    background: color-mix(in srgb, var(--slip) 70%, transparent);
}

.slot img,
.slot-preview {
    width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
    object-position: center center;
    display: block;
    background: #ebe4d8;
}

.slot-label, .empty-slot { margin: 0; font-family: var(--sans); }

.empty-slot {
    display: grid;
    place-items: center;
    min-height: 8rem;
    background: var(--rule);
    color: var(--muted);
}

.check { grid-template-columns: auto 1fr; align-items: center; }

.check input { width: 1.1rem; min-height: 1.1rem; }

.banner {
    padding: 0.75rem 0.9rem;
    border-left: 3px solid var(--accent);
    background: var(--slip);
}

.savebar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 0 calc(0.8rem + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--paper) 28%);
}

.text-link {
    display: inline-flex;
    align-items: center;
    color: var(--ink);
}

.status { font-family: var(--sans); color: var(--accent); }

@media (min-width: 720px) {
    .slots { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 720px) {
    .cards { gap: 0.85rem; }
    .card-link {
        grid-template-columns: 3.25rem minmax(0, 1fr);
        gap: 0.7rem;
        padding: 0.7rem 0.8rem;
    }
    .card-frame { width: 3.25rem; height: 3.25rem; }
}

@media (max-width: 560px) {
    .frames {
        width: 100%;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.7rem;
    }

    .frame {
        width: 100%;
        max-width: 250px;
        height: auto;
        aspect-ratio: 1 / 1;
    }
}

@media (min-width: 1100px) {
    .frames { grid-template-columns: repeat(4, 250px); }
}

@media (max-width: 380px) {
    .mast { align-items: flex-start; flex-direction: column; }
    .facts li { grid-template-columns: 18px 5.4rem minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
