:root {
    --bg: #f7f3ee;
    --surface: #ffffff;
    --surface-2: #fbf8f4;
    --text: #2a2622;
    --muted: #6f665e;
    --border: #e6ddd3;
    --accent: #9a5b1e;
    --accent-strong: #7b4512;
    --accent-soft: #f6e7d4;
    --flame: #f2a33a;
    --ok: #2f6f3e;
    --ok-soft: #e3f0e5;
    --danger: #a33a2c;
    --danger-soft: #f8e3df;
    --header: #2b2622;
    --header-text: #f3ece3;
    --radius: 12px;
    --shadow: 0 6px 24px rgba(43, 38, 34, .12);
    --serif: Georgia, "Times New Roman", serif;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1b1916;
        --surface: #25221e;
        --surface-2: #2d2924;
        --text: #efe8df;
        --muted: #aea398;
        --border: #3b3631;
        --accent: #e0a35c;
        --accent-strong: #f0b673;
        --accent-soft: #3a2d1e;
        --ok: #7cc28b;
        --ok-soft: #1f3324;
        --danger: #ef8a7a;
        --danger-soft: #3d2420;
        --header: #141210;
        --shadow: 0 6px 24px rgba(0, 0, 0, .4);
        color-scheme: dark;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    line-height: 1.55;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); font-weight: normal; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--flame); outline-offset: 2px; }

/* Header */
.site-header {
    background: var(--header);
    color: var(--header-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--header-text); text-decoration: none; font-family: var(--serif); font-size: 1.35rem; }
.brand:hover { color: #fff; }
.brand-flame { width: 18px; height: 24px; fill: var(--flame); }
.site-nav { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; }
.site-nav a:not(.btn) { color: var(--header-text); text-decoration: none; font-size: .9rem; opacity: .85; padding: 4px 0; }
.site-nav a:not(.btn):hover, .site-nav a.active { opacity: 1; text-decoration: underline; text-underline-offset: 4px; }

@media (max-width: 640px) {
    .site-header { padding: 8px 16px; }
    .site-nav { width: 100%; justify-content: space-between; }
    .site-nav a:not(.btn) { font-size: .85rem; }
}

/* Layout */
.main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 32px 16px 48px; }
.main.wide { max-width: 1100px; }
.main-map { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }
.map-page { height: 100dvh; overflow: hidden; }
.map-page.scroll { height: auto; overflow: visible; }
@media (min-width: 960px) { .map-page.scroll { height: 100dvh; overflow: hidden; } }

