/* ibm-plex-sans-regular - latin */
@font-face {
    font-display: swap;
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 400;
    src: url("/assets/fonts/ibm-plex-sans-v23-latin-regular.woff2") format("woff2");
}

/* =========================================
   1. VARIABLES & BASE RESETS
   ========================================= */
:root {
    --text: #1f1f1f;
    --muted: #666;
    --surface: #fff;
    --button: #fff;
    --button-hover: #f8f8f8;
    --button-text: #5f5f5f;
    --button-border: #dddddd;
    --danger: #b00020;
    --space-xs: 8px;
    --space-sm: 10px;
    --space-md: 14px;
    --space-lg: 40px;
    --page-padding: 16px;
    --button-padding-y: 10px;
    --button-padding-x: 18px;
    --button-max-width: 280px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100dvh;
    padding: var(--page-padding);
    display: grid;
    place-items: center;
    font-family: "IBM Plex Sans", sans-serif;
    color: var(--text);
    background: var(--surface);
}

/* =========================================
   2. SHARED COMPONENTS (Buttons)
   ========================================= */
/* Add class="btn" to your share, time-travel, and subscribe buttons */

.btn {
    /* Desktop: Standard centered grouping */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    /* Consistent spacing between icon and text */
    padding: var(--button-padding-y) var(--button-padding-x);
    border: 0.5px solid var(--button-border);
    border-radius: 999px;
    background: var(--button);
    color: var(--button-text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    /* Ensures the icon never squishes */
    display: block;
}

.btn span {
    display: inline-block;
    white-space: nowrap;
    line-height: 1;
}

/* Ensure these states stay clean */
.btn:focus-visible {
    background: var(--button-hover);
    border-color: var(--button-border);
}

@media (hover: hover) {
    .btn:hover:not(:disabled) {
        background: var(--button-hover);
        border-color: var(--button-border);
    }
}

.btn:disabled {
    opacity: 1;
    cursor: not-allowed;
}

.js-only {
    display: inline-flex;
}

html:not(.js) .js-only {
    display: none;
}

/* =========================================
   3. PAGE LAYOUT (Photos)
   ========================================= */
.photo-page {
    width: min(100%, 1186px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: var(--space-md);
    text-align: center;
}

#photoHeading {
    margin: 0;
    font-size: 1.5em;
    font-weight: 400;
}

#photoDate {
    margin: 0;
    font-size: 0.85em;
    color: var(--muted);
}

.photo-media {
    aspect-ratio: 960/636;
    width: 960px;
    height: 636px;
    max-width: 960px;
    max-height: 636px;
    min-width: 0;
    min-height: 0;
    border-radius: 0;
    position: relative;
    overflow: hidden;
    background: var(--surface);
    align-self: center;
    margin-left: auto;
    margin-right: auto;
}

#randomPhoto {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    display: block;
    display: block;
    position: relative;
    z-index: 2;
}

#randomPhoto img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain;
    object-position: center center;
    margin-left: auto;
    margin-right: auto;
    opacity: 1;
    transition: opacity 160ms ease;
}

.photo-actions {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.action-buttons {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 10px;
}

#shareStatus {
    min-height: 1.2em;
    margin: var(--space-xs) 0 0;
    font-size: 0.85em;
}

#shareStatus.error {
    color: var(--danger);
}

/* =========================================
   4. MODAL STYLES
   ========================================= */
.subscribe-modal {
    padding: 0;
    border: none;
    border-radius: 16px;
    background: transparent;
    overflow: visible;
}

.subscribe-modal::backdrop {
    background: rgba(10, 10, 10, 0.42);
    backdrop-filter: blur(6px);
}

/* Content */
.subscribe-modal__content {
    background: #fcfcfd;
    border-radius: 16px;
    border: 1px solid rgba(18, 30, 43, 0.08);
    box-shadow:
        0 20px 50px -18px rgba(15, 23, 42, 0.45),
        0 6px 18px rgba(15, 23, 42, 0.16);

    min-width: 320px;
    max-width: 92vw;
    padding: 26px 26px 22px;

    position: relative;
    overflow: hidden;

    display: flex;
    flex-direction: column;
    align-items: center;

    animation: modalIn 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Form */
#subscribeForm {
    width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Header */
.subscribe-modal__header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    margin-bottom: 14px;
}

.subscribe-modal__header-spacer {
    display: none;
}

