/* ============================================================
 *  Icey Theme - A clean, minimal Hugo theme with grid background
 *  Fonts: LXGW WenKai (headings), Noto Sans (body), JetBrains Mono (code)
 * ============================================================ */

/* ===== Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=LXGW+WenKai:wght@400;700&family=Noto+Sans:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ===== CSS Variables ===== */
:root {
    /* Typography */
    --font-heading: 'LXGW WenKai', serif;
    --font-body: 'Noto Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Colors */
    --color-bg: #fafafa;
    --color-text: #2c2c2c;
    --color-text-secondary: #666;
    --color-border: #d0d0d0;
    --color-border-light: #e8e8e8;
    --color-accent: #4a6fa5;
    --color-accent-hover: #3a5a8a;
    --color-grid: #e0e0e0;
    --color-card-bg: #fff;
    --color-tag-bg: #f0f0f0;
    --color-code-bg: #f5f5f5;

    /* Layout */
    --max-width: 50vw;
    --content-width: 50vw;
    --toc-width: 220px;
    --nav-height: 56px;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Base ===== */
body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.7;
    color: var(--color-text);
    background-color: var(--color-bg);
    background-image:
        linear-gradient(var(--color-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--color-grid) 1px, transparent 1px);
    background-size: 40px 40px;
    min-height: 100vh;
}

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color 0.2s;
}

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

img {
    max-width: 100%;
    height: auto;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
    margin-bottom: 0.5em;
}

h1 { font-size: 2em; margin-bottom: 0.6em; }
h2 { font-size: 1.6em; margin-top: 1.8em; }
h3 { font-size: 1.3em; margin-top: 1.5em; }

p { margin-bottom: 1em; }

code, pre {
    font-family: var(--font-mono);
}

code {
    background: var(--color-tag-bg);
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

pre {
    background: var(--color-code-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 1em;
    overflow-x: auto;
    margin-bottom: 1.5em;
}

pre code {
    background: none;
    padding: 0;
}

blockquote {
    border-left: 3px solid var(--color-accent);
    padding-left: 1em;
    color: var(--color-text-secondary);
    margin-bottom: 1em;
}

/* ===== Table ===== */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.95em;
}

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

th {
    background: var(--color-border-light);
    font-weight: 600;
}

tr:nth-child(even) {
    background: var(--color-tag-bg);
}

/* ===== Divider ===== */
hr {
    border: none;
    border-top: 1px solid var(--color-text);
    margin: 1.5em 0;
}

/* ===== Navigation ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    height: var(--nav-height);
}

.navbar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5em;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5em;
}

.nav-links a {
    color: var(--color-text-secondary);
    font-family: var(--font-heading);
    font-size: 0.95em;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--color-accent);
}

.nav-search {
    font-size: 1.1em;
    cursor: pointer;
}

/* ===== Layout Containers ===== */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2em 1.5em;
}

.content-narrow {
    max-width: var(--content-width);
    margin: 0 auto;
}

/* ===== Homepage Profile ===== */
.profile {
    max-width: var(--content-width);
    margin: 3em auto;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1em;
    margin-bottom: 0;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--color-border);
    flex-shrink: 0;
}

.profile-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5em;
}

.profile-name {
    font-size: 1.8em;
    font-family: var(--font-heading);
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.profile-bio {
    color: var(--color-text-secondary);
    font-size: 1.05em;
    margin: 0;
    line-height: 1.2;
    text-align: right;
}

.profile-about {
    color: var(--color-text);
    font-size: 1em;
    line-height: 1.8;
    margin: 1em 0;
}

.profile-about p {
    margin-bottom: 0.8em;
}

.profile-about p:last-child {
    margin-bottom: 0;
}

/* ===== Post List (Homepage & Section Pages) ===== */
.post-list {
    list-style: none;
    margin-top: 2em;
}

.post-list h2 {
    font-size: 1.3em;
    margin-top: 0;
    margin-bottom: 0.8em;
}

.post-item {
    padding: 1em 0;
    border-bottom: 1px solid var(--color-border-light);
}

.post-item:last-child {
    border-bottom: none;
}

.post-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1em;
}

.post-item-title {
    font-family: var(--font-heading);
    font-size: 1.05em;
    flex: 1;
}

.post-item-title a {
    color: var(--color-text);
}

.post-item-title a:hover {
    color: var(--color-accent);
}

.post-item-date {
    color: var(--color-text-secondary);
    font-size: 0.85em;
    white-space: nowrap;
    font-family: var(--font-mono);
}

.post-item-summary {
    color: var(--color-text-secondary);
    font-size: 0.9em;
    margin: 0.4em 0 0.5em;
    line-height: 1.5;
}

/* ===== Tag Badges (shared across pages) ===== */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em;
    margin-top: 0.5em;
}

.tag-list a {
    background: var(--color-tag-bg);
    padding: 0.15em 0.6em;
    border-radius: 3px;
    font-size: 0.82em;
    color: var(--color-text-secondary);
}

