/*
 * Memorial page - one layout for every theme.
 *
 * Colours come from CSS variables the page prints from the theme's palette
 * (apps/home/memorial_themes.py): --mp-bg, --mp-surface, --mp-soft,
 * --mp-cover, --mp-line, --mp-ink, --mp-muted, --mp-accent,
 * --mp-accent-text, --mp-accent-ink. Never write a colour for one theme here.
 *
 * Everything is scoped under .mp because Bootstrap 4 and Tailwind 2 are
 * loaded on the same page.
 */

html,
body {
    background: var(--mp-bg);
}

.mp {
    --mp-serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
    --mp-sans: 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
    --mp-radius: 16px;
    min-height: 100vh;
    background: var(--mp-bg);
    color: var(--mp-ink);
    font-family: var(--mp-sans);
    font-size: 16px;
    line-height: 1.6;
    padding-bottom: 48px;
}

.mp a {
    color: inherit;
    text-decoration: none;
}

.mp a:hover {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.mp h1,
.mp h2,
.mp h3 {
    font-family: var(--mp-serif);
    font-weight: 600;
    color: var(--mp-ink);
    letter-spacing: -0.005em;
}

.mp [hidden] {
    display: none !important;
}

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

.mp-wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 24px;
}

/* --- Top bar ------------------------------------------------------------ */

.mp-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    gap: 16px;
}

.mp-brand {
    font-family: var(--mp-serif);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.mp-top__link {
    font-size: 15px;
    color: var(--mp-muted) !important;
}

/* Notice on the demo memorial (/memorial/demo) */
.mp-demo {
    margin: 0 0 16px;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--mp-soft);
    color: var(--mp-muted);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

.mp-demo a {
    color: var(--mp-accent-text) !important;
    font-weight: 600;
    white-space: nowrap;
}

/* --- Hero --------------------------------------------------------------- */

.mp-cover,
.mp .header-container {
    position: relative;
    height: 340px;
    border-radius: 20px;
    overflow: hidden;
    background: var(--mp-cover);
}

.mp .header-image-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: -100px;
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    transition: transform 0.3s ease;
}

.mp .header-container.editing {
    outline: 2px solid var(--mp-accent);
    outline-offset: 2px;
    cursor: move;
}

.mp .header-container.editing .header-image-wrapper,
.mp .header-container.touching .header-image-wrapper {
    transition: none;
}

.mp .icon-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    z-index: 3;
}

.mp .icon-controls i {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    color: #ffffff;
    cursor: pointer;
}

.mp .icon-controls i.hidden {
    display: none;
}

.mp-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-top: -92px;
    position: relative;
    z-index: 2;
}

.mp-portrait {
    width: 184px;
    height: 184px;
    border-radius: 50%;
    border: 6px solid var(--mp-bg);
    background: var(--mp-soft);
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mp-serif);
    font-size: 60px;
    color: var(--mp-muted);
}

.mp-eyebrow {
    margin-top: 22px;
    font-size: 13px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--mp-muted);
}

.mp .mp-name {
    margin: 6px 0 0;
    font-size: clamp(40px, 6vw, 64px);
    line-height: 1.05;
}

.mp-dates {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    font-size: 19px;
    color: var(--mp-muted);
}

.mp-dates::before,
.mp-dates::after {
    content: '';
    width: 40px;
    height: 1px;
    background: var(--mp-line);
}

.mp-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 28px;
}

.mp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 22px;
    border-radius: 999px;
    border: 1px solid var(--mp-line);
    background: var(--mp-surface);
    color: var(--mp-ink) !important;
    font: 600 16px var(--mp-sans);
    cursor: pointer;
    text-decoration: none !important;
    transition: filter 0.15s ease, background 0.15s ease;
}

.mp-btn:hover {
    filter: brightness(0.97);
}

.mp-btn svg {
    flex-shrink: 0;
}

.mp-btn--primary {
    border-color: transparent;
    background: var(--mp-accent);
    color: var(--mp-accent-ink) !important;
}

.mp-btn--primary:hover {
    filter: brightness(1.08);
}

.mp-btn--ghost {
    border-color: transparent;
    background: transparent;
    color: var(--mp-muted) !important;
}

.mp-btn--block {
    width: 100%;
}

