:root {
  --cream: #f6efe3;
  --cream-deep: #efe5d2;
  --ink: #3a2f2a;
  --muted: #7a6f63;
  --gold: #c9a44c;
  --gold-soft: #e9dcb5;
  --line: #e2d8c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
}

canvas#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #1a1a2e;
  box-shadow: 0 10px 40px rgba(58, 47, 42, 0.18);
  display: block;
}

/* ---------- Touch controls ---------- */
#touch {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
#touch[hidden] { display: none; }
.pad {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
}
.pad-left { left: max(18px, env(safe-area-inset-left)); }
.pad-right { right: max(18px, env(safe-area-inset-right)); }
.tbtn {
  pointer-events: auto;
  touch-action: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(201, 164, 76, 0.8);
  background: rgba(58, 47, 42, 0.28);
  color: rgba(246, 239, 227, 0.9);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  outline: none;
}
.tbtn:active, .tbtn.down { background: rgba(201, 164, 76, 0.55); }
.tbtn-jump { width: 84px; height: 84px; font-size: 28px; }

#mute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: rgba(246, 239, 227, 0.85);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  z-index: 6;
  padding: 0;
}
#mute.muted { opacity: 0.45; text-decoration: line-through; }

#letter-btn {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: 15px;
  padding: 8px 18px;
  background: rgba(246, 239, 227, 0.9);
}
#letter-btn[hidden] { display: none; }

#music-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(60px, calc(env(safe-area-inset-right) + 48px));
  z-index: 30;
  font-size: 15px;
  padding: 8px 16px;
  background: rgba(246, 239, 227, 0.95);
  animation: pulse 1.6s ease-in-out infinite;
}
#music-btn[hidden] { display: none; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(201, 164, 76, 0.5); } 50% { box-shadow: 0 0 0 8px rgba(201, 164, 76, 0); } }

/* gizli YouTube oynatıcı (sadece ses) */
.music-host, .music-host iframe {
  position: fixed;
  left: 0; top: 0;
  width: 1px; height: 1px;
  opacity: 0.01;
  pointer-events: none;
  z-index: -1;
}

#rotate-hint {
  position: fixed;
  left: 0; right: 0;
  bottom: max(120px, calc(env(safe-area-inset-bottom) + 110px));
  text-align: center;
  font-size: 18px;
  font-style: italic;
  color: var(--muted);
  z-index: 4;
  pointer-events: none;
}
#rotate-hint[hidden] { display: none; }
@media (orientation: landscape) { #rotate-hint { display: none !important; } }

/* ---------- Ending overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(201, 164, 76, 0.22), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(201, 164, 76, 0.10), transparent 70%),
    var(--cream);
  opacity: 0;
  transition: opacity 0.9s ease;
  z-index: 10;
  user-select: text;
  -webkit-user-select: text;
}
.overlay::before {
  /* ince kağıt dokusu */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    repeating-linear-gradient(0deg, rgba(58, 47, 42, 0.025) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(58, 47, 42, 0.02) 0 1px, transparent 1px 4px);
}
.overlay[hidden] { display: none; }
.overlay.visible { opacity: 1; }

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.ending-inner {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 72px 20px 72px;
}

/* ---- Hero ---- */
.ending-hero { text-align: center; padding-bottom: 36px; min-height: 60vh; }
.eyebrow {
  font-size: 13px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 20px;
}
.eyebrow::before, .eyebrow::after {
  content: "";
  display: inline-block;
  width: 28px;
  height: 1px;
  background: var(--gold);
  vertical-align: middle;
  margin: 0 12px;
  opacity: 0.7;
}
.ending-title {
  font-size: clamp(44px, 9vw, 84px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: 0.01em;
  margin: 0 0 20px;
}
.ending-title em { color: var(--gold); font-style: italic; font-weight: 400; }
.ending-sub { font-size: 21px; font-style: italic; color: var(--muted); margin: 0 auto; max-width: 34ch; }

.cast-wrap { margin: 44px auto 8px; display: inline-block; position: relative; }
.cast {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin: 0 auto;
}
.cast-wrap::after {
  /* zemin çizgisi */
  content: "";
  display: block;
  height: 1px;
  margin-top: -1px;
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold) 80%, transparent);
}
.cast-names {
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 12px 0 0;
}

