/* Trainsh Theme - A minimal, content-focused blog theme. */

:root {
    /*--width: 680px;*/
	--width: 900px;
    --font-main: Verdana, sans-serif;
    --font-secondary: Verdana, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --font-scale: 1rem;

    /* Light theme palette */
    --background-color: #fafafa;
    --heading-color: #1a1a1a;
    --text-color: #444;
    --link-color: #0066cc;
    --visited-color: #551a8b;
    --accent-color: #0077cc;
    --code-background-color: #f5f5f5;
    --code-color: #333;
    --blockquote-color: #666;
    --border-color: #ddd;
    --muted-color: #888;
    --selection-bg: #b3d4fc;
    --selection-text: #000;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --input-bg: #fff;
    --hover-bg: rgba(0, 0, 0, 0.04);
}

/* Dark theme - applied via data-theme attribute or system preference */
[data-theme="dark"] {
    --background-color: #121212;
    --heading-color: #e8e8e8;
    --text-color: #b8b8b8;
    /*--link-color: #6bb3ff;*/
	--link-color: #ffffff;
    --visited-color: #b794f4;
    --accent-color: #5da8f4;
    --code-background-color: #1e1e1e;
    --code-color: #d4d4d4;
    --blockquote-color: #9a9a9a;
    --border-color: #2a2a2a;
    --muted-color: #707070;
    --selection-bg: #264f78;
    --selection-text: #fff;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --input-bg: #1a1a1a;
    --hover-bg: rgba(255, 255, 255, 0.06);
}

/* System preference fallback when no explicit theme is set */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background-color: #121212;
        --heading-color: #e8e8e8;
        --text-color: #b8b8b8;
        --link-color: #6bb3ff;
        --visited-color: #b794f4;
        --accent-color: #5da8f4;
        --code-background-color: #1e1e1e;
        --code-color: #d4d4d4;
        --blockquote-color: #9a9a9a;
        --border-color: #2a2a2a;
        --muted-color: #707070;
        --selection-bg: #264f78;
        --selection-text: #fff;
        --shadow-color: rgba(0, 0, 0, 0.4);
        --input-bg: #1a1a1a;
        --hover-bg: rgba(255, 255, 255, 0.06);
    }
}

/* Text selection */
::selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

::-moz-selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

body {
    font-family: var(--font-secondary);
    font-size: var(--font-scale);
    margin: auto;
    padding: 24px 20px;
    max-width: var(--width);
    text-align: left;
    background-color: var(--background-color);
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.7;
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-main);
    color: var(--heading-color);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

h1 { margin-top: 0; }
h2 { margin-top: 2em; }
h3 { margin-top: 1.5em; }

h1 { margin-left: auto; margin-right: auto; text-align: center;}

a {
    color: var(--link-color);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.25em;
}

a:hover {
    text-decoration-color: var(--accent-color);
}

nav a {
    margin-right: 10px;
    text-decoration: none;
}

nav a:hover {
    text-decoration: underline;
}

/* Header: title left, nav right */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5em 1em;
}

.site-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5em;
}

.site-nav a {
    margin-right: 0.75em;
}

.site-nav a:last-child {
    margin-right: 0;
}

/* Language dropdown */
.lang-dropdown {
    position: relative;
    display: inline-block;
    margin-left: 0.75em;
}

.lang-toggle {
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.35em 0.5em;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 0.25em;
    border-radius: 4px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    color: var(--text-color);
}

.lang-toggle:hover {
    background: var(--hover-bg, rgba(0, 0, 0, 0.05));
    border-color: var(--link-color);
}

.lang-name {
    white-space: nowrap;
}

.lang-arrow {
    flex-shrink: 0;
    opacity: 0.7;
}

.lang-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    display: none;
    flex-direction: column;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.35em;
    z-index: 100;
    box-shadow: 0 4px 12px var(--shadow-color, rgba(0, 0, 0, 0.15));
    font-size: 0.75rem;
}

.lang-dropdown.open .lang-menu {
    display: flex;
}

.lang-menu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25em 0.75em;
    color: var(--text-color);
    text-decoration: none;
    white-space: nowrap;
    background: var(--code-background-color);
    border-radius: 4px;
    margin: 0.15em 0;
    transition: background-color 0.2s, color 0.2s;
}

.lang-menu a:hover {
    background: var(--accent-color);
    color: var(--background-color);
    text-decoration: none;
}

.lang-menu a.lang-active {
    font-weight: 600;
}

.lang-menu a.lang-active:hover {
    background: var(--accent-color);
    color: var(--background-color);
}

.lang-menu a.lang-active .lang-item-check::after {
    content: "✓";
}

