/* ===== Baseline Lock ===== */
html {
  font-size: 16px;
}

body {
  font-size: 1rem;
  line-height: 1.6;
  margin: 0;
  padding: 1.5em;
  background-color: #fff;
  font-family: var(--font-main);
  text-align: center;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

/* ===== Global Layout ===== */
:root {
  --content-max: 800px;
  --fade-duration: 2s;

  /* Base stacks */
  --font-main: 'Georgia', serif;
  --font-script: 'Brush Script MT', cursive;
}

/* ===== Typography emphasis ===== */
.instruction,
.final-story,
.signature,
.attribution,
.final-word {
  font-weight: bold;
}

/* ===== Intro ===== */
.intro {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-family: 'Yomogi', cursive;
  font-size: 1.3rem;
  line-height: 1.6;
  opacity: 0;
  transition: opacity 1s ease;
  z-index: 20;
  max-width: 90%;
  margin: 0 auto;
}
.intro.visible { opacity: 1; }
.intro.fade-out { opacity: 0; }

/* ===== Page Container ===== */
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* ===== Layers ===== */
#washi-bg { z-index: -1; }
img.fade-in, #stamp { z-index: 2; }
.final-word,
.final-story,
.signature,
.attribution,
.final-emoji { z-index: 3; }

/* ===== Fade-in Images ===== */
.fade-in {
  opacity: 0;
  transition: opacity 0.9s ease-in;
}
.fade-in.visible { opacity: 1; }

/* ===== Stroke Images ===== */
img.fade-in {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 400px;
  height: auto;
  opacity: 0;
  transition: opacity var(--fade-duration) ease-in;
}
img.visible { opacity: 1; }

/* ===== Final Kanji ===== */
.final-word {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2rem;
  font-weight: bold;
  font-family: var(--font-script);
  color: #000;
  opacity: 0;
  transition: opacity 1s ease-in-out;
}
.final-word.visible { opacity: 1; }

/* ===== Final Story ===== */
.final-story {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 600px;
  font-size: 1.1rem;
  line-height: 1.6;
  color: #222;
  text-align: center;
  font-family: var(--font-main);
  opacity: 0;
  transition: opacity 1s ease-in-out;
}
.final-story.visible { opacity: 1; }

/* ===== Final Block ===== */
.final-block {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
  z-index: 3;
}
.final-block.visible { opacity: 1; }

.final-block .emoji-icon {
  width: 70px;
  margin: 0 auto 0.4rem;
  display: block;
}
.final-block .emoji-keyword {
  font-family: 'Yomogi', cursive;
  font-size: 1.5rem;
  color: #ff5722;
  font-weight: bold;
  margin-bottom: 0.9rem;
}
.final-block .attribution {
  font-size: 1rem;
  color: #555;
  line-height: 1.2;
  margin-bottom: 0.8rem;
}
.final-block .signature {
  font-size: 1.2rem;
  font-family: 'Yomogi', cursive;
  color: #333;
}

/* ===== Stamp ===== */
#stamp {
  width: 100px;
  height: auto;
  position: absolute;
  bottom: 15px;
  right: 60px;
  opacity: 0;
  transition: opacity 1s ease-in-out;
}
#stamp.visible { opacity: 1; }

/* ===== Closing Screen ===== */
.closing {
  text-align: center;
  margin-top: 2rem;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
}
.closing.visible { opacity: 1; }

.closing-art {
  max-width: 300px;
  width: 80%;
  height: auto;
  margin: 2rem auto 1rem;
  display: block;
  filter: grayscale(100%) contrast(120%);
  opacity: 0;
  transition: opacity 1.8s ease-in-out;
}
.closing.visible .closing-art { opacity: 1; }

/* ===== Closing Buttons ===== */
.closing-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  flex-wrap: nowrap;
  margin-top: 20px;
}

.closing-buttons button {
  font-family: 'Segoe UI', sans-serif;
  font-size: 1.1rem;
  padding: 10px 24px;
  border: 2px solid #333;
  border-radius: 10px;
  background-color: #fffaf3;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
}

.closing-buttons button:hover {
  background-color: #f0e4d7;
  transform: scale(1.05);
}

/* Highlight "Next" button */
.next-btn {
  background-color: #ffd24d;
  border-color: #cc9a00;
  font-weight: bold;
}
.next-btn:hover {
  background-color: #ffce2e;
}

/* Blue tint for "Study Kanji" */
.study-btn {
  background-color: #d8ecff;
  border-color: #2b7fc1;
  font-weight: bold;
  color: #1a3f5f;
}
.study-btn:hover {
  background-color: #bfe2ff;
}

/* ===== Background Washi Layer ===== */
#washi-bg {
  position: fixed;
  inset: 0;
  background: url('../images/washi.png') center center no-repeat;
  background-size: cover;
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 1.5s ease-in-out;
}
#washi-messy {
  position: fixed;
  inset: 0;
  background: url('../images/washi-messy.png') center center no-repeat;
  background-size: cover;
  opacity: 0;
  z-index: -1;
  pointer-events: none;
  transition: opacity 1.5s ease-in-out;
}
#washi-messy.visible { opacity: 0.4; }

/* ===== Utilities ===== */
.fade-out {
  opacity: 0 !important;
  pointer-events: none;
  transition: opacity 1.2s ease-in-out;
}

/* ===== Responsive tweaks ===== */
@media (max-width: 480px) {
  .final-story { max-width: 85vw; font-size: 1rem; top: 34%; }
  .signature { top: 56%; font-size: 1.05rem; }
  .final-emoji { top: 74%; }
  .attribution { top: 80%; font-size: 0.95rem; }
  #stamp { right: 24px; width: 80px; }
}
