/* Keep the theme image frame, but make it thinner. */
img {
  border-width: 6px;
  padding: 6px;
}

iframe[src*="youtube.com"] {
  border-width: 6px !important;
  padding: 6px !important;
}

/* Subtle hover animation for images inside blog posts. */
@media (hover: hover) and (pointer: fine) {
  .post .post-content img {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  }

  .post .post-content img:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 18px rgba(255, 68, 68, 0.16);
    border-color: var(--link-hover);
  }

  :root[data-theme="light"] .post .post-content img:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.16);
  }
}

/* Post screenshot lightbox (subtle zoom + navigation). */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.74);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.lightbox.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.lightbox__panel {
  position: relative;
  width: max-content;
  max-width: calc(100vw - 48px);
}

.lightbox__figure {
  position: relative;
  margin: 0;
  transform: scale(0.985);
  transition: transform 0.2s ease;
}

.lightbox.is-open .lightbox__figure {
  transform: scale(1);
}

.lightbox__image {
  display: block;
  width: auto;
  max-width: min(90vw, 1300px);
  max-height: 86vh;
  border: 4px solid var(--accent);
  padding: 4px;
  background: var(--background);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.34);
}

.lightbox__caption {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 9px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--foreground);
  opacity: 0.9;
}

button.lightbox__close,
button.lightbox__nav {
  appearance: none;
  -webkit-appearance: none;
  border: 0 !important;
  background: transparent !important;
  color: var(--accent);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  box-shadow: none !important;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    filter 0.18s ease,
    opacity 0.18s ease,
    color 0.18s ease;
  outline: none !important;
  font-size: 0;
}

.lightbox__nav svg,
.lightbox__close svg {
  display: block;
  width: 34px;
  height: 34px;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: square;
  stroke-linejoin: miter;
  fill: none;
  pointer-events: none;
}

.lightbox__close svg {
  width: 28px;
  height: 28px;
}

.lightbox__close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 46px;
  height: 46px;
  z-index: 2;
}

.lightbox__nav {
  position: fixed;
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translateY(-50%);
  z-index: 2;
}

.lightbox__prev {
  left: 22px;
}

.lightbox__next {
  right: 22px;
}

.lightbox__nav[disabled] {
  opacity: 0.25;
  pointer-events: none;
}

.lightbox__close:hover,
.lightbox__close:focus-visible,
.lightbox__nav:hover,
.lightbox__nav:focus-visible {
  background: transparent !important;
  border: 0 !important;
  outline: none !important;
  box-shadow: none !important;
  filter: drop-shadow(0 0 8px rgba(255, 68, 68, 0.45));
}

.lightbox__close:hover,
.lightbox__close:focus-visible {
  transform: translateY(-1px);
}

.lightbox__nav:hover,
.lightbox__nav:focus-visible {
  transform: translateY(calc(-50% - 1px));
}

/* MITRE ATT&CK mapping template block for analysis posts. */
.mitre-mapping {
  margin: 2rem 0 1.6rem;
  padding: 0.85rem 1rem 1rem;
  border: 1px dashed color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--code-bg) 80%, transparent);
}

.mitre-mapping__title {
  margin: 0 0 0.45rem;
  color: var(--accent);
}

.mitre-mapping__meta {
  margin: 0 0 0.75rem;
  opacity: 0.9;
}

.mitre-mapping__meta code {
  font-size: 0.92em;
}

.mitre-mapping__content p {
  margin: 0;
}

