@import url('https://fonts.googleapis.com/css2?family=IM+Fell+English:ital@0;1&display=swap');

:root {
    --color-primary:        #2c1810;
    --color-accent:         #8b4513;
    --color-accent-dark:    #5a2d0c;
    --color-bg:             #f4e4bc;
    --color-bg-light:       #fdf6e3;
    --color-notice:         #ffe4b5;
    --color-stamp-border:   #c8a96e;

    --shadow-sm:  0.125em 0.125em 0.5em rgba(0,0,0,0.20);
    --shadow-md:  2px 3px 10px          rgba(0,0,0,0.20);
    --shadow-lg:  drop-shadow(0 4px 18px rgba(0,0,0,0.38))
                  drop-shadow(0 2px 6px  rgba(0,0,0,0.22))
                  drop-shadow(-2px -1px 4px rgba(0,0,0,0.12));

    --spacing-xs: 0.5em;
    --spacing-sm: 1em;
    --spacing-md: 1.25em;
    --spacing-lg: 2em;
    --spacing-xl: 2.5em;

    /* Stamp perforation tooth radius */
    --perf: 7px;
}

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

html { height: 100%; font-size: 16px; }

body {
    min-height: 100vh;
    background-image: url('../assets/planks.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--color-primary);
    font-family: 'IM Fell English', Georgia, serif;
    line-height: 1.6;
    padding: var(--spacing-md);
}


/* ============================================================
   PAGE CONTAINER & PAPER
   ============================================================ */

.page-container {
    max-width: 52.5em;
    margin: var(--spacing-xl) auto;
    padding: var(--spacing-md);
    perspective: 62.5em;
    filter: var(--shadow-lg);
}

.page {
    position: relative;
    max-width: 50em;
    margin: 0 auto;
    padding: var(--spacing-xl);
    background-color: var(--color-bg);
    transform-style: preserve-3d;
    will-change: transform;
    box-shadow: var(--shadow-md),
                inset 0 0 50px  rgba(0,0,0,0.08),
                inset 0 0 100px rgba(139,69,19,0.06);
    animation: paperMovement 12s infinite ease-in-out;
    overflow: hidden;
}

.page:hover {
    animation-play-state: paused;
    transform: translate3d(0, -0.2em, 0) scale(1.01);
}

@keyframes paperMovement {
    0%,100% { transform: translate3d(0,0,0)     scale(1.01) rotateY(-0.6deg) rotateX( 0.3deg) rotate( 0.15deg); }
    25%      { transform: translate3d(2px,2px,0)  scale(1.01) rotateY( 0.3deg) rotateX( 0.5deg) rotate(-0.2deg);  }
    50%      { transform: translate3d(-1px,3px,0) scale(1.01) rotateY( 0.6deg) rotateX(-0.3deg) rotate( 0.1deg);  }
    75%      { transform: translate3d(1px,1px,0)  scale(1.01) rotateY( 0.3deg) rotateX(-0.5deg) rotate(-0.15deg); }
}


/* ---- Paper texture ---- */

.page-texture {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background-color: var(--color-bg);
    opacity: 0.85;
    background-image:
        linear-gradient(to right,  rgba(101,55,10,0.28) 0%, rgba(139,69,19,0.12) 4%, transparent 12%),
        linear-gradient(to left,   rgba(101,55,10,0.28) 0%, rgba(139,69,19,0.12) 4%, transparent 12%),
        linear-gradient(to bottom, rgba(80,40,8,0.22) 0%, rgba(139,69,19,0.09) 3%, transparent 13%),
        linear-gradient(to top,    rgba(80,40,8,0.25) 0%, rgba(139,69,19,0.10) 4%, transparent 12%),
        linear-gradient(180deg,
            transparent 43.5%, rgba(0,0,0,0.005) 44.2%, rgba(0,0,0,0.09) 44.7%,
            rgba(255,255,255,0.14) 45.0%, rgba(0,0,0,0.06) 45.3%, transparent 46.0%),
        linear-gradient(180deg,
            transparent 68%, rgba(0,0,0,0.003) 68.5%, rgba(0,0,0,0.055) 68.9%,
            rgba(255,255,255,0.08) 69.15%, rgba(0,0,0,0.03) 69.4%, transparent 69.9%),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 250 250' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-blend-mode: multiply, multiply, multiply, multiply, multiply, multiply, overlay;
}

.page-texture::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 15% 15%, rgba(139,69,19,0.08) 0%, transparent 4%),
        radial-gradient(circle at 85% 30%, rgba(139,69,19,0.06) 0%, transparent 5%),
        radial-gradient(circle at 20% 85%, rgba(200,200,200,0.5) 0%, transparent 8%);
    background-blend-mode: multiply;
    pointer-events: none;
}

