/* ==========================================================================
   Sana Bir Mektubum Var — ana stil dosyası
   Eski mektup / kitap / günlük hissi. Renkler: #F5EBDD #E8D8C2 #C5A77B #72563F #382B24
   ========================================================================== */

:root {
    --cream: #F5EBDD;
    --sand: #E8D8C2;
    --gold: #C5A77B;
    --brown: #72563F;
    --ink: #382B24;
    --paper: #F3E7D3;
    --wax: #7A3527;

    --serif: "Cormorant Garamond", "EB Garamond", Garamond, "Times New Roman", Georgia, serif;
    --hand: "Caveat", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;

    --ease-soft: cubic-bezier(.22, .8, .25, 1);
    --ease-inout: cubic-bezier(.45, .05, .25, 1);

    --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    color: var(--ink);
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.5;
    background:
        radial-gradient(ellipse 120% 80% at 50% 35%, #FAF3E8 0%, var(--cream) 55%, #EADBC4 100%);
    background-attachment: fixed;
    overflow-x: hidden;
}

.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: var(--noise);
    opacity: .18;
    mix-blend-mode: multiply;
    z-index: 50;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

/* ---------- Marka ---------- */

.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: max(18px, env(safe-area-inset-top)) 22px 0;
    color: var(--brown);
    letter-spacing: .14em;
    text-transform: uppercase;
    font-size: .72rem;
    font-weight: 600;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--gold);
    font-style: italic;
    font-size: .95rem;
    letter-spacing: 0;
    text-transform: none;
}

/* ---------- Ekranlar ---------- */

main {
    flex: 1;
    display: grid;
    position: relative;
}

.screen {
    grid-area: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px max(24px, env(safe-area-inset-bottom));
    opacity: 0;
    transition: opacity .9s var(--ease-soft);
}
.screen[hidden] { display: none; }
.screen.is-active { opacity: 1; }

body.is-loading .home-copy,
body.is-loading .envelope-stage,
body.is-loading .home-note { opacity: 0; }

.home-copy, .envelope-stage, .home-note {
    transition: opacity 1.2s var(--ease-soft);
}

/* ---------- Ana ekran ---------- */

.screen-home { gap: 8px; text-align: center; }

.home-title {
    margin: 0;
    font-weight: 500;
    font-style: italic;
    font-size: clamp(2rem, 7vw, 3rem);
    line-height: 1.15;
    letter-spacing: .01em;
}

.home-sub {
    margin: .5rem 0 0;
    color: var(--brown);
    font-size: clamp(1.05rem, 3.6vw, 1.25rem);
}

.envelope-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Üst boşluk, açılan kapağın (zarf yüksekliğinin %62'si) sığacağı kadar */
    padding-top: calc(min(78vw, 340px) / 1.55 * .62 + 8px);
    margin: clamp(4px, 2vh, 20px) 0 clamp(16px, 4vh, 32px);
}

.tap-hint {
    margin: 22px 0 0;
    font-family: var(--hand);
    font-size: 1.3rem;
    color: var(--brown);
    animation: breathe 3.6s ease-in-out infinite;
    transition: opacity .5s ease;
}
.tap-hint.is-hidden { opacity: 0 !important; animation: none; }

@keyframes breathe {
    0%, 100% { opacity: .45; }
    50% { opacity: .9; }
}

.home-note {
    max-width: 28rem;
    margin: 0 0 8px;
    color: var(--brown);
    font-style: italic;
    font-size: 1.08rem;
}

.home-date {
    margin: auto 0 0;
    padding-top: 18px;
    font-size: .8rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--brown);
    opacity: .75;
}

/* ---------- Zarf ---------- */

.envelope {
    --w: min(78vw, 340px);
    position: relative;
    display: block;
    width: var(--w);
    aspect-ratio: 1.55;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .8s var(--ease-soft);
}
.envelope:hover:not(.is-busy):not(:disabled) { transform: translateY(-3px) rotate(-.4deg); }
.envelope:disabled { cursor: default; }