.tag-list a:hover {
    background: var(--color-accent);
    color: #fff;
}

/* ===== Post Single with TOC ===== */
.post-layout {
    display: grid;
    grid-template-columns: 1fr var(--content-width) 1fr;
    gap: 0 2em;
    padding: 2em 1.5em;
}

.post-content {
    grid-column: 2;
    min-width: 0;
}

.post-content h1 {
    margin-top: 0;
}

.post-meta {
    color: var(--color-text-secondary);
    font-size: 0.9em;
    margin-bottom: 1.5em;
    font-family: var(--font-mono);
}

.post-meta span + span::before {
    content: "·";
    margin: 0 0.5em;
}

/* ===== TOC Sidebar ===== */
.toc-sidebar {
    grid-column: 3;
    justify-self: start;
    position: sticky;
    top: calc(var(--nav-height) + 2em);
    align-self: start;
    max-height: calc(100vh - var(--nav-height) - 4em);
    overflow-y: auto;
}

.toc-sidebar h3 {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.8em;
    margin-top: 0;
}

.toc-sidebar nav#TableOfContents {
    font-size: 0.85em;
    line-height: 1.6;
}

.toc-sidebar nav#TableOfContents ul {
    list-style: none;
    padding-left: 0;
}

.toc-sidebar nav#TableOfContents ul ul {
    padding-left: 1em;
    border-left: 1px solid var(--color-border-light);
}

.toc-sidebar nav#TableOfContents li {
    margin-bottom: 0.3em;
}

.toc-sidebar nav#TableOfContents a {
    color: var(--color-text-secondary);
}

.toc-sidebar nav#TableOfContents a:hover {
    color: var(--color-accent);
}

/* ===== Archive Page ===== */
.archive-list {
    max-width: var(--content-width);
    margin: 0 auto;
}

.archive-list h1 {
    margin-bottom: 1.5em;
}

.archive-year {
    margin-bottom: 2em;
}

.archive-year h2 {
    font-size: 1.3em;
    color: var(--color-accent);
    border-bottom: 1px solid var(--color-border-light);
    padding-bottom: 0.3em;
    margin-bottom: 0.8em;
}

.archive-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.4em 0;
    gap: 1em;
}

.archive-item-title {
    flex: 1;
}

.archive-item-title a {
    color: var(--color-text);
}

.archive-item-title a:hover {
    color: var(--color-accent);
}

.archive-item-date {
    font-size: 0.85em;
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
    white-space: nowrap;
}

/* ===== Note Page ===== */
.note-list {
    max-width: var(--content-width);
    margin: 0 auto;
}

.note-card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border-light);
    border-radius: 6px;
    padding: 1.2em 1.5em;
    margin-bottom: 1em;
}

.note-card h2 {
    font-size: 1.1em;
    margin-top: 0;
    margin-bottom: 0.3em;
}

.note-card h2 a {
    color: var(--color-text);
}

.note-card h2 a:hover {
    color: var(--color-accent);
}

.note-date {
    font-size: 0.8em;
    color: var(--color-text-secondary);
    font-family: var(--font-mono);
}

/* ===== Search Overlay ===== */
.search-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
}

.search-overlay.active {
    display: flex;
}

.search-box {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5em;
    width: 90%;
    max-width: 560px;
}

.search-box input {
    width: 100%;
    padding: 0.6em 0.8em;
    font-size: 1em;
    font-family: var(--font-body);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--color-accent);
}

/* ===== Footer ===== */
.site-footer {
    border-top: 1px solid var(--color-border);
    margin-top: 3em;
    padding: 1.5em;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: var(--color-text-secondary);
    flex-wrap: wrap;
    gap: 0.8em;
}

.footer-left,
.footer-center,
.footer-right {
    display: flex;
    align-items: center;
    gap: 1em;
}

.footer-left a {
    color: var(--color-text-secondary);
}

.footer-left a:hover {
    color: var(--color-accent);
}

.footer-sep {
    color: var(--color-text);
}

.footer-uptime {
    font-family: var(--font-mono);
}

/* ===== 404 Page ===== */
.page-404 {
    text-align: center;
    padding: 5em 1em;
}

.page-404 h1 {
    font-size: 4em;
    color: var(--color-border);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    :root {
        --max-width: 100%;
        --content-width: 100%;
    }

    .post-layout {
        grid-template-columns: 1fr;
        padding: 1.5em;
    }

    .post-content {
        grid-column: 1;
    }

    .toc-sidebar {
        grid-column: 1;
        position: static;
        border: 1px solid var(--color-border-light);
        border-radius: 6px;
        padding: 1em;
        margin-bottom: 1em;
        max-height: none;
    }

    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: 0.8em;
    }

    .profile-info {
        align-items: center;
        text-align: center;
    }

    .profile-bio {
        text-align: center;
    }

    .post-item-header {
        flex-direction: column;
        gap: 0.2em;
    }

    .archive-item {
        flex-direction: column;
        gap: 0.1em;
    }
}