.foxing {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    opacity: 0.9;
    mix-blend-mode: multiply;
    background-image:
        radial-gradient(circle at 12% 15%, rgba(139,69,19,0.25) 0%, rgba(139,69,19,0.15) 0.6%, transparent 1.2%),
        radial-gradient(circle at 45% 32%, rgba(139,69,19,0.25) 0%, rgba(139,69,19,0.15) 0.6%, transparent 1.2%),
        radial-gradient(circle at 78% 67%, rgba(139,69,19,0.25) 0%, rgba(139,69,19,0.15) 0.6%, transparent 1.2%),
        radial-gradient(circle at 25% 82%, rgba(139,69,19,0.22) 0%, transparent 1.2%),
        radial-gradient(circle at 88% 45%, rgba(160,82,45,0.22) 0%, transparent 1.2%),
        radial-gradient(circle at 8%  65%, rgba(139,69,19,0.20) 0%, transparent 0.5%),
        radial-gradient(circle at 52% 83%, rgba(160,82,45,0.21) 0%, transparent 0.4%),
        radial-gradient(circle at 71% 44%, rgba(139,69,19,0.23) 0%, transparent 0.5%),
        radial-gradient(circle at 95% 88%, rgba(139,69,19,0.21) 0%, transparent 0.4%),
        radial-gradient(circle at 38% 56%, rgba(139,69,19,0.19) 0%, transparent 0.3%);
}


/* ============================================================
   HEADER
   ============================================================ */

.header {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    position: relative;
    z-index: 3;
}

.header h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }

.fancy-divider {
    text-align: center;
    position: relative;
    margin: var(--spacing-md) 0;
}

.fancy-divider::before,
.fancy-divider::after {
    content: "";
    display: inline-block;
    width: 28%;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--color-accent), transparent);
    vertical-align: middle;
    margin: 0 var(--spacing-sm);
}

.fancy-divider span { color: var(--color-accent); font-size: 1.5em; }


/* ============================================================
   CONTENT
   ============================================================ */

.content {
    position: relative;
    z-index: 3;
}

.letter-date {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--color-accent);
    text-align: right;
    margin-bottom: var(--spacing-md);
}

.letter-body { font-size: 0.95rem; }
.letter-body p { margin-bottom: var(--spacing-sm); }

.letter-closing {
    text-align: right;
    margin-top: var(--spacing-md);
    font-style: italic;
    font-size: 0.9rem;
    color: var(--color-accent-dark);
}

.notice {
    background: var(--color-notice);
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px dashed var(--color-accent);
    margin: var(--spacing-sm) 0;
    font-size: 0.85rem;
}

/* ============================================================
   LINK STYLES
   ============================================================ */

/* All links in the main content */
.content a {
    color: #6b3010;
    text-decoration: underline;
    text-decoration-color: rgba(107, 48, 16, 0.4);
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
    font-style: italic;
}

.content a:visited {
    color: #4a2510;
}

.content a:hover,
.content a:focus {
    color: #3a1a08;
    text-decoration-color: rgba(58, 26, 8, 0.8);
    outline: none;
}

