/* MemeRipPedia — жёсткий минимализм в стиле Grokipedia */

:root {
    --bg: #FFFFFF;
    --fg: #0F0F0F;
    --muted: #6B6B6B;
    --line: #E8E8E8;
    --line-strong: #1A1A1A;
    --accent: #000000;
    --hover-bg: #F5F5F5;
    --code-bg: #F5F5F5;
    --quote-bg: #FAFAFA;
    --link: #0F0F0F;
    --link-hover: #555;
    --cat-bg: #F0F0F0;
    --cat-fg: #333;
}

[data-theme="dark"] {
    --bg: #0F0F0F;
    --fg: #ECECEC;
    --muted: #888;
    --line: #1F1F1F;
    --line-strong: #ECECEC;
    --accent: #ECECEC;
    --hover-bg: #1A1A1A;
    --code-bg: #1A1A1A;
    --quote-bg: #161616;
    --link: #ECECEC;
    --link-hover: #999;
    --cat-bg: #1A1A1A;
    --cat-fg: #CCC;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Inter", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* === Header === */
.mr-header {
    border-bottom: 1px solid var(--line-strong);
    padding: 22px 32px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}

.mr-logo {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--fg);
    text-decoration: none;
    line-height: 1;
}
.mr-logo .accent {
    color: var(--muted);
    font-weight: 300;
}

.mr-nav-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.mr-search {
    display: flex;
    align-items: center;
    border: 1px solid var(--line-strong);
    background: var(--bg);
    padding: 8px 14px;
    gap: 10px;
    width: 360px;
    max-width: 100%;
}
.mr-search input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--fg);
    font: inherit;
    width: 100%;
    font-size: 14px;
}
.mr-search button {
    background: transparent;
    border: none;
    color: var(--fg);
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 0;
}

.mr-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mr-flag {
    width: 22px;
    height: 16px;
    display: inline-block;
    cursor: pointer;
    border: 1px solid var(--line-strong);
    vertical-align: middle;
    background-size: cover;
    background-position: center;
}
.mr-flag.active {
    outline: 2px solid var(--fg);
    outline-offset: 1px;
}

.mr-theme-toggle {
    background: transparent;
    border: 1px solid var(--line-strong);
    color: var(--fg);
    cursor: pointer;
    padding: 4px 10px;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* === Subnav === */
.mr-subnav {
    border-bottom: 1px solid var(--line);
    padding: 10px 32px;
    display: flex;
    gap: 24px;
    font-size: 13px;
    color: var(--muted);
    flex-wrap: wrap;
    align-items: center;
}
.mr-subnav a {
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
}
.mr-subnav a:hover {
    color: var(--fg);
}
.mr-subnav .sep {
    color: var(--line);
}

/* === Layout === */
.mr-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 0;
    min-height: calc(100vh - 120px);
}

.mr-sidebar {
    border-right: 1px solid var(--line);
    padding: 28px 24px;
    font-size: 14px;
    color: var(--muted);
}
.mr-sidebar h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 12px;
    font-weight: 600;
}
.mr-sidebar ul {
    list-style: none;
    margin-bottom: 28px;
}
.mr-sidebar li {
    padding: 4px 0;
}
.mr-sidebar a {
    color: var(--fg);
    text-decoration: none;
    font-weight: 500;
}
.mr-sidebar a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

.mr-main {
    padding: 48px 64px;
    max-width: 880px;
    width: 100%;
}

/* === Page article === */
.mr-article h1 {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.1;
    margin-bottom: 8px;
}
.mr-article .tagline {
    color: var(--muted);
    font-size: 15px;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}
.mr-article h2 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-top: 36px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px;
}
.mr-article h3 {
    font-size: 18px;
    font-weight: 700;
    margin-top: 24px;
    margin-bottom: 8px;
}
.mr-article p {
    margin-bottom: 16px;
}
.mr-article ul {
    margin: 0 0 16px 24px;
    padding-left: 8px;
}
.mr-article li {
    margin-bottom: 6px;
}
.mr-article blockquote {
    background: var(--quote-bg);
    border-left: 3px solid var(--fg);
    padding: 12px 18px;
    margin: 0 0 20px;
    font-size: 15px;
    color: var(--fg);
}
.mr-article blockquote p {
    margin: 0;
}
.mr-article code {
    background: var(--code-bg);
    padding: 1px 5px;
    font-size: 0.9em;
    font-family: "SF Mono", Monaco, Consolas, monospace;
}
.mr-article a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
.mr-article a:hover {
    color: var(--link-hover);
}

.mr-cat-link {
    display: inline-block;
    background: var(--cat-bg);
    color: var(--cat-fg) !important;
    padding: 2px 8px;
    margin: 0 4px 4px 0;
    font-size: 13px;
    text-decoration: none !important;
}
.mr-cat-link:hover {
    background: var(--fg);
    color: var(--bg) !important;
}

