/*
Theme Name: NovaMag
Theme URI: https://example.com/novamag
Author: Your Studio
Author URI: https://example.com
Description: NovaMag — лёгкая, семантическая тема для журналов и блогов. Построена с нуля: без унаследованного кода, лишних библиотек и плагинов-зависимостей. Заточена под Core Web Vitals, доступность (a11y), структурированные данные Schema.org и удобство чтения роботами поисковых систем и ИИ-агентов.
Version: 1.0.0
Requires at least: 6.4
Tested up to: 6.8
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: novamag
Tags: blog, news, custom-logo, custom-menu, custom-colors, featured-images, threaded-comments, translation-ready, right-sidebar, one-column, two-columns, accessibility-ready
*/

/* =========================================================
   0. DESIGN TOKENS
   ========================================================= */
:root {
    --nm-max-width: 1180px;
    --nm-gap: 2.5rem;
    --nm-radius: 10px;

    --nm-bg: #ffffff;
    --nm-bg-soft: #f6f6f7;
    --nm-text: #17181a;
    --nm-text-muted: #6b7076;
    --nm-border: #e7e8ea;

    --nm-accent: #b8531a;
    --nm-accent-contrast: #ffffff;

    --nm-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --nm-font-heading: Georgia, "Times New Roman", Times, serif;

    --nm-fs-base: 1rem;
    --nm-lh-base: 1.65;

    --nm-shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 8px 24px rgba(20, 20, 20, .05);
    --nm-transition: 160ms ease;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-nm-theme="light"]) {
        --nm-bg: #121214;
        --nm-bg-soft: #1a1b1e;
        --nm-text: #e9e9ea;
        --nm-text-muted: #9a9ca1;
        --nm-border: #2a2b2e;
        --nm-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    }
}

[data-nm-theme="dark"] {
    --nm-bg: #121214;
    --nm-bg-soft: #1a1b1e;
    --nm-text: #e9e9ea;
    --nm-text-muted: #9a9ca1;
    --nm-border: #2a2b2e;
    --nm-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

/* =========================================================
   1. RESET
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    background: var(--nm-bg);
    color: var(--nm-text);
    font-family: var(--nm-font-body);
    font-size: var(--nm-fs-base);
    line-height: var(--nm-lh-base);
    -webkit-font-smoothing: antialiased;
    transition: background var(--nm-transition), color var(--nm-transition);
}
img, picture, svg, video { max-width: 100%; height: auto; display: block; }
a { color: var(--nm-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { padding-left: 1.25em; }
h1, h2, h3, h4, h5, h6 {
    font-family: var(--nm-font-heading);
    line-height: 1.25;
    font-weight: 700;
    margin: 0 0 .55em;
    color: var(--nm-text);
}
p { margin: 0 0 1.2em; }
figure { margin: 0; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
table { width: 100%; border-collapse: collapse; }

/* =========================================================
   2. ACCESSIBILITY HELPERS
   ========================================================= */
.screen-reader-text {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
    border: 0; padding: 0; margin: -1px;
}
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10000;
    background: var(--nm-accent);
    color: var(--nm-accent-contrast);
    padding: .75em 1.25em;
    border-radius: 0 0 8px 0;
}
.skip-link:focus {
    left: 0;
}
:focus-visible {
    outline: 2px solid var(--nm-accent);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* =========================================================
   3. LAYOUT
   ========================================================= */
.nm-container {
    max-width: var(--nm-max-width);
    margin: 0 auto;
    padding: 0 1.25rem;
}
.nm-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--nm-gap);
    align-items: start;
    padding: 2rem 0 2rem;
}
.nm-layout--no-sidebar { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 880px) {
    .nm-layout { grid-template-columns: minmax(0, 1fr); }
}

/* =========================================================
   4. HEADER
   ========================================================= */
.nm-site-header {
    border-bottom: 1px solid var(--nm-border);
    background: var(--nm-bg);
}
.nm-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 1.1rem 0;
    flex-wrap: wrap;
}
.nm-logo {
    font-family: var(--nm-font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--nm-text);
    letter-spacing: -.01em;
    margin: 0;
    flex-shrink: 0;
}
.nm-logo a { color: inherit; text-decoration: none; }
.nm-logo img { max-height: 44px; width: auto; }

.nm-nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--nm-border);
    border-radius: 8px;
    padding: .5rem .65rem;
    cursor: pointer;
    margin-left: auto;
}
.nm-nav-toggle svg { width: 20px; height: 20px; display: block; }