.mp-btn[disabled],
.mp-btn.is-lit {
    cursor: default;
    filter: none;
}

.mp-btn.is-lit {
    background: var(--mp-soft);
    color: var(--mp-accent-text) !important;
    border-color: transparent;
}

.mp-meta {
    margin-top: 18px;
    font-size: 15px;
    color: var(--mp-muted);
}

/* --- Tabs --------------------------------------------------------------- */

.mp-tabs {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 44px;
    border-bottom: 1px solid var(--mp-line);
    overflow-x: auto;
    scrollbar-width: none;
}

.mp-tabs::-webkit-scrollbar {
    display: none;
}

.mp-tabs .tab-link {
    flex-shrink: 0;
    padding: 14px 2px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--mp-muted);
    font-weight: 400;
    white-space: nowrap;
    text-decoration: none !important;
}

.mp-tabs .tab-link:hover {
    color: var(--mp-ink);
}

.mp-tabs .tab-link.active {
    color: var(--mp-ink);
    font-weight: 600;
    border-bottom-color: var(--mp-accent);
}

.mp .tab-pane {
    display: none;
}

.mp .tab-pane.active {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* --- Layout ------------------------------------------------------------- */

.mp-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 32px;
    align-items: start;
    margin-top: 40px;
}

.mp-side {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.mp-card {
    background: var(--mp-surface);
    border: 1px solid var(--mp-line);
    border-radius: var(--mp-radius);
    padding: 32px 36px;
}

.mp-side .mp-card {
    padding: 28px;
}

.mp-card__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.mp .mp-card__title {
    margin: 0;
    font-size: 30px;
    line-height: 1.2;
}

.mp-side .mp-card__title {
    font-size: 26px;
}

.mp-more {
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--mp-accent-text) !important;
}

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

.mp-empty {
    margin: 0;
    color: var(--mp-muted);
}

.mp-bio {
    max-width: 66ch;
}

.mp-bio p {
    margin: 0 0 12px;
}

.mp-bio p:last-child {
    margin-bottom: 0;
}

/* --- Timeline -----------------------------------------------------------
 * Events alternate left and right of a centre line: the card on one side,
 * its year large on the other, level with the dot. On a
 * phone they stack right of a line on the left, the year inside the card.
 */

.mp-tl {
    position: relative;
    list-style: none;
    margin: 0;
    padding: 8px 0;
}

.mp-tl::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: var(--mp-line);
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 32px, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to bottom, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}

.mp-tl__item {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr);
    align-items: start;
}

.mp-tl__item + .mp-tl__item {
    margin-top: 20px;
}

.mp-tl__year {
    grid-row: 1;
    grid-column: 3;
    padding: 11px 6px 0;
    font-family: var(--mp-serif);
    font-size: 34px;
    font-weight: 600;
    line-height: 1;
    color: var(--mp-accent-text);
    overflow-wrap: anywhere;
}

/* Full dates ("1961 m. gegužės 4 d.") are longer than a year. */
.mp-tl--full .mp-tl__year {
    padding-top: 17px;
    font-size: 22px;
    line-height: 1.2;
}

.mp-tl__item:nth-child(even) .mp-tl__year {
    grid-column: 1;
    text-align: right;
}

.mp-tl__item::before {
    content: '';
    position: absolute;
    top: 21px;
    left: 50%;
    width: 14px;
    height: 14px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: var(--mp-surface);
    border: 2px solid var(--mp-accent);
    box-shadow: 0 0 0 5px var(--mp-surface);
    box-sizing: border-box;
    z-index: 1;
}

.mp-tl__card {
    position: relative;
    grid-row: 1;
    grid-column: 1;
    padding: 16px 20px;
    border: 1px solid var(--mp-line);
    border-radius: 14px;
    background: var(--mp-bg);
    text-align: right;
}

.mp-tl__card::after {
    content: '';
    position: absolute;
    top: 28px;
    right: -21px;
    width: 20px;
    height: 1px;
    background: var(--mp-line);
}

.mp-tl__item:nth-child(even) .mp-tl__card {
    grid-column: 3;
    text-align: left;
}

.mp-tl__item:nth-child(even) .mp-tl__card::after {
    right: auto;
    left: -21px;
}