.mitre-mapping__content {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mitre-mapping__content table {
  margin: 0;
  width: 100%;
  min-width: 720px;
}

.mitre-mapping__content th,
.mitre-mapping__content td {
  word-break: normal;
  overflow-wrap: break-word;
  vertical-align: top;
}

.mitre-mapping__content th:nth-child(3),
.mitre-mapping__content td:nth-child(3) {
  white-space: nowrap;
}

@media (max-width: 684px) {
  .lightbox {
    padding: 12px;
  }

  .lightbox__close {
    top: 10px;
    right: 4px;
    width: 42px;
    height: 42px;
  }

  .lightbox__nav {
    width: 42px;
    height: 42px;
  }

  .lightbox__nav svg,
  .lightbox__close svg {
    width: 30px;
    height: 30px;
  }

  .lightbox__close svg {
    width: 25px;
    height: 25px;
  }

  .lightbox__prev {
    left: 4px;
  }

  .lightbox__next {
    right: 4px;
  }
}

/* Prevent header/nav horizontal jump when page height changes between themes. */
html {
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  html {
    overflow-y: scroll;
  }
}

/* Homepage ASCII variant swap (dark by default, light when theme is light). */
.ascii-wrap {
  display: grid;
  justify-content: center;
  margin: 0;
}

.ascii-art {
  grid-area: 1 / 1;
  justify-self: center;
  width: max-content;
}

.ascii-art--dark,
.ascii-art--light {
  display: block !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

:root:not([data-theme="light"]) .ascii-art--dark {
  visibility: visible;
  opacity: 1;
}

:root[data-theme="light"] .ascii-art--light {
  visibility: visible;
  opacity: 1;
  background: #ffffff;
  transform: translateY(-16px) scaleX(0.97);
  transform-origin: top center;
}

/* Theme toggle feature: isolated block for easy full removal if needed. */
:root[data-theme="light"] {
  --background: #ffffff;
  --foreground: #111111;
  --code-bg: #f4f4f4;
  --secondary: #4a4a4a;
  --link-hover: #cc3333;
  --accent-glow: rgba(255, 68, 68, 0.14);
}

:root[data-theme="light"] .post-credits {
  border-top-color: rgba(0, 0, 0, 0.24) !important;
}

:root[data-theme="light"] .misc-categories {
  border-top-color: rgba(0, 0, 0, 0.12) !important;
  border-bottom-color: rgba(0, 0, 0, 0.12) !important;
}

:root[data-theme="light"] .misc-categories-title {
  color: var(--foreground) !important;
}

:root[data-theme="light"] .misc-terminal-screen {
  color: rgba(17, 17, 17, 0.94) !important;
}

:root[data-theme="light"] .misc-terminal-line.is-out {
  color: rgba(17, 17, 17, 0.9) !important;
}

:root[data-theme="light"] .about-page {
  --about-fg: #161616 !important;
  --about-border: rgba(0, 0, 0, 0.1) !important;
}

:root[data-theme="light"] .about-page::before {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px) !important;
}

:root[data-theme="light"] .about-page::after {
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.018),
      rgba(0, 0, 0, 0.018) 1px,
      transparent 1px,
      transparent 5px
    ) !important;
}

:root[data-theme="light"] .about-section {
  border-color: rgba(0, 0, 0, 0.12) !important;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(246, 246, 246, 0.94)) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

:root[data-theme="light"] .about-section::before {
  border-bottom-color: rgba(0, 0, 0, 0.1) !important;
  background: linear-gradient(
    90deg,
    rgba(255, 77, 77, 0.1) 0%,
    rgba(255, 77, 77, 0.05) 24%,
    rgba(0, 0, 0, 0.03) 56%,
    rgba(0, 0, 0, 0.02) 100%
  ) !important;
  color: rgba(0, 0, 0, 0.64) !important;
}

:root .about-page .project-toggle,
:root .about-page .project-toggle:hover,
:root .about-page .project-toggle:focus,
:root .about-page .project-toggle:focus-visible,
:root .about-page .project-toggle:active {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

:root .about-page .project-item {
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.22s ease,
    transform 0.2s ease;
}

:root .about-page .project-item:hover {
  border-color: rgba(255, 77, 77, 0.3) !important;
  background: linear-gradient(
    110deg,
    rgba(255, 77, 77, 0.055) 0%,
    rgba(255, 255, 255, 0.02) 54%,
    rgba(255, 77, 77, 0.035) 100%
  ) !important;
  box-shadow: 0 4px 14px rgba(255, 77, 77, 0.08);
}

:root[data-theme="light"] .project-item {
  border-color: rgba(255, 77, 77, 0.3) !important;
  background: rgba(0, 0, 0, 0.015) !important;
}

:root[data-theme="light"] .project-item:hover {
  border-color: rgba(255, 77, 77, 0.36) !important;
  background: linear-gradient(
    110deg,
    rgba(255, 77, 77, 0.085) 0%,
    rgba(255, 255, 255, 0.75) 53%,
    rgba(255, 77, 77, 0.06) 100%
  ) !important;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.09) !important;
}