.nm-primary-nav {
    flex: 1 1 auto;
}
.nm-primary-nav ul {
    list-style: none;
    margin: 0; padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: .25rem 1.75rem;
}
.nm-primary-nav li { position: relative; }
.nm-primary-nav a {
    display: block;
    padding: .5rem 0;
    color: var(--nm-text);
    font-weight: 600;
    font-size: .92rem;
    text-decoration: none;
    border-bottom: 2px solid transparent;
}
.nm-primary-nav a:hover,
.nm-primary-nav .current-menu-item > a {
    color: var(--nm-accent);
    border-bottom-color: var(--nm-accent);
}
.nm-primary-nav .sub-menu {
    display: none;
    position: absolute;
    top: 100%; left: 0;
    background: var(--nm-bg);
    border: 1px solid var(--nm-border);
    border-radius: var(--nm-radius);
    box-shadow: var(--nm-shadow);
    padding: .5rem 0;
    min-width: 200px;
    z-index: 50;
    text-align: left;
}
.nm-primary-nav li:hover > .sub-menu,
.nm-primary-nav li:focus-within > .sub-menu { display: block; }
.nm-primary-nav .sub-menu a { padding: .55rem 1rem; border-bottom: none; }

@media (max-width: 880px) {
    .nm-nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .nm-primary-nav {
        display: none;
        flex-basis: 100%;
        order: 3;
        border-top: 1px solid var(--nm-border);
        margin-top: .75rem;
        padding-top: .5rem;
    }
    .nm-primary-nav.is-open { display: block; }
    .nm-primary-nav ul { flex-direction: column; gap: 0; justify-content: flex-start; }
    .nm-primary-nav .sub-menu { position: static; border: none; box-shadow: none; padding-left: 1rem; }
}

/* =========================================================
   5. POST CARD / LOOP
   ========================================================= */
.nm-post-list { display: flex; flex-direction: column; gap: 2rem; }
.nm-post-card {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 1.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--nm-border);
}
.nm-post-card:last-child { border-bottom: none; }
.nm-post-card--no-thumb { grid-template-columns: 1fr; }
.nm-post-card__thumb {
    border-radius: var(--nm-radius);
    overflow: hidden;
    background: var(--nm-bg-soft);
    aspect-ratio: 4 / 3;
}
.nm-post-card__thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; transition: transform var(--nm-transition); }
.nm-post-card:hover .nm-post-card__thumb img { transform: scale(1.03); }
.nm-post-card__meta {
    font-size: .8rem;
    color: var(--nm-text-muted);
    display: flex;
    gap: .6rem;
    align-items: center;
    margin-bottom: .4rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.nm-post-card__meta a { color: var(--nm-accent); text-decoration: none; }
.nm-post-card__title { font-size: 1.4rem; margin-bottom: .5rem; }
.nm-post-card__title a { color: var(--nm-text); text-decoration: none; }
.nm-post-card__title a:hover { color: var(--nm-accent); }
.nm-post-card__excerpt { color: var(--nm-text-muted); font-size: .95rem; }

@media (max-width: 560px) {
    .nm-post-card { grid-template-columns: 1fr; }
}

/* Pagination */
.nm-pagination { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 2.5rem; }
.nm-pagination a, .nm-pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 2.25rem; height: 2.25rem; padding: 0 .6rem;
    border: 1px solid var(--nm-border); border-radius: 8px;
    color: var(--nm-text); text-decoration: none; font-size: .9rem;
}
.nm-pagination .current { background: var(--nm-accent); border-color: var(--nm-accent); color: var(--nm-accent-contrast); }
.nm-pagination a:hover { border-color: var(--nm-accent); color: var(--nm-accent); }

/* =========================================================
   6. SINGLE POST
   ========================================================= */
.nm-article-header { margin-bottom: 1.5rem; }
.nm-article-title { font-size: clamp(1.35rem, 2.6vw, 1.85rem); }
.nm-article-meta {
    display: flex; flex-wrap: wrap; gap: .3rem 1rem;
    color: var(--nm-text-muted); font-size: .875rem; align-items: center;
}
.nm-article-meta a { color: var(--nm-text-muted); }
.nm-article-date-bottom {
    text-align: right;
    color: var(--nm-text-muted);
    font-size: .85rem;
    margin: 1.5rem 0 0;
}
.nm-article-thumb { margin: 1.5rem 0; border-radius: var(--nm-radius); overflow: hidden; }
.nm-article-thumb img { width: 100%; height: auto; }
.nm-article-thumb figcaption {
    font-size: .8rem; color: var(--nm-text-muted); padding: .6rem .2rem 0;
}
.nm-content { font-size: 1.05rem; }
.nm-content h2 { margin-top: 1.8em; font-size: 1.5rem; }
.nm-content h3 { margin-top: 1.5em; font-size: 1.25rem; }
.nm-content blockquote {
    margin: 1.5em 0; padding: .25em 1.25em;
    border-left: 3px solid var(--nm-accent);
    color: var(--nm-text-muted); font-style: italic;
}
.nm-content pre {
    background: var(--nm-bg-soft); padding: 1em; border-radius: 8px; overflow-x: auto;
}
.nm-content img { border-radius: var(--nm-radius); }
.nm-content a { text-decoration: underline; }

