/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables for consistent theming */
:root {
    --bg-primary: #101010;
    --bg-secondary: #1c1c1c;
    --bg-tertiary: #2c2c2c;
    --bg-hover: #383838;
    --text-primary: #c0c0c0;
    --text-secondary: #848484;
    --text-muted: #696969;
    --border-color: #4c4c4c;
    --accent-blue: #54a0ff;
    --accent-cyan: #48dbfb;
    --accent-purple: #5f27cd;
    --accent-pink: #ff9ff3;
    --accent-red: #ff6b6b;
    --accent-orange: #ff6348;
    --accent-yellow: #feca57;
}

body {
    font-family: 'JetBrains Mono', monospace;
    font-feature-settings: "rlig" 1, "calt" 1;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Main wrapper - critical for preventing overflow */
.wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    margin: 1.5rem 0 1rem 0;
    font-weight: 300;
    letter-spacing: 0.025em;
}

h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.5rem, 4vw, 2rem); }
h3 { font-size: clamp(1.25rem, 3vw, 1.5rem); }

p {
    margin-bottom: 1rem;
    line-height: 1.7;
    max-width: 100%;
    word-wrap: break-word;
}

/* Special styling for hashtag-like content */
.hashtags, .tags {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.9;
}

/* Ensure hashtags in content don't get code styling */
p code[class*="language-"], 
h1 code[class*="language-"], 
h2 code[class*="language-"], 
h3 code[class*="language-"] {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2em auto;
    border-radius: 6px;
    max-height: 600px;
    object-fit: contain;
}

/* Enhanced Links with gradient hover */
a {
    color: var(--accent-cyan);
    text-decoration: none;
    position: relative;
    transition: all 0.3s ease;
    word-break: break-word;
    border-bottom: 1px solid transparent;
}

a:hover {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
    text-shadow: 0 0 8px rgba(84, 160, 255, 0.3);
}

a:active {
    color: var(--accent-purple);
}

/* Lists */
ul, ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
    word-wrap: break-word;
}

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--accent-blue);
    padding-left: 1rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: var(--text-muted);
    word-wrap: break-word;
    background: rgba(84, 160, 255, 0.05);
    border-radius: 0 6px 6px 0;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

@media (min-width: 768px) {
    table {
        display: table;
        white-space: normal;
    }
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--bg-hover);
    word-wrap: break-word;
}

th {
    background-color: var(--bg-tertiary);
    font-weight: 700;
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

/* Inline code with enhanced styling */
code:not(pre code) {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-hover));
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-cyan);
    word-break: break-word;
    border: 1px solid var(--border-color);
}

/* Code blocks - Enhanced styling with gradient background */
pre {
    background: linear-gradient(135deg, var(--bg-secondary), #1a1a1a);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin: 1.5rem 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

pre code {
    display: block;
    padding: 1.5rem;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    background: none;
    border-radius: 0;
    white-space: pre;
    word-wrap: normal;
    tab-size: 4;
}

/* Ensure all code blocks get the enhanced styling */
pre:not([class]) {
    background: linear-gradient(135deg, var(--bg-secondary), #1a1a1a);
    border: 1px solid var(--border-color);
}

/* Style for plain code blocks without language classes */
pre:not([class*="language-"]):not([data-lang]) {
    position: relative;
}

pre:not([class*="language-"]):not([data-lang])::after {
    content: 'CODE';
    position: absolute;
    top: 0;
    right: 0;
    background: linear-gradient(135deg, #404040, #606060);
    color: white;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0 0.5rem 0 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    opacity: 0.7;
}

/* Code block with language indicator */
pre[class*="language-"]::before {
    content: attr(class);
    position: absolute;
    top: 0;
    right: 0;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    color: white;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0 0.5rem 0 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Enhanced syntax highlighting with vibrant colors */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--text-muted);
    font-style: italic;
}

.token.punctuation {
    color: var(--text-secondary);
}

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
    color: var(--accent-red);
    font-weight: 500;
}

.token.boolean,
.token.number {
    color: var(--accent-yellow);
    font-weight: 600;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
    color: var(--accent-cyan);
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
    color: var(--accent-pink);
}

.token.atrule,
.token.attr-value,
.token.function,
.token.class-name {
    color: var(--accent-blue);
    font-weight: 600;
}

.token.keyword {
    color: var(--accent-purple);
    font-weight: 700;
}

.token.regex,
.token.important {
    color: var(--accent-orange);
    font-weight: 600;
}

/* Language-specific highlighting */
.language-c .token.macro,
.language-c .token.directive-hash {
    color: var(--accent-red);
}

.language-c .token.type,
.language-c .token.storage {
    color: var(--accent-purple);
}

/* Highlight function names */
.token.function-name {
    color: var(--accent-blue);
    font-weight: 600;
    text-shadow: 0 0 4px rgba(84, 160, 255, 0.3);
}

/* Horizontal rules - theme styling */
hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
    margin: 2rem 0;
}

/* Back to top link - theme colors */
.back-to-top {
    text-align: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.back-to-top a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.3s ease;
}

.back-to-top a:hover {
    color: var(--text-primary);
}

/* Custom scrollbar - theme colors */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-hover);
}

/* Responsive design */
@media (max-width: 768px) {
    .wrapper {
        padding: 1rem;
    }
    
    pre code {
        padding: 1rem;
        font-size: 0.8rem;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    
    ul, ol {
        padding-left: 1.5rem;
    }
}

@media (max-width: 480px) {
    .wrapper {
        padding: 0.75rem;
    }
    
    pre code {
        padding: 0.75rem;
        font-size: 0.75rem;
    }
    
    th, td {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}