/*
Theme Name: Thirteenmag
Author: Arif Hassan
Theme URI: https://www.arifhassan.com/thirteenmag
Author URI: https://www.arifhassan.com
Description: Thirteenmag is a modern, fast, and accessible WordPress blog and magazine theme built for publishers, bloggers, news sites, and content creators. Designed with clean typography, responsive layouts, dark mode support, Gutenberg compatibility, SEO-friendly structure, and performance-focused code for an excellent reader experience on all devices.
Version: 3.0.0
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 7.4
Text Domain: thirteenmag
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: blog, news, one-column, two-columns, right-sidebar, custom-background, custom-header, custom-logo, custom-menu, featured-images, full-width-template, threaded-comments, translation-ready, accessibility-ready, block-styles, wide-blocks, editor-style, sticky-post
*/

/* ==========================================================================
   1. CSS CUSTOM PROPERTIES
   Tailwind cannot declare or swap CSS variables — must live here.
   ========================================================================== */

:root {
  /* Brand */
  --color-primary: #e63946;
  --color-primary-dark: #c1121f;
  --color-primary-light: #ff6b6b;

  /* Grays (fixed — never swap with mode) */
  --color-gray-900: #1a1a1a;
  --color-gray-800: #2d2d2d;
  --color-gray-500: #888888;
  --color-gray-400: #aaaaaa;
  --color-gray-300: #cccccc;

  /* Semantic — light mode defaults */
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #555555;
  --color-text-muted: #888888;
  --color-border: #e5e5e5;
  --color-bg-body: #f9f9f9;
  --color-bg-surface: #ffffff;
  --color-bg-subtle: #f4f4f4;

  /* Footer semantic tokens — light mode */
  --footer-bg: #1a1a1a;
  --footer-bg-surface: #2d2d2d;
  --footer-text: #aaaaaa;
  --footer-text-muted: #666666;
  --footer-text-heading: #ffffff;
  --footer-border: #2d2d2d;
  --footer-link: #888888;
  --footer-link-hover: #ffffff;

  /* Fonts */
  --font-sans:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Playfair Display", Georgia, serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.04);
  --shadow-focus: 0 0 0 3px rgba(230, 57, 70, 0.25);

  /* Layout */
  --container-width: 1200px;
  --content-width: 780px;
  --sidebar-width: 320px;

  /* Z-index */
  --z-overlay: 100;
  --z-header: 200;
  --z-modal: 300;
}

/* Dark mode — JS toggles html.dark-mode */
html.dark-mode {
  color-scheme: dark;
  --color-text-primary: #f0f0f0;
  --color-text-secondary: #bbbbbb;
  --color-text-muted: #888888;
  --color-border: #333333;
  --color-bg-body: #121212;
  --color-bg-surface: #1e1e1e;
  --color-bg-subtle: #2a2a2a;

  --footer-bg: #0d0d0d;
  --footer-bg-surface: #1a1a1a;
  --footer-text: #888888;
  --footer-text-muted: #555555;
  --footer-text-heading: #f0f0f0;
  --footer-border: #1e1e1e;
  --footer-link: #666666;
  --footer-link-hover: #f0f0f0;
}

/* OS dark preference — before JS loads */
@media (prefers-color-scheme: dark) {
  html:not(.dark-mode):not(.light-mode) {
    --color-text-primary: #f0f0f0;
    --color-text-secondary: #bbbbbb;
    --color-text-muted: #888888;
    --color-border: #333333;
    --color-bg-body: #121212;
    --color-bg-surface: #1e1e1e;
    --color-bg-subtle: #2a2a2a;

    --footer-bg: #0d0d0d;
    --footer-bg-surface: #1a1a1a;
    --footer-text: #888888;
    --footer-text-muted: #555555;
    --footer-text-heading: #f0f0f0;
    --footer-border: #1e1e1e;
    --footer-link: #666666;
    --footer-link-hover: #f0f0f0;
  }
}

/* ==========================================================================
   2. DROPDOWN NAV
   Multi-property opacity + visibility + transform on hover/focus-within
   cannot be expressed in Tailwind without a build step + custom config.
   ========================================================================== */

.primary-nav li::after {
  content: "";
  display: block;
  position: absolute;
  height: 0.5rem;
  left: 0;
  right: 0;
  bottom: -0.5rem;
}

