/* ===== Dark Mode Overrides ===== */
html.dark-mode {
  --wp--preset--color--base: #171f1b;
  --wp--preset--color--surface: #1f2b25;
  --wp--preset--color--text: #d1d9d4;
  --wp--preset--color--heading: #f0f5f2;
  --wp--preset--color--accent: #5cb896;
  --wp--preset--color--subtle: #8fa99b;
  --wp--preset--color--code-bg: #1e2a24;
  --wp--preset--color--border: #2d3f35;
  --wp--preset--color--white: #f0f5f2;
  color-scheme: dark;
}

html.dark-mode img:not([src*=".svg"]) {
  filter: brightness(0.92);
}

/* ===== Typography ===== */
h3 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--wp--preset--color--border) transparent;
}

/* ===== Site Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--wp--preset--color--base);
}

@supports (backdrop-filter: blur(12px)) {
  .site-header {
    background: color-mix(in srgb, var(--wp--preset--color--base) 88%, transparent);
    backdrop-filter: blur(12px) saturate(1.2);
  }
}

/* ===== Header Action Buttons ===== */
.header-actions {
  flex-shrink: 0;
}

.header-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 6px;
  background: transparent;
  color: var(--wp--preset--color--subtle);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.header-actions button:hover {
  color: var(--wp--preset--color--heading);
  border-color: var(--wp--preset--color--subtle);
}

.theme-toggle .icon-sun {
  display: none;
}
.theme-toggle .icon-moon {
  display: block;
}
html.dark-mode .theme-toggle .icon-sun {
  display: block;
}
html.dark-mode .theme-toggle .icon-moon {
  display: none;
}

/* ===== Search Modal ===== */
@keyframes search-backdrop-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes search-content-enter {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.search-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
}

.search-modal.active {
  display: flex;
}

.search-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.search-modal.active .search-modal-backdrop {
  animation: search-backdrop-enter 0.2s ease-out;
}

