:root {
    --sys-bg: #ece9d8;
    --sys-text: #000000;
    --sys-highlight: #316ac5;
    --sys-highlight-text: #ffffff;

    --accent-orange: #eb7d00;
    --accent-grey: #727272;

    --sidebar-width: 280px;

    --border-light: #ffffff;
    --border-shadow: #aca899;
    --border-dark: #404040;

    --font-ui: "Segoe UI", "Tahoma", sans-serif;
    --font-data: "Consolas", "Courier New", monospace;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--sys-bg);
    color: var(--sys-text);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
    font-size: 12px;
}

/* --- GRID LAYOUT --- */
.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100%;
    padding: 4px;
    gap: 4px;
    box-sizing: border-box;
    transition: grid-template-columns 0.3s ease;
}

.app-container.collapsed {
    grid-template-columns: 0px 1fr;
    gap: 0;
}

/* --- PANELS --- */
.panel-3d {
    background: var(--sys-bg);
    border: 2px solid var(--sys-bg);
    display: flex;
    flex-direction: column;
    box-shadow:
        inset 1px 1px 0 var(--border-light),
        1px 1px 0 var(--border-dark),
        2px 2px 0 var(--border-dark);
    overflow: hidden;
}

.sunked-panel {
    border: 2px solid;
    border-color: var(--border-shadow) var(--border-light) var(--border-light) var(--border-shadow);
    background: #ffffff;
}

/* --- SIDEBAR --- */
.sidebar {
    padding: 2px;
    min-width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    gap: 4px;
    user-select: none;
}