:root[data-theme="light"] .project-content {
  border-left-color: rgba(0, 0, 0, 0.2) !important;
}

:root[data-theme="light"] .cert-box {
  border-color: rgba(0, 0, 0, 0.18) !important;
  background: linear-gradient(180deg, #f7f7f7, #ebebeb) !important;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.16) !important;
}

:root[data-theme="light"] .cert-box::before {
  border-color: rgba(0, 0, 0, 0.14) !important;
}

:root[data-theme="light"] .cert-box::after {
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.09), transparent) !important;
}

:root[data-theme="light"] .cert-link:hover .cert-box {
  box-shadow: 0 5px 13px rgba(0, 0, 0, 0.24) !important;
}

:root[data-theme="light"] .about-fs-tree button.dir:focus {
  outline-color: rgba(0, 0, 0, 0.16) !important;
}

.theme-toggle {
  margin-left: 14px;
  width: auto;
  height: auto;
  min-width: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: var(--accent);
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: transparent;
  box-shadow: none;
}

.theme-toggle__icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, text-shadow 0.15s ease, color 0.15s ease;
}

.theme-toggle__icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  display: block;
}

.theme-toggle__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.theme-toggle.is-light {
  background: transparent;
  box-shadow: none;
  color: var(--accent);
}

.theme-toggle.is-light .theme-toggle__icon {
  text-shadow: 0 0 8px rgba(255, 68, 68, 0.34);
}

.theme-toggle:hover .theme-toggle__icon {
  transform: translateY(-1px);
  text-shadow: 0 0 8px rgba(255, 68, 68, 0.26);
}

@media (max-width: 684px) {
  .theme-toggle {
    margin-left: 8px;
  }

  .theme-toggle__icon {
    width: 20px;
    height: 20px;
  }
}

/* Mobile/header QoL: compact sticky header, horizontal nav, safe content overflow. */
@media (max-width: 900px) {
  .header {
    position: sticky !important;
    top: 0;
    animation: none !important;
  }

  .header__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "logo toggle"
      "nav nav";
    align-items: center;
    gap: 8px 10px;
    padding: 10px 14px !important;
  }

  .header__logo {
    grid-area: logo;
    min-width: 0;
  }

  .theme-toggle {
    grid-area: toggle;
    margin-left: 0;
  }

  .navigation-menu {
    grid-area: nav;
    width: 100%;
    margin: 0;
    justify-content: stretch;
  }

  .navigation-menu .menu--desktop,
  .navigation-menu .navigation-menu__primary,
  .navigation-menu__inner {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    width: 100%;
    gap: 6px;
    align-items: stretch !important;
    justify-content: space-between;
  }

  .navigation-menu__inner > li {
    flex: 1 1 0;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
    white-space: normal;
  }

  .navigation-menu__inner > li a {
    display: block;
    width: 100%;
    text-align: center;
    padding: 7px 4px !important;
    font-size: 0.9rem !important;
    line-height: 1.2;
  }

  .menu--mobile .menu__trigger {
    display: none !important;
  }

  .container {
    padding: 16px !important;
    padding-top: 12px !important;
  }

  .post {
    overflow-x: hidden;
  }

  .post-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .post-content pre,
  .post-content code {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ascii-wrap {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    contain: layout paint;
  }

  .ascii-art {
    display: block;
    width: auto;
    min-width: 0;
    font-size: clamp(2.4px, 0.76vw, 3.4px);
    line-height: 1;
    letter-spacing: 0;
    contain: paint;
  }

  .ascii-art span {
    letter-spacing: 0;
  }

  body,
  .blog-list li,
  .post {
    animation: none !important;
  }

  .blog-list li,
  .blog-list a,
  .navigation-menu__inner a,
  .navigation-menu__inner a::before,
  .logo,
  .theme-toggle__icon,
  .post-title a {
    transition: none !important;
  }
}
