:root {
    --bg-color: #ffffff; --text-color: #333333; --header-bg: #1a1a1a;
    --header-text: #ffffff; --link-color: #007bff; --border-color: #ccc;
    --accent-bg: #f8f9fa; --font-size-base: 16px;
    --font-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    --code-bg: #f6f8fa; --code-text: #24292e;
    --quote-border: #8d7455; --quote-bg: #fcfaf2;
    --sidebar-width: 300px;
}
body.dark-mode {
    --bg-color: #121212; --text-color: #e0e0e0; --header-bg: #1f1f1f;
    --header-text: #e0e0e0; --link-color: #bb86fc; --border-color: #555;
    --accent-bg: #1e1e1e;
    --code-bg: #2d2d2d; --code-text: #e0e0e0;
    --quote-border: #6d5d4b; --quote-bg: #1a1a17;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color); color: var(--text-color); line-height: 1.7;
    transition: background-color 0.3s, color 0.3s; touch-action: manipulation;
}
.content-wrapper { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 20px; }

header {
    background-color: var(--header-bg); color: var(--header-text);
    width: 100%; max-width: 1200px; margin: 0 auto;
    position: sticky; top: 0; z-index: 1000; box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-content { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; width: 100%; }
header h1 {
    font-size: 1.6rem;
    font-weight: 600;
    white-space: nowrap;
    margin-right: auto;
}
.header-actions { display: flex; align-items: center; gap: 15px; }
.search-container { position: relative; }
#search-box { width: 100%; max-width: 240px; min-width: 150px; padding: 8px 12px; border-radius: 20px; border: 1px solid #555; background-color: #333; color: #fff; }
#search-results {
    position: absolute; top: 100%; right: 0; width: 280px; background-color: var(--bg-color);
    border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    margin-top: 8px; max-height: 300px; overflow-y: auto; z-index: 101;
}
#search-results a { display: block; padding: 10px 15px; color: var(--text-color); text-decoration: none; border-bottom: 1px solid var(--accent-bg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#search-results a:last-child { border-bottom: none; }
#search-results a:hover { background-color: var(--accent-bg); }
#download-button { padding: 8px 15px; background-color: var(--link-color); color: white; border: none; border-radius: 20px; cursor: pointer; text-decoration: none; white-space: nowrap; }
#sidebar-toggle { background: none; border: none; color: white; cursor: pointer; padding: 5px; }
#sidebar-toggle svg { width: 24px; height: 24px; fill: currentColor; }

#sidebar {
    position: fixed; top: 0; right: 0; width: var(--sidebar-width); height: 100%; 
    background-color: var(--bg-color);
    box-shadow: -5px 0 25px rgba(0,0,0,0.15); 
    z-index: 1002; transform: translateX(calc(100% + 30px)); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 25px; display: flex; flex-direction: column; gap: 20px;
    overflow-y: auto;
}
#sidebar.open { transform: translateX(0); }
#sidebar-header { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 10px; padding-bottom: 10px; 
    border-bottom: 1px solid var(--border-color); 
}
.sidebar-home-link {
    font-size: 1.1rem; font-weight: 600; color: var(--text-color); text-decoration: none;
    display: flex; align-items: center; gap: 10px; opacity: 0.9; transition: opacity 0.2s;
}
.sidebar-home-link:hover { opacity: 1; color: var(--link-color); }
.sidebar-home-link svg { width: 22px; height: 22px; fill: currentColor; }
#sidebar-close-btn { 
    background: rgba(0,0,0,0.05); border: none; color: var(--text-color); 
    cursor: pointer; padding: 8px; border-radius: 50%; display: flex; 
    align-items: center; justify-content: center; transition: background 0.2s;
}
body.dark-mode #sidebar-close-btn { background: rgba(255,255,255,0.1); }
#sidebar-close-btn:hover { background: rgba(0,0,0,0.1); }
#sidebar-close-btn svg { width: 20px; height: 20px; fill: currentColor; }
#sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 1001;
    opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(2px);
}
#sidebar-overlay.visible { opacity: 1; visibility: visible; }

.sidebar-section-title {
    font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-color); opacity: 0.6; margin-bottom: 8px; font-weight: 600;
}
.control-group { display: flex; flex-direction: column; }