/* Reading progress + reading time */
.nm-reading-time { display: inline-flex; align-items: center; gap: .3rem; }

/* Table of contents (auto-generated from H2 headings, long articles only) */
.nm-toc {
    background: var(--nm-bg-soft);
    border: 1px solid var(--nm-border);
    border-radius: var(--nm-radius);
    padding: 1.1rem 1.4rem;
    margin: 0 0 2rem;
}
.nm-toc summary {
    cursor: pointer;
    font-weight: 700;
    font-size: .95rem;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nm-toc summary::-webkit-details-marker { display: none; }
.nm-toc summary::after {
    content: "";
    width: 9px; height: 9px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--nm-transition);
    flex-shrink: 0;
}
.nm-toc[open] summary { margin-bottom: .9rem; }
.nm-toc[open] summary::after { transform: rotate(-135deg); }
.nm-toc ol { margin: 0; padding-left: 1.2rem; }
.nm-toc li { margin-bottom: .5rem; font-size: .9rem; }
.nm-toc li:last-child { margin-bottom: 0; }
.nm-toc a { color: var(--nm-text); text-decoration: none; }
.nm-toc a:hover { color: var(--nm-accent); text-decoration: underline; }

/* Related posts (no visible heading — see aria-label) */
.nm-related-posts {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--nm-border);
}
.nm-related-posts ul {
    list-style: none;
    margin: 0; padding: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}
.nm-related-posts__thumb {
    display: block;
    border-radius: var(--nm-radius);
    overflow: hidden;
    aspect-ratio: 4 / 3;
    background: var(--nm-bg-soft);
    margin-bottom: .6rem;
}
.nm-related-posts__thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.nm-related-posts__title {
    display: block;
    font-weight: 600;
    font-size: .92rem;
    color: var(--nm-text);
    text-decoration: none;
    line-height: 1.35;
    margin-bottom: .3rem;
}
.nm-related-posts__title:hover { color: var(--nm-accent); }
.nm-related-posts time { font-size: .78rem; color: var(--nm-text-muted); }
@media (max-width: 880px) { .nm-related-posts ul { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .nm-related-posts ul { grid-template-columns: 1fr; } }

/* =========================================================
   7. SIDEBAR / WIDGETS
   ========================================================= */
.nm-sidebar .widget {
    margin-bottom: 2.25rem;
    padding-bottom: 2.25rem;
    border-bottom: 1px solid var(--nm-border);
}
.nm-sidebar .widget:last-child { border-bottom: none; }
.nm-sidebar .widget-title {
    font-size: 1rem; text-transform: uppercase; letter-spacing: .04em;
    margin-bottom: 1.1rem; position: relative; padding-bottom: .6rem;
}
.nm-sidebar .widget-title::after {
    content: ""; position: absolute; left: 0; bottom: 0;
    width: 34px; height: 2px; background: var(--nm-accent);
}
.nm-popular-posts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.nm-popular-posts li { display: grid; grid-template-columns: 64px 1fr; gap: .8rem; align-items: center; }
.nm-popular-posts img { width: 64px; height: 64px; object-fit: cover; object-position: top; border-radius: 8px; }
.nm-popular-posts a { color: var(--nm-text); font-size: .9rem; font-weight: 600; text-decoration: none; line-height: 1.35; }
.nm-popular-posts a:hover { color: var(--nm-accent); }
.nm-popular-posts time { display: block; font-size: .75rem; color: var(--nm-text-muted); margin-top: .2rem; }

.nm-social-links { display: flex; flex-wrap: wrap; gap: .6rem; list-style: none; margin: 0; padding: 0; }
.nm-social-links a {
    width: 38px; height: 38px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--nm-bg-soft); color: var(--nm-text);
    transition: background var(--nm-transition), color var(--nm-transition);
}
.nm-social-links a:hover { background: var(--nm-accent); color: var(--nm-accent-contrast); }
.nm-social-links svg { width: 18px; height: 18px; }

.nm-search-form { display: flex; gap: .5rem; }
.nm-search-form input[type="search"] {
    flex: 1; padding: .6rem .8rem; border: 1px solid var(--nm-border); border-radius: 8px; background: var(--nm-bg);
}
.nm-search-form button {
    background: var(--nm-accent); color: var(--nm-accent-contrast); border: none;
    border-radius: 8px; padding: 0 1rem; cursor: pointer;
}