.mp-tl__date {
    display: none;
    font-family: var(--mp-serif);
    font-size: 26px;
    font-weight: 600;
    line-height: 1.15;
    color: var(--mp-accent-text);
    overflow-wrap: anywhere;
}

.mp .mp-tl__text {
    margin: 0;
    font-family: var(--mp-sans);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0;
    color: var(--mp-ink);
}

@media (max-width: 640px) {
    .mp-tl::before {
        left: 7px;
        transform: none;
    }

    .mp-tl__item {
        grid-template-columns: 30px minmax(0, 1fr);
    }

    .mp-tl__item + .mp-tl__item {
        margin-top: 12px;
    }

    .mp-tl__year {
        display: none;
    }

    .mp-tl__date {
        display: block;
    }

    .mp-tl__item::before {
        left: 1px;
        top: 22px;
        transform: none;
    }

    .mp-tl__card,
    .mp-tl__item:nth-child(even) .mp-tl__card {
        grid-column: 2;
        padding: 12px 16px;
        text-align: left;
    }

    .mp-tl__card::after,
    .mp-tl__item:nth-child(even) .mp-tl__card::after {
        display: none;
    }

    .mp-tl__date {
        font-size: 22px;
    }

    .mp .mp-tl__text {
        margin-top: 4px;
    }
}

/* --- Gallery ------------------------------------------------------------ */

.mp-gallery {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.mp-gallery--full {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mp-gallery .gallery-item {
    display: block;
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    background: var(--mp-soft);
}

.mp-gallery .gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}

.mp-gallery .video-gallery-item > div {
    height: 100%;
}

/* --- Candle ------------------------------------------------------------- */

.mp-candle {
    background: var(--mp-soft);
    border-radius: var(--mp-radius);
    padding: 28px;
    text-align: center;
}

.mp-candle__flame {
    display: block;
    margin: 0 auto;
    color: var(--mp-accent-text);
}

.mp-candle.is-lit .mp-candle__flame path {
    fill: var(--mp-accent);
    fill-opacity: 0.25;
    transform-origin: 12px 14px;
    animation: mp-flicker 2.4s ease-in-out infinite;
}

@keyframes mp-flicker {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06, 0.96); }
}

@media (prefers-reduced-motion: reduce) {
    .mp-candle.is-lit .mp-candle__flame path {
        animation: none;
    }
}

.mp-candle__count {
    margin-top: 6px;
    font-family: var(--mp-serif);
    font-size: 44px;
    font-weight: 600;
    line-height: 1;
}

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

.mp-candle__last {
    margin-top: 6px;
    font-size: 14px;
    color: var(--mp-muted);
    min-height: 1.4em;
}

.mp-candle__form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 18px;
    text-align: left;
}

/* --- Forms -------------------------------------------------------------- */

.mp-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.mp-field label,
.mp-label {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--mp-ink);
}

.mp-input,
.mp-field input[type="text"],
.mp-field input[type="email"],
.mp-field textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--mp-line);
    border-radius: 10px;
    background: var(--mp-bg);
    color: var(--mp-ink);
    font: 16px var(--mp-sans);
}

.mp-field textarea {
    resize: vertical;
}

.mp-input::placeholder,
.mp-field input::placeholder,
.mp-field textarea::placeholder {
    color: var(--mp-muted);
    opacity: 0.8;
}

.mp-upload {
    display: block;
    cursor: pointer;
    margin: 0;
}

.mp-upload .border-dashed {
    padding: 16px;
    border: 1px dashed var(--mp-line);
    border-radius: 10px;
    text-align: center;
    font-size: 14px;
    color: var(--mp-muted);
}

.mp-upload .border-dashed:hover,
.mp-upload .border-dashed.is-over {
    border-color: var(--mp-accent);
}

.mp-upload .upload-text {
    font-weight: 600;
    color: var(--mp-accent-text);
}

.mp-upload .text-xs.text-gray-500 {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    color: var(--mp-muted) !important;
}

.mp-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 4px 0 16px;
    font-size: 14px;
    color: var(--mp-muted);
}

.mp-check input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--mp-accent);
}

.mp-check a {
    text-decoration: underline;
}

/* --- Tributes ----------------------------------------------------------- */

.mp-tributes {
    display: flex;
    flex-direction: column;
}

