/* ==========================================================================
   Doğum günü mektubu — pixel art tema
   Palet, orijinal Sevgililer Günü varlıklarından örneklendi.

   Ölçek mantığı:
   · .pencere  → ekrana sığan, en/boy oranı sabit bir kutu (arka planı PNG)
   · .icerik   → PNG'nin dama desenli alanına birebir oturan kap;
                 `container-type: size` sayesinde içindeki her şey cq
                 birimleriyle ölçekleniyor → her ekranda aynı düzen.
   · Telefonda (dikey) daha uzun bir pencere görseline geçiliyor ki
     ekranın tamamı kullanılsın.
   ========================================================================== */

/* Pixelify Sans (SIL Open Font License) yerel olarak sunuluyor:
   sayfa internet olmadan da, ilk karede doğru fontla açılır. */
@font-face {
  font-family: "Pixelify Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/pixelify-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

@font-face {
  font-family: "Pixelify Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/pixelify-sans-latin.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;
}

:root {
  /* viewport-fit=cover ile ekranın tamamını kapladığımız için pencerenin
     boyu hesaplanırken çentik + ana ekran çubuğu payı düşülüyor. */
  --dikey-pay: calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px));
  --yan-pay: calc(env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px));

  --gul: #c8685e; /* ana çerçeve / metin */
  --gul-ara: #d38a7f;
  --gul-acik: #e9d2d5;
  --bar: #e0c1cb; /* pencere başlık çubuğu / buton içi */
  --yesil: #b5d0a6; /* orijinal yes.png vurgusu */
  --mor: #c493aa; /* orijinal no.png vurgusu */
  --krem: #f7eee9;
  --alev: #e9c46a;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  min-height: var(--vh, 100svh);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--krem);
  background-image: url("heart-bg.jpg");
  background-size: 420px auto;
  color: var(--gul);
  font-family: "Pixelify Sans", "Trebuchet MS", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

/* ---------- arka plan katmanları ---------------------------------------- */

.balonlar,
.konfeti {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.balonlar {
  overflow: hidden;
  z-index: 0;
}

.balon {
  position: absolute;
  bottom: -22vh;
  width: 46px;
  opacity: 0.55;
  animation: yukselen linear infinite;
  will-change: transform;
}

@keyframes yukselen {
  0% {
    transform: translate3d(0, 0, 0) rotate(-3deg);
  }
  50% {
    transform: translate3d(22px, -60vh, 0) rotate(3deg);
  }
  100% {
    transform: translate3d(0, -125vh, 0) rotate(-3deg);
  }
}

.konfeti {
  z-index: 40;
}

/* ---------- ekranlar ----------------------------------------------------- */

/* viewport-fit=cover kullanıldığı için arka plan ekranın tamamını kaplıyor;
   içerik çentiğin ve ana ekran çubuğunun altına girmesin diye güvenli alan
   payları burada veriliyor. */
.ekran {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  text-align: center;
}

.ekran[hidden] {
  display: none;
}

/* ---------- 1. ekran: zarf ---------------------------------------------- */

.zarf-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.zarf {
  width: clamp(200px, 58vw, 270px);
  height: auto;
  animation: nabiz 1.6s ease-in-out infinite;
  filter: drop-shadow(6px 6px 0 rgba(200, 104, 94, 0.22));
}

@keyframes nabiz {
  0%,
  100% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.07) translateY(-6px);
  }
}

.zarf-yazi {
  font-size: clamp(21px, 5.8vw, 32px);
  font-weight: 600;
  line-height: 1.25;
  text-wrap: balance;
}

.ipucu {
  font-size: clamp(14px, 3.6vw, 17px);
  opacity: 0.7;
  animation: solup 2s ease-in-out infinite;
}

@keyframes solup {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 0.85;
  }
}

/* ---------- 2. ekran: mektup penceresi ----------------------------------- */