/* Generic widget list resets (categories, archives, recent posts, etc.) */
.widget ul { list-style: none; margin: 0; padding: 0; }
.widget ul li { padding: .5rem 0; border-bottom: 1px dashed var(--nm-border); font-size: .9rem; }
.widget ul li:last-child { border-bottom: none; }
.widget a { color: var(--nm-text); text-decoration: none; }
.widget a:hover { color: var(--nm-accent); }
.widget select, .widget input { width: 100%; padding: .5rem; border: 1px solid var(--nm-border); border-radius: 6px; }
.tagcloud a {
    display: inline-block; margin: 0 .4rem .4rem 0; padding: .25rem .7rem;
    border: 1px solid var(--nm-border); border-radius: 999px; font-size: .8rem !important;
}

/* =========================================================
   8. COMMENTS
   ========================================================= */
.nm-comments { margin-top: 3rem; }
.nm-comments-title { font-size: 1.3rem; margin-bottom: 1.5rem; }
.comment-list { list-style: none; margin: 0; padding: 0; }
.comment-list .children { list-style: none; padding-left: 2rem; }
.nm-comment { display: flex; gap: 1rem; padding: 1.25rem 0; border-bottom: 1px solid var(--nm-border); }
.nm-comment img { border-radius: 50%; }
.nm-comment-author { font-weight: 700; font-size: .9rem; }
.nm-comment-meta { font-size: .78rem; color: var(--nm-text-muted); margin-bottom: .4rem; }
.nm-comment-content p:last-child { margin-bottom: 0; }
.comment-reply-link {
    font-size: .78rem; border: 1px solid var(--nm-border); border-radius: 999px;
    padding: .2rem .75rem; text-decoration: none;
}
.comment-form input, .comment-form textarea {
    width: 100%; padding: .65rem .8rem; border: 1px solid var(--nm-border);
    border-radius: 8px; margin-bottom: 1rem; background: var(--nm-bg);
}
.comment-form label { display: block; font-size: .85rem; margin-bottom: .35rem; }
.comment-form .form-submit input {
    width: auto; background: var(--nm-accent); color: var(--nm-accent-contrast);
    border: none; cursor: pointer; padding: .65rem 1.5rem; font-weight: 600;
}

/* =========================================================
   9. FOOTER
   ========================================================= */
.nm-site-footer { border-top: 1px solid var(--nm-border); margin-top: 1.5rem; background: var(--nm-bg-soft); }
.nm-footer-widgets {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem;
    padding: 2rem 0;
}
@media (max-width: 880px) { .nm-footer-widgets { grid-template-columns: 1fr; } }
.nm-footer-widgets .widget-title { font-size: .9rem; }
.nm-footer-bottom {
    border-top: 1px solid var(--nm-border);
    padding: 1.1rem 0; font-size: .82rem; color: var(--nm-text-muted);
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem;
}
.nm-footer-bottom a { color: var(--nm-text-muted); }

/* =========================================================
   10. MISC / UTILITY
   ========================================================= */
.nm-breadcrumbs { font-size: .8rem; color: var(--nm-text-muted); margin-bottom: 1.25rem; }
.nm-breadcrumbs a { color: var(--nm-text-muted); }
.nm-breadcrumbs a:hover { color: var(--nm-accent); }
.nm-badge {
    display: inline-block; background: var(--nm-accent); color: var(--nm-accent-contrast);
    font-size: .7rem; text-transform: uppercase; padding: .15rem .55rem; border-radius: 4px;
}
.nm-empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--nm-text-muted); }
.alignwide { max-width: 100%; }
.alignfull { width: 100vw; position: relative; left: 50%; right: 50%; margin-left: -50vw; margin-right: -50vw; }
.wp-caption, .wp-caption-text { font-size: .8rem; color: var(--nm-text-muted); }

/* WordPress core image alignment classes */
.aligncenter,
.nm-content .aligncenter {
    display: block;
    margin-left: auto;
    margin-right: auto;
    float: none;
}
.alignleft,
.nm-content .alignleft {
    float: left;
    margin: .3em 1.5em 1em 0;
}
.alignright,
.nm-content .alignright {
    float: right;
    margin: .3em 0 1em 1.5em;
}
.wp-caption.aligncenter { margin-left: auto; margin-right: auto; }

/* Scroll-to-top button */
.nm-scroll-top {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--nm-border);
    background: var(--nm-bg);
    color: var(--nm-text);
    box-shadow: var(--nm-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity var(--nm-transition), transform var(--nm-transition), visibility var(--nm-transition);
    cursor: pointer;
    z-index: 500;
    padding: 0;
}
.nm-scroll-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.nm-scroll-top:hover { border-color: var(--nm-accent); color: var(--nm-accent); }
.nm-scroll-top svg { width: 20px; height: 20px; }
