/* ================================================================
   SENDOFF – Memorial Page Styles
   ================================================================
   
   CUSTOMISE THESE VALUES
   Change the colours or sizes here to adjust the whole page.
   ================================================================ */

:root {
  /* ---- Colours (light mode) ---- */
  --color-bg:       #FAF6EF;       /* warm cream background         */
  --color-text:     #2B2521;       /* deep warm charcoal-brown       */
  --color-text-sub: #6B5E54;       /* softer brown for subtitles     */
  --color-accent:   #A85A3F;       /* warm terracotta (WCAG AA 5:1)  */
  --color-accent-hover: #965137;   /* darker terracotta on hover     */
  --color-accent-text: #FFFFFF;    /* white text on button           */
  --color-card-bg:  #FFFFFF;       /* white card for the preview     */
  --color-card-border: #EDE7DF;    /* subtle warm border             */
  --color-shadow:   rgba(43, 37, 33, 0.08);
  --color-shadow-lg: rgba(43, 37, 33, 0.12);
  --color-link:     #A85A3F;       /* terracotta links               */
  --color-footer:   #8A7D74;       /* muted footer text              */
  --color-success:  #5B7A5E;       /* gentle green for success msg   */
  --color-error:    #A85A3F;       /* reuse accent for errors        */

  /* ---- Typography ---- */
  --font-serif: 'Cormorant Garamond', 'Georgia', 'Times New Roman', serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Fluid type scale: min at 320px, max at 520px viewport */
  --text-xs:    clamp(0.75rem,  0.7rem  + 0.25vw, 0.8125rem);
  --text-sm:    clamp(0.8125rem, 0.75rem + 0.3vw, 0.9375rem);
  --text-base:  clamp(0.9375rem, 0.875rem + 0.3vw, 1.0625rem);
  --text-lg:    clamp(1.0625rem, 0.9rem  + 0.5vw, 1.25rem);
  --text-xl:    clamp(1.25rem,  1rem    + 1vw,   1.75rem);
  --text-2xl:   clamp(1.75rem,  1.25rem + 2vw,   2.75rem);
  --text-3xl:   clamp(2.25rem,  1.5rem  + 3vw,   3.5rem);

  /* ---- Spacing ---- */
  --space-xs:   0.5rem;
  --space-sm:   0.75rem;
  --space-md:   1rem;
  --space-lg:   1.5rem;
  --space-xl:   2rem;
  --space-2xl:  3rem;
  --space-3xl:  4rem;

  /* ---- Shapes ---- */
  --radius-sm:  0.5rem;
  --radius-md:  0.875rem;
  --radius-lg:  1.25rem;
  --radius-btn: 0.875rem;

  /* ---- Layout ---- */
  --max-width:  500px;
  --side-pad:   clamp(1.25rem, 5vw, 2rem);
}

/* ================================================================
   Dark mode – follows device setting automatically
   ================================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:         #1E1915;
    --color-text:       #F0EAE2;
    --color-text-sub:   #BEB3A7;
    --color-accent:     #C87A60;       /* lighter terracotta for dark bg */
    --color-accent-hover: #D48B72;
    --color-accent-text: #1E1915;      /* dark text on light button      */
    --color-card-bg:    #2A2320;
    --color-card-border: #3D342E;
    --color-shadow:     rgba(0, 0, 0, 0.2);
    --color-shadow-lg:  rgba(0, 0, 0, 0.3);
    --color-link:       #C87A60;
    --color-footer:     #8A7D74;
    --color-success:    #8DB88F;
    --color-error:      #C87A60;
  }
}

/* ================================================================
   Font faces – self-hosted, no external requests
   ================================================================ */
@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;  /* text visible immediately while font loads */
  src: url('fonts/cormorant-garamond-regular.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF,
                 U+FFFD;
}

@font-face {
  font-family: 'Cormorant Garamond';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/cormorant-garamond-semibold.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF,
                 U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/inter-regular.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF,
                 U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/inter-semibold.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF,
                 U+FFFD;
}

