

/* 1. Imports and Animations */
@import url('https://fonts.googleapis.com/css2?family=BIZ+UDPGothic:wght@400;700&family=BIZ+UDPMincho:wght@400;700&family=Hachi+Maru+Pop&family=Josefin+Sans:ital,wght@0,100..700;1,100..700&family=Kaisei+Decol:wght@400;500;700&family=Kiwi+Maru:wght@300;400;500&family=Klee+One:wght@400;600&family=M+PLUS+1p:wght@100;300;400;500;700;800;900&family=M+PLUS+Rounded+1c:wght@100;300;400;500;700;800;900&family=Noto+Sans+JP:wght@100..900&family=Noto+Serif+JP:wght@200..900&family=Potta+One&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&family=Shippori+Antique&family=Shippori+Antique+B1&family=Shippori+Mincho:wght@400;500;600;700;800&family=Yuji+Boku&family=Zen+Antique+Soft&family=Zen+Kaku+Gothic+Antique:wght@300;400;500;700;900&family=Zen+Kaku+Gothic+New:wght@300;400;500;700;900&family=Zen+Maru+Gothic:wght@300;400;500;700;900&family=Zen+Old+Mincho:wght@400;500;600;700;900&display=swap');

@keyframes swing {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(10deg); }
  100% { transform: rotate(-10deg); }
}

h1 + p, h2 + p, h3 + p,
h1 + ul, h2 + ul, h3 + ul,
h1 + ol, h2 + ol, h3 + ol,
p + ul, p + ol{
  page-break-before: avoid;
  break-before: avoid;
  page-break-after: avoid;
  break-after: avoid;
}

/* Add these rules to your existing CSS */
.page ul, .page ol {
  padding-left: 20px;
  margin-bottom: 1.5rem; /* Add more bottom margin */
  box-sizing: border-box;
  max-width: 100%;
}

.page li {
  margin-bottom: 0.5rem; /* Add spacing between list items */
}

.page li:last-child {
  margin-bottom: 0; /* Remove margin from last item */
}

/* Ensure nested lists have proper spacing */
.page li > ul, .page li > ol {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}



/* 2. Core Layout */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background-color: #ffffff;
}

#reader {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: serif;
  font-size: 1.2rem;
  line-height: 1.6;
  position: relative;
  overflow: hidden;
}

.page-container {
  width: 100vw;
  height: 100vh;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.5s ease-in-out;
  background: white;
}

.page {
  width: 100%;
  height: 100%;
  max-width: 200mm;
  padding: 20px 20px 80px 20px;
  box-sizing: border-box;
  overflow-y: auto;
  position: relative;
}

.page.has-filler {
  max-width: 100vw;
  padding: 0;
  overflow: hidden;
}

/* 3. Navigation Controls */
#left-edge-zone, #right-edge-zone {
  position: fixed;
  top: 0;
  width: 10vw;
  height: 100vh;
  z-index: 100;
  cursor: pointer;
  pointer-events: auto;
}
#left-edge-zone { left: 0; }
#right-edge-zone { right: 0; }

/* 4. Filler Pages */
.filler {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: 0;
}

.cover {
  background: #657c2d;
  color: white;
}

.footer {
  font-family: "Roboto Mono", monospace;
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: gray;
  padding: 0 8px;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.8s ease-in-out;
}

.footer.show { opacity: 1; }

/* 5. Typography */
h1 {
  font-family: "Zen Maru Gothic", serif;
  font-size: 1.9rem;
  margin-bottom: 2rem;
}

h2 {
  font-family: "Shippori Antique";
  font-size: 1.4rem;
  color: #333333;
  margin-bottom: 2rem;
}

p,ul,li {
  font-family: "Noto Sans JP";
  line-height: 2;
  font-weight: 300;
}

.title {
  font-family: 'Hachi Maru Pop', sans-serif;
  font-size: clamp(3rem, 12vw, 5rem);
  margin-bottom: 5rem;
  line-height: 1;
}

.title-eng {
  font-family: Zen Maru Gothic, serif;
  color: white;
  font-size: clamp(1.2rem, 7vw, 2.8rem);
  line-height: 1;
}

