:root {
    color-scheme: dark;
    --bg: #161817;
    --panel: #242722;
    --panel-2: #1d211f;
    --line: #3d453c;
    --text: #f4f0e6;
    --muted: #b8b09f;
    --accent: #d2b46b;
    --accent-2: #8db7b0;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

.login-page {
    min-height: 100vh;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, .58), rgba(0, 0, 0, .08)),
        url("scriptorium.png") center / cover no-repeat;
    position: relative;
}

.login-box {
    position: fixed;
    left: 34px;
    bottom: 30px;
    width: min(340px, calc(100vw - 48px));
    display: grid;
    gap: 10px;
    padding: 18px;
    background: rgba(18, 19, 17, .72);
    border: 1px solid rgba(255, 255, 255, .22);
    backdrop-filter: blur(8px);
}

.login-box label {
    color: var(--muted);
    font-size: 13px;
}

.login-box input {
    height: 42px;
    border: 1px solid rgba(255, 255, 255, .3);
    background: rgba(0, 0, 0, .35);
    color: var(--text);
    padding: 0 12px;
    outline: none;
}

.login-box button,
.language-tabs button {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
}

.login-box button {
    height: 40px;
}

.login-error {
    margin: 0;
    color: #ffb3a8;
}

.topbar {
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: #111311;
}

.topbar a {
    color: var(--accent);
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    gap: 18px;
    align-items: center;
}

.workspace {
    height: calc(100vh - 42px);
    display: grid;
    grid-template-rows: minmax(220px, 33vh) auto 42px 1fr;
    overflow: hidden;
}

.image-strip {
    position: relative;
    background: #090a09;
    border-bottom: 1px solid var(--line);
}

.image-scroll {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

#charterImage {
    width: 100%;
    height: auto;
    display: block;
}

.empty-image {
    display: none;
    color: var(--muted);
    padding: 80px 20px;
}

.nav-button {
    position: absolute;
    z-index: 2;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 74px;
    border: 1px solid rgba(255, 255, 255, .28);
    background: rgba(0, 0, 0, .48);
    color: var(--text);
    font-size: 28px;
    cursor: pointer;
}

.charter-prev {
    left: 10px;
}

.page-prev {
    left: 62px;
}

.page-next {
    right: 62px;
}

.charter-next {
    right: 10px;
}

.info-row {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
}

.title {
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 78vw;
}

.meta,
.page-counter {
    color: var(--muted);
    font-size: 13px;
}

.language-tabs {
    display: flex;
    border-bottom: 1px solid var(--line);
    background: #171a17;
}

.language-tabs button {
    min-width: 118px;
    padding: 0 18px;
    border-width: 0 1px 0 0;
}

.language-tabs button.active {
    background: var(--accent);
    color: #18140a;
}

.model-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(260px, 1fr));
    gap: 1px;
    background: var(--line);
}

.model-card {
    min-width: 0;
    min-height: 0;
    background: var(--panel);
    display: grid;
    grid-template-rows: auto 1fr;
}

.model-head {
    min-height: 70px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 4px;
}

.model-slot {
    color: var(--accent-2);
    font-weight: 700;
}

.model-name {
    font-size: 13px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-body {
    min-height: 0;
    overflow: auto;
    padding: 14px;
    white-space: pre-wrap;
    line-height: 1.48;
    font-size: 15px;
}

.model-body.metadata {
    white-space: normal;
    font-size: 13px;
}

.kv {
    margin: 0 0 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.kv dt {
    color: var(--accent-2);
    font-weight: 700;
    margin-bottom: 4px;
}

.kv dd {
    margin: 0;
    color: var(--text);
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-rows: minmax(190px, 32vh) auto 42px 1fr;
    }

    .model-grid {
        grid-template-columns: repeat(2, minmax(260px, 1fr));
    }
}