.site-footer { border-top: 1px solid var(--border); padding: 28px 16px 20px; color: var(--muted); font-size: .85rem; }
.footer-inner { max-width: 860px; margin: 0 auto; display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.footer-inner nav { display: flex; flex-direction: column; gap: 4px; }
.footer-small { max-width: 860px; margin: 16px auto 0; font-size: .75rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-size: 1rem; line-height: 1.2;
    padding: 14px 22px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer;
    min-height: 48px;
}
.btn:hover { border-color: var(--accent); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-primary:hover { color: #1b1916; } }
.btn-sm { padding: 8px 14px; font-size: .88rem; min-height: 38px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; text-decoration: underline; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Cards & forms */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card + .card { margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 16px; }

.field { margin-bottom: 18px; }
.field label, .label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { display: block; font-size: .85rem; color: var(--muted); margin-top: 4px; font-weight: normal; }
.optional { font-weight: normal; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=email], input[type=date], input[type=search], input[type=password], textarea, select {
    width: 100%; font: inherit; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 14px; min-height: 48px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=file] { font: inherit; max-width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

.check { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; font-size: .92rem; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; margin-top: 2px; accent-color: var(--accent); }

.field-validation-error, .text-danger { color: var(--danger); font-size: .88rem; display: block; margin-top: 4px; }
.validation-summary-errors ul { margin: 0; padding-left: 20px; }
.validation-summary-errors, .alert-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; }
.validation-summary-valid { display: none; }
.alert { border-radius: 10px; padding: 14px 18px; margin-bottom: 18px; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); }

.price { font-family: var(--serif); font-size: 1.1rem; }

/* Map */
/* maplibre-gl.css (loaded later) sets .maplibregl-map { position: relative }, which would collapse the map to 0 height. */
.map-wrap > .map.maplibregl-map, .map-wrap > .map { position: absolute; inset: 0; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
.maplibregl-ctrl-group button { width: 40px; height: 40px; }
.evening-btn { color: #4a433d; }
.evening-btn[aria-pressed="true"] { color: #f2a33a; background: #2b2622 !important; }
.maplibregl-popup-content { border-radius: 12px; padding: 14px 16px; font: inherit; font-size: .95rem; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { font-size: 22px; width: 32px; height: 32px; color: var(--muted); }

.map-overlay { position: absolute; z-index: 2; }
.map-search { top: 12px; left: 12px; right: 64px; max-width: 380px; }
.map-search input { box-shadow: var(--shadow); background: var(--surface); }
.suggestions { list-style: none; margin: 6px 0 0; padding: 6px; background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
.suggestions:empty { display: none; }
.suggestions li button { all: unset; display: block; width: 100%; padding: 10px 12px; border-radius: 8px; cursor: pointer; box-sizing: border-box; }
.suggestions li button:hover, .suggestions li button:focus { background: var(--accent-soft); }
.suggestions .kind { font-size: .75rem; color: var(--muted); display: block; }

.map-legend { left: 12px; bottom: 28px; background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: .78rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw-cemetery { background: rgba(47, 111, 62, .45); }
.sw-city { background: rgba(163, 58, 44, .25); border: 1px dashed var(--danger); }
.sw-lit { background: var(--flame); border-radius: 50%; }

.intro {
    left: 12px; right: 12px; bottom: 28px; max-width: 420px;
    background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
}
.intro h1 { font-size: 1.5rem; }
.intro p { color: var(--muted); font-size: .95rem; }
.intro .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.intro-close { position: absolute; top: 6px; right: 8px; }
.intro[hidden], .map-legend[hidden] { display: none; }

.sheet {
    left: 0; right: 0; bottom: 0; max-height: 60%; overflow: auto;
    background: var(--surface); border-radius: 16px 16px 0 0; padding: 18px 16px 24px; box-shadow: var(--shadow);
}
@media (min-width: 720px) { .sheet { left: auto; right: 12px; bottom: 12px; width: 380px; border-radius: var(--radius); } }
.sheet[hidden] { display: none; }
.sheet { max-height: 75%; }
.sheet.tall { max-height: 88%; }
@media (min-width: 720px) { .sheet.tall { width: 440px; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; flex: 1; }
.icon-btn {
    flex: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 1.05rem;
}
.icon-btn:hover { border-color: var(--accent); }
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-btn-float { width: 48px; height: 48px; background: var(--surface); box-shadow: var(--shadow); border-radius: 10px; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
.form-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.form-head h1 { margin-bottom: .5em; }
.icon-btn[hidden] { display: none; }
button.grave-item { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.grave-card { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.grave-card-photo { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; flex: none; }
.grave-card .grave-dates { font-size: .95rem; }
.grave-card-epitaph { font-family: var(--serif); font-style: italic; margin: 6px 0 0; white-space: pre-line; }
.grave-card-candles { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.grave-card-candles .candles-lit { margin: 0; justify-content: flex-start; gap: 2px 4px; }
.sheet .candle { transform: scale(.7); margin: -6px -3px; }
.sheet-messages { margin-top: 10px; }
.sheet-messages .message { padding: 10px 0; }
.sheet-links { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .88rem; margin-top: 12px; }
.sheet-links .btn-link { font-size: .88rem; }
.sheet-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.candle-inline { margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-actions .btn-primary { flex: 1; }

/* Grave list items */
.grave-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.grave-item { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: var(--text); background: var(--surface); }
.grave-item:hover { border-color: var(--accent); color: var(--text); }
.grave-item .thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; }
.grave-item .thumb svg { width: 20px; height: 28px; fill: var(--flame); }
.grave-item .name { font-family: var(--serif); font-size: 1.1rem; display: block; }
.grave-item .years { color: var(--muted); font-size: .85rem; }
.grave-item .lit-dot { margin-left: auto; width: 10px; height: 10px; border-radius: 50%; background: var(--flame); box-shadow: 0 0 10px var(--flame); flex: none; }

/* Register page */
.register { display: grid; grid-template-columns: 1fr; min-height: 0; flex: 1; }
.register .map-wrap { min-height: 55dvh; }
.register-form { padding: 20px 16px 40px; }
@media (min-width: 960px) {
    .register { grid-template-columns: 1fr 460px; height: 100%; }
    .register .map-wrap { min-height: 0; }
    .register-form { overflow: auto; border-left: 1px solid var(--border); }
}
.cell-status { border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; background: var(--surface-2); border: 1px solid var(--border); font-size: .95rem; }
.cell-status.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.cell-status.bad { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 20px; }
.steps li { counter-increment: step; display: flex; gap: 10px; margin-bottom: 6px; font-size: .92rem; color: var(--muted); }
.steps li::before { content: counter(step); flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 600; }

/* Grave page */
.grave-hero { text-align: center; padding: 8px 0 24px; }
.grave-photo { width: 220px; height: 220px; margin: 0 auto 20px; border-radius: 50%; object-fit: cover; border: 6px solid var(--surface); box-shadow: var(--shadow); }
.grave-photo-empty { width: 140px; height: 140px; margin: 0 auto 20px; border-radius: 50%; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; }
.grave-photo-empty svg { width: 46px; height: 62px; fill: var(--flame); }
.grave-name { font-size: 2.4rem; margin-bottom: 8px; }
.grave-dates { color: var(--muted); font-size: 1.05rem; }
.grave-epitaph { font-family: var(--serif); font-style: italic; font-size: 1.2rem; max-width: 560px; margin: 18px auto 0; white-space: pre-line; }

.candles-lit { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; margin: 8px 0 12px; min-height: 10px; }
.candle { width: 22px; height: 46px; position: relative; }
.candle::before { content: ""; position: absolute; bottom: 0; left: 4px; width: 14px; height: 26px; border-radius: 3px 3px 2px 2px; background: linear-gradient(#fff8ee, #e9dccb); border: 1px solid var(--border); }
.candle::after {
    content: ""; position: absolute; top: 2px; left: 6px; width: 10px; height: 16px;
    background: radial-gradient(ellipse at 50% 70%, #fff6c8 0%, var(--flame) 45%, rgba(242, 163, 58, 0) 70%);
    border-radius: 50% 50% 45% 45%; filter: drop-shadow(0 0 6px rgba(242, 163, 58, .9));
    animation: flicker 2.6s infinite ease-in-out; transform-origin: 50% 100%;
}
.candle:nth-child(3n)::after { animation-duration: 3.1s; }
.candle:nth-child(4n)::after { animation-duration: 2.2s; animation-delay: -.7s; }
@keyframes flicker { 0%, 100% { transform: scale(1) rotate(-1deg); opacity: 1; } 30% { transform: scale(.94, 1.06) rotate(2deg); opacity: .92; } 60% { transform: scale(1.04, .96) rotate(-2deg); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .candle::after { animation: none; } }

.candle-cta { text-align: center; margin: 12px 0 28px; }
.candle-form summary { list-style: none; }
.candle-form summary::-webkit-details-marker { display: none; }
.candle-form[open] summary { display: none; }

.messages { list-style: none; padding: 0; margin: 0; }
.message { padding: 16px 0; border-bottom: 1px solid var(--border); }
.message:last-child { border-bottom: none; }
.message-head { display: flex; align-items: center; gap: 10px; font-size: .88rem; color: var(--muted); }
.message-head .who { color: var(--text); font-weight: 600; }
.message-head .flame-sm { width: 10px; height: 14px; fill: var(--flame); }
.message-head .flame-sm.out { fill: var(--border); }
.message-body { margin: 6px 0 0; white-space: pre-line; font-family: var(--serif); font-size: 1.05rem; }
.message-report { margin-left: auto; font-size: .78rem; color: var(--muted); }

.share { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mini-map { height: 220px; border-radius: var(--radius); overflow: hidden; position: relative; margin-top: 12px; }

/* Payment / status pages */
.order-line { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-top: 12px; }
.order-line .price { white-space: nowrap; }
.test-banner { background: #f2a33a; color: #2b2622; text-align: center; font-size: .82rem; padding: 6px 16px; }
.status-icon { width: 64px; height: 64px; margin: 0 auto 12px; }
.qr { width: 180px; height: 180px; margin: 12px auto; image-rendering: pixelated; }

/* Admin */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form input[type=text] { min-height: 36px; padding: 6px 10px; width: auto; flex: 1; min-width: 140px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat b { display: block; font-size: 1.5rem; font-family: var(--serif); font-weight: normal; }

/* Prose (legal pages) */
.prose h2 { margin-top: 1.6em; }
.prose li { margin-bottom: .4em; }
.prose .draft-note { background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; font-size: .9rem; }