.mektup-ekrani {
  position: fixed;
  inset: 0;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

.pencere {
  /* window-bday.png ölçüleri ve dama alanının koordinatları */
  --en: 63;
  --boy: 67;
  --oran: 0.9403;
  --gorsel: url("window-bday.png");
  --ic-sol: 6.3492%;
  --ic-ust: 31.3433%;
  --ic-en: 87.3016%;
  --ic-boy: 62.6866%;
  --pay: 0.88;

  position: relative;
  aspect-ratio: var(--en) / var(--boy);
  /* --vw / --vh, script.js tarafından gerçek görünür ölçülere yazılır:
     mobil tarayıcı çubukları vh/svh değerlerini şaşırtsa bile pencere sığar. */
  width: min(94vw, 620px, 88vh * 0.9403);
  width: min(
    calc((var(--vw, 100vw) - var(--yan-pay, 0px)) * 0.94),
    620px,
    calc((var(--vh, 100svh) - var(--dikey-pay, 0px)) * var(--pay) * var(--oran))
  );
  background: var(--gorsel) center / 100% 100% no-repeat;
  image-rendering: pixelated;
  transform: scale(1.15);
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.2, 1.3, 0.4, 1), opacity 0.45s ease;
}

.pencere.acik {
  transform: scale(1);
  opacity: 1;
}

.icerik {
  position: absolute;
  left: var(--ic-sol);
  top: var(--ic-ust);
  width: var(--ic-en);
  height: var(--ic-boy);
  padding: 3% 4%;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--gul) transparent;
  container-type: size;
}

.adim {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  gap: 2.6cqh;
  min-height: 100%;
  text-align: center;
  animation: belir 0.45s ease both;
}

.adim[hidden] {
  display: none;
}

@keyframes belir {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.icerik h1,
.icerik h2 {
  margin: 0;
  line-height: 1.15;
  font-size: 22px;
  font-size: 7.4cqw;
  font-weight: 700;
  text-wrap: balance;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.5);
}

.icerik p {
  margin: 0;
  font-size: 15px;
  font-size: 5cqw;
  line-height: 1.35;
  text-wrap: balance;
}

/* Kediler yüksekliğe göre ölçekleniyor: iki gif farklı en-boy oranında */
.kedi {
  height: 100px;
  height: 30cqh;
  width: auto;
  max-width: 100%;
  flex: 0 0 auto;
}

.kedi-kucuk {
  height: 34px;
  height: 9cqh;
}

/* ---------- butonlar ----------------------------------------------------- */

.butonlar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 16px;
  gap: 6cqw;
  position: relative;
}

.butonlar[hidden] {
  display: none;
}

.btn-img {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  line-height: 0;
  transition: transform 0.18s ease;
}

.btn-img img {
  height: 26px;
  height: 11cqh;
  width: auto;
}

.btn-img:hover,
.btn-img:focus-visible {
  transform: translate(-1px, -2px);
}

.btn-img:active {
  transform: translate(1px, 2px);
}

.hayir {
  transition: transform 0.25s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.3s ease;
}

.hayir.kacti {
  position: relative;
  z-index: 3;
}

/* ---------- pasta -------------------------------------------------------- */

/* Pasta genişliğe göre değil yüksekliğe göre ölçekleniyor: içerik alanı
   ister geniş-alçak (masaüstü) ister dar-yüksek (telefon) olsun aynı oranda
   yer kaplasın diye. */
.pasta-btn {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  line-height: 0;
  flex: 0 0 auto;
  height: 130px;
  height: 45cqh;
  max-width: 100%;
  transition: transform 0.2s ease;
}

.pasta-btn:hover,
.pasta-btn:focus-visible {
  transform: translateY(-3px);
}

.pasta {
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 48 / 46;
  overflow: visible;
}

.alev {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: titre 0.35s steps(2, end) infinite alternate;
  transition: opacity 0.25s ease, transform 0.35s ease;
}

@keyframes titre {
  from {
    transform: scaleY(1) translateY(0);
  }
  to {
    transform: scaleY(0.86) translateY(1px);
  }
}

.alev.sondu {
  opacity: 0;
  transform: scale(0.4) translateY(-4px);
  animation: none;
}

.duman {
  opacity: 0;
  transform-box: fill-box;
}

.duman.ciksin {
  animation: duman-cik 1.1s ease-out forwards;
}

@keyframes duman-cik {
  0% {
    opacity: 0.7;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-12px) scale(1.8);
  }
}

.ipucu-pasta {
  opacity: 0.75;
  font-size: 13px;
  font-size: 4.4cqw;
  animation: solup 2s ease-in-out infinite;
}

/* ---------- mektup metni -------------------------------------------------- */

/* Mektup uzarsa kutunun kendisi kayar; TEKRAR düğmesi hep görünür kalır. */
.adim-mektup {
  height: 100%;
  gap: 6px;
  gap: 2cqh;
  justify-content: flex-start;
}