/* Title */
.subscribe-modal__title {
    flex: 1;
    margin: 0;
    padding: 0;
    font-size: 1.32em;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: #111;
    text-align: center;
    line-height: 1.3;
}

/* Input */
.subscribe-modal__input {
    width: 100%;
    max-width: 320px;
    padding: 12px 14px;
    font-size: 0.95em;

    background: #f7f8fa;
    border: 1px solid #dde3ea;
    margin-bottom: 14px;

    outline: none;
    transition:
        border-color 0.18s,
        box-shadow 0.18s,
        background 0.18s;
}

.subscribe-modal__input:focus {
    background: #fff;
    border-color: #999;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

/* Button (softer, not black, not loud) */
.subscribe-modal__submit {
    width: 100%;
    max-width: 320px;
    padding: 12px 0;

    background: #805d48;
    color: #fff;

    font-size: 1.02em;
    font-weight: 400;

    border: none;
    border-radius: 10px;
    cursor: pointer;

    margin-bottom: 0;
    transition:
        background 0.18s,
        transform 0.18s;
}

.subscribe-modal__submit:hover:not(:disabled) {
    background: #6b4736;
}

.subscribe-modal__submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Message */
.subscribe-modal__message {
    display: none;
    margin-top: 14px;
    font-size: 0.88em;
    color: #444;
    text-align: center;
}

.subscribe-modal__message.show {
    display: block;
}

.unsubscribe-page {
    min-height: 100vh;
    margin: 0;
    padding: 24px;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at top,
            rgba(128, 93, 72, 0.12),
            transparent 40%),
        linear-gradient(180deg, #f7f5f2 0%, #f2ede7 100%);
}

.unsubscribe-page__shell {
    width: 100%;
    display: flex;
    justify-content: center;
}

.unsubscribe-page__card {
    width: min(480px, 100%);
}

.unsubscribe-page__copy {
    width: 100%;
    max-width: 320px;
    margin: 0 0 14px;
    color: #4f5b66;
    text-align: center;
    font-size: 0.95em;
    line-height: 1.55;
}

.unsubscribe-page__form {
    width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.unsubscribe-page__input[hidden] {
    display: none;
}

.unsubscribe-page__home {
    margin: 14px 0 0;
    font-size: 0.88em;
    color: #5f6770;
    text-align: center;
}

.unsubscribe-page__home a {
    color: #805d48;
    text-decoration: underline;
}

.unsubscribe-page__home a:hover {
    color: #6b4736;
}

.subscribe-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;

    min-width: 32px;
    min-height: 32px;

    border: none;
    background: none;
    box-shadow: none;

    color: #b5bcc6;
    cursor: pointer;

    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    transition:
        background 0.18s,
        color 0.18s;
    outline: none;
}

.subscribe-modal__close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #222;
}

.subscribe-modal__close:focus-visible {
    background: #eef2f6;
    color: #111;
}

/* =========================================
   5. ANIMATIONS (Loading, Shimmer, Success)
   ========================================= */
/* Image Loading Shimmer */
.photo-media::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, #f0f0f0 8%, #f8f8f8 18%, #f0f0f0 33%);
    background-size: 200% 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}

.photo-media.is-loading::before {
    opacity: 0.18;
    animation: shimmer 1.25s linear infinite;
}

.photo-media.is-loading #randomPhoto img {
    opacity: 0;
}

/* Button Loading Spinner */
.subscribe-modal__submit.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.subscribe-modal__submit.loading::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border: 2.5px solid #fff;
    border-top: 2.5px solid #1877c9;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    z-index: 2;
}

/* Success Animations */
.subscribe-modal__content.success-animating>*:not(.subscribe-modal__success-bg):not(.subscribe-modal__success-check) {
    opacity: 0 !important;
    pointer-events: none !important;
}

