:root {
    --bg: #f4efe6;
    --ink: #1c1915;
    --muted: #5c564c;
    --paper: #fffcf7;
    --line: #d9d0c3;
    --accent: #0f6e62;
    --accent-ink: #fff;
    --danger: #9b2c2c;
    --ok: #1f6b3a;
    --shadow: 0 10px 30px rgba(28, 25, 21, 0.08);
    --radius: 14px;
    --tap: 44px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --ui: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--ui);
    line-height: 1.45;
}
a { color: var(--accent); }
h1, h2, .brand, .brand-mark { font-family: var(--font); font-weight: 600; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 0.75rem; }

.app {
    display: grid;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
}
.sidebar {
    display: none;
    background: #241f1a;
    color: #f4efe6;
    padding: 1.25rem 1rem calc(1rem + var(--safe-b));
}
.brand { color: inherit; text-decoration: none; font-size: 1.4rem; display: block; margin-bottom: 1.5rem; }
.side-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.side-nav a {
    color: inherit;
    text-decoration: none;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    border-radius: 10px;
}
.side-nav a.is-active { background: #3a332c; }
.side-nav a.is-disabled, .tabbar a.is-disabled { opacity: 0.4; pointer-events: none; }

.main-wrap { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 56px;
    padding: 0.5rem 1rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.user-chip { font-size: 0.9rem; color: var(--muted); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 1rem 1rem calc(5.5rem + var(--safe-b)); }

.tabbar {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--paper);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe-b);
}
.tabbar a {
    min-height: var(--tap);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--ink);
    font-size: 0.82rem;
}
.tabbar a.is-active { color: var(--accent); font-weight: 600; }

@media (max-width: 767px) {
    .sidebar.is-open {
        display: flex;
        position: fixed;
        inset: 0 auto 0 0;
        width: min(80vw, 280px);
        z-index: 30;
        box-shadow: var(--shadow);
    }
}

