/* ==========================================================================
   CSS Variables and Theme Support
   ========================================================================== */

:root {
    --max-width: 1100px;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-serif: Georgia, 'Times New Roman', Times, serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;

    --bg-color: #1a1a1a;
    --text-color: #e5e5e5;
    --text-muted: #999999;
    --border-color: #333333;
    --link-color: #9fc7f5;
    --link-hover: #c2dcf9;
    --tag-bg: transparent;
    --tag-text: #5ecfc4;
    --tag-border: #2a6e68;
    --code-bg: #2a2a2a;
    --blockquote-border: #444;
    --header-bg: #1a1a1a;
    --draft-bg: #3d3100;
    --draft-border: #ffc107;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

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

a {
    color: var(--link-color);
    text-decoration: none;
}

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

p {
    margin: 1em 0;
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: var(--code-bg);
    border-radius: 4px;
}

code {
    padding: 0.2em 0.4em;
}

pre {
    padding: 1rem;
    overflow-x: auto;
}

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

blockquote {
    margin: 1.5em 0;
    padding: 0.5em 1em;
    border-left: 4px solid var(--blockquote-border);
    font-style: italic;
    color: var(--text-muted);
}

blockquote p:first-child {
    margin-top: 0;
}

blockquote p:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Header and Navigation
   ========================================================================== */

.site-header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.site-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-color);
}

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

.nav-links {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.nav-links a {
    color: var(--text-muted);
}

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

/* ==========================================================================
   Theme Toggle
   ========================================================================== */

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.875rem;
}

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

/* ==========================================================================
   Content Feed
   ========================================================================== */

.content-feed {
    margin: 2rem 0;
}

