/*
* Improved Hamburger Menu
* Based on Erik Terwan's design
* Responsive without media queries
*/

:root {
  /* Colors */
  --menu-bg: #ededed;
  --text-color: #232323;
  --text-hover: tomato;
  --hamburger-color: #cdcdcd;
  --cross-color: #232323;
  --accent-color: goldenrod;
  --button-color:white;

  /* Sizes */
  --hamburger-width: 28px;
  --hamburger-height: 3px;
  --hamburger-gap: 4px;
  --menu-padding: max(2rem, 5vw);
  --menu-top-padding: max(5rem, 12vh);
}

nav {
  margin-bottom: 0;
  margin-top: 1%;
  margin-bottom: 1%;
  width: 100%;
  flex-wrap: wrap;
  justify-content: space-around;
}

nav button a {
  color: var(--button-color);
}

nav button {
  background-color: var(--primary-dark);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: x-large;
  padding: 0 2% 0 2%;
  @media (max-width: 768px) {
      font-size: 0.8em;
  }
}

nav button:hover {
  background-color: var(--light-text);
}

nav .navButtons {
  display: flex;
  justify-content: space-around;
}

body.menu-open {
  overflow: hidden;
}
#menuToggle {
  display: inline-block;
  position: relative; /* Positioned relative for proper stacking context */
  z-index: 20; /* Increased to be above the menu */
  user-select: none;
  background-color: var(--primary-dark);
  color: var(--button-color);
  padding: 0.5rem;
}

#menuToggle a {
  text-decoration: none;
  color: var(--text-color);
  transition: color 0.3s ease;
}

#menuToggle a:hover {
  color: var(--text-hover);
}

/* Make the checkbox cover the entire menuToggle area */
#menuToggle input {
  display: block;
  width: 100%; /* Cover the entire width of menuToggle */
  height: 100%; /* Cover the entire height of menuToggle */
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  opacity: 0; /* hide this */
  z-index: 21; /* Increased to ensure it stays on top */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Container for the hamburger lines for better positioning */
#menuToggle .hamburger-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  width: 100%;
}

/* Hamburger styling */
#menuToggle span {
  display: block;
  width: var(--hamburger-width);
  height: var(--hamburger-height);
  margin-bottom: var(--hamburger-gap);
  background: var(--hamburger-color);
  border-radius: 2px;
  position: relative;
  z-index: 19; /* Keep below the checkbox but above other elements */
  transform-origin: 6px 1px;
  transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
              background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
              opacity 0.55s ease;
}

#menuToggle span:last-child {
  margin-bottom: 0; /* Remove margin from last span */
}

#menuToggle span:first-child {
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2) {
  transform-origin: 0% 100%;
}

/* Transform hamburger into crossmark */
#menuToggle input:checked ~ span {
  opacity: 1;
  transform: rotate(45deg) translate(-1px, -1px);
  background: var(--cross-color);
}

/* Hide the middle line */
#menuToggle input:checked ~ span:nth-last-child(3) {
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/* Rotate last line */
#menuToggle input:checked ~ span:nth-last-child(2) {
  transform: rotate(-45deg) translate(0, -1px);
}

/* Menu styling */
#menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  padding: var(--menu-padding);
  padding-top: var(--menu-top-padding);
  background: var(--menu-bg);
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  z-index: 10; /* Lower than the menuToggle to keep it behind */
  /* Grid layout for menu items */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, auto));
  grid-gap: 1rem;
  align-content: start;
  /* Transform for sliding in/out */
  transform: translateX(-100%);
  transition: transform 0.7s cubic-bezier(0.77, 0.2, 0.05, 1.0);
  /* Ensure menu is off-screen when closed */
  pointer-events: none;
  overflow-y: auto;
  overscroll-behavior: contain; /* optional: prevent background scroll */
  scrollbar-gutter: stable;     /* optional: prevent layout shift */
}

/* Open menu styling */
#menuToggle input:checked ~ #menu {
  transform: translateX(0);
  pointer-events: auto;
}

/* Menu items */
#menu li {
  padding: 10px 0;
}

#menu a {
  display: block;
  padding: 10px 15px;
  border-radius: 5px;
  transition: background-color 0.3s ease;
  text-align: center;
}

#menu a:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

/* Title item styling */
.titleli {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--accent-color);
  font-size: clamp(1rem, 2vw, 1.5rem);
  margin-bottom: 1rem;
}

/* For images in the menu */
#menu img {
  max-width: 100%;
  height: auto;
  max-height: min(350px, 50vh);
  display: block;
  margin: 0 auto;
}