.subscribe-modal__success-bg {
    position: absolute;
    inset: 0;
    background: #22b573;
    transform: translateX(-100%);
    opacity: 1;
    z-index: 20;
    pointer-events: none;
    animation: modalSuccessSlide 1.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.subscribe-modal__success-check,
.subscribe-modal__checkmark {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    pointer-events: none;
}

.subscribe-modal__success-check {
    z-index: 30;
    opacity: 0;
    animation: modalCheckFadeIn 0.32s 0.48s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.subscribe-modal__checkmark {
    z-index: 10;
    opacity: 0;
    animation: checkmarkIn 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.subscribe-modal__success-check svg,
.subscribe-modal__checkmark svg {
    width: 100%;
    height: 100%;
    display: block;
}

.subscribe-modal__success-checkmark-path {
    stroke-dasharray: 36;
    stroke-dashoffset: 36;
    animation: checkmarkStroke 0.4s 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.subscribe-modal__checkmark-path {
    stroke-dasharray: 36;
    stroke-dashoffset: 36;
    animation: checkmarkStroke 0.5s 0.15s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Keyframes */
@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes modalIn {
    0% {
        transform: scale(0.85) translateY(40px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes modalSuccessSlide {
    0% {
        transform: translateX(-100%);
        opacity: 1;
    }

    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes modalCheckFadeIn {
    to {
        opacity: 1;
    }
}

@keyframes checkmarkIn {
    0% {
        opacity: 0;
        transform: scale(0.7) translate(-50%, -50%);
    }

    60% {
        opacity: 1;
        transform: scale(1.1) translate(-50%, -50%);
    }

    100% {
        opacity: 1;
        transform: scale(1) translate(-50%, -50%);
    }
}

@keyframes checkmarkStroke {
    to {
        stroke-dashoffset: 0;
    }
}

/* =========================================
   6. MEDIA QUERIES
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    .photo-media.is-loading::before {
        animation: none;
    }
}

@media (min-width: 769px) {
    body {
        height: 100dvh;
        overflow: hidden;
    }

    .photo-page {
        height: calc(100dvh - (var(--page-padding) * 2));
        grid-template-rows: auto auto auto auto;
        align-content: center;
    }

    /*
   * Removed desktop overrides for .photo-media to enforce fixed 960x636px size.
   * See main .photo-media block above for enforced sizing.
   */

    .photo-media.is-panorama #randomPhoto img {
        object-position: center center;
    }

    .action-buttons>.btn {
        width: 180px;
        max-width: 100%;
    }

    .subscribe-modal__content {
        max-width: 380px;
    }
}

@media (max-width: 768px) {
    body {
        padding: var(--space-sm);
    }

    .photo-page {
        width: 100%;
        height: auto;
        grid-template-rows: auto auto auto auto;
        gap: 14px;
    }

    .photo-media {
        height: auto;
        max-height: 56dvh;
        width: 100%;
        max-width: 100%;
        margin-inline: 0;
    }

    #randomPhoto img {
        object-position: center;
    }

    #photoHeading {
        font-size: 1.45em;
    }

    #photoDate {
        font-size: 0.95em;
    }

    .btn {
        width: min(100%, 340px);
        max-width: var(--button-max-width);
        font-size: 1rem;
        padding: 12px 18px;
    }

    .subscribe-modal {
        margin-top: 18vh;
        margin-bottom: auto;
    }
}

@media (max-width: 480px) {
    body {
        padding: var(--space-xs);
    }

    .photo-page {
        gap: 12px;
    }

    #photoHeading {
        font-size: 1.4em;
    }

    #photoDate {
        font-size: 0.95em;
    }

    .subscribe-modal__content {
        min-width: 0;
        padding: 24px 18px 20px;
    }

    .subscribe-modal__title {
        font-size: 1.15em;
        font-weight: 400;
        padding: 0;
    }
}

/* Portrait photos on small phones: icon-only buttons free up space for a taller image */
@media (max-width: 480px) {
    .photo-page:has(.is-portrait) {
        height: calc(100dvh - var(--space-xs) * 2);
        grid-template-rows: auto 1fr auto auto;
        overflow: hidden;
        padding-top: 20px;
        padding-bottom: 4px;
    }

    .photo-page:has(.is-portrait) .photo-actions {
        margin-top: auto;
    }

    .photo-page:has(.is-portrait) .photo-media {
        max-height: 100%;
        height: 100%;
        overflow: hidden;
    }

    .photo-page:has(.is-portrait) .action-buttons {
        gap: var(--space-md);
    }

    .photo-page:has(.is-portrait) .btn {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        padding: 0;
        max-width: none;
        margin: 0;
    }

    .photo-page:has(.is-portrait) .btn span {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .photo-page:has(.is-portrait) .btn svg {
        width: 20px;
        height: 20px;
        display: block;
        flex-shrink: 0;
    }
}
