/* header.css */

#shared-header,
#shared-footer {
  background-color: var(--ht-bg-color);
}

/* 2. Navigation Area */
.nav-container {
  width: 100%;
  background-color: var(--ht-bg-color);
  border-bottom: 1px solid var(--ht-border-color);
  /*font-family: "Noto Serif TC", "Songti TC", serif;*/
  font-family: "標楷體", "DFKai-SB", "BiauKai", "AR PL UKai TW", serif;
  font-size: 1.5rem;
}

.navbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
}

.navbar-brand {
  color: var(--text-color) !important;
  text-decoration: none;
  font-weight: 800;
  font-size: 2rem;
}
.navbar-nav > li > a {
  color: var(--text-color) !important;
  text-decoration: none;
  font-weight: 500;
}

.navbar-nav {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.navbar-nav > li {
  position: relative;
  margin-left: 30px;
}

/* 3. Sub-menu (Dropdown) */
.sub-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-color-light-gray);
  min-width: 180px;
  padding: 10px 0;
  list-style: none;
  box-shadow: 0 8px 15px rgba(0,0,0,0.1);
  border: 1px solid var(--bg-color-light-gray);
  display: none; 
  z-index: 1001;
}

/* Show sub-menu on hover */
.navbar-nav li:hover .sub-menu {
  display: block;
}

/* Show sub-menu when parent li is active (for mobile JS toggle) */
.navbar-nav li.active > .sub-menu {
  display: block;
}

/* Style submenu-toggle button to look like a link */
.submenu-toggle {
  background: none;
  border: none;
  color: var(--text-color);
  font: inherit;
  cursor: pointer;
  padding: 0;
  margin: 0;
  text-align: left;
}


.sub-menu li a {
  padding: 8px 20px;
  display: block;
  color: var(--text-color) !important;
  text-decoration: none;
  font-size: 1.3rem;
}

.sub-menu li a:hover {
  background-color: var(--bg-color);
}

/* 4. Mobile Navigation */
.menu-toggle {
  display: none; /* Hidden on desktop */
  flex-direction: column;
  cursor: pointer;
  gap: 4px; /* Space between the lines */
  background: none;
  border: none;
  padding: 0;
}


@media (max-width: 768px) {
  .navbar {
    /* Ensure the parent doesn't clip the children or block touches */
    overflow: visible !important; 
    touch-action: auto;
  }

  .navbar-nav {
    display: none; 
    flex-direction: column;
    position: fixed;
    top: 81px; /* navbar height (80px) + border (1px) */
    left: 0;
    right: 0;
    width: 100%;
    background: var(--ht-bg-color);
    z-index: 999999 !important; 
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    padding: 10px 0;
    /* Ensures the menu itself is clickable */
    pointer-events: auto !important;
    /* Ensures Safari doesn't try to "rubber-band" the menu */
    overscroll-behavior: contain;
  }

  .navbar-nav.active {
    display: flex !important;
  }

  .navbar-nav li {
    width: 100%;
    margin-left: 0;
    text-align: center;
    border-bottom: 1px solid var(--card-border); /* Separator for mobile links */
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .navbar-nav li:last-child {
    border-bottom: none;
  }

  .navbar-nav li a {
    padding: 15px 20px; /* Larger tap area for mobile */
  }

  /* Sub-menu on mobile */
  .sub-menu {
    position: static !important; /* Stack vertically on mobile */
    top: auto !important;
    left: auto !important;
    display: none; /* Hidden by default */
    box-shadow: none;
    border-radius: 0;
    background-color: var(--bg-color-light-gray); /* Use dropdown bg for consistency */
    min-width: 0;
    padding: 0;
    width: 100%;
  }

  .sub-menu li {
    width: 100%;
  }

  .sub-menu li a {
    padding-left: 30px; /* Indent sub-menu items */
    background-color: var(--bg-color-light-gray); /* Ensure background is set for mobile sub-menu items */
    width: 100%;
    box-sizing: border-box;
  }
  

  .main-wrapper {
	  /* Ensure main content doesn't overlap the navbar area */
    position: relative;
    z-index: 1;
    max-width: 100%; /* <--- Overrides max-width to make it fill the screen on mobile */
    min-width: unset; /* <--- IMPORTANT: Unset min-width for mobile, so it can shrink */
    margin: 0;        /* <--- Removes the auto margins on mobile, allowing it to go edge-to-edge */
    padding: 20px 10px; /* Optional: Adjust padding for mobile screens if desired */
    align-items: stretch; /* <--- NEW! Makes content items stretch to fill the mobile screen's width */
  }


  /* Mobile hamburger menu */
  .menu-toggle {
    display: flex;
    z-index: 1000000 !important;
    position: relative;
    /* Increase physical hit area for mobile thumbs */
    padding: 15px; /* Even larger hit area for Safari */
    margin: -15px;
    cursor: pointer;
    pointer-events: auto !important;
    /* CRITICAL FOR SAFARI: Disables double-tap-to-zoom delay */
    touch-action: manipulation !important;
    
    /* Prevents Safari from highlighting the whole area on tap */
    -webkit-tap-highlight-color: transparent;
  }

  .menu-toggle .bar {
    width: 25px;
    height: 3px;
    background-color: var(--text-color);
    transition: all 0.3s ease-in-out;
    border-radius: 2px;
  }

  /* When menu is active, transform bars into X */
  .menu-toggle.active .bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .menu-toggle.active .bar:nth-child(2) {
    opacity: 0;
  }

  .menu-toggle.active .bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

}

/* 5. Footer Styling */
.site-footer {
  width: 100%;
  /* Content-wise, it follows the main block. 
     Visually, the background matches the body's infinite color. */
  background-color: var(--bg-light-gray) !important;
  border-top: 1px solid var(--ht-border-color);
   padding: 20px 0 40px 0;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 1rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  background-color: var(--ht-bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.site-footer p {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: inherit;
  color: var(--text-color);
  margin: 0 0 15px 0;
}

.footer-nav a {
  color: var(--text-color);
  font-size: inherit;
  text-decoration: none;
}