.stats {
  list-style: none;
  margin: 26px auto 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 10px 26px;
  flex-wrap: wrap;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats li { display: flex; align-items: center; gap: 8px; }
.stats b { font-weight: 600; color: var(--ink); font-size: 20px; letter-spacing: 0; }
.stats .ico { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 3px rgba(201, 164, 76, 0.25); }

.btn-song { display: inline-block; margin-top: 26px; text-decoration: none; font-size: 17px; }
.btn-song[hidden] { display: none; }

.scroll-hint { color: var(--gold); font-size: 22px; margin: 36px 0 0; animation: bob 1.8s ease-in-out infinite; opacity: 0.8; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(6px); } }

/* ---- Section labels ---- */
.section-kicker {
  font-size: 12px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  margin: 0 0 14px;
}
.section-kicker::before { content: "✦  "; }
.section-title {
  font-size: 34px;
  font-weight: 500;
  text-align: center;
  margin: 0 0 36px;
}
.ornament { color: var(--gold); text-align: center; font-size: 14px; letter-spacing: 0.5em; margin: 0 0 28px; }

/* ---- Letter (paper) ---- */
.paper {
  position: relative;
  background: #fffcf5;
  border: 1px solid var(--line);
  box-shadow:
    0 1px 0 #fff inset,
    0 18px 50px -20px rgba(58, 47, 42, 0.35),
    0 2px 6px rgba(58, 47, 42, 0.06);
}
.paper::before, .paper::after {
  /* altta hafif ikinci kağıt */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #fbf6ea;
  border: 1px solid var(--line);
  transform: rotate(-1.2deg);
}
.paper::after { transform: rotate(1deg); background: #f8f1e2; }
.letter { margin: 24px 0 72px; padding: 52px clamp(22px, 6vw, 64px) 44px; }
.letter .section-kicker { margin-bottom: 30px; }
.letter-body p {
  font-size: 20.5px;
  line-height: 1.75;
  margin: 0 0 20px;
  max-width: 62ch;
}
.letter-body p:first-child {
  font-size: 30px;
  font-style: italic;
  font-weight: 400;
  margin-bottom: 26px;
  color: var(--ink);
}
.letter-body p:first-child::after {
  content: "";
  display: block;
  width: 56px;
  height: 1px;
  background: var(--gold);
  margin-top: 18px;
}
.letter-sign {
  font-family: "Caveat", "Cormorant Garamond", cursive;
  font-size: 34px;
  font-weight: 500;
  color: var(--gold);
  text-align: right;
  margin: 34px 0 0;
  transform: rotate(-2deg);
  transform-origin: right;
}

/* ---- Video ---- */
.video { padding: 0 0 72px; text-align: center; }
.video[hidden] { display: none; }
.video-frame {
  display: inline-block;
  max-width: 100%;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(58, 47, 42, 0.08), 0 24px 50px -18px rgba(58, 47, 42, 0.45);
  transform: rotate(-0.6deg);
}
.video-frame video, .video-frame iframe {
  display: block;
  background: #1a1a2e;
  max-width: 100%;
}
.video-frame video { width: auto; max-height: 70vh; max-width: min(100%, 720px); }
.video-frame iframe { width: min(92vw, 720px); aspect-ratio: 16 / 9; height: auto; border: 0; }
.video-cap {
  font-family: "Caveat", cursive;
  font-size: 24px;
  color: #5a4e45;
  margin: 18px 0 0;
}
.video-cap:empty { display: none; }

/* ---- Gallery (polaroid) ---- */
.gallery { padding: 0 0 72px; }
.gallery[hidden] { display: none; }
.gallery-grid {
  list-style: none;
  margin: 0;
  padding: 10px 6px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 30px 22px;
  justify-items: center;
}
.gallery-grid li { margin: 0; width: 100%; max-width: 250px; }
.gallery-grid button {
  width: 100%;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  background: #fff;
  box-shadow: 0 1px 2px rgba(58, 47, 42, 0.08), 0 14px 34px -14px rgba(58, 47, 42, 0.45);
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1), box-shadow 0.35s ease;
  display: block;
}
.gallery-grid li:nth-child(5n+1) button { transform: rotate(-2.2deg); }
.gallery-grid li:nth-child(5n+2) button { transform: rotate(1.6deg); }
.gallery-grid li:nth-child(5n+3) button { transform: rotate(-1deg); }
.gallery-grid li:nth-child(5n+4) button { transform: rotate(2.4deg); }
.gallery-grid li:nth-child(5n+5) button { transform: rotate(-1.6deg); }
.gallery-grid li:hover button, .gallery-grid li:focus-within button {
  transform: rotate(0) translateY(-6px) scale(1.03);
  box-shadow: 0 2px 4px rgba(58, 47, 42, 0.08), 0 26px 44px -16px rgba(58, 47, 42, 0.5);
  z-index: 2;
  position: relative;
}
.gallery-grid figure { margin: 0; padding: 11px 11px 14px; }
.gallery-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--cream-deep);
  filter: saturate(0.95) contrast(1.02);
}
.gallery-grid figcaption {
  font-family: "Caveat", cursive;
  font-size: 22px;
  line-height: 1.15;
  color: #5a4e45;
  margin-top: 12px;
  min-height: 26px;
  text-align: center;
  overflow-wrap: anywhere;
}
.gallery-grid figcaption:empty { min-height: 14px; }