/* ================================================================
   Reset & base
   ================================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-bottom: calc(10.5rem + env(safe-area-inset-bottom, 0px));
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height for mobile */
  overflow-x: hidden;
}

/* ================================================================
   Page layout — single centred column
   ================================================================ */
.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top, 0px)
    calc(var(--side-pad) + env(safe-area-inset-right, 0px))
    env(safe-area-inset-bottom, 0px)
    calc(var(--side-pad) + env(safe-area-inset-left, 0px));
}

.content {
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  padding-top: var(--space-2xl);
  padding-bottom: var(--space-lg);
}

/* ================================================================
   Fade-in animation
   ================================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.content {
  animation: fadeIn 0.6s ease-out both;
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  .content {
    animation: none;
  }
  .btn-download,
  .preview-card,
  .btn-progress,
  .feedback-message {
    transition: none !important;
    animation: none !important;
  }
}

/* ================================================================
   Header text
   ================================================================ */
.memorial-prefix {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-sub);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--space-xs);
}

.memorial-name {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.15;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

/* YEARS – easy to hide: delete or comment out the element in HTML */
.memorial-years {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-sub);
  letter-spacing: 0.08em;
  margin-bottom: var(--space-lg);
}

.memorial-tagline {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: 400;
  font-style: italic;
  color: var(--color-text-sub);
  margin-bottom: var(--space-xl);
}

/* ================================================================
   Preview card – like a sheet of paper resting on the page
   ================================================================ */
.preview-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow:
    0 1px 3px var(--color-shadow),
    0 6px 20px var(--color-shadow),
    0 12px 40px var(--color-shadow-lg);
  margin-bottom: var(--space-xl);
  width: 100%;
  max-width: 320px;
  transition: box-shadow 0.3s ease;
}

.preview-card:hover {
  box-shadow:
    0 2px 6px var(--color-shadow),
    0 10px 28px var(--color-shadow),
    0 16px 48px var(--color-shadow-lg);
}

.preview-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}

/* Limit preview height on small phones so button stays in view */
@media (max-height: 700px) {
  .preview-card {
    max-width: 260px;
  }
}

/* ================================================================
   Download button – full width on mobile, generous tap target
   ================================================================ */
.btn-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  width: 100%;
  max-width: 360px;
  min-height: 3.5rem;  /* 56px – exceeds 52px minimum */
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius-btn);
  background-color: var(--color-accent);
  color: var(--color-accent-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px var(--color-shadow);
  position: relative;
  overflow: hidden;
}

.btn-download:hover {
  background-color: var(--color-accent-hover);
  box-shadow: 0 4px 14px var(--color-shadow-lg);
}

.btn-download:active,
.btn-download.is-pressing {
  transform: scale(0.97);
}

/* Keyboard focus ring */
.btn-download:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

/* Button states */
.btn-download .btn-icon {
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
}

.btn-download.is-preparing {
  background-color: var(--color-accent);
  opacity: 0.9;
}

.btn-download.is-starting,
.btn-download.is-downloading {
  background-color: var(--color-accent);
}

/* Progress bar inside button */
.btn-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background-color: var(--color-accent-text);
  opacity: 0.35;
  border-radius: 0 0 var(--radius-btn) var(--radius-btn);
  transition: width 0.3s ease;
  width: 0;
}

.btn-download.is-starting .btn-progress,
.btn-download.is-downloading .btn-progress {
  width: 100%;
  transition: width 1.2s ease-in-out;
}

.btn-download.is-complete {
  background-color: var(--color-accent);
}

/* ================================================================
   Pinned bottom action bar (Apple-style frosted glass)
   ================================================================ */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 100;
  display: flex;
  justify-content: center;
  padding:
    0.75rem
    calc(var(--side-pad) + env(safe-area-inset-right, 0px))
    calc(0.75rem + env(safe-area-inset-bottom, 0px))
    calc(var(--side-pad) + env(safe-area-inset-left, 0px));
  background-color: var(--color-bg); /* Solid fallback for browsers without blur */
  border-top: 1px solid rgba(43, 37, 33, 0.08);
  box-shadow: 0 -4px 20px rgba(43, 37, 33, 0.05);
}