.content a:focus-visible {
    outline: 1px dashed rgba(107, 48, 16, 0.6);
    outline-offset: 3px;
    border-radius: 1px;
}


/* ============================================================
   TOOLTIPS
   ============================================================ */

.tooltip-link {
    position: relative;
}

/* The tooltip bubble */
.tooltip-link::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 0.6em);
    left: 50%;
    transform: translateX(-50%) translateY(0.3em);
    
    /* Sizing & text */
    width: max-content;
    max-width: 16em;
    padding: 0.45em 0.75em;
    font-size: 0.8rem;
    font-style: normal;
    line-height: 1.45;
    text-align: center;
    
    /* Parchment styling */
    background-color: #f9edd5;
    color: #2c1810;
    border: 1px solid rgba(139, 69, 19, 0.5);
    box-shadow: 
        1px 2px 6px rgba(0, 0, 0, 0.18),
        inset 0 0 12px rgba(139, 69, 19, 0.06);
    
    /* Visibility */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 100;
    
    /* Prevent tooltip from inheriting link italic */
    font-style: italic;
    letter-spacing: 0.01em;
}

/* The little downward-pointing caret */
.tooltip-link::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 0.25em);
    left: 50%;
    transform: translateX(-50%) translateY(0.3em);
    
    width: 0;
    height: 0;
    border-left: 0.4em solid transparent;
    border-right: 0.4em solid transparent;
    border-top: 0.4em solid rgba(139, 69, 19, 0.5);
    
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 101;
}

/* Show on hover/focus */
.tooltip-link:hover::before,
.tooltip-link:focus::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tooltip-link:hover::after,
.tooltip-link:focus::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Keep tooltip on screen when near left/right edges */
@media (max-width: 48em) {
    .tooltip-link::before {
        max-width: 12em;
        left: 0;
        transform: translateX(0) translateY(0.3em);
    }
    .tooltip-link:hover::before,
    .tooltip-link:focus::before {
        transform: translateX(0) translateY(0);
    }
    .tooltip-link::after {
        left: 1em;
    }
}

/* ============================================================
   GUESTBOOK
   ============================================================ */

.guestbook-section {
    margin-top: var(--spacing-lg);
    border-top: 1px solid rgba(139,69,19,0.25);
    padding-top: var(--spacing-md);
}

.guestbook-section h3 {
    font-variant: small-caps;
    color: var(--color-accent);
    margin-bottom: var(--spacing-sm);
}

.guestbook-entries {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    max-height: 18em;
    overflow-y: auto;
    padding-right: 0.5em;
    margin-bottom: var(--spacing-sm);
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent) transparent;
}

.guestbook-entries::-webkit-scrollbar { width: 6px; }
.guestbook-entries::-webkit-scrollbar-thumb { background: rgba(139,69,19,0.4); border-radius: 3px; }

.entry {
    background: rgba(255,255,255,0.55);
    border-left: 3px solid var(--color-accent);
    padding: 0.4em 0.7em;
    backdrop-filter: blur(2px);
}

.entry-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--color-accent);
    margin-bottom: 0.15em;
    font-variant: small-caps;
}

.entry-text { font-size: 0.88rem; }

.guestbook-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5em var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.guestbook-form label {
    display: block;
    font-size: 0.75rem;
    font-variant: small-caps;
    color: var(--color-accent);
    margin-bottom: 0.2em;
}

.guestbook-form .field-full { grid-column: 1 / -1; }

.guestbook-form input,
.guestbook-form textarea {
    width: 100%;
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(139,69,19,0.40);
    padding: 0.35em 0.5em;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 0.88rem;
    color: var(--color-primary);
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    resize: vertical;
}

.guestbook-form input:focus,
.guestbook-form textarea:focus {
    border-color: var(--color-accent);
    background: rgba(255,255,255,0.92);
}

.btn-sign {
    grid-column: 1 / -1;
    background: var(--color-bg);
    border: 1px solid var(--color-accent);
    padding: 0.4em var(--spacing-sm);
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 0.9rem;
    font-variant: small-caps;
    color: var(--color-accent-dark);
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: background 0.2s, color 0.2s;
}