html.dark-mode .search-modal-backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.search-modal-content {
  position: relative;
  width: 90%;
  max-width: 560px;
  background: var(--wp--preset--color--base);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.search-modal.active .search-modal-content {
  animation: search-content-enter 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

html.dark-mode .search-modal-content {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.search-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  color: var(--wp--preset--color--subtle);
}

.search-modal-header form {
  flex: 1;
}

.search-modal-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  color: var(--wp--preset--color--heading);
  font-family: inherit;
}

.search-modal-input::placeholder {
  color: var(--wp--preset--color--subtle);
}

.search-modal-esc {
  flex-shrink: 0;
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-family: var(--wp--preset--font-family--mono);
  color: var(--wp--preset--color--subtle);
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 4px;
  line-height: 1.5;
}

/* ===== Page Transition ===== */
@keyframes page-enter {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

main {
  animation: page-enter 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

main.page-exit {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* ===== Post Card (list item on home/archive) ===== */
.post-card {
  transition: background-color 0.2s;
  border-radius: 6px;
  margin-left: -0.75rem;
  margin-right: -0.75rem;
  padding-left: 0.75rem !important;
  padding-right: 0.75rem !important;
}

.post-card:hover {
  background-color: var(--wp--preset--color--surface);
}

.post-card .wp-block-post-title,
.post-card .wp-block-post-title.has-lg-font-size {
  max-width: none !important;
  width: 100% !important;
  box-sizing: border-box;
}

.post-card .wp-block-post-title a {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100% !important;
  word-break: break-word;
}

/* ===== Recommend Cards ===== */
.recommend-card {
  border-radius: 8px;
  padding: var(--wp--preset--spacing--sm);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.recommend-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

html.dark-mode .recommend-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.recommend-card .wp-block-post-featured-image {
  margin-bottom: var(--wp--preset--spacing--xs);
  overflow: hidden;
  border-radius: 6px;
}

.recommend-card .wp-block-post-featured-image img {
  transition: transform 0.3s ease;
}

.recommend-card:hover .wp-block-post-featured-image img {
  transform: scale(1.03);
}

/* ===== Featured Image ===== */
.wp-block-post-featured-image img {
  object-fit: cover;
  transition: filter 0.2s, transform 0.3s ease;
}

/* ===== Inline Code ===== */
:where(p, li, td, th) code {
  font-family: var(--wp--preset--font-family--mono);
  font-size: 0.875em;
  padding: 2px 6px;
  background: var(--wp--preset--color--code-bg);
  border-radius: 3px;
  word-break: break-word;
}

/* ===== Kbd (keyboard shortcut hint) ===== */
kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-family: var(--wp--preset--font-family--mono);
  color: var(--wp--preset--color--heading);
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--wp--preset--color--border);
  line-height: 1.5;
}

/* ===== Footer ===== */
.site-footer {
  margin-left: calc(-1 * var(--wp--preset--spacing--lg)) !important;
  margin-right: calc(-1 * var(--wp--preset--spacing--lg)) !important;
  padding-left: var(--wp--preset--spacing--2xl) !important;
  padding-right: var(--wp--preset--spacing--2xl) !important;
  max-width: none !important;
}

.site-footer .footer-links {
  list-style: none;
  padding: 0;
}

.site-footer .footer-links li + li {
  margin-top: 0.25rem;
}

.site-footer .footer-links a {
  color: var(--wp--preset--color--subtle);
  text-decoration: none;
  transition: color 0.2s;
}

.site-footer .footer-links a:hover {
  color: var(--wp--preset--color--accent);
}

.site-footer h4 {
  font-family: var(--wp--preset--font-family--sans);
  color: var(--wp--preset--color--heading);
  margin-bottom: 0.75rem;
}

/* ===== Comments ===== */
.wp-block-post-comments-form textarea,
.wp-block-post-comments-form input[type="text"],
.wp-block-post-comments-form input[type="email"],
.wp-block-post-comments-form input[type="url"] {
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 6px;
  color: var(--wp--preset--color--text);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.9375rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.wp-block-post-comments-form textarea:focus,
.wp-block-post-comments-form input:focus {
  outline: none;
  border-color: var(--wp--preset--color--accent);
  box-shadow: 0 0 0 3px rgba(45, 125, 95, 0.15);
}

html.dark-mode .wp-block-post-comments-form textarea:focus,
html.dark-mode .wp-block-post-comments-form input:focus {
  box-shadow: 0 0 0 3px rgba(92, 184, 150, 0.2);
}

.wp-block-post-comments-form .form-submit input[type="submit"] {
  background: var(--wp--preset--color--accent);
  color: var(--wp--preset--color--white);
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.wp-block-post-comments-form .form-submit input[type="submit"]:hover {
  background: var(--wp--preset--color--heading);
}

/* ===== Pagination ===== */
.wp-block-query-pagination {
  margin-top: 40px !important;
  margin-bottom: 40px !important;
}

.wp-block-query-pagination-numbers .page-numbers {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--wp--preset--color--subtle);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.wp-block-query-pagination-numbers .page-numbers:hover {
  background: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--heading);
}

.wp-block-query-pagination-numbers .page-numbers.current {
  background: var(--wp--preset--color--accent);
  color: var(--wp--preset--color--white);
}

/* ===== Navigation Link Styles ===== */
.wp-block-navigation a {
  text-decoration: none;
  color: var(--wp--preset--color--subtle);
  padding-bottom: 4px;
  background-image: linear-gradient(var(--wp--preset--color--accent), var(--wp--preset--color--accent));
  background-size: 0% 2px;
  background-position: 0% 100%;
  background-repeat: no-repeat;
  transition: color 0.2s, background-size 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.wp-block-navigation a:hover {
  color: var(--wp--preset--color--heading);
  background-size: 100% 2px;
}

/* Current menu item — active underline (JS .nav-active + WP fallback) */
.wp-block-navigation .nav-active > a,
.wp-block-navigation .current-menu-item > a,
.wp-block-navigation .current-menu-ancestor > a {
  color: var(--wp--preset--color--heading);
  background-size: 100% 2px;
}

/* ===== Search Shortcut Hint ===== */
.search-shortcut {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  font-size: 0.65rem;
  font-family: var(--wp--preset--font-family--mono);
  color: var(--wp--preset--color--subtle);
  background: var(--wp--preset--color--surface);
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 4px;
  line-height: 1.6;
  letter-spacing: 0.02em;
  user-select: none;
  white-space: nowrap;
}

/* ===== Post Navigation (prev/next) ===== */
.wp-block-post-navigation-link a {
  color: var(--wp--preset--color--accent);
  text-decoration: none;
  font-family: var(--wp--preset--font-family--sans);
  transition: color 0.2s;
}

.wp-block-post-navigation-link a:hover {
  color: var(--wp--preset--color--heading);
}

/* ===== Selection ===== */
::selection {
  background: rgba(45, 125, 95, 0.15);
  color: var(--wp--preset--color--heading);
}

html.dark-mode ::selection {
  background: rgba(92, 184, 150, 0.25);
}

/* ===== Back to Top Button ===== */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--wp--preset--color--border);
  background: var(--wp--preset--color--base);
  color: var(--wp--preset--color--subtle);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

@supports (backdrop-filter: blur(8px)) {
  .back-to-top {
    background: color-mix(in srgb, var(--wp--preset--color--base) 85%, transparent);
    backdrop-filter: blur(8px);
  }
}

.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  color: var(--wp--preset--color--heading);
  border-color: var(--wp--preset--color--accent);
  box-shadow: 0 4px 16px rgba(45, 125, 95, 0.12);
}

html.dark-mode .back-to-top {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

html.dark-mode .back-to-top:hover {
  box-shadow: 0 4px 16px rgba(92, 184, 150, 0.15);
}

/* ===== Scroll Reveal Animations ===== */
.will-reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.will-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.recommend-card.will-reveal:nth-child(2) {
  transition-delay: 0.08s;
}

.recommend-card.will-reveal:nth-child(3) {
  transition-delay: 0.16s;
}

/* ===== Mobile Navigation Overlay ===== */
.site-header:has(.wp-block-navigation__responsive-container.is-menu-open) {
  backdrop-filter: none !important;
  background: var(--wp--preset--color--base) !important;
  overflow: visible !important;
  position: relative !important;
}

@keyframes nav-overlay-enter {
  from {
    opacity: 0;
    clip-path: inset(0 0 100% 0);
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
}

@keyframes nav-item-enter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.wp-block-navigation__responsive-container.is-menu-open {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  max-width: none !important;
  overflow-y: auto !important;
  background: rgba(247, 250, 248, 0.55) !important;
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  z-index: 9998 !important;
  animation: nav-overlay-enter 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

html.dark-mode .wp-block-navigation__responsive-container.is-menu-open {
  background: rgba(23, 31, 27, 0.55) !important;
}

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-close {
  top: 40px !important;
  right: 40px !important;
}

html.dark-mode .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-close button {
  color: #fff !important;
}

html.dark-mode .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-close svg {
  fill: #fff !important;
  stroke: #fff !important;
}

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-content {
  overflow: visible !important;
  max-height: none !important;
  padding: 48px;
  gap: 0;
}

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item {
  padding: var(--wp--preset--spacing--sm) 0;
  border-bottom: 1px solid var(--wp--preset--color--border);
  animation: nav-item-enter 0.35s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(1) { animation-delay: 0.06s; }
.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(2) { animation-delay: 0.12s; }
.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(3) { animation-delay: 0.18s; }
.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(4) { animation-delay: 0.24s; }
.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(5) { animation-delay: 0.30s; }
.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item:nth-child(6) { animation-delay: 0.36s; }

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item a {
  padding-bottom: 0;
  font-size: var(--wp--preset--font-size--lg);
  color: var(--wp--preset--color--heading);
  display: block;
  background-image: none;
  transition: color 0.2s;
}

.wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation-item a:hover {
  color: var(--wp--preset--color--accent);
}

/* ===== Archive Header ===== */
.archive-header {
  background: var(--wp--preset--color--accent);
}

.archive-header .wp-block-query-title {
  color: var(--wp--preset--color--white);
  font-weight: 700;
}

/* ===== About Page Typography ===== */
body.page .wp-block-post-content {
  font-size: 13px;
}

body.page .wp-block-post-content h2,
body.page .wp-block-post-content h3,
body.page .wp-block-post-content h4,
body.page .wp-block-post-content h5,
body.page .wp-block-post-content h6 {
  font-size: 16px;
  font-weight: 700;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .post-card .wp-block-columns {
    flex-direction: column !important;
  }

  .post-card .wp-block-column[style*="flex-basis:200px"] {
    flex-basis: 100% !important;
  }

  .site-footer {
    padding-left: var(--wp--preset--spacing--lg) !important;
    padding-right: var(--wp--preset--spacing--lg) !important;
    padding-top: var(--wp--preset--spacing--lg) !important;
    padding-bottom: var(--wp--preset--spacing--lg) !important;
  }

  .site-footer .wp-block-columns {
    gap: var(--wp--preset--spacing--lg) !important;
  }

  .recent-posts-section .wp-block-post-template {
    grid-template-columns: 1fr !important;
    gap: var(--wp--preset--spacing--lg) !important;
  }

  .back-to-top {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 38px;
    height: 38px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .recent-posts-section .wp-block-post-template {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