.mr-wiki-link {
    color: var(--link);
    text-decoration: underline dotted;
}

/* === Meta footer статьи === */
.mr-article-meta {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--muted);
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.mr-article-meta a {
    color: var(--muted);
    text-decoration: underline;
}
.mr-article-meta a:hover {
    color: var(--fg);
}

/* === Home page === */
.mr-hero {
    text-align: left;
    padding: 32px 0 48px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 48px;
}
.mr-hero h1 {
    font-size: 56px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.05;
    margin-bottom: 16px;
}
.mr-hero .tagline {
    font-size: 18px;
    color: var(--muted);
    max-width: 580px;
    margin-bottom: 24px;
}
.mr-hero-stats {
    font-size: 13px;
    color: var(--muted);
}
.mr-hero-stats strong {
    color: var(--fg);
    font-weight: 700;
}

/* === New page form === */
.mr-new-form {
    display: flex;
    gap: 0;
    margin: 24px 0 48px;
    max-width: 680px;
    border: 1px solid var(--line-strong);
}
.mr-new-form input {
    flex: 1;
    padding: 14px 16px;
    border: none;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
    font-size: 16px;
    outline: none;
}
.mr-new-form button {
    background: var(--fg);
    color: var(--bg);
    border: none;
    padding: 14px 24px;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: -0.01em;
}
.mr-new-form button:hover {
    background: var(--muted);
}

/* === List of pages === */
.mr-page-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.mr-page-list li {
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}
.mr-page-list li:last-child {
    border-bottom: none;
}
.mr-page-list a {
    font-size: 17px;
    font-weight: 600;
    color: var(--fg);
    text-decoration: none;
    letter-spacing: -0.01em;
}
.mr-page-list a:hover {
    text-decoration: underline;
}
.mr-page-list .meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.mr-section-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 16px;
    font-weight: 600;
}

/* === Edit form === */
.mr-edit-form textarea {
    width: 100%;
    min-height: 480px;
    padding: 16px;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 14px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line-strong);
    outline: none;
    resize: vertical;
}
.mr-edit-form input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    font: inherit;
    font-size: 16px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line-strong);
    margin-bottom: 12px;
}
.mr-edit-actions {
    margin-top: 16px;
    display: flex;
    gap: 12px;
}
.mr-btn {
    background: var(--fg);
    color: var(--bg);
    border: none;
    padding: 12px 24px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    letter-spacing: -0.01em;
}
.mr-btn:hover {
    background: var(--muted);
}
.mr-btn.mr-btn-ghost {
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--line-strong);
}
.mr-btn-ghost:hover {
    background: var(--hover-bg);
}

/* === Generating === */
.mr-generating {
    text-align: center;
    padding: 80px 24px;
}
.mr-generating .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--line);
    border-top-color: var(--fg);
    border-radius: 50%;
    margin: 0 auto 24px;
    animation: mr-spin 0.8s linear infinite;
}
@keyframes mr-spin {
    to { transform: rotate(360deg); }
}
.mr-generating h2 {
    border: none;
    margin: 0 0 8px;
    padding: 0;
    font-size: 22px;
    font-weight: 700;
}
.mr-generating p {
    color: var(--muted);
    font-size: 14px;
}

/* === Not found === */
.mr-not-found {
    padding: 60px 0;
    text-align: center;
}
.mr-not-found h1 {
    font-size: 64px;
    font-weight: 800;
    letter-spacing: -0.04em;
    margin-bottom: 12px;
}
.mr-not-found p {
    color: var(--muted);
    margin-bottom: 24px;
}

/* === Footer === */
.mr-footer {
    border-top: 1px solid var(--line-strong);
    padding: 24px 32px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

/* === Responsive === */
@media (max-width: 900px) {
    .mr-layout {
        grid-template-columns: 1fr;
    }
    .mr-sidebar {
        display: none;
    }
    .mr-main {
        padding: 32px 24px;
    }
    .mr-header {
        padding: 16px 20px;
        flex-direction: column;
        align-items: stretch;
    }
    .mr-search {
        width: 100%;
    }
    .mr-hero h1 {
        font-size: 40px;
    }
    .mr-article h1 {
        font-size: 32px;
    }
}

/* === Auth buttons (login/register) === */
.mr-auth-btn {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--fg);
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    letter-spacing: -0.01em;
}
.mr-auth-btn:hover {
    background: var(--hover-bg);
}
.mr-auth-btn-primary {
    background: var(--fg);
    color: var(--bg);
    border-color: var(--fg);
}
.mr-auth-btn-primary:hover {
    background: var(--muted);
    color: var(--bg);
}