.btn-sign:hover {
    background: var(--color-accent);
    color: var(--color-bg-light);
}

.form-status {
    grid-column: 1 / -1;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--color-accent-dark);
    min-height: 1.2em;
}


/* ============================================================
   STAMPS — fixed to the viewport background
   
   Serrated edge technique: four radial-gradient masks, one per
   side, each tiling a row/column of semicircular bites.
   A solid linear-gradient fills the interior so only the
   teeth along the edges are punched out.
   ============================================================ */

.stamp-pin {
    position: fixed;
    z-index: 50;
    text-decoration: none;
    color: var(--color-primary);

    /* tooth diameter = --perf * 2 */
    -webkit-mask-image:
        radial-gradient(circle at 50% 0%,   transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 50% 100%, transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 0%  50%,  transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 100% 50%, transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        linear-gradient(#000, #000);
    -webkit-mask-size:
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        100% 100%;
    -webkit-mask-position:
        var(--perf) 0,
        var(--perf) 100%,
        0 var(--perf),
        100% var(--perf),
        0 0;
    -webkit-mask-repeat: repeat-x, repeat-x, repeat-y, repeat-y, no-repeat;
    -webkit-mask-composite: source-in, source-in, source-in, source-in, destination-over;

    mask-image:
        radial-gradient(circle at 50% 0%,   transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 50% 100%, transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 0%  50%,  transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        radial-gradient(circle at 100% 50%, transparent var(--perf), #000 calc(var(--perf) + 0.5px)),
        linear-gradient(#000, #000);
    mask-size:
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        calc(var(--perf) * 2) calc(var(--perf) * 2),
        100% 100%;
    mask-position:
        var(--perf) 0,
        var(--perf) 100%,
        0 var(--perf),
        100% var(--perf),
        0 0;
    mask-repeat: repeat-x, repeat-x, repeat-y, repeat-y, no-repeat;
    mask-composite: subtract, subtract, subtract, subtract, add;

    filter: drop-shadow(2px 3px 8px rgba(0,0,0,0.42));
    transition: transform 0.2s ease, filter 0.2s ease;
}

.stamp-pin:hover { filter: drop-shadow(3px 5px 14px rgba(0,0,0,0.58)); }

/* Hover tilts — odd stamps lean right, even lean left */
.stamp-pin:nth-child(odd):hover  { transform: var(--base-t) rotate( 2.5deg) scale(1.06) !important; }
.stamp-pin:nth-child(even):hover { transform: var(--base-t) rotate(-2.5deg) scale(1.06) !important; }

/* Inner face */
.stamp-face {
    background: var(--color-bg-light);
    padding: 0.55em 0.55em 0.42em;
    border: 2px solid var(--color-stamp-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25em;
    position: relative;
}

.stamp-illustration {
    width: 100%;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4em;
    background: linear-gradient(135deg, rgba(244,228,188,0.5), rgba(255,248,220,0.9));
    border: 1px solid rgba(139,69,19,0.18);
}

.stamp-label {
    font-size: 0.62rem;
    font-variant: small-caps;
    letter-spacing: 0.06em;
    color: var(--color-accent-dark);
    text-align: center;
    line-height: 1.25;
}

.stamp-value {
    font-size: 0.55rem;
    color: var(--color-accent);
    letter-spacing: 0.04em;
}

/* Postmark ink circle */
.stamp-postmark {
    position: absolute;
    top: 12%;
    right: 5%;
    width: 44%;
    aspect-ratio: 1;
    border: 2px solid rgba(139,69,19,0.40);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.36rem;
    text-align: center;
    color: rgba(139,69,19,0.55);
    letter-spacing: 0.07em;
    font-variant: small-caps;
    rotate: -22deg;
    pointer-events: none;
    line-height: 1.3;
    padding: 0.25em;
}

.stamp-postmark::before,
.stamp-postmark::after {
    content: '';
    position: absolute;
    left: -5px; right: -5px;
    height: 1px;
    background: rgba(139,69,19,0.32);
}
.stamp-postmark::before { top: 36%; }
.stamp-postmark::after  { top: 64%; }


/* ---- Individual stamp positions & base rotations ---- */

.stamp-pin.s1 { width: 9em;   top: 12vh; left: 2vw;   --base-t: rotate(-4deg);  transform: var(--base-t); }
.stamp-pin.s2 { width: 9.5em; top: 38vh; left: 1.5vw; --base-t: rotate( 3deg);  transform: var(--base-t); }
.stamp-pin.s3 { width: 8.5em; top: 62vh; left: 2.5vw; --base-t: rotate(-2deg);  transform: var(--base-t); }

.stamp-pin.s4 { width: 9em;   top: 10vh; right: 2vw;   --base-t: rotate( 5deg); transform: var(--base-t); }
.stamp-pin.s5 { width: 9.5em; top: 36vh; right: 1.5vw; --base-t: rotate(-3deg); transform: var(--base-t); }
.stamp-pin.s6 { width: 8.5em; top: 60vh; right: 2.5vw; --base-t: rotate( 2deg); transform: var(--base-t); }

/* Hide when there isn't room beside the page */
@media (max-width: 72em) { .stamp-pin { display: none; } }


/* ============================================================
   PARTICLES
   ============================================================ */

.particle-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    overflow: visible;
}

.particle {
    position: absolute;
    width: 4px; height: 4px;
    background: rgba(139,69,19,0.3);
    border-radius: 50%;
    pointer-events: none;
}

.particle.small  { width: 3px; height: 3px; background: rgba(139,69,19,0.2); }
.particle.large  { width: 6px; height: 6px; background: rgba(139,69,19,0.4); }
.particle:nth-child(2n) { filter: blur(1px); }

@keyframes floatParticle1 {
    0%   { transform: translate(calc(var(--start-x) - 50%), 110vh) rotate(0deg);    opacity: 0; }
    10%  { opacity: 0.8; }
    90%  { opacity: 0.8; }
    100% { transform: translate(calc(var(--start-x) + 50vw), -10vh) rotate(360deg); opacity: 0; }
}
@keyframes floatParticle2 {
    0%   { transform: translate(calc(var(--start-x) + 50%), 110vh) rotate(0deg);     opacity: 0; }
    10%  { opacity: 0.6; }
    90%  { opacity: 0.6; }
    100% { transform: translate(calc(var(--start-x) - 50vw), -10vh) rotate(-360deg); opacity: 0; }
}
@keyframes floatParticle3 {
    0%   { transform: translate(var(--start-x), 110vh) rotate(0deg);                 opacity: 0; }
    10%  { opacity: 0.7; }
    90%  { opacity: 0.7; }
    100% { transform: translate(calc(var(--start-x) - 25vw), -10vh) rotate(180deg);  opacity: 0; }
}

.particle:nth-child(3n+1) { animation: floatParticle1 12s infinite linear; animation-delay: calc(var(--delay) * 1s); }
.particle:nth-child(3n+2) { animation: floatParticle2 15s infinite linear; animation-delay: calc(var(--delay) * 1s); }
.particle:nth-child(3n+3) { animation: floatParticle3 18s infinite linear; animation-delay: calc(var(--delay) * 1s); }


/* ============================================================
   RESPONSIVE & MISC
   ============================================================ */

@media (max-width: 36em) {
    :root { --spacing-xl: 1.5em; --spacing-lg: 1.25em; }
    .page { padding: var(--spacing-md); }
}

@media (prefers-reduced-motion: reduce) {
    .page { animation: none; }
    .particle { animation: none !important; }
}

@media print {
    body { background: none; }
    .page { box-shadow: none; animation: none; transform: none; }
    .page-texture, .foxing, .particle-container, .stamp-pin { display: none; }
}