.feed-item {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

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

.feed-item h2 {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.item-type {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.item-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

.item-meta time {
    margin-right: 1rem;
}

/* Read more link */
.read-more {
    display: inline-block;
    margin-top: 0.75rem;
    font-weight: 500;
    color: var(--link-color);
}

.read-more:hover {
    color: var(--link-hover);
}

/* Source link */
.source-link {
    margin-right: 1rem;
    color: var(--link-color);
    font-weight: 500;
}

/* Link items */
.link-domain {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.external-link::after {
    content: ' ↗';
    font-size: 0.75em;
}

.permalink {
    font-size: 0.875rem;
}

/* Quotation items */
.quotation {
    font-size: 1.1rem;
    margin: 0.5rem 0;
}

cite {
    font-style: normal;
    color: var(--text-muted);
}

/* ==========================================================================
   Tags
   ========================================================================== */

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background-color: var(--tag-bg);
    color: var(--tag-text);
    border: 1px solid var(--tag-border);
    border-radius: 20px;
    font-size: 0.75rem;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
}

.tag:hover {
    border-color: var(--link-color);
    color: var(--link-color);
    background-color: var(--tag-bg);
    text-decoration: none;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.tag-cloud .tag {
    font-size: 0.9rem;
}

.tag .count {
    opacity: 0.7;
}

.tag-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 2rem;
}

.tag-hint code {
    font-size: 0.85em;
}

/* ==========================================================================
   Article Pages
   ========================================================================== */

article.entry,
article.note,
article.blogmark,
article.til,
article.quotation {
    margin: 2rem auto;
    max-width: 720px;
}

article header h1 {
    margin-top: 0.5rem;
}

article header time {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.body, .commentary, .e-content {
    line-height: 1.7;
}

.body img,
.commentary img,
.e-content img {
    max-width: 100%;
    height: auto;
}

/* Entry navigation */
.entry-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.nav-prev, .nav-next {
    max-width: 45%;
}

/* Via attribution */
.via {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Draft warning */
.draft-warning {
    background-color: var(--draft-bg);
    border: 1px solid var(--draft-border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* ==========================================================================
   Archive Pages
   ========================================================================== */

.archive-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.archive-table th,
.archive-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.archive-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.archive-nav {
    margin: 1.5rem 0;
}

.result-count {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 1rem 0;
}

/* ==========================================================================
   Search
   ========================================================================== */

.search-form {
    display: flex;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.search-input:focus {
    outline: none;
    border-color: var(--link-color);
}

.search-button {
    padding: 0.75rem 1.5rem;
    background-color: var(--link-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.search-button:hover {
    background-color: var(--link-hover);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.footer-nav a {
    color: var(--text-muted);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    html {
        font-size: 15px;
    }

    .site-nav {
        flex-direction: column;
        align-items: flex-start;
    }

    .entry-nav {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-prev, .nav-next {
        max-width: 100%;
    }

    .search-form {
        flex-direction: column;
    }

    .archive-table {
        font-size: 0.875rem;
    }

    .archive-table th,
    .archive-table td {
        padding: 0.5rem;
    }
}

/* ==========================================================================
   Syntax Highlighting (for code blocks)
   ========================================================================== */

.codehilite {
    background-color: var(--code-bg);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
}

.codehilite pre {
    margin: 0;
    padding: 0;
}

/* ==========================================================================
   Writing Rhythm heatmap
   ========================================================================== */

.heatmap-strip {
    margin: 1.75rem 0 1.5rem;
}

.heatmap-caption {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    opacity: 0.75;
}

.heatmap-grid {
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

.heatmap-months {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    height: 14px;
    width: max-content;
}

.heatmap-months span {
    white-space: nowrap;
    overflow: visible;
}

.heatmap-cells {
    display: grid;
    grid-auto-flow: column;
    gap: 3px;
    width: max-content;
}

.heatmap-col {
    display: grid;
    grid-template-rows: repeat(7, 10px);
    gap: 3px;
}

.heatmap-cells .cell {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: #232a29;
}

.heatmap-cells .cell[data-level="1"] { background: #1e4a44; }
.heatmap-cells .cell[data-level="2"] { background: #2a8077; }
.heatmap-cells .cell[data-level="3"] { background: #3aada0; }
.heatmap-cells .cell[data-level="4"] { background: #5ecfc4; }

.heatmap-cells .cell.empty {
    visibility: hidden;
}

/* ==========================================================================
   About card (sidebar)
   ========================================================================== */

.about-card {
    display: block;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.9rem 1rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease;
}

.about-card:hover {
    border-color: var(--tag-border);
}

.about-tagline {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    line-height: 1.45;
    color: var(--text-color);
    margin: 0 0 0.65rem;
}

.about-link {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--tag-text);
    letter-spacing: 0.02em;
}

/* ==========================================================================
   Quick Note (mobile-first capture form at /quick/)
   ========================================================================== */

body.quick-page {
    background: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    margin: 0;
    -webkit-text-size-adjust: 100%;
    padding-bottom: env(safe-area-inset-bottom);
}

.quick-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    padding: env(safe-area-inset-top) 1rem 0.75rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.quick-back {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1.4rem;
    line-height: 1;
    padding: 0.4rem 0.5rem;
    margin: -0.4rem -0.5rem;
}

.quick-header h1 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    margin: 0;
    line-height: 1;
}

.quick-main {
    max-width: 560px;
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}

.quick-banner {
    background: rgba(94, 207, 196, 0.08);
    border: 1px solid var(--tag-border);
    border-radius: 6px;
    padding: 0.75rem 0.9rem;
    margin-bottom: 1.25rem;
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
}

.quick-banner-check {
    color: var(--tag-text);
    font-weight: bold;
    font-size: 1.1rem;
    line-height: 1.4;
}

.quick-banner-text {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.4;
}

.quick-banner-text a {
    display: block;
    color: var(--tag-text);
    text-decoration: none;
    margin-top: 0.15rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.quick-error {
    background: rgba(255, 99, 99, 0.08);
    border: 1px solid #aa3a3a;
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    margin-bottom: 1rem;
    color: #ff9999;
    font-size: 0.85rem;
}

.quick-form {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.quick-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.quick-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.quick-hint {
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.7;
    font-size: 0.85em;
}

.quick-form input[type="text"],
.quick-form textarea {
    background: var(--code-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px;
    font-family: var(--font-sans);
    line-height: 1.5;
    padding: 0.75rem 0.85rem;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.quick-form textarea {
    resize: vertical;
    min-height: 96px;
}

.quick-form input[type="text"]:focus,
.quick-form textarea:focus {
    outline: none;
    border-color: var(--tag-border);
    background: #2f2f2f;
}

.quick-radios {
    border: none;
    padding: 0;
    margin: 0;
}

.quick-radio-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.quick-radio {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.7rem 0.75rem;
    font-size: 0.95rem;
    cursor: pointer;
    min-height: 44px;
}

.quick-radio input[type="radio"] {
    accent-color: var(--tag-text);
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
}

.quick-radio:has(input:checked) {
    border-color: var(--tag-border);
    background: #2f2f2f;
}

.quick-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.quick-submit {
    background: var(--tag-border);
    color: var(--bg-color);
    border: none;
    border-radius: 6px;
    padding: 0.95rem 1rem;
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    min-height: 50px;
    margin-top: 0.5rem;
}

.tag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.tag-suggestion {
    background: transparent;
    border: 1px solid var(--tag-border);
    color: var(--tag-text);
    border-radius: 14px;
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    cursor: pointer;
    min-height: 36px;
    -webkit-tap-highlight-color: rgba(94, 207, 196, 0.2);
}

.tag-suggestion:active,
.tag-suggestion:hover {
    background: rgba(94, 207, 196, 0.12);
}

.quick-submit:active {
    background: var(--tag-text);
}

@media (max-width: 380px) {
    .quick-radio-grid {
        grid-template-columns: 1fr;
    }
    .quick-row {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Page Layout with Sidebar
   ========================================================================== */

.page-layout {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 3rem;
    margin: 2rem 0;
}

.page-layout .content-feed {
    margin: 0;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 2rem;
    height: fit-content;
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin: 0 0 0.75rem 0;
    font-family: var(--font-sans);
}

.filter-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.filter-list li {
    margin-bottom: 0.5rem;
}

.filter-list a {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    color: var(--text-color);
    text-decoration: none;
    transition: background-color 0.15s;
}

.filter-list a:hover {
    background-color: var(--tag-bg);
    text-decoration: none;
}

.filter-list a.active {
    background-color: var(--code-bg);
    color: var(--tag-text);
    border-left: 3px solid var(--tag-border);
    padding-left: calc(0.75rem - 3px);
}

.filter-list a.active .count {
    color: var(--tag-text);
    opacity: 0.7;
}

.filter-list .count {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.sidebar-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Responsive: stack sidebar below on mobile */
@media (max-width: 768px) {
    .page-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .sidebar {
        position: static;
        border-top: 1px solid var(--border-color);
        padding-top: 2rem;
    }
}

/* ==========================================================================
   Visitor Counter — Amber, dark-mode primary
   ========================================================================== */

.odometer-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
}

.odometer-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #f5a623;
    opacity: 0.55;
}

.odometer {
    display: flex;
    gap: 2px;
    background: #1f1800;
    border: 1px solid #5a3d00;
    border-radius: 4px;
    padding: 4px 8px;
}

.odometer-digit {
    position: relative;
    font-family: var(--font-mono);
    font-size: 1.15rem;
    width: 1.4ch;
    min-height: 1.8em;
    text-align: center;
    overflow: hidden;
}

.odometer-inner {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: #f5a623;
    line-height: 1.8;
    animation: digitFlip 0.35s ease-out both;
}

/* Stagger per digit */
.odometer-digit:nth-child(1) .odometer-inner { animation-delay: 0.04s; }
.odometer-digit:nth-child(2) .odometer-inner { animation-delay: 0.08s; }
.odometer-digit:nth-child(3) .odometer-inner { animation-delay: 0.12s; }
.odometer-digit:nth-child(4) .odometer-inner { animation-delay: 0.16s; }
.odometer-digit:nth-child(5) .odometer-inner { animation-delay: 0.20s; }
.odometer-digit:nth-child(6) .odometer-inner { animation-delay: 0.24s; }
.odometer-digit:nth-child(7) .odometer-inner { animation-delay: 0.28s; }

@keyframes digitFlip {
    0%   { transform: rotateX(90deg); opacity: 0; }
    100% { transform: rotateX(0deg);  opacity: 1; }
}

/* Leading zeros are dimmer */
.odometer-digit.leading-zero .odometer-inner {
    color: #3a2600;
}