.lang-item-name {
    flex: 1;
    text-align: left;
}

.lang-item-check {
    width: 1em;
    text-align: right;
    margin-left: 1em;
}

strong, b {
    color: var(--heading-color);
}

button {
    margin: 0;
    cursor: pointer;
}

time {
    font-family: var(--font-main);
    font-size: 0.875rem;
    font-style: normal;
    color: var(--muted-color);
}

main {
    line-height: 1.7;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.5em;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--heading-color);
}

hr {
    border: 0;
    border-top: 1px dashed var(--border-color);
    margin: 2em 0;
}

img {
    max-width: 100%;
    border-radius: 4px;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 2px 6px;
    background-color: var(--code-background-color);
    color: var(--code-color);
    border-radius: 4px;
}

pre code {
    padding: 0;
    background-color: transparent;
    border-radius: 0;
    font-size: 0.875em;
}

blockquote {
    border-left: 3px solid var(--accent-color);
    color: var(--blockquote-color);
    padding-left: 1.25em;
    margin-left: 0;
    font-style: italic;
}

footer {
    padding: 2em 0;
    text-align: center;
    color: var(--muted-color);
    font-size: 0.875rem;
}

/* Only site footer has top border */
body > footer {
    border-top: 1px solid var(--border-color);
    margin-top: 3em;
}

header {
    margin-bottom: 2em;
}

/* Only site header has bottom border */
body > header {
    padding-bottom: 1em;
    border-bottom: 1px solid var(--border-color);
}

.title {
    text-decoration: none;
    color: var(--heading-color);
}

.title:hover {
    text-decoration: none;
    color: var(--link-color);
}

.title h1 {
    font-size: 1.5em;
    margin-bottom: 0.25em;
}

.inline {
    width: auto !important;
}

.highlight, .code {
    padding: 1px 15px;
    background-color: var(--code-background-color);
    color: var(--code-color);
    border-radius: 3px;
    margin-block-start: 1em;
    margin-block-end: 1em;
    overflow-x: auto;
}

/* Code block actions (wrap/copy) */
.codeblock {
    position: relative;
}

.codeblock-actions {
    position: absolute;
    top: 8px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 2;
    opacity: 0.75;
}

.codeblock:hover .codeblock-actions {
    opacity: 1;
}

.codeblock-action {
    margin: 0;
    padding: 2px;
    border: 0;
    background: transparent;
    color: inherit;
    line-height: 0;
    cursor: pointer;
}

.codeblock-action:hover {
    background-color: var(--hover-bg);
    border-radius: 4px;
}

.codeblock-action:focus-visible {
    outline: 2px solid var(--link-color);
    border-radius: 4px;
}

.codeblock-action svg {
    width: 18px;
    height: 18px;
    display: block;
}

.codeblock-action--wrap.is-active {
    color: var(--accent-color);
}

.codeblock-action--copy .icon-check {
    display: none;
}

.codeblock-action--copy.is-copied .icon-copy {
    display: none;
}

.codeblock-action--copy.is-copied .icon-check {
    display: block;
    color: var(--accent-color);
}

.codeblock.wrapped pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Chroma: keep background controlled by `.highlight`. */
.chroma {
    background-color: transparent !important;
    color: inherit;
}

/* blog post list - clean grid */
ul.blog-posts {
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2em 3em;
}

@media (max-width: 560px) {
    ul.blog-posts {
        grid-template-columns: 1fr;
        gap: 1.5em;
    }
}

ul.blog-posts li {
    position: relative;
}

ul.blog-posts li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 3px;
    height: 100%;
    background: var(--border-color);
    transition: background 0.2s;
}

ul.blog-posts li:hover::before {
    background: var(--link-color);
}

ul.blog-posts li a {
    display: block;
    padding-left: 1em;
    font-weight: 500;
    text-decoration: none;
    color: var(--heading-color);
    line-height: 1.4;
}

ul.blog-posts li a:hover {
    color: var(--link-color);
}

ul.blog-posts li a:visited {
    color: var(--heading-color);
}

ul.blog-posts li time {
    display: block;
    padding-left: 1em;
    color: var(--muted-color);
    font-size: 0.8rem;
    margin-top: 0.3em;
}