.env-back,
.env-pocket,
.env-flap,
.env-letter,
.seal { position: absolute; display: block; }

.env-back {
    inset: 0;
    border-radius: 5px;
    background:
        var(--noise),
        linear-gradient(180deg, #D9C2A1, #CDB38E);
    box-shadow:
        0 18px 30px -12px rgba(56, 43, 36, .35),
        0 3px 6px rgba(56, 43, 36, .12);
}

.env-letter {
    left: 7%;
    right: 7%;
    top: 7%;
    bottom: 9%;
    z-index: 2;
    border-radius: 2px;
    background:
        var(--noise),
        linear-gradient(180deg, #FBF5EA, #F1E4CF);
    box-shadow: 0 1px 3px rgba(56, 43, 36, .18);
    transition: transform 1.3s var(--ease-soft);
}

.env-letter-lines {
    position: absolute;
    inset: 22% 14% 30%;
    background: repeating-linear-gradient(180deg, transparent 0 11px, rgba(114, 86, 63, .18) 11px 12px);
}

.env-pocket {
    inset: 0;
    z-index: 3;
    border-radius: 5px;
    background:
        var(--noise),
        linear-gradient(185deg, #E9D7BB 0%, #E1CBAA 100%);
    clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
}
.env-pocket::before,
.env-pocket::after {
    content: "";
    position: absolute;
    inset: 0;
}
/* Yan kanatların hafif gölgeli kıvrımları */
.env-pocket::before {
    background: linear-gradient(100deg, rgba(255, 252, 245, .35), transparent 60%);
    clip-path: polygon(0 0, 50% 56%, 0 100%);
}
.env-pocket::after {
    background: linear-gradient(260deg, rgba(114, 86, 63, .14), transparent 60%);
    clip-path: polygon(100% 0, 50% 56%, 100% 100%);
}

.env-flap {
    left: 0;
    right: 0;
    top: 0;
    height: 62%;
    z-index: 4;
    transform-origin: 50% 0;
    transform: perspective(900px) rotateX(0deg);
    transition: transform 1.1s var(--ease-inout);
    filter: drop-shadow(0 3px 3px rgba(56, 43, 36, .2));
}
.env-flap-face {
    position: absolute;
    inset: 0;
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    background:
        var(--noise),
        linear-gradient(180deg, #E6D2B3, #D8BF9B);
    border-radius: 5px 5px 0 0;
}

/* Mühür */
.seal {
    left: 50%;
    top: 62%;
    z-index: 5;
    width: 19%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
}
.seal-half {
    position: absolute;
    inset: 0;
    transition: transform .9s var(--ease-soft), opacity .8s ease .12s;
}
.seal-left  { clip-path: polygon(0 0, 53% 0, 46% 28%, 55% 52%, 45% 76%, 51% 100%, 0 100%); }
.seal-right { clip-path: polygon(53% 0, 100% 0, 100% 100%, 51% 100%, 45% 76%, 55% 52%, 46% 28%); }
.seal-face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 48% 52% 50% 50% / 52% 47% 53% 48%;
    background: radial-gradient(circle at 36% 30%, #A2503D 0%, var(--wax) 48%, #4E1D15 100%);
    box-shadow:
        inset 0 0 0 calc(var(--w) * .012) rgba(40, 10, 5, .25),
        inset 0 calc(var(--w) * -.01) calc(var(--w) * .02) rgba(0, 0, 0, .3),
        0 2px 4px rgba(56, 20, 10, .35);
    color: rgba(255, 214, 190, .42);
    font-family: var(--serif);
    font-style: italic;
    font-weight: 600;
    font-size: calc(var(--w) * .085);
    text-shadow: 0 -1px 0 rgba(0, 0, 0, .35), 0 1px 0 rgba(255, 200, 170, .2);
    user-select: none;
}

/* Zarf animasyon adımları (JS sınıfları ekler) */
.envelope.is-nudge { animation: nudge .6s var(--ease-inout); }
@keyframes nudge {
    0%   { transform: none; }
    25%  { transform: rotate(-1.6deg) translateY(-3px); }
    55%  { transform: rotate(1.2deg) translateY(-1px); }
    80%  { transform: rotate(-.5deg); }
    100% { transform: none; }
}
.envelope.is-seal-broken .seal-left  { transform: translate(-30%, 12%) rotate(-22deg); opacity: 0; }
.envelope.is-seal-broken .seal-right { transform: translate(30%, 16%) rotate(18deg); opacity: 0; }
.envelope.is-flap-open .env-flap { transform: perspective(900px) rotateX(180deg); }
.envelope.is-flap-behind .env-flap { z-index: 1; filter: none; }
.envelope.is-flap-open .env-flap-face { background: var(--noise), linear-gradient(0deg, #E9D8BE, #DCC5A4); }
.envelope.is-letter-up .env-letter { transform: translateY(-62%); }
.envelope.is-letter-peek .env-letter { transform: translateY(-24%); }
.envelope.is-open .seal { display: none; }
.envelope.is-instant, .envelope.is-instant * { transition: none !important; }

.envelope-stage.is-leaving {
    transition: opacity .8s ease, transform 1s var(--ease-soft);
    opacity: 0;
    transform: translateY(-24px) scale(1.04);
}

/* ---------- Onarım ekranı ---------- */

.screen-repair { padding-top: 12px; }

.repair-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    width: 100%;
}

.paper-stage {
    --pw: min(90vw, 470px, calc((100dvh - 260px) * .75));
    position: relative;
    width: var(--pw);
    min-width: 260px;
    aspect-ratio: 3 / 4;
    container-type: inline-size;
}
.screen-repair.is-entering .paper-stage { animation: paper-arrive 1.3s var(--ease-soft) both; }
@keyframes paper-arrive {
    from { opacity: 0; transform: perspective(1000px) translateY(-14%) rotateX(52deg) scale(.62); }
    60%  { opacity: 1; }
    to   { opacity: 1; transform: none; }
}

.paper-shadow {
    position: absolute;
    inset: 0;
    filter: blur(10px);
    transform: translate(2px, 12px) scale(.985);
    opacity: .5;
    pointer-events: none;
}
.paper-shadow > span {
    position: absolute;
    inset: 0;
    background: #3a2a1e;
    clip-path: var(--clip);
    transition: clip-path .7s var(--ease-inout);
}

.paper {
    --text-blur: 3px;
    --text-op: .4;
    position: absolute;
    inset: 0;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    background:
        radial-gradient(ellipse 80% 70% at 50% 42%, rgba(255, 251, 243, .85), rgba(255, 251, 243, 0) 70%),
        radial-gradient(ellipse at center, transparent 58%, rgba(139, 101, 62, .28) 100%),
        var(--noise),
        linear-gradient(170deg, #F4E8D4, #EAD9BE);
    clip-path: var(--clip);
    transition: clip-path .7s var(--ease-inout);
    touch-action: none;
}

/* Kâğıt, gölgesi ve katlı köşe birlikte eğilir */
.paper-tilt {
    position: absolute;
    inset: 0;
    transform: var(--paper-tf, none);
    transition: transform .8s var(--ease-soft);
}

.paper-content {
    position: absolute;
    inset: 10% 11% 12%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    filter: blur(var(--text-blur));
    opacity: var(--text-op);
    transition: filter .6s ease, opacity .6s ease;
}
.paper-date {
    margin: 0 0 1.2em;
    align-self: flex-end;
    font-family: var(--hand);
    font-size: 5.2cqw;
    color: var(--brown);
}
.paper-message {
    margin: 0;
    font-style: italic;
    font-weight: 500;
    font-size: var(--msg-size, 6.4cqw);
    line-height: 1.42;
    color: var(--ink);
    text-wrap: pretty;
}
.paper-sign {
    margin: 1.4em 0 0;
    align-self: flex-end;
    font-family: var(--hand);
    font-size: 5cqw;
    color: var(--brown);
}

.layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transition: opacity .9s ease;
}

/* Yırtıklar: dokunma alanı + bant */
.tear {
    position: absolute;
    width: 24%;
    height: 14%;
}
.tear-0 { left: -2%; top: 31%; }
.tear-1 { left: 52%; top: -2%; width: 24%; height: 17%; }
.tape {
    position: absolute;
    left: 8%;
    top: 30%;
    width: 84%;
    height: 40%;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, .25), rgba(255, 255, 255, 0) 40%, rgba(255, 255, 255, .2)),
        rgba(232, 216, 186, .78);
    box-shadow: 0 1px 2px rgba(56, 43, 36, .2);
    clip-path: polygon(0 8%, 4% 0, 9% 10%, 14% 0, 86% 0, 91% 10%, 96% 0, 100% 8%, 100% 92%, 96% 100%, 91% 90%, 86% 100%, 14% 100%, 9% 90%, 4% 100%, 0 92%);
    transform: rotate(var(--tape-rot, -8deg)) scaleX(0);
    transform-origin: 0 50%;
    opacity: 0;
    transition: transform .55s var(--ease-soft), opacity .3s ease;
}
.tear-1 .tape { --tape-rot: 82deg; left: 0; top: 40%; width: 100%; }
.tear.is-taped .tape { transform: rotate(var(--tape-rot, -8deg)) scaleX(1); opacity: 1; }
.tear.is-pulse { animation: tear-pulse 1.1s ease 2; }
@keyframes tear-pulse {
    50% { background: radial-gradient(circle, rgba(197, 167, 123, .45), transparent 65%); }
}

/* Katlanmış köşe */
.paper-fold {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22%;
    aspect-ratio: 1;
    pointer-events: none;
    transform: perspective(700px) rotate3d(1, -1, 0, 0deg);
    transform-origin: 50% 50%;
    backface-visibility: hidden;
    transition: transform 1s var(--ease-inout), opacity .3s ease .45s;
    filter: drop-shadow(-3px -3px 4px rgba(56, 43, 36, .22));
}
.paper-fold::before {
    content: "";
    position: absolute;
    inset: 0;
    clip-path: polygon(0 0, 100% 0, 0 100%);
    background:
        var(--noise),
        linear-gradient(135deg, #DCC5A2 0%, #E8D6BA 55%, #D2B791 100%);
}
.paper-fold.is-open {
    transform: perspective(700px) rotate3d(1, -1, 0, 180deg);
    opacity: 0;
}

.touch-ring {
    position: absolute;
    left: 0;
    top: 0;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border-radius: 50%;
    border: 1.5px solid rgba(114, 86, 63, .55);
    background: rgba(255, 250, 240, .15);
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s ease;
}
.touch-ring.is-visible { opacity: 1; }

/* Onarım tamamlandığında */
.paper.is-restored { --text-blur: 0px; --text-op: 1; }
.paper.is-restored .layer { opacity: 0 !important; }

/* Araç çubuğu */
.repair-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 470px;
    transition: opacity .7s ease;
}
.repair-side.is-hidden { opacity: 0; pointer-events: none; }

.repair-hint {
    min-height: 2.9em;
    margin: 0;
    text-align: center;
    color: var(--brown);
    font-style: italic;
    font-size: 1.05rem;
    line-height: 1.4;
    transition: opacity .4s ease;
}

.toolbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
}

.tool {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border: 1px solid rgba(197, 167, 123, .45);
    border-radius: 10px;
    background: rgba(250, 244, 234, .65);
    color: var(--brown);
    font-size: .92rem;
    font-weight: 600;
    letter-spacing: .02em;
    cursor: pointer;
    transition: background .3s ease, border-color .3s ease, transform .3s var(--ease-soft), box-shadow .3s ease;
    -webkit-tap-highlight-color: transparent;
}
.tool svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.tool:hover { background: rgba(250, 244, 234, .95); }
.tool[aria-pressed="true"] {
    background: var(--sand);
    border-color: var(--gold);
    color: var(--ink);
    transform: translateY(-2px);
    box-shadow: 0 6px 14px -8px rgba(56, 43, 36, .45);
}
.tool-dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: 1px solid var(--gold);
    transition: background .5s ease;
}
.tool.is-done .tool-dot { background: var(--gold); }
.tool.is-done { color: rgba(114, 86, 63, .7); }

.progress { width: 70%; }
.progress-line {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: rgba(197, 167, 123, .3);
    overflow: hidden;
}
.progress-fill {
    display: block;
    height: 100%;
    width: 0;
    background: var(--brown);
    transition: width .8s var(--ease-soft);
}

@media (min-width: 860px) {
    .repair-layout {
        flex-direction: row;
        justify-content: center;
        gap: 56px;
    }
    .paper-stage { --pw: min(470px, calc((100dvh - 140px) * .75)); }
    .repair-side { width: 210px; }
    .toolbar { grid-template-columns: 1fr; }
    .tool { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 16px; }
    .progress { width: 100%; }
}

/* ---------- Mektup (açığa çıkan metin) ---------- */

.screen-reveal { text-align: center; gap: 22px; }

.reveal-card {
    width: min(92vw, 560px);
    padding: clamp(36px, 8vw, 64px) clamp(24px, 7vw, 60px);
    background:
        radial-gradient(ellipse 80% 70% at 50% 40%, rgba(255, 251, 243, .9), rgba(255, 251, 243, 0) 75%),
        var(--noise),
        linear-gradient(170deg, #F7EDDC, #EEDFC7);
    box-shadow: 0 24px 40px -24px rgba(56, 43, 36, .45), 0 2px 6px rgba(56, 43, 36, .08);
    border-radius: 2px;
}
.screen-reveal.is-active .reveal-card { animation: card-in 1.2s var(--ease-soft) both; }
@keyframes card-in {
    from { opacity: 0; transform: translateY(14px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.reveal-date {
    margin: 0 0 1.4rem;
    font-family: var(--hand);
    font-size: 1.35rem;
    color: var(--brown);
}
.reveal-message {
    margin: 0;
    font-style: italic;
    font-weight: 500;
    font-size: clamp(1.55rem, 5.2vw, 2.15rem);
    line-height: 1.45;
    color: var(--ink);
    text-wrap: balance;
}
.reveal-message .w {
    display: inline-block;
    opacity: 0;
    filter: blur(5px);
    transform: translateY(6px);
    animation: word-in 1.1s var(--ease-soft) forwards;
}
@keyframes word-in {
    to { opacity: 1; filter: blur(0); transform: none; }
}
.reveal-ornament {
    margin: 1.6rem 0 .4rem;
    color: var(--gold);
    letter-spacing: .6em;
    font-size: 1rem;
}
.reveal-category {
    margin: 0;
    font-size: .78rem;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--brown);
    opacity: .8;
}
.reveal-note {
    max-width: 30rem;
    margin: 0;
    color: var(--brown);
    font-style: italic;
    font-size: 1.1rem;
    opacity: 0;
    transition: opacity 1.4s ease;
}
.reveal-note.is-visible { opacity: 1; }

.link-button {
    border: 0;
    background: none;
    padding: 6px 4px;
    color: var(--brown);
    font-size: .95rem;
    text-decoration: underline;
    text-decoration-color: rgba(114, 86, 63, .35);
    text-underline-offset: 4px;
    cursor: pointer;
}
.link-button:hover { color: var(--ink); }

/* ---------- Hata sayfası, noscript ---------- */

.page-error { align-items: center; justify-content: center; text-align: center; padding: 24px 16px; }
.error-card { max-width: 30rem; }
.error-card h1 { font-style: italic; font-weight: 500; font-size: 2rem; margin: .2rem 0 .6rem; }
.error-card a { color: var(--brown); }
.eyebrow { letter-spacing: .3em; color: var(--brown); font-size: .8rem; margin: 0; }
.debug { text-align: left; white-space: pre-wrap; font-size: .8rem; background: var(--sand); padding: 12px; }
.noscript { text-align: center; padding: 16px; color: var(--brown); }

/* ---------- Hareket azaltma ---------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .25s !important;
    }
}