.subtitle {
  font-family: "Josefin Sans", sans-serif;
  color: white;
  font-size: clamp(1.1rem, 6vw, 2.2rem);
  margin-top: 1rem;
  text-decoration-thickness: 10px;
  text-decoration: underline;
  text-decoration-color: #c2573c;
}

.highlight {
  background: linear-gradient(transparent 60%, yellow);
}

/* 6. TOC Styles */
.toc {
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
  font-family: "Zen Maru Gothic", serif;
  display: flex;
  flex-direction: column;
  justify-content: center; /* Center vertically */
  align-items: center; /* Center horizontally */
  background: #eaefde !important;
  color: black;
  padding: 40px;
  overflow-y: auto;
}

.toc ul {
  list-style: none;
  padding: 0;
  margin: 0 auto; /* Center the list container */
  max-width: 400px; /* Fixed width for the list container */
  text-align: left; /* Left-align text within the list items */
}

.toc li {
  font-size: 1em;
  margin-bottom: 0.8em;
  line-height: 1.4;
}

.toc h2 {
  text-align: center;
  font-size: 1.8em;
  margin-bottom: 1.5em;
}

.toc li.h2-entry {
  margin-left: 1.5em;
  font-size: 1em;
}

.toc a {
  text-decoration: none;
  color: #0000ee;
  position: relative;
}

.toc a:hover {
  background: linear-gradient(transparent 60%, yellow);
}

/* 7. Audio Controls */
.play-all-container {
  background-color: transparent;
  text-align: center;
  margin-bottom: 2em;
}

#play-all-audio {
  font-size: 3em;
  cursor: pointer;
  border: none;
  background: none;
  transform-origin: center bottom;
}

#play-all-audio.is-swinging {
  animation: swing 1.5s ease-in-out infinite alternate;
}

#play-all-audio:not(.is-swinging):hover {
  animation: swing 1.5s ease-in-out infinite alternate;
}

.audio-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0 0.5em 0 0;
  font-size: 1em;
  line-height: 1;
  color: #333;
  cursor: pointer;
  vertical-align: middle;
  transition: opacity 0.2s ease;
}

.audio-button:hover { opacity: 0.7; }
.audio-button:active { opacity: 0.5; }

/* 8. Translation Button */
.translation-button {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.6em;
  cursor: pointer;
  vertical-align: middle;
  line-height: 1;
  display: inline-block;
}

.translation-button img {
  height: 30px;
  width: auto;
  vertical-align: middle;
}

.translation-button:hover img { opacity: 0.7; }

/* 9. Last Page Content */
.last-page-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #f0f0f0;
  height: 100vh;
  padding: 20px;
  box-sizing: border-box;
  overflow: hidden;
  text-align: left;
}

.last-page-inner {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.last-page-image {
  width: 150px;
  height: auto;
  display: block;
  margin: 0 auto 20px auto;
  max-height: 40vh;
}

.last-page-text {
  text-align: left;
  font-family: "Roboto Mono", monospace;
  font-size: 0.9em;
  color: #555;
  line-height: 1.4;
  margin-bottom: 30px;
}

.background-image-container {
  width: 150px;
  height: 150px;
  background-image: url('nez.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  margin: 20px auto;
}

/* 10. Colophon Box */
.colophon-box {
  background-color: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 20px 25px;
  margin: 0 auto;
  display: flex;
  flex-direction: row-reverse;
  gap: 18px;
  width: max-content;
  box-shadow: 5px 5px 0px #ddd;
  text-align: left;
}

.colophon-box b { font-size: 1.2em; }

.vertical-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "Zen Maru Gothic", serif;
  font-size: 0.7em;
  color: #333;
  padding: 5px 0;
  margin: 0;
  line-height: 1.5;
}

/* 11. Images */
.content-image {
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 80%;
  object-fit: contain;
}

.content-image2 {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

.cover-image { width: 200px; }

.qr-code-print {
  display: none;
  max-width: 150px;
  height: auto;
  margin: 20px auto;
}

/* 12. Note Button */
.note {
  background-color: #6f8635;
  color: rgb(214, 235, 206);
  padding: 14px 18px;
  border-radius: 5px;
  margin-top: 15px;
  cursor: pointer;
  font-size: 1em;
  font-weight: 500;
  text-align: center;
  display: inline-block;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: background-color 0.3s, transform 0.2s;
  font-family: Kiwi Maru, sans-serif;
}

.note:hover {
  background-color: #546a24;
  transform: translateY(-2px);
}

.note:active { transform: translateY(0); }

/* 13. Mobile Styles */
@media (max-width: 450px) {
  .note { display: none !important; }
  
  .footer { background-color: rgba(255, 255, 255, 0.9); }
  
  #reader {
    font-size: 1rem !important;
    margin: 0 !important;
  }
  
  .page {
    max-width: 100vw;
    padding: 0 20px;
  }
  
  .page.has-filler {
    max-width: 100vw;
    padding: 0; /* Remove the padding that was causing white space */
    font-size: 1.2rem;
  }
  
  .filler {
    justify-content: flex-start !important;
    padding-top: 40px !important;
  }
  
  .title { margin-top: 100px !important; }
  
  
  
  ruby { display: block; }
  
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.3rem !important; }
}