.segmented-control {
    display: flex; background-color: var(--accent-bg);
    padding: 4px; border-radius: 10px; position: relative;
    border: 1px solid var(--border-color);
}
.segmented-control input { display: none; }
.segmented-control label {
    flex: 1; text-align: center; padding: 8px 0;
    font-size: 0.9rem; cursor: pointer; color: var(--text-color);
    border-radius: 8px; transition: all 0.2s ease;
    font-weight: 500; opacity: 0.7;
}
.segmented-control input:checked + label {
    background-color: var(--bg-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 1; color: var(--link-color); font-weight: 600;
}

.sidebar-menu-link {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    color: var(--text-color); background-color: transparent;
    padding: 12px 5px; border-radius: 6px;
    text-decoration: none; font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-menu-link:hover { background-color: var(--accent-bg); color: var(--link-color); }
.sidebar-menu-link svg { width: 20px; height: 20px; fill: currentColor; opacity: 0.7; }

.sidebar-bottom-content { position: relative; margin-top: auto; text-align: center; border-top: 1px solid var(--border-color); padding-top: 20px; }
#sidebar-uptime { opacity: 0.6; font-size: 0.85rem; font-family: var(--font-code); cursor: pointer; user-select: none; display: inline-block; }
.time-bubble { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--header-bg); color: var(--header-text); padding: 5px 12px; border-radius: 6px; font-size: 0.75rem; white-space: nowrap; margin-bottom: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); animation: fadeIn 0.2s forwards; z-index: 1003; }
.time-bubble::after { content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--header-bg); }

#main-view { animation: fadeIn 0.35s ease both; }
#article-view.article-enter { animation: fadeIn 0.25s ease both; }
.hero-image-container { 
    position: relative; width: 100%; max-width: 1200px; margin: 0 auto; 
    line-height: 0; max-height: 60vh; overflow: hidden; 
}
.hero-image-container img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-image-container::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 30%; background: linear-gradient(to bottom, transparent, var(--bg-color)); pointer-events: none; }

.signature-wrapper { padding-bottom: 20px; }
.signature-box-common { 
    border: 2px dashed var(--border-color); border-radius: 8px; 
    aspect-ratio: 2.5 / 1; display: flex; overflow-y: auto; padding: 20px; 
    align-items: center; justify-content: center; width: 100%;
}
.signature-content-common {
    width: 100%; text-align: center;
    font-size: var(--font-size-base);
    transition: opacity 0.3s ease-in-out;
    margin: auto;
}
#change-signature { text-align: center; margin-top: 4px; font-size: 0.9rem; color: var(--link-color); cursor: pointer; text-decoration: underline; opacity: 0.8; transition: opacity 0.2s; }
#change-signature:hover { opacity: 1; }

#articles-container { padding-bottom: 20px; overflow: hidden; }
.article-item { padding: 20px 0; border-bottom: 1px dotted var(--border-color); user-select: none; }
.article-item a {
    color: inherit; text-decoration: none; display: flex; justify-content: space-between; align-items: center; font-size: calc(var(--font-size-base) + 0.2rem); transition: color 0.2s;
}
.article-item a:hover { color: var(--link-color); }
/* Reserve an ordinary one-line row without adding any visible or clickable content. */
.article-placeholder {
    border-bottom-color: transparent;
    pointer-events: none;
    user-select: none;
}
.article-placeholder::before {
    content: "";
    display: block;
    height: 1.7em;
    font-size: calc(var(--font-size-base) + 0.2rem);
}
.article-ext-box {
    font-size: 0.8rem; color: var(--link-color); border: 1px solid var(--link-color);
    border-radius: 4px; padding: 2px 6px; margin-left: 15px; white-space: nowrap;
}
.signature-list-item { padding: 20px 0; user-select: text; }

#pagination-container { display: flex; flex-direction: column; align-items: center; gap: 15px; padding: 20px 0; }
.pagination-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; }
#pagination-container a { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-color); padding: 6px 10px; border-radius: 5px; cursor: pointer; text-decoration: none; font-size: 0.9rem; min-width: 36px; text-align: center; }
#pagination-container a.active { background-color: var(--link-color); color: white; border-color: var(--link-color); }
#pagination-container a:hover:not(.active):not(.disabled) { background-color: var(--accent-bg); color: var(--link-color); border-color: var(--link-color); }
#pagination-container span.ellipsis { color: var(--text-color); padding: 0 4px; opacity: 0.6; }
#pagination-container input.page-jump-input { width: 80px; padding: 6px; border: 1px solid var(--border-color); border-radius: 5px; background-color: var(--bg-color); color: var(--text-color); text-align: center; font-size: 0.9rem; }
#pagination-container input.page-jump-input:focus { outline: none; border-color: var(--link-color); }
.page-text-btn { padding: 6px 15px !important; }

#article-view { padding: 20px 0; }
#article-content {
    font-size: var(--font-size-base);
}
/* Restore readable spacing after the global CSS reset without changing other pages. */
#article-content > p { margin: 0 0 1em; }
#article-content > h1,
#article-content > h2,
#article-content > h3,
#article-content > h4,
#article-content > h5,
#article-content > h6 {
    line-height: 1.4;
    margin: 1.5em 0 0.65em;
}
#article-content > :first-child { margin-top: 0; }
/* Additional Markdown empty lines beyond the usual paragraph separation. */
#article-content .markdown-extra-lines {
    display: block;
    height: calc(var(--extra-lines) * 1.7em);
    pointer-events: none;
}
#article-content img, .signature-content-common img { max-width: 100%; border-radius: 8px; }
#article-content a, .signature-content-common a { color: var(--link-color); }
#article-content pre, .signature-content-common pre {
    font-family: var(--font-code);
    background-color: var(--accent-bg);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}