.primary-nav .sub-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 220px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  list-style: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition:
    opacity 250ms ease,
    visibility 250ms ease,
    transform 250ms ease;
  z-index: var(--z-overlay);
}
.primary-nav li:hover > .sub-menu,
.primary-nav li:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.primary-nav .sub-menu .sub-menu {
  top: 0;
  left: calc(100% - 4px);
  transform: translateX(-8px);
}
.primary-nav .sub-menu li:hover > .sub-menu,
.primary-nav .sub-menu li:focus-within > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}
.primary-nav .sub-menu .menu-item-has-children > a::after {
  content: " ›";
  float: right;
  color: var(--color-text-muted);
  margin-left: 0.5rem;
}

/* ==========================================================================
   3. HEADER SCROLL BEHAVIOURS
   JS adds .is-scrolled / .is-hidden — transition must be pre-declared.
   ========================================================================== */

.site-header {
  transition:
    box-shadow 250ms ease,
    transform 250ms ease;
}
.site-header.is-scrolled {
  box-shadow: var(--shadow-md);
}
.site-header.is-hidden {
  transform: translateY(-100%);
  box-shadow: none;
}

/* ==========================================================================
   4. DARK MODE ICON SWAP
   Reacts to both a JS-toggled class and a media query simultaneously.
   ========================================================================== */

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

@media (prefers-color-scheme: dark) {
  html:not(.dark-mode):not(.light-mode) .dark-mode-toggle .icon-sun {
    display: block;
  }
  html:not(.dark-mode):not(.light-mode) .dark-mode-toggle .icon-moon {
    display: none;
  }
}

/* ==========================================================================
   5. MOBILE NAV DRAWER
   Fixed positioning + translateX slide — too verbose as Tailwind arbitrary.
   ========================================================================== */

.mobile-nav {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg-surface);
  z-index: calc(var(--z-header) - 1);
  overflow-y: auto;
  padding: 1.5rem;
  transform: translateX(-100%);
  transition: transform 250ms ease;
}
.mobile-nav.is-open {
  transform: translateX(0);
}
@media (max-width: 768px) {
  .mobile-nav {
    display: block;
  }
}

/* ==========================================================================
   6. STICKY SIDEBAR — @supports block
   ========================================================================== */

@supports (position: sticky) {
  .sidebar-sticky {
    position: sticky;
    top: calc(64px + 1.5rem);
  }
}

/* ==========================================================================
   7. READING PROGRESS BAR
   Width is set by JS dynamically — base declaration must be in CSS.
   ========================================================================== */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--color-primary);
  z-index: calc(var(--z-header) + 1);
  transition: width 0.1s linear;
}

/* ==========================================================================
   8. BACK TO TOP — JS toggles .is-visible
   opacity + visibility + transform together, no Tailwind equivalent.
   ========================================================================== */

.back-to-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition:
    opacity 250ms ease,
    visibility 250ms ease,
    transform 250ms ease;
}
.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ==========================================================================
   9. SCROLL FADE-IN — JS IntersectionObserver toggles .is-visible
   ========================================================================== */

.fade-in {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.4s ease,
    transform 0.4s ease;
}
.fade-in.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   10. @KEYFRAMES — cannot be written as Tailwind utilities
   ========================================================================== */

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes boxSlideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.search-overlay.is-open {
  animation: overlayFadeIn 0.25s ease forwards;
}
.search-overlay__box {
  animation: boxSlideIn 0.25s ease forwards;
}

/* ==========================================================================
   11. POST CARD IMAGE ZOOM
   Parent:hover affecting a child element — needs CSS, not Tailwind.
   ========================================================================== */

.post-card:hover .post-card__thumbnail img {
  transform: scale(1.04);
}

/* ==========================================================================
   12. FOOTER HOVER STATES
   inline style="" cannot handle :hover pseudo-selectors.
   ========================================================================== */

.footer-link:hover {
  color: var(--footer-link-hover) !important;
}
.footer-social-icon:hover {
  background-color: var(--color-primary) !important;
  color: #fff !important;
}
.site-footer .menu a {
  color: var(--footer-link);
  font-size: 0.875rem;
  transition: color 150ms ease;
}
.site-footer .menu a:hover {
  color: var(--footer-link-hover);
}