.mp-tribute {
    padding: 18px 0;
    border-bottom: 1px solid var(--mp-line);
}

.mp-tribute:first-child {
    padding-top: 0;
}

.mp-tribute:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.mp-tribute__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}

.mp-tribute__name {
    font-weight: 600;
    font-size: 15px;
}

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

.mp-tribute__text {
    margin: 6px 0 0;
    white-space: pre-line;
}

.mp-tribute__img {
    display: block;
    margin-top: 12px;
    max-width: 280px;
    border-radius: 12px;
}

.mp-tribute__actions {
    display: flex;
    gap: 18px;
    margin-top: 10px;
}

.mp-link-btn,
.mp .like-button,
.mp .reply-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0;
    border: none;
    background: none;
    color: var(--mp-muted);
    font: 14px var(--mp-sans);
    cursor: pointer;
}

.mp .like-button:hover,
.mp .reply-button:hover {
    color: var(--mp-ink);
}

.mp .like-button.liked {
    color: var(--mp-accent-text);
}

.mp .like-button.liked svg path {
    fill: currentColor;
}

.mp .reply-form {
    margin-top: 14px;
    padding: 16px;
    border-radius: 12px;
    background: var(--mp-bg);
}

.mp .reply-form.hidden {
    display: none;
}

.mp-form-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.mp-replies {
    margin: 14px 0 0 20px;
    padding-left: 16px;
    border-left: 2px solid var(--mp-line);
}

.mp-reply + .mp-reply {
    margin-top: 12px;
}

/* --- Footer ------------------------------------------------------------- */

.mp-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 24px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--mp-line);
    font-size: 14px;
    color: var(--mp-muted);
}

/* --- Toasts (appended to <body>, outside .mp) ---------------------------- */

.memorial-toast-stack {
    position: fixed;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 2000;
    pointer-events: none;
}

.memorial-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 260px;
    max-width: 340px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--mp-surface);
    border: 1px solid var(--mp-line);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
    color: var(--mp-ink);
    font-family: 'Source Sans 3', system-ui, sans-serif;
    line-height: 1.4;
    pointer-events: auto;
    animation: mp-toast-in 0.3s ease forwards;
}

.memorial-toast__icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--mp-soft);
    color: var(--mp-accent-text);
}

.memorial-toast--error .memorial-toast__icon {
    color: #b42318;
}

.memorial-toast__body {
    flex: 1;
}

.memorial-toast__message {
    margin: 0;
    font-size: 15px;
}

.memorial-toast__close {
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    font-size: 18px;
    cursor: pointer;
}

.memorial-toast--closing {
    animation: mp-toast-out 0.25s ease forwards;
}

@keyframes mp-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes mp-toast-out {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(8px); }
}

/* --- Narrow screens ----------------------------------------------------- */

@media (max-width: 960px) {
    .mp-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .mp-gallery--full {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .mp-wrap {
        padding: 0 16px;
    }

    .mp-top {
        min-height: 56px;
    }

    .mp-brand {
        font-size: 24px;
    }

    .mp-cover,
    .mp .header-container {
        height: 200px;
        border-radius: 16px;
    }

    .mp-hero {
        margin-top: -60px;
    }

    .mp-portrait {
        width: 120px;
        height: 120px;
        border-width: 5px;
        font-size: 40px;
    }

    .mp-eyebrow {
        margin-top: 16px;
        font-size: 12px;
    }

    .mp-dates {
        font-size: 17px;
    }

    .mp-actions {
        width: 100%;
    }

    .mp-actions .mp-btn {
        flex: 1 1 140px;
    }

    .mp-actions .mp-btn--primary {
        flex-basis: 100%;
    }

    .mp-tabs {
        justify-content: flex-start;
        gap: 24px;
        margin-top: 28px;
    }

    .mp-layout {
        gap: 16px;
        margin-top: 20px;
    }

    .mp-card,
    .mp-side .mp-card,
    .mp-candle {
        padding: 22px 20px;
    }

    .mp .mp-card__title {
        font-size: 26px;
    }


    .mp-gallery,
    .mp-gallery--full {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .memorial-toast-stack {
        top: auto;
        bottom: 16px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(92vw, 360px);
    }
}