/* === User chip (header) === */
.mr-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--fg);
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--line-strong);
}
.mr-user-chip:hover {
    background: var(--hover-bg);
}
.mr-avatar {
    width: 22px;
    height: 22px;
    background: var(--fg);
    color: var(--bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
}

/* === Auth card (login/register page) === */
.mr-auth-card {
    max-width: 420px;
    margin: 32px auto;
    padding: 32px;
    border: 1px solid var(--line-strong);
}
.mr-auth-card h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 24px;
}
.mr-auth-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.mr-auth-form label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
    margin-top: 12px;
}
.mr-auth-form label:first-child { margin-top: 0; }
.mr-auth-form input {
    padding: 12px 14px;
    font: inherit;
    font-size: 15px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line-strong);
    outline: none;
}
.mr-auth-form input:focus {
    border-color: var(--fg);
}
.mr-auth-form button {
    margin-top: 20px;
    padding: 12px;
    background: var(--fg);
    color: var(--bg);
    border: none;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: -0.01em;
}
.mr-auth-form button:hover {
    background: var(--muted);
}
.mr-auth-error {
    background: #fee;
    color: #c00;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 14px;
    border-left: 3px solid #c00;
}
[data-theme="dark"] .mr-auth-error {
    background: #2a0a0a;
    color: #ff8080;
}
.mr-auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--muted);
}
.mr-auth-switch a {
    color: var(--fg);
    text-decoration: underline;
}

/* === Profile === */
.mr-profile-header {
    display: flex;
    gap: 24px;
    align-items: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--line);
}

/* === Create page === */
.mr-auth-warning {
    background: var(--quote-bg);
    border-left: 3px solid var(--fg);
    padding: 14px 18px;
    margin-bottom: 24px;
    font-size: 14px;
}
.mr-create-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 720px;
    margin-bottom: 48px;
}
.mr-create-form textarea {
    min-height: 140px;
    padding: 18px;
    font: inherit;
    font-size: 18px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--line-strong);
    outline: none;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
}
.mr-create-form textarea:focus {
    border-color: var(--fg);
}
.mr-create-form button {
    align-self: flex-start;
    padding: 14px 28px;
    background: var(--fg);
    color: var(--bg);
    border: none;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: -0.01em;
}
.mr-create-form button:hover:not(:disabled) {
    background: var(--muted);
}
.mr-create-form button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.mr-create-tips {
    margin-top: 16px;
}
.mr-tip-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}
.mr-tip-list li {
    padding: 8px 12px;
    background: var(--quote-bg);
    font-size: 13px;
}
.mr-tip-list code {
    background: transparent;
    padding: 0;
    color: var(--fg);
}

/* === Typewriter animation ===
   Когда статья только что создана — буквы вырастают по очереди.
   Используется на /?page=X&fresh=1 (после генерации).
*/
.mr-typewriter-target.fresh h1,
.mr-typewriter-target.fresh h2,
.mr-typewriter-target.fresh h3,
.mr-typewriter-target.fresh p,
.mr-typewriter-target.fresh li,
.mr-typewriter-target.fresh blockquote {
    animation: mr-pop-in 0.4s ease-out both;
}
.mr-typewriter-target.fresh > *:nth-child(1) { animation-delay: 0.05s; }
.mr-typewriter-target.fresh > *:nth-child(2) { animation-delay: 0.15s; }
.mr-typewriter-target.fresh > *:nth-child(3) { animation-delay: 0.25s; }
.mr-typewriter-target.fresh > *:nth-child(4) { animation-delay: 0.35s; }
.mr-typewriter-target.fresh > *:nth-child(5) { animation-delay: 0.45s; }
.mr-typewriter-target.fresh > *:nth-child(6) { animation-delay: 0.55s; }
.mr-typewriter-target.fresh > *:nth-child(7) { animation-delay: 0.65s; }
.mr-typewriter-target.fresh > *:nth-child(8) { animation-delay: 0.75s; }
.mr-typewriter-target.fresh > *:nth-child(9) { animation-delay: 0.85s; }
.mr-typewriter-target.fresh > *:nth-child(10) { animation-delay: 0.95s; }
.mr-typewriter-target.fresh > *:nth-child(n+11) { animation-delay: 1.05s; }

@keyframes mr-pop-in {
    0% {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
        filter: blur(2px);
    }
    60% {
        opacity: 1;
        transform: translateY(0) scale(1.02);
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

/* Reduced motion — отключаем анимацию для тех кому плохо */
@media (prefers-reduced-motion: reduce) {
    .mr-typewriter-target.fresh > * {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
    }
}

/* === Responsive auth === */
@media (max-width: 900px) {
    .mr-auth-card {
        margin: 16px;
        padding: 20px;
    }
    .mr-profile-header {
        flex-direction: column;
        text-align: center;
    }
}