/* ---- Footer ---- */
.ending-footer { text-align: center; padding-top: 8px; }
.btn {
  font: inherit;
  font-size: 18px;
  letter-spacing: 0.08em;
  padding: 13px 32px;
  background: none;
  border: 1.5px solid var(--gold);
  color: var(--ink);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s ease, transform 0.25s ease;
}
.btn:hover { background: var(--gold-soft); transform: translateY(-1px); }
.ending-credit { font-size: 15px; font-style: italic; color: var(--muted); margin-top: 30px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(24, 20, 34, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
  animation: lbIn 0.25s ease;
}
@keyframes lbIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox[hidden] { display: none; }
.lb-fig { margin: 0; text-align: center; max-width: 92vw; animation: lbPop 0.3s cubic-bezier(.2,.8,.2,1); }
@keyframes lbPop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.lightbox img {
  max-width: 92vw;
  max-height: 74vh;
  display: block;
  margin: 0 auto;
  padding: 10px;
  background: #fff;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7);
}
.lightbox figcaption {
  color: var(--cream);
  font-family: "Caveat", cursive;
  font-size: 26px;
  margin-top: 16px;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
.lb-count { font-family: "Cormorant Garamond", serif; font-size: 14px; letter-spacing: 0.2em; color: rgba(246, 239, 227, 0.6); }
.lb-close, .lb-nav {
  position: fixed;
  background: rgba(246, 239, 227, 0.08);
  border: 1px solid rgba(246, 239, 227, 0.25);
  color: var(--cream);
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s ease;
}
.lb-close:hover, .lb-nav:hover { background: rgba(246, 239, 227, 0.2); }
.lb-close { top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); font-size: 30px; }
.lb-nav { top: 50%; transform: translateY(-50%); font-size: 36px; padding-bottom: 4px; }
.lb-prev { left: max(10px, env(safe-area-inset-left)); }
.lb-next { right: max(10px, env(safe-area-inset-right)); }

.fade-in { opacity: 0; transform: translateY(18px); transition: opacity 1s ease, transform 1s ease; }
.fade-in.in { opacity: 1; transform: none; }

@media (max-width: 520px) {
  .ending-inner { padding-top: 56px; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); gap: 22px 14px; padding: 10px 0 0; }
  .gallery-grid figure { padding: 7px 7px 10px; }
  .gallery-grid figcaption { font-size: 19px; }
  .letter-body p { font-size: 19px; }
  .video-frame { padding: 6px; }
  .video-frame video { max-height: 60vh; }
  .letter-body p:first-child { font-size: 26px; }
  .stats { gap: 8px 18px; font-size: 13px; }
  .cast-names { font-size: 11px; letter-spacing: 0.14em; }
  .cast-wrap { margin-top: 36px; }
  .ending-title { font-size: clamp(40px, 12vw, 64px); }
  .lb-nav { width: 40px; height: 40px; font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .fade-in { transition: none; opacity: 1; transform: none; }
  .overlay, .lightbox, .lb-fig, .scroll-hint { transition: none; animation: none; }
}