.icon-btn, .btn {
    min-height: var(--tap);
    min-width: var(--tap);
    border: 1px solid var(--line);
    background: var(--paper);
    border-radius: 10px;
    font: inherit;
    cursor: pointer;
    padding: 0 1rem;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.inline { display: inline; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.92rem; }
input[type="email"], input[type="password"], input[type="text"], input[type="number"], input[type="datetime-local"], input[type="search"], input[type="url"], textarea {
    min-height: var(--tap);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 0.85rem;
    font: inherit;
    background: #fff;
    width: 100%;
}
textarea { min-height: 10rem; padding: 0.75rem 0.85rem; resize: vertical; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.row-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.row-form input { flex: 1; min-width: 12rem; }
.inline-check { display: flex; align-items: center; gap: 0.4rem; min-height: var(--tap); }
.inline-check input { width: auto; min-height: 1.25rem; flex: none; }

.panel, .card, .guest-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem;
    margin-bottom: 1rem;
}
.card-grid { display: grid; gap: 0.75rem; }
.card { text-decoration: none; color: inherit; display: block; }
.card.muted { opacity: 0.7; }
.lede { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: 0.88rem; }
.break { overflow-wrap: anywhere; }
.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: #efe7d8; }
.alert-error { background: #f8d7d3; color: var(--danger); }
.alert-ok { background: #dcefe3; color: var(--ok); }
code.secret { display: block; overflow-wrap: anywhere; margin-top: 0.35rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; gap: 0.75rem; align-items: center; padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
.tag { font-size: 0.75rem; color: var(--muted); }
.kv { display: grid; grid-template-columns: 8rem 1fr; gap: 0.35rem 0.75rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.steps { padding-left: 1.2rem; }
.steps li { margin: 0.4rem 0; }
.chip {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #efe7d8;
    color: inherit;
    text-decoration: none;
    margin-right: 0.25rem;
}
.chip-row { margin-top: 0.25rem; }
.favicon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 0.2rem; }
.favicon-empty { display: inline-block; background: var(--line); border-radius: 3px; }
.bookmark-list li, .note-list li { align-items: flex-start; }
.bookmark-main { flex: 1; min-width: 0; }
.bookmark-link { display: flex; gap: 0.65rem; color: inherit; text-decoration: none; }
.bookmark-link strong, .note-list strong { display: block; }

body.guest {
    display: grid;
    place-items: center;
    padding: 1.25rem;
    padding-bottom: max(1.25rem, var(--safe-b));
}
.guest-card { width: min(26rem, 100%); }
.brand-mark { font-size: 1.6rem; margin: 0 0 0.5rem; }

.crumbs { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-bottom: 0.75rem; }
.crumbs a { color: inherit; text-decoration: none; font-weight: 600; }
.toolbar, .file-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.85rem; align-items: center; }
.search-form { display: flex; gap: 0.4rem; flex: 1; min-width: 12rem; }
.file-pick { display: inline-flex; align-items: center; cursor: pointer; }
select {
    min-height: var(--tap);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 0.7rem;
    font: inherit;
    width: 100%;
    background: #fff;
}
.file-list { display: flex; flex-direction: column; }
.file-row {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    border-bottom: 1px solid var(--line);
    gap: 0.35rem;
}
.file-main {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--tap);
    text-decoration: none;
    color: inherit;
    min-width: 0;
}
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
.preview { max-width: 100%; border-radius: 12px; }
.preview-frame {
    width: 100%;
    min-height: 70vh;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}
.preview-text {
    white-space: pre-wrap;
    max-height: 24rem;
    overflow: auto;
    background: var(--paper);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    margin: 0;
}
.cal-toolbar, .contact-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}
.contact-list li { align-items: flex-start; }
.contact-list .hint { display: block; }
.pagination-more { margin-top: 1rem; }
.dropzone {
    border: 2px dashed var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    color: var(--muted);
    margin-bottom: 1rem;
}
.dropzone.is-over { border-color: var(--accent); background: #e7f3f0; }
.sheet[hidden] { display: none !important; }
.sheet {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 21, 0.4);
    z-index: 40;
    display: grid;
    align-items: end;
}
.sheet-card {
    background: var(--paper);
    border-radius: 16px 16px 0 0;
    padding: 1rem 1rem calc(1rem + var(--safe-b));
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-height: 85dvh;
    overflow: auto;
}

@media (min-width: 768px) {
    .app { grid-template-columns: 240px 1fr; grid-template-rows: 1fr; }
    .sidebar { display: flex; flex-direction: column; }
    .sidebar-toggle { display: none; }
    .tabbar { display: none; }
    .content { padding: 1.5rem 1.75rem; }
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sheet { align-items: center; justify-items: center; }
    .sheet-card { border-radius: var(--radius); width: min(28rem, 92vw); max-height: 80vh; }
}

@media (min-width: 1200px) {
    .app { grid-template-columns: 260px 1fr; }
    .content { max-width: 960px; }
    .content.content-wide { max-width: none; }
}

.album-strip {
    display: flex;
    gap: 0.6rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
}
.album-chip {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: var(--tap);
    padding: 0 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--paper);
    text-decoration: none;
    color: inherit;
    max-width: 14rem;
}
.album-chip img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 50%;
}
.photos-layout { display: grid; gap: 1rem; }
.photos-months { display: none; }
.photo-day { font-size: 1rem; margin: 1rem 0 0.5rem; }
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
}
.photo-tile, .photo-tile-wrap .photo-tile {
    display: block;
    aspect-ratio: 1;
    overflow: hidden;
    background: #d9d0c3;
    padding: 0;
    border: 0;
    cursor: pointer;
    width: 100%;
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile-wrap { display: flex; flex-direction: column; gap: 0.25rem; }
.photo-figure { margin: 0 0 1rem; }
.meta-list { display: grid; gap: 0.5rem; }
.meta-list div { display: grid; grid-template-columns: 8rem 1fr; gap: 0.5rem; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; }

.viewer[hidden] { display: none !important; }
.viewer {
    position: fixed;
    inset: 0;
    background: #140f0c;
    z-index: 50;
    display: grid;
    grid-template-rows: auto 1fr auto;
    align-items: center;
    justify-items: center;
}
.viewer img {
    max-width: 100vw;
    max-height: calc(100dvh - 6rem);
    object-fit: contain;
}
.viewer-close {
    position: absolute;
    top: max(0.5rem, env(safe-area-inset-top));
    right: 0.5rem;
    color: #fff;
    background: transparent;
    border-color: transparent;
}
.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    text-decoration: none;
    font-size: 2.4rem;
    min-width: var(--tap);
    min-height: var(--tap);
    display: grid;
    place-items: center;
}
.viewer-prev { left: 0.25rem; }
.viewer-next { right: 0.25rem; }
.viewer-cap { color: #f4efe6; padding: 0.5rem 1rem calc(0.5rem + var(--safe-b)); }

@media (min-width: 768px) {
    .photos-layout { grid-template-columns: 9rem 1fr; }
    .photos-months { display: flex; flex-direction: column; gap: 0.2rem; }
    .photos-months a {
        color: inherit;
        text-decoration: none;
        min-height: 2.2rem;
        display: flex;
        align-items: center;
        padding: 0 0.4rem;
        border-radius: 8px;
    }
    .photos-months a.is-active { background: #efe7d8; font-weight: 600; }
    .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
}

@media (min-width: 1200px) {
    .photos-layout { grid-template-columns: 11rem 1fr; }
    .photo-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

body.share {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
}
.share-shell {
    width: min(52rem, 100%);
    margin: 0 auto;
    padding: 1.25rem 1rem calc(1.5rem + var(--safe-b));
}
.share-gallery { margin-top: 1rem; }
.share-gallery .btn { min-height: 2.5rem; }
.check {
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem;
}
.check input { width: auto; min-height: 1.25rem; }
.share-row { align-items: flex-start; }

@media (min-width: 768px) {
    .share-gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
    .share-gallery { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

.recipe-card h2 { margin: 0.4rem 0 0.2rem; font-size: 1.05rem; }
.recipe-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 10px;
    background: #efe7d8;
    display: block;
}
.recipe-hero {
    width: 100%;
    max-height: 14rem;
    object-fit: cover;
    border-radius: 12px;
}
.ingredient-list { padding-left: 1.2rem; margin: 0.5rem 0 1rem; }
.ingredient-list li { margin: 0.35rem 0; }
.instructions { white-space: normal; line-height: 1.55; }
@media (min-width: 768px) {
    .recipe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
