/**
 * Author: MAKATANGA
 * Telegram: @MAKATANGA
 */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    
    --bg-light: #f3f4f6;
    --card-light: rgba(255, 255, 255, 0.8);
    --text-light: #1f2937;
    --text-muted-light: #6b7280;
    --border-light: rgba(229, 231, 235, 0.5);
    
    --bg-dark: #0f172a;
    --card-dark: rgba(30, 41, 59, 0.7);
    --text-dark: #f8fafc;
    --text-muted-dark: #94a3b8;
    --border-dark: rgba(51, 65, 85, 0.5);

    --radius: 1.25rem;
    --transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    --blur: 20px;
    --primary-glow: rgba(99, 102, 241, 0.35);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
    border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Text Selection */
::selection {
    background: var(--primary);
    color: white;
}

[data-theme="dark"] {
    --bg: var(--bg-dark);
    --card: var(--card-dark);
    --text: var(--text-dark);
    --text-muted: var(--text-muted-dark);
    --border: var(--border-dark);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] {
    --bg: var(--bg-light);
    --card: var(--card-light);
    --text: var(--text-light);
    --text-muted: var(--text-muted-light);
    --border: var(--border-light);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg);
    background-image: 
        radial-gradient(at 0% 0%, var(--primary-light) 0, transparent 50%), 
        radial-gradient(at 100% 100%, var(--primary-light) 0, transparent 50%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    transition: var(--transition);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

html {
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Prevent ALL content from overflowing viewport */
img, video, iframe, table { max-width: 100%; }

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Glassmorphism Navbar */
nav {
    background: var(--card);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 72px;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

/* Modern Inputs */
.search-wrapper {
    flex: 1;
    max-width: 600px;
    margin: 0 2rem;
    position: relative;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1.25rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    transition: var(--transition);
    outline: none;
}

select.form-control option {
    background-color: var(--bg);
    color: var(--text);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
    transform: scale(1.01);
}

.search-wrapper input:focus {
    max-width: 100% !important;
    width: 110% !important;
}

/* Premium Cards */
.card {
    background: var(--card);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.topic-row:hover {
    transform: translateX(8px) scale(1.01);
    border-color: var(--primary);
    background: var(--card);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

/* Voting System */
.vote-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg);
    padding: 0.5rem;
    border-radius: 1rem;
    gap: 0.25rem;
    height: fit-content;
}

.vote-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.5rem;
    transition: var(--transition);
}

.vote-btn:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.vote-btn.active {
    color: var(--primary);
}

/* Typography & Layout */
h1, h2, h3 { font-weight: 700; color: var(--text); }
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { opacity: 0.8; }

.main-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    margin-top: 2.5rem;
}

/* Badges & Tags */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
}

.tag {
    background: var(--bg);
    color: var(--text);
    padding: 0.2rem 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

/* Animations */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.fade-in {
    animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Scroll Progress */
#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #ec4899);
    z-index: 2001;
    transition: width 0.1s ease-out;
}

/* Notification Pulse */
.pulse-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--card);
}
.pulse-dot::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #ef4444;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(3); opacity: 0; }
}

/* Interactive Navigation */
nav a {
    position: relative;
    padding-bottom: 4px;
}
nav a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary);
    transition: var(--transition);
}
nav a:hover::after {
    width: 100%;
}

/* Avatar Visual Contact */
img {
    transition: var(--transition);
}
img:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 15px var(--primary-glow);
}