/* 14. Print Styles */
@media print {
  /* Hide elements not needed in print */
  #play-all-audio,
  .note,
  #reader,
  #full-content-for-print .audio-button,
  #full-content-for-print #play-all-audio,
  #full-content-for-print .translation-button {
    display: none !important;
  }
  
  /* Show elements for print */
  .qr-code-print {
    display: block !important;
    max-width: 150px;
    height: auto;
    margin-top: 0;
    margin-bottom: 60px;
  }
  
  #full-content-for-print {
    display: block !important;
    font-size: 15pt;
    line-height: 1.4;
    font-family: serif;
  }
  
  body { overflow: visible; }
  
  .highlight { background: none !important; }
  
  .toc a { color: black; }
  
  /* Page setup */
  @page:first {
    counter-reset: page 0;
    @bottom-center { content: ""; }
  }
  
  @page {
    size: JIS-A5 portrait;
    margin: 2cm 3cm 2cm 3cm !important;
    @bottom-center {
      margin-top:-20px;
      content: counter(page);
      font-size: 10pt !important;
      font-family: "Roboto Mono", monospace;
    }
  }
  
  @page cover-page {
    size: JIS-A5 portrait;
    margin: 0 !important;
  }
  
  @page toc-page {
    size: JIS-A5 portrait;
    margin: 0 !important;
  }
  
  @page last-page {
    size: JIS-A5 portrait;
    margin: 0cm !important;
  }
  
  @page :left {
    @right-middle {
      content: "+";
      font-size: 20pt;
      color: #cccccc;
      margin-right: -40px;
    }
  }
  
  @page :right {
    @left-middle {
      content: "+";
      font-size: 20pt;
      color: #cccccc;
      margin-left: -40px;
    }
  }
  
  /* Print-specific styles for components */
  #full-content-for-print .toc {
    page: toc-page;
    margin: 0 !important;
    padding: 0 !important;
    height: 100vh !important;
    overflow: visible !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    background: #eaefde !important;
  }
  
  #full-content-for-print .toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }
  
  #full-content-for-print .toc li {
    font-size: 1.1em;
    margin-bottom: 0.8em;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }
  
  p, li, ul {
    font-family: Noto Sans JP, sans-serif;
    font-weight: 400 !important;
    font-size: 1rem;
  }
  
  #full-content-for-print h1,
  #full-content-for-print h2,
  #full-content-for-print .filler:not(.last-page-content) {
    page-break-before: always;
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  
  #full-content-for-print .last-page-content {
    page: last-page;
    background-color: #f0f0f0;
    text-align: center;
    height: 100vh !important;
  }
  
  #full-content-for-print h1 {
    font-size: 1.4em;
    font-weight: 900;
  }
  
  #full-content-for-print .cover {
    text-align: center;
    background: #657c2d;
    color: white;
    page: cover-page;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  #full-content-for-print .cover .title {
    display: block;
    font-family: "Hachi Maru Pop";
    font-size: 12vw;
    font-weight: bold;
    white-space: nowrap;
    line-height: 1;
    width: 100%;
    text-align: center;
  }
  
  #full-content-for-print .background-image-container {
    width: 150px;
    height: 150px;
    background-image: url('nez.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin: 20px auto;
  }
}