/* Upvote widget */
.upvote-button {
    padding: 0;
    margin: 0;
    border: 0;
    background-color: inherit;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.upvote-button:disabled {
    opacity: 0.9;
    cursor: default;
}

.upvote-button--active {
    color: var(--accent-color);
}

.upvote-count {
    margin-top: -3px;
}

/* Figures (kept minimal; compatible with Hugo render hooks). */
figure {
    margin: 1.5em 0;
}

figure img,
figure video,
figure audio {
    margin-bottom: 0;
}

figure figcaption {
    text-align: center;
    font-style: italic;
    font-size: 0.85em;
    color: var(--muted-color);
    margin-top: 0.5em;
}

/* Mermaid blocks (optional). */
.mermaid {
    margin-block-start: 1em;
    margin-block-end: 1em;
    overflow-x: auto;
    background: transparent;
    padding: 0;
    border-radius: 0;
    display: flex;
    justify-content: center;
}

.mermaid svg {
    max-width: 100%;
    height: auto;
    background: transparent !important;
}

/* Home: avoid flashing the server-rendered fallback list for "most popular posts". */
#home-popular-posts[data-popular-state="loading"] {
    display: none;
}

/* Blog page layout */
.blog-header {
    margin-bottom: 2em;
}

#blog-search {
    width: 100%;
    padding: 0.75em 1em;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--background-color);
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.2s;
}

#blog-search:focus {
    outline: none;
    border-color: var(--link-color);
}

#blog-search::placeholder {
    color: var(--muted-color);
}

.tag-filters {
    margin-top: 1em;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
}

/* Tags styling */
.tags, .tags-section {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    margin: 1.5em 0;
}

.tags a, .tags-section a, .tag-filters a {
    display: inline-block;
    padding: 0.25em 0.75em;
    background: var(--code-background-color);
    color: var(--text-color);
    border-radius: 4px;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}

.tags a:hover, .tags-section a:hover, .tag-filters a:hover {
    background: var(--accent-color);
    color: var(--background-color);
}

.tag-filters a.active {
    background: var(--link-color);
    color: var(--background-color);
}

/* Active tag filters */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 1.5em;
}

.active-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.3em 0.75em 0.3em 0.75em;
    background: var(--link-color);
    color: var(--background-color);
    border-radius: 4px;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.2s;
}

.active-tag:hover {
    background: var(--accent-color);
    text-decoration: none;
}

.active-tag-x {
    font-size: 1.1em;
    opacity: 0.7;
    line-height: 1;
}

.active-tag:hover .active-tag-x {
    opacity: 1;
}

.clear-filters {
    font-size: 0.8rem;
    color: var(--muted-color);
    text-decoration: none;
    margin-left: 0.5em;
}

.clear-filters:hover {
    color: var(--link-color);
    text-decoration: underline;
}

/* Post tags at article footer */
.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
}

.post-tags a {
    display: inline-block;
    padding: 0.25em 0.75em;
    background: var(--code-background-color);
    color: var(--text-color);
    border-radius: 4px;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}

.post-tags a:hover {
    background: var(--accent-color);
    color: var(--background-color);
}

/* Footer links */
.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5em 1.5em;
    margin-bottom: 1em;
}

.footer-links a {
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--link-color);
}

/* Article/Post page styles */
.post {
    max-width: 100%;
}

.post-header {
    margin-bottom: 2em;
}

.post-title {
    font-size: 1.75em;
    line-height: 1.3;
    margin: 0 0 0.25em 0;
}

.page-header {
    margin-bottom: 1.5em;
}

.page-title {
    font-size: 1.5em;
    margin: 0;
}

.post-meta {
    color: var(--muted-color);
    font-size: 0.875rem;
}

.post-meta time {
    color: var(--muted-color);
}

.post-meta-sep {
    margin: 0 0.25em;
    opacity: 0.5;
}

.post-content {
    line-height: 1.75;
}

.post-content h2 {
    margin-top: 2em;
}

.post-content h3 {
    margin-top: 1.5em;
}

.post-content p {
    margin: 1.25em 0;
}

.post-content ul, .post-content ol {
    margin: 1.25em 0;
}

.post-content li > ul,
.post-content li > ol {
    margin: 0.2em 0;
}

.post-content li {
    margin: 0.4em 0;
}

.post-content img {
    margin: 1em 0 0 0;
}

.post-content figure {
    margin: 1em 0;
}

.post-content pre {
    margin: 1.25em 0;
}

.post-content blockquote {
    margin: 1.25em 0;
}

/* Post footer */
.post-footer {
    margin-top: 2.5em;
    padding: 0;
    text-align: left;
    color: inherit;
    font-size: inherit;
}

.post-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
}

.post-footer .post-tags {
    margin: 0;
    padding-top: 0;
    border-top: none;
    flex: 1;
}

.post-upvote {
    flex-shrink: 0;
}

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25em;
    margin-left: 0.75em;
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
    vertical-align: middle;
}

.theme-toggle:hover {
    color: var(--link-color);
    background-color: var(--hover-bg);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    display: block;
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun {
        display: block;
    }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon {
        display: none;
    }
}