@media (prefers-color-scheme: dark) {
  .action-bar {
    border-top: 1px solid rgba(240, 234, 226, 0.08);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  }
}

/* Translucent blurred backdrop when supported */
@supports (backdrop-filter: blur(16px)) or (-webkit-backdrop-filter: blur(16px)) {
  .action-bar {
    background-color: rgba(250, 246, 239, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }
  @media (prefers-color-scheme: dark) {
    .action-bar {
      background-color: rgba(30, 25, 21, 0.88);
    }
  }
}

/* Solid background when reduced transparency is requested */
@media (prefers-reduced-transparency: reduce) {
  .action-bar {
    background-color: var(--color-bg) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

.action-bar-inner {
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.action-bar .btn-download {
  width: 100%;
  max-width: 340px;
  height: 3.25rem;
  min-height: 3.25rem;
  margin: 0 auto;
}

/* Reserved space for feedback/open-link so bar never shifts height */
.download-feedback {
  width: 100%;
  max-width: 340px;
  height: 3.5rem;
  min-height: 3.5rem;
  margin: 0.25rem auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.feedback-message {
  opacity: 0;
  transition: opacity 0.4s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
  width: 100%;
}

.feedback-message.is-visible {
  opacity: 1;
}

.feedback-primary {
  display: block;
  font-family: var(--font-serif);
  font-size: var(--text-base);
  font-style: italic;
  color: var(--color-text-sub);
  line-height: 1.3;
}

.feedback-secondary {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-footer);
  font-style: normal;
  line-height: 1.35;
}

.feedback-secondary a,
.feedback-link {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.feedback-secondary a:hover,
.feedback-link:hover {
  opacity: 0.75;
}

/* "Open in browser" link */
.open-link {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  padding: 0.25rem 0.5rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
}

.open-link:hover {
  opacity: 0.75;
}

.open-link:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.open-link.is-hidden {
  display: none !important;
}

/* ================================================================
   Footer
   ================================================================ */
.footer {
  width: 100%;
  max-width: var(--max-width);
  text-align: center;
  padding-top: var(--space-xl);
  padding-bottom: calc(10.5rem + env(safe-area-inset-bottom, 0px));
  margin-top: auto;
}

.footer-text {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--color-footer);
  letter-spacing: 0.04em;
}

/* ================================================================
   404 Page (Unpinned, centered)
   ================================================================ */
.not-found-title {
  margin-top: var(--space-2xl);
  font-size: var(--text-2xl);
}

.not-found-desc {
  margin-top: var(--space-md);
}

.not-found-btn-wrap {
  margin-top: var(--space-xl);
}

.not-found-btn {
  text-decoration: none;
  display: inline-flex;
}

/* ================================================================
   Responsive fine-tuning
   ================================================================ */

/* Very small phones (320px) */
@media (max-width: 350px) {
  .memorial-name {
    font-size: clamp(1.75rem, 8vw, 2.25rem);
  }
  .preview-card {
    max-width: 240px;
  }
  .btn-download {
    font-size: var(--text-sm);
    min-height: 3.25rem;
  }
}

/* Tablets and up */
@media (min-width: 768px) {
  .content {
    padding-top: var(--space-3xl);
  }
  .preview-card {
    max-width: 340px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .content {
    padding-top: 5rem;
  }
}

/* Fallback to normal flow when screen height is short (<30% threshold, e.g. landscape phone or very large text) */
@media (max-height: 500px) {
  html {
    scroll-padding-bottom: 0px;
  }
  .action-bar {
    position: static;
    width: 100%;
    max-width: var(--max-width);
    margin: var(--space-lg) auto 0;
    padding: 0;
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-top: none;
    box-shadow: none;
  }
  .footer {
    padding-bottom: var(--space-lg);
  }
}

/* ================================================================
   Screen reader only utility
   ================================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