.panel-header {
    background: linear-gradient(to right, #808080, #b0b0b0);
    padding: 4px 6px;
    color: #fff;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.panel-header h3 { margin: 0; font-size: 11px; letter-spacing: 1px; }

.btn-tiny {
    width: 20px; height: 20px;
    background: linear-gradient(#fdfcf7, #ddd9c9);
    border: 2px solid; border-color: #ffffff #9a968a #9a968a #ffffff;
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    display: flex; align-items: center; justify-content: center;
}
.btn-tiny:active { border-color: #9a968a #ffffff #ffffff #9a968a; }

.toolbar { padding: 0 0 2px 0; }

.search-box {
    width: 100%;
    box-sizing: border-box;
    border: 2px inset var(--sys-bg);
    padding: 4px;
    font-family: var(--font-ui);
    font-size: 12px;
}

/* ARTICLE INDEX */
.article-list {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #fff;
    padding: 0;
}

.list-note { padding: 10px; color: #666; margin: 0; }

.group-header {
    background: #d4d0c8;
    border-bottom: 1px solid var(--border-shadow);
    border-top: 1px solid var(--border-light);
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #333;
    position: sticky;
    top: 0;
    z-index: 5;
}
.group-header .group-count {
    float: right;
    font-family: var(--font-data);
    font-weight: normal;
    color: #666;
}

.article-item {
    padding: 6px 8px;
    cursor: pointer;
    border-bottom: 1px dotted #eee;
    display: flex;
    flex-direction: column;
}
.article-item:hover { background-color: #f0f0f0; }
.article-item.active {
    background-color: var(--sys-highlight);
    color: var(--sys-highlight-text);
}
.article-item.active .article-blurb,
.article-item.active .article-meta { color: rgba(255,255,255,0.85) !important; }

.article-head-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
}
.article-name { font-weight: bold; font-size: 13px; }
.article-meta { font-size: 9px; color: #888; font-family: var(--font-data); white-space: nowrap; }
.article-blurb { font-size: 10px; color: #666; margin-top: 2px; line-height: 1.35; }

.article-item.gallery-item .article-name { color: var(--accent-orange); }
.article-item.gallery-item.active .article-name { color: #fff; }

.status-bar-mini {
    font-size: 10px;
    color: #666;
    text-align: right;
    padding-right: 4px;
    margin-top: 2px;
}

/* --- VIEWPORT --- */
.viewport {
    background-color: var(--sys-bg);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.viewport-header {
    padding: 6px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

.btn-toggle-sidebar {
    background: linear-gradient(#fdfcf7, #ddd9c9);
    border: 2px solid; border-color: #ffffff #9a968a #9a968a #ffffff;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 1px 1px 0 #6b675c;
    flex-shrink: 0;
}
.btn-toggle-sidebar:active {
    border-color: #9a968a #ffffff #ffffff #9a968a; box-shadow: none; transform: translate(1px, 1px);
}

.viewport-title-group { flex-grow: 1; min-width: 0; }
.viewport-title-group h2 {
    margin: 0;
    font-size: 18px;
    color: #333;
    font-weight: 900;
    letter-spacing: -0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.crumb {
    font-family: var(--font-data);
    font-size: 10px;
    color: #777;
}

.copy-clone-btn {
    font-size: 10px;
    padding: 3px 6px;
    border: 2px solid; border-color: #ffffff #9a968a #9a968a #ffffff;
    box-shadow: 1px 1px 0 #6b675c;
    background: linear-gradient(#fdfcf7, #ddd9c9);
    cursor: pointer;
    color: #333;
    margin-left: 8px;
    text-decoration: none;
    white-space: nowrap;
}
.copy-clone-btn:active { background: #ccc; }

/* TABS */
.tabs-bar {
    padding: 0 8px;
    display: flex;
    gap: 2px;
    margin-bottom: -2px;
    z-index: 10;
    margin-top: 4px;
}

.tab-btn {
    background: linear-gradient(#e6e3d6, #d6d2c2);
    border: 1px solid var(--border-shadow);
    border-bottom: none;
    border-radius: 3px 3px 0 0;
    padding: 4px 12px;
    font-size: 11px;
    cursor: pointer;
    position: relative;
    top: 2px;
    font-family: var(--font-ui);
}

.tab-btn.active {
    background: #fff;
    font-weight: bold;
    border-color: var(--border-shadow) var(--border-shadow) #fff var(--border-shadow);
    border-top: 2px solid var(--accent-orange);
    z-index: 100;
    top: 0;
    padding-bottom: 6px;
}

.content-wrapper {
    flex-grow: 1;
    background: #fff;
    border-top: 1px solid var(--border-shadow);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
}

.placeholder { text-align: center; margin-top: 50px; color: #999; }

/* --- ARTICLE BODY --- */
.markdown-body {
    font-family: var(--font-ui);
    line-height: 1.7;
    color: #24292e;
    font-size: 14px;
    max-width: 800px;
    margin: 0 auto;
}

.markdown-body h1 {
    font-size: 2em;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.3em;
    margin-top: 0;
}
.markdown-body h2 {
    font-size: 1.3em;
    border-left: 4px solid var(--accent-orange);
    border-bottom: 1px solid #d4d0c8;
    background: #f4f1e7;
    padding: 8px 12px;
    margin: 1.8em 0 0.8em;
    scroll-margin-top: 12px;
}
.markdown-body p { margin: 0.8em 0 1.1em; }
.markdown-body li { margin: 0.4em 0; }
.markdown-body li > p { margin: 0.35em 0; }
.markdown-body h2:focus-visible { outline: 2px solid var(--accent-orange); }
.article-nav {
    margin: 20px 0 24px;
    padding: 12px;
    background: #f7f6f2;
    border: 1px solid #d4d0c8;
}
.article-nav > strong { display: block; margin-bottom: 8px; font-size: 12px; }
.article-nav-items { display: flex; flex-wrap: wrap; gap: 7px; }
.article-nav button {
    font: inherit;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
    padding: 6px 9px;
    color: #0b4f9e;
    background: #fff;
    border: 1px solid #bab8ae;
    cursor: pointer;
}
.article-nav button:hover { background: #fff4de; border-color: #b8860b; }
.article-nav button:focus-visible { outline: 2px solid var(--accent-orange); outline-offset: 2px; }
.markdown-body h3 { font-size: 1.2em; margin-top: 1.4em; }

.markdown-body a { color: #0b4f9e; }
.markdown-body a.wikilink { font-weight: bold; }

.markdown-body code {
    font-family: var(--font-data);
    background: #f0f0f0;
    border: 1px solid #e0e0e0;
    padding: 0 3px;
    font-size: 12px;
}

.markdown-body pre {
    background-color: #f0f0f0;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 2px;
    overflow-x: auto;
    font-family: var(--font-data);
    font-size: 12px;
}
.markdown-body pre code { background: none; border: none; padding: 0; }

.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    font-size: 12px;
    margin: 12px 0;
    display: block;
    overflow-x: auto;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-shadow);
    padding: 5px 8px;
    text-align: left;
    vertical-align: top;
}
.markdown-body th { background: #d4d0c8; }
.markdown-body tr:nth-child(even) td { background: #f7f6f2; }

/* a note from the site, above an article it did not write */
.markdown-body .banner {
    border: 1px solid #b8860b;
    border-left: 4px solid var(--accent-orange);
    background: #fdf6e3;
    padding: 8px 12px;
    margin: 0 0 18px 0;
    font-size: 12px;
    line-height: 1.5;
}
.markdown-body .banner a { font-weight: bold; }

.markdown-body blockquote {
    border-left: 3px solid var(--accent-orange);
    margin: 12px 0;
    padding: 2px 12px;
    background: #faf8f2;
    color: #444;
}

.markdown-body hr { border: none; border-top: 1px solid #ddd; margin: 20px 0; }

/* FIGURES: screen captures. Whether the pixels stay square is decided per
   picture in wiki.js, from the size it ends up drawn at. */
.figure {
    margin: 16px auto;
    text-align: center;
    max-width: 540px;
}
.figure img,
.figure-grid img,
#lightbox-img {
    background: #fff;
}
.figure img {
    max-width: 100%;
    border: 2px solid;
    border-color: var(--border-shadow) var(--border-light) var(--border-light) var(--border-shadow);
    padding: 4px;
    cursor: zoom-in;
    display: block;
    margin: 0 auto;
}
.figure figcaption {
    font-family: var(--font-data);
    font-size: 10px;
    color: #777;
    margin-top: 4px;
}

/* a contact sheet: pictures laid out in a table, one per cell */
.markdown-body td .figure {
    margin: 4px auto;
}
.markdown-body td .figure img { padding: 2px; }
.markdown-body td[align="center"] { text-align: center; }

/* FIGURES TAB */
.figure-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    align-content: start;
    align-items: start;
}
.figure-card {
    border: 1px solid #ccc;
    background: #fbfbfb;
    padding: 6px;
    text-align: center;
}
/* portrait panels and landscape ones share the grid, so cap the tall ones
   rather than let one row set its height from the tallest picture in it */
.figure-card img {
    max-width: 100%;
    max-height: 240px;
    width: auto;
    height: auto;
    margin: 0 auto;
    cursor: zoom-in;
    display: block;
}
.figure-card .cap {
    font-family: var(--font-data);
    font-size: 9px;
    color: #666;
    margin-top: 4px;
    word-break: break-word;
}
.figure-grid .empty { color: #999; padding: 20px; }

/* LIGHTBOX */
#lightbox {
    border: 2px solid;
    border-color: var(--border-light) var(--border-dark) var(--border-dark) var(--border-light);
    background: var(--sys-bg);
    padding: 10px;
    max-width: 92vw;
    max-height: 92vh;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.4);
}
#lightbox::backdrop { background: rgba(0,0,0,0.55); }
#lightbox img {
    display: block;
    max-width: 88vw;
    max-height: 74vh;
    margin: 0 auto;
    border: 1px solid var(--border-shadow);
}
#lightbox p {
    font-family: var(--font-data);
    font-size: 10px;
    color: #444;
    text-align: center;
    margin: 8px 0;
}
#lightbox form { text-align: center; }

.btn-action {
    background: linear-gradient(#fdfcf7, #ddd9c9);
    border: 2px solid; border-color: #ffffff #9a968a #9a968a #ffffff;
    box-shadow: 1px 1px 0 #6b675c;
    padding: 4px 14px;
    font-weight: bold;
    color: #000;
    font-size: 11px;
    font-family: var(--font-ui);
    cursor: pointer;
}
.btn-action:active {
    border-color: #9a968a #ffffff #ffffff #9a968a; box-shadow: none; transform: translate(1px, 1px);
}

/* FOOTER */
.viewport-footer {
    background: var(--sys-bg);
    border-top: 1px solid var(--border-shadow);
    padding: 2px 8px;
    font-size: 10px;
    color: #444;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    font-family: var(--font-data);
}

/* --- MOBILE --- */
@media (max-width: 768px) {
    .app-container { grid-template-columns: 1fr; }
    .app-container.collapsed { grid-template-columns: 1fr; }

    .sidebar {
        position: absolute;
        top: 0; left: 0; bottom: 0;
        width: 85%;
        max-width: 300px;
        z-index: 500;
        box-shadow: 4px 0 15px rgba(0,0,0,0.5);
        transform: translateX(0);
        transition: transform 0.3s ease;
    }
    .app-container.collapsed .sidebar { transform: translateX(-100%); }

    .viewport-header h2 { font-size: 15px; }
    .btn-toggle-sidebar { width: 32px; height: 32px; font-size: 18px; }
    .scroll-container { padding: 10px; }
    .markdown-body { font-size: 14px; }
    .figure-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