#article-content :not(pre) > code, .signature-content-common :not(pre) > code {
    background-color: var(--code-bg);
    color: var(--code-text);
    font-family: var(--font-code);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid rgba(0,0,0,0.1);
}
#article-content blockquote, .signature-content-common blockquote {
    margin: 2em 0;
    padding: 0.8em 1.5em;
    border-left: 4px solid var(--quote-border);
    border-right: 1px solid rgba(141, 116, 85, 0.1);
    background-color: var(--quote-bg);
    color: var(--text-color);
    position: relative;
    border-radius: 2px;
    box-shadow: inset 2px 0 0 rgba(141, 116, 85, 0.2);
}
#article-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border-color), var(--border-color), transparent);
    width: 70%;
    margin: 40px auto;
    opacity: 0.5;
    border-radius: 10px;
}
.related-articles {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}
.related-articles h2 { font-size: 1.15em; margin-bottom: 0.8rem; }
.related-articles-list { display: grid; gap: 0.6rem; }
#article-content .related-article-link {
    display: block;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--accent-bg);
    color: var(--text-color);
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color 0.2s, border-color 0.2s;
}
#article-content .related-article-link:hover {
    color: var(--link-color);
    border-color: var(--link-color);
}
#article-content .related-article-link:focus-visible {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
}

#article-content ul, #article-content ol, .signature-content-common ul, .signature-content-common ol {
    margin: 1em 0;
    padding-left: 2em;
}
.sandbox-browser-window {
    border: none;
    border-radius: 0;
    overflow: hidden;
    margin: 20px 0;
    background-color: transparent;
}

.snake-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 2000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.snake-modal-content { position: relative; width: 90vmin; height: 90vmin; max-width: 600px; max-height: 600px; background: #000; border-radius: 12px; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.snake-modal-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 20px; z-index: 2001; transition: background 0.2s; }
.snake-modal-close:hover { background: rgba(255,255,255,0.4); }

.notice-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-color); z-index: 3000; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.3s; }
.notice-modal-wrapper { position: relative; width: 100vw; height: 100vh; background: var(--bg-color); overflow: hidden; }
.notice-modal-close { position: absolute; top: 20px; right: 20px; width: 48px; height: 48px; background: rgba(0,0,0,0.1); color: var(--text-color); border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 32px; z-index: 3001; transition: background 0.2s; }
body.dark-mode .notice-modal-close { background: rgba(255,255,255,0.1); }
.notice-modal-close:hover { background: rgba(0,0,0,0.2); }
.notice-iframe { width: 100%; height: 100%; border: none; display: block; background: transparent; }

.site-footer { text-align: center; padding: 40px 20px 20px; font-size: 0.85rem; color: var(--text-color); opacity: 0.7; }
.site-footer a { color: inherit; text-decoration: underline; }
.hidden { display: none !important; }
/* Each list entry starts invisible well below its final position, then rises into place. */
.slide-in-up { animation: slideInUp 0.48s cubic-bezier(0.16, 1, 0.3, 1) both; }
.slide-out-up { animation: slideOutUp 0.18s ease-in both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInUp { from { opacity: 0; transform: translateY(72px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideOutUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-8px); } }

/* During typing, keep unreached article blocks completely invisible. */
.typewriter-pending { display: none !important; }
.article-loading { opacity: 0.7; }
body.low-motion .slide-in-up { animation: fadeIn 0.12s both; }
body.low-motion .slide-out-up { animation: none; }
body.low-motion #sidebar-overlay { backdrop-filter: none; }
body.low-motion #article-view.article-enter { animation: none; }
@media (max-width: 600px) {
    #sidebar-overlay { backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) {
    .slide-in-up, .slide-out-up, #main-view,
    #article-view.article-enter, .time-bubble, .notice-modal-overlay {
        animation: none !important;
    }
    #sidebar, #sidebar-overlay, .signature-content-common,
    body, .segmented-control label {
        transition: none !important;
    }
}

.testmd-container h2 {
    margin-bottom: 15px;
}
.testmd-textarea {
    width: 100%;
    height: 200px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--accent-bg);
    color: var(--text-color);
    font-family: var(--font-code);
    font-size: 0.95rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 20px;
    box-sizing: border-box;
}
.testmd-textarea:focus {
    border-color: var(--link-color);
}

