html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  user-select: none;
  font-family: "Noto Serif", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  width: 90%;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
}

.nav-left {
  width: 80px;
  color: black;
  font-size: 22px;
  text-align: right;
}

.nav-right #cartToggleBtn {
  color: black;
  background-color: transparent;
  border: none;
  font-size: 22px;
  font-family: "Noto Serif", serif;
  cursor: pointer;
}

.cart-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: #000;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  white-space: nowrap;
  user-select: none;
  display: none;
}

.cart-badge.show {
  display: inline-block;
}

.nav-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 300px;
  min-width: 80px;
}

.nav-brand-logo {
  width: 100%;
  height: auto;
  display: block;
}

/* menu */
/* 全螢幕選單 */
#menu-toggle {
  z-index: 10000;
  cursor: pointer;
  text-align: left;
  width: 30%;
}

.overlay-menu {
  position: fixed;
  top: 0;
  left: 0;
  color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 10000;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 8000;
}

/* menu hover 時顯示（桌機） */
nav:hover~.menu-backdrop {
  opacity: 1;
}

/* menu 開啟時顯示（桌機 + 手機） */
.menu-backdrop.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* 顯示狀態 */
.overlay-menu.open {
  opacity: 1;
  visibility: visible;
}

/* 選單內容樣式 */
.overlay-menu .menu {
  position: absolute;
  top: var(--menuTop);
  left: var(--menuLeft);
  list-style: none;
  padding: 0;
  text-align: left;
}

.overlay-menu .menu-item {
  position: relative;
  margin: 1.5rem 0;
  cursor: pointer;
}

.overlay-menu a {
  color: #000;
  font-size: 1rem;
  text-decoration: none;
  transition: color 0.3s ease;
}

.overlay-menu a:hover,
.menu-toggle-item:hover {
  color: gray;
}

.close-btn {
  display: none;
  position: absolute;
  top: 50px;
  right: 30px;
  font-size: 1rem;
  cursor: pointer;
}

/* 子選單 */
.submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 1rem;
  list-style: none;
  width: 100%;
  min-width: 200px;
  max-width: 500px;
}

/* 展開狀態 */
.submenu.open {
  max-height: 500px;
}

/* Footer */
footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 1rem;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  gap: 15px;
}

footer .links {
  margin: 0 auto;
  width: 200px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  font-size: 25px;
}

footer a {
  text-decoration: none;
  color: #000;
}

.info {
  display: flex;
  gap: 12px;
  align-items: center;
}

.info span {
  text-align: center;
}

.copyright {
  margin: 0;
}

/* cart slideout panel */
/* overlay */
.cart-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 9998;
}

.cart-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* Panel */
.cart-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(550px, 90vw);
  background: #fff;
  box-shadow: -2px 0 12px rgba(0, 0, 0, .12);
  transform: translateX(100%);
  transition: transform .25s ease;
  display: grid;
  grid-template-rows: auto 1fr auto;
  z-index: 9999;
}

.cart-panel.is-open {
  transform: translateX(0);
}

.cart-panel-header,
.cart-panel-footer {
  padding: 16px;
  border-bottom: 1px solid #eee;
}

.cart-panel-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.cart-panel-header .icon-btn {
  justify-self: start;
}

.cart-panel-header h2 {
  justify-self: center;
  font-size: 22px;
}

.cart-panel-footer {
  border-top: 1px solid #eee;
  border-bottom: 0;
}

.cart-panel-items {
  padding: 12px 16px;
  overflow: auto;
}

.cart-item {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f3f3f3;
}

.cart-item__thumb {
  width: 200px;
  height: auto;
  object-fit: cover;
  background: #f5f5f5;
  display: block;
  justify-self: start;
  border-radius: 6px;
  overflow: hidden;
}

.cart-item__title {
  font-size: 18px;
  margin: 0 0 4px;
}

.cart-item__meta {
  font-size: 16px;
  color: #666;
}

.qty-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
}

.qty-btn.remove-btn {
  border: none;
}

.price {
  font-weight: 600;
  justify-self: end;
}

.primary-btn {
  width: 100%;
  padding: 12px 16px;
  font-weight: 600;
  border: none;
  background-color: black;
  color: #fff;
  transition: all 0.3s ease-out;
  cursor: pointer;
}

.primary-btn:hover {
  border: 1px solid #dcdcdc;
  color: black;
  background-color: #ffffff;
  transition: all 0.3s ease-in;
}

#cartCloseBtn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}


@media screen and (max-width: 768px) {
  .nav-center {
    max-width: 200px;
  }
}

@media screen and (max-width: 500px) {
  .nav-center {
    max-width: 150px;
  }

  .nav-left,
  .nav-right #cartToggleBtn {
    font-size: 16px;
  }

  .cart-badge {
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
  }

  .overlay-menu {
    width: 100%;
    height: 100vh;
    background-color: #fff;
    color: #000;
    transform: translateY(-100%);
    transition: all 0.2s ease-in;
    z-index: 1001;
  }

  .overlay-menu.open {
    transform: translateY(0);
  }

  .overlay-menu .menu {
    width: 100%;
    list-style: none;
    top: 100px;
    left: 0;
    padding: 0;
    text-align: center;
  }

  .menu-backdrop {
    display: none;
  }

  .submenu {
    padding: 0;
    text-align: center;
  }

  .close-btn {
    display: block;
  }

  nav {
    z-index: 1000;
  }

  .shop-items {
    padding: 0;
  }

  .cart-panel {
    left: 50%;
    right: auto;
    transform: translateX(100%);
    height: 90vh;
  }

  .cart-panel.is-open {
    transform: translateX(-50%);
  }

  .cart-item {
    grid-template-columns: 100px minmax(0px, 1fr) auto;
    gap: 12px;
  }

  .cart-item__thumb {
    width: 100px;
    object-fit: cover;
    justify-self: start;
    display: block;
  }
}

@media (max-width: 360px) {
  .cart-item {
    grid-template-columns: var(--thumb-size) 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      "thumb info"
      "thumb price";
    align-items: start;
    gap: 8px 12px;
  }

  .cart-item> :nth-child(1) {
    grid-area: thumb;
  }

  .cart-item> :nth-child(2) {
    grid-area: info;
    min-width: 0;
  }

  .cart-item .price {
    grid-area: price;
    justify-self: end;
  }
}