/* Responsive */
@media (max-width: 1024px) {
    .main-grid { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}

.sidebar {
    height: fit-content;
    position: sticky;
    top: 92px; /* 72px navbar + 20px gap */
}

@media (max-width: 640px) {
    .container { padding: 0 1rem; }
    .nav-content .search-wrapper { display: none; }
}

/* Forum Enhancements */
.topic-row {
    transition: var(--transition);
    border-left: 4px solid transparent;
}
.topic-row:hover {
    border-left-color: var(--primary);
    background: var(--primary-light);
}
.status-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}
.status-solved { background: #10b981; color: white; }
.status-open { background: var(--primary); color: white; }
.forum-stat {
    text-align: center;
    padding: 0.5rem;
}
.forum-stat .count {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}
.forum-stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Premium Markdown Preview & Editor */
.markdown-body {
    line-height: 1.6;
    color: var(--text);
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { 
    margin: 1.5rem 0 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}
.markdown-body h1 { font-size: 1.75rem; }
.markdown-body h2 { font-size: 1.5rem; }
.markdown-body h3 { font-size: 1.25rem; }
.markdown-body p { margin-bottom: 1.2rem; }
.markdown-body ul, .markdown-body ol { 
    padding-left: 2rem; 
    margin-bottom: 1.2rem;
}
.markdown-body li { margin-bottom: 0.5rem; }
.markdown-body blockquote {
    border-left: 4px solid var(--primary);
    padding: 0.5rem 1rem;
    background: var(--primary-light);
    margin: 1rem 0;
    border-radius: 0 0.5rem 0.5rem 0;
    font-style: italic;
}
.markdown-body code { 
    background: rgba(99, 102, 241, 0.1); 
    padding: 0.2rem 0.4rem; 
    border-radius: 4px; 
    font-size: 0.9em;
}
.markdown-body pre { 
    background: #1e293b; 
    color: #f8fafc;
    padding: 1.5rem; 
    border-radius: 1rem; 
    overflow-x: auto; 
    margin: 1.5rem 0;
    border: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 1024px) {
    .editor-dual-pane { 
        grid-template-columns: 1fr !important; 
    }
}

/* PC Tooltips — desktop only */
[data-tooltip] { position: relative; cursor: pointer; }
[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(15, 23, 42, 0.95);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    z-index: 2000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
[data-tooltip]:hover::before { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================
   macOS / Safari WebKit Optimizations
   ============================================ */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Fix Safari sticky backdrop-filter */
nav, .card {
    -webkit-backdrop-filter: blur(var(--blur));
}

/* Prevent iOS zoom on input focus */
input, select, textarea { font-size: max(16px, 1em); }

/* Remove iOS tap highlight */
* { -webkit-tap-highlight-color: transparent; }

/* Allow text selection where needed */
p, h1, h2, h3, h4, h5, .markdown-body { -webkit-user-select: text; user-select: text; }

/* Smooth scroll iOS */
html { scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }

/* Minimum touch target 44x44px (Apple HIG) */
.btn, nav a { min-height: 44px; }

/* ============================================
   Hamburger Menu
   ============================================ */
#mobile-menu-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1100;
}
#mobile-menu-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: var(--transition);
}
#mobile-menu-btn.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
#mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
#mobile-menu-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

#mobile-nav-drawer {
    display: none;
    position: fixed;
    top: 60px; left: 0; right: 0; bottom: 0;
    background: var(--card);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    z-index: 999;
    padding: 1.5rem;
    flex-direction: column;
    gap: 0.75rem;
    border-top: 1px solid var(--border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
#mobile-nav-drawer.open { display: flex; animation: slideUp 0.3s ease forwards; }
#mobile-nav-drawer a, #mobile-nav-drawer button {
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    cursor: pointer;
}
#mobile-nav-drawer a:hover, #mobile-nav-drawer button:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Bottom Navigation Bar */
#bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border-top: 1px solid var(--border);
    z-index: 998;
    justify-content: space-around;
    align-items: center;
}
.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0.5rem;
    border-radius: 0.75rem;
    transition: var(--transition);
    min-width: 52px;
    text-transform: uppercase;
}
.bottom-nav-item i { font-size: 1.2rem; }
.bottom-nav-item.active, .bottom-nav-item:hover { color: var(--primary); background: var(--primary-light); }
.bottom-nav-item.primary-action {
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    border-radius: 50%;
    width: 52px; height: 52px;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    padding: 0;
}
.bottom-nav-item.primary-action i { font-size: 1.3rem; }

/* ============================================
   Tablet (1024px)
   ============================================ */
@media (max-width: 1024px) {
    .main-grid { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .editor-dual-pane { grid-template-columns: 1fr !important; }
    .profile-main-grid { grid-template-columns: 1fr !important; }
    .profile-stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ============================================
   Mobile (768px)
   ============================================ */
@media (max-width: 768px) {
    #mobile-menu-btn { display: flex; }
    #bottom-nav { display: flex; }
    .nav-desktop-actions { display: none !important; }
    .search-wrapper { display: none !important; }

    main.container { padding-bottom: calc(75px + env(safe-area-inset-bottom)) !important; }
    .container { padding: 0 1rem; }
    .nav-content { height: 60px; }

    .card { padding: 1.25rem; border-radius: 1rem; }
    .main-grid { margin-top: 1.25rem; gap: 1rem; }

    /* Profile */
    .profile-header-inner {
        padding: 0 1rem 1rem !important;
        margin-top: -50px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }
    .profile-header-inner img {
        width: 90px !important;
        height: 90px !important;
    }
    .profile-header-inner > div:last-child { width: 100%; }
    .profile-header-inner [style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }
    .profile-main-grid { grid-template-columns: 1fr !important; }
    .profile-stats-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* Home feed topic rows */
    .topic-row > div[style*="display: flex"] {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    /* Footer stacks */
    footer > .container { display: flex !important; flex-direction: column !important; gap: 2rem !important; }

    /* Disable heavy hover on touch */
    .topic-row:hover { transform: none; }
    .btn-primary:hover { transform: none; box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39); }
    .card:hover { box-shadow: var(--shadow); }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }

    /* Prevent text overflow */
    p, h1, h2, h3, h4, h5, h6, a, span, li, td, th {
        word-break: break-word;
        overflow-wrap: break-word;
    }
    .markdown-body pre { overflow-x: auto; max-width: 100%; }
    .markdown-body { overflow-x: hidden; }

    /* Cover photo shorter on mobile */
    .cover-photo { height: 140px !important; }

    /* Post show: vote bar horizontal on mobile */
    .post-main-flex {
        flex-direction: column !important;
        gap: 1rem !important;
    }
    .post-main-flex .vote-container {
        flex-direction: row !important;
        padding: 0.5rem 1rem !important;
        border-radius: 2rem !important;
        width: fit-content !important;
        gap: 1rem !important;
    }
    .post-main-flex .vote-container .score-count { font-size: 1rem !important; }

    /* Post card smaller padding */
    .post-card-mobile { padding: 1.25rem !important; }

    /* Post title smaller */
    .post-title-mobile { font-size: 1.4rem !important; }

    /* Action buttons wrap */
    .post-actions-mobile { flex-wrap: wrap !important; gap: 0.5rem !important; }

    /* Hide topic author avatar on mobile (saves space) */
    .topic-avatar { display: none !important; }

    /* Topic row tweaks */
    .topic-row { gap: 1rem !important; }
    .topic-row .vote-container { min-width: 40px !important; }

    /* Create post page */
    .hotkey-hint { display: none !important; }
    .create-grid { grid-template-columns: 1fr !important; }
    .create-grid > div:last-child { display: none !important; }
    #editor-toolbar { padding: 0.5rem 0.75rem !important; gap: 0.35rem !important; }
    #editor-toolbar span { display: none !important; }
    .md-btn { min-width: 36px !important; min-height: 36px !important; padding: 0 !important; font-size: 0.9rem !important; }
    .editor-dual-pane { grid-template-columns: 1fr !important; }
    .editor-preview-pane { display: none !important; }
    .create-actions .btn-label { display: none; }

    /* Language suggestion banner */
    #lang-suggestion .btn { min-height: unset !important; padding: 0.35rem 0.75rem !important; font-size: 0.78rem !important; }
}

/* ============================================
   Small Mobile (480px)
   ============================================ */
@media (max-width: 480px) {
    .container { padding: 0 0.75rem; }
    .logo { font-size: 1.35rem; }
    .vote-container { flex-direction: row; padding: 0.35rem 0.75rem; border-radius: 2rem; }
    .badge { font-size: 0.7rem; padding: 0.15rem 0.5rem; }
    .btn { padding: 0.6rem 1rem; font-size: 0.9rem; }
    .profile-stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 0.5rem !important; }
    .profile-stats-grid .card { padding: 1rem !important; }
    /* Create form: category+type stacks */
    .create-grid form div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
}

/* ============================================
   Landscape Mobile
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    #bottom-nav { display: none; }
    main.container { padding-bottom: 1rem !important; }
}