.mektup {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  /* `safe center`: mektup uzayıp taşarsa üst satırlar kırpılmasın,
     kaydırılabilir kalsın. */
  justify-content: center;
  justify-content: safe center;
  gap: 2px;
  gap: 0.4cqh;
  padding: 3% 4%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gul) transparent;
  background: rgba(255, 249, 250, 0.82);
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(200, 104, 94, 0.35);
  -webkit-user-select: text;
  user-select: text;
}

.mektup p {
  font-size: 12px;
  font-size: 3.4cqw;
  line-height: 1.4;
  opacity: 0;
  animation: satir-gel 0.5s ease forwards;
  animation-delay: calc(var(--i) * 0.35s);
}

@keyframes satir-gel {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.mektup .imza {
  align-self: flex-end;
  margin-top: 1.2cqh;
  font-weight: 600;
}

/* ---------- müzik düğmesi ------------------------------------------------- */

.muzik-btn {
  position: fixed;
  right: 14px;
  right: max(14px, env(safe-area-inset-right));
  bottom: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 50;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--gul);
  background: var(--bar);
  border: 3px solid var(--gul);
  border-radius: 4px;
  box-shadow: 4px 4px 0 var(--mor);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.muzik-btn[aria-pressed="true"] {
  opacity: 1;
  box-shadow: 4px 4px 0 var(--yesil);
}

.muzik-btn:hover {
  opacity: 1;
}

.muzik-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--mor);
}

/* ---------- odak görünürlüğü --------------------------------------------- */

:focus-visible {
  outline: 3px solid var(--gul);
  outline-offset: 3px;
}

/* ==========================================================================
   TELEFON — dikey. Ekranı dolduran uzun pencere görseline geçiliyor
   (window-bday-tall.png, 63x95 ızgara) ve içerik ona göre büyütülüyor.
   ========================================================================== */

@media (orientation: portrait) and (max-width: 620px) {
  .pencere {
    --boy: 95;
    --oran: 0.66316;
    --gorsel: url("window-bday-tall.png");
    --ic-ust: 22.1053%;
    --ic-boy: 73.6842%;
    --pay: 0.94;
    width: min(96vw, 96vh * 0.66316);
    width: min(
      calc((var(--vw, 100vw) - var(--yan-pay, 0px)) * 0.96),
      calc((var(--vh, 100svh) - var(--dikey-pay, 0px)) * var(--pay) * var(--oran))
    );
  }

  .icerik {
    padding: 4% 5%;
  }

  .adim {
    gap: 3cqh;
  }

  .icerik h1,
  .icerik h2 {
    font-size: 9.4cqw;
  }

  .icerik p {
    font-size: 5.8cqw;
  }

  .kedi {
    height: 34cqh;
  }

  .kedi-kucuk {
    height: 10cqh;
  }

  .btn-img img {
    height: 10.4cqh; /* dokunma hedefi ~46px */
  }

  .butonlar {
    gap: 7cqw;
  }

  .ipucu-pasta {
    font-size: 5cqw;
  }

  .mektup p {
    font-size: 4.8cqw;
  }

  .mektup {
    gap: 0.6cqh;
  }

  .adim-mektup {
    gap: 1.6cqh;
  }
}

/* ---------- alçak ekran (telefon yatay vb.) ------------------------------- */

@media (max-height: 560px) and (orientation: landscape) {
  .pencere {
    --pay: 0.95;
  }

  .mektup-ekrani {
    padding: 2px;
  }

  /* Yatayda pencere zorunlu olarak küçülüyor (yükseklik sınırlıyor);
     yazıları ve dokunma hedeflerini görece büyütüyoruz. Mektup bu modda
     kutunun içinde kayabilir — `safe center` sayesinde hiçbir satır
     erişilemez hâle gelmiyor. */
  .btn-img img {
    height: 13cqh;
  }

  .pasta-btn {
    height: 40cqh;
  }

  .icerik h1,
  .icerik h2 {
    font-size: 8cqw;
  }

  .icerik p {
    font-size: 5.4cqw;
  }

  .ipucu-pasta {
    font-size: 5cqw;
  }

  .mektup p {
    font-size: 4.6cqw;
  }

  .kedi-kucuk {
    height: 8cqh;
  }

  .muzik-btn {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }
}

/* ---------- hareket azaltma tercihi --------------------------------------- */

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

  .balonlar {
    display: none;
  }

  .mektup p {
    opacity: 1;
  }
}