/* ==========================================================================
   13. WORDPRESS / GUTENBERG OUTPUT
   WordPress generates this HTML — you cannot add Tailwind classes to it.
   ========================================================================== */

.entry-content {
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--color-text-primary);
  max-width: 72ch;
}
.entry-content > * + * {
  margin-top: 1.5rem;
}
.entry-content h2,
.entry-content h3,
.entry-content h4 {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}
.entry-content p {
  color: var(--color-text-secondary);
}
.entry-content ul {
  list-style: disc;
  padding-left: 1.5rem;
}
.entry-content ol {
  list-style: decimal;
  padding-left: 1.5rem;
}
.entry-content li + li {
  margin-top: 0.5rem;
}
.entry-content img {
  border-radius: 8px;
  width: 100%;
}
.entry-content a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.entry-content table {
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
.entry-content th {
  background: var(--color-bg-subtle);
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.entry-content td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}
.entry-content tr:last-child td {
  border-bottom: none;
}

.wp-block-image figcaption {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-top: 0.5rem;
}
.wp-block-pullquote {
  border-top: 4px solid var(--color-primary);
  border-bottom: 4px solid var(--color-primary);
  padding: 1.5rem 0;
  text-align: center;
}
.wp-block-pullquote blockquote {
  background: none;
  border: none;
  padding: 0;
}
.wp-block-pullquote p {
  font-family: var(--font-serif);
  font-size: 1.5rem !important;
  font-style: italic;
  color: var(--color-text-primary) !important;
}
.wp-block-button__link {
  background: var(--color-primary) !important;
  border-radius: 8px !important;
  font-weight: 600 !important;
}
.wp-block-separator {
  border-color: var(--color-border);
  opacity: 1;
}

.tm-video-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 8px;
  margin: 1.5rem 0;
}
.tm-video-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ==========================================================================
   14. ACCESSIBILITY
   clip / clip-path — no Tailwind equivalent.
   ========================================================================== */

.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}
.screen-reader-text:focus {
  clip: auto !important;
  clip-path: none;
  display: block;
  height: auto;
  left: 1rem;
  top: 1rem;
  width: auto;
  z-index: var(--z-modal);
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  font-size: 0.875rem;
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--color-primary);
  color: #fff;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  z-index: var(--z-modal);
  transition: top 150ms ease;
}
.skip-link:focus {
  top: 0;
  color: #fff;
}

/* ==========================================================================
   15. PRINT
   ========================================================================== */

@media print {
  .site-header,
  .sidebar-area,
  .share-buttons,
  .post-nav,
  .newsletter-block,
  .site-footer,
  .back-to-top,
  .reading-progress,
  .search-overlay,
  .breaking-bar {
    display: none !important;
  }
  body {
    font-size: 12pt;
    color: #000;
    background: #fff;
  }
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 10pt;
    color: #555;
  }
  h1,
  h2,
  h3 {
    page-break-after: avoid;
  }
  p,
  blockquote {
    orphans: 3;
    widows: 3;
  }
}

/* ==========================================================================
   16. REDUCE MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .fade-in {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* Pause ticker instead of stopping — it is functional navigation */
  .breaking-bar__ticker-inner {
    animation-play-state: paused !important;
  }
}
/* Breaking news ticker */
.breaking-bar__ticker-inner {
  display: inline-block;
  white-space: nowrap;
  animation: ticker-scroll 30s linear infinite;
}

.breaking-bar__ticker-inner:hover {
  animation-play-state: paused;
}

@keyframes ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

/* ==========================================================================
   WORDPRESS REQUIRED IMAGE CLASSES
   ========================================================================== */

.alignleft {
  float: left;
  margin: 0 1.5rem 1rem 0;
}
.alignright {
  float: right;
  margin: 0 0 1rem 1.5rem;
}
.aligncenter {
  clear: both;
  display: block;
  margin: 0 auto 1rem;
}

.wp-caption {
  max-width: 100%;
  margin-bottom: 1rem;
}
.wp-caption img {
  display: block;
  width: 100%;
}
.wp-caption-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.gallery-caption {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
}

.bypostauthor > .comment-body {
  border-left: 3px solid var(--color-primary);
}
