* {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: gray #111111;
}
html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}
body {
    overflow: hidden;
    background: #111111;
    color: #f0f1e9;
    font:
        13px Arial,
        sans-serif;
}

button {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
}
.hidden {
    display: none !important;
}
b {
    font-weight: normal;
}

.app {
    height: 100vh;
    display: grid;
    grid-template: 32px minmax(0, 1fr) 0 / var(--sw, 180px) 0 1fr;
    grid-template-areas: "h h h" "s r m" "s r f";
}
.app.has-book {
    grid-template-rows: 32px minmax(0, 1fr) 32px;
}
.app.collapsed {
    grid-template-columns: 0 0 1fr !important;
}
.app.collapsed aside,
.app.collapsed #resizer {
    display: none;
}
#resizer {
    grid-area: r;
    width: 8px;
    margin-left: -4px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    z-index: 10;
}
header {
    grid-area: h;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-bottom: 1px solid #1e1e1e;
}
.brand-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand {
    color: #f0f1e9;
    text-decoration: none;
    font-size: 12px;
}
.icon-btn {
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
    transform: translateY(-2px);
}

aside {
    grid-area: s;
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid #1e1e1e;
    display: flex;
    flex-direction: column;
}
.head {
    padding: 8px 12px;
    border-bottom: 1px solid #1e1e1e;
    color: white;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    height: 32px;
    flex: 0 0 auto;
}
.head b {
    color: #5599cc;
}
#shelf {
    padding-top: 6px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.add-btn {
    flex: 0 0 auto;
    margin: 6px;
    padding: 8px;
    border: 1px dashed #4b5948;
    border-radius: 8px;
    text-align: center;
    font-size: 12px;
    color: #5599cc;
}
.add-btn:hover {
    border-color: #5599cc;
    background: #1f3859;
}
.book {
    display: flex;
    gap: 8px;
    padding: 6px;
    margin: 0 6px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    align-items: center;
    position: relative;
}
.book.on {
    background: #1f3859;
}
.book img {
    width: 32px;
    height: 42px;
    object-fit: cover;
    border-radius: 4px;
    flex: 0 0 32px;
}
.book .shelf-info {
    overflow: hidden;
    flex: 1;
    min-width: 0;
}
.book .t {
    white-space: nowrap;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book:hover .t {
    text-overflow: clip;
}
.book .t-inner {
    display: inline-block;
}
.book:hover .t-inner {
    animation: scroll-title 8s linear infinite alternate;
}
@keyframes scroll-title {
    0%,
    5% {
        transform: translateX(0);
    }
    95%,
    100% {
        transform: translateX(calc(-100% - 100%));
    }
}
.book .m {
    color: white;
    font-size: 8px;
}
.book .actions {
    display: none;
    position: absolute;
    right: 4px;
    bottom: 4px;
    z-index: 3;
    background: #111111;
    border-radius: 4px;
}
.book:hover .actions {
    display: flex;
}
.book .actions button {
    font-size: 11px;
    padding: 2px 4px;
    color: #5599cc;
}

main {
    grid-area: m;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.bar {
    height: 32px;
    padding: 0 12px;
    border-bottom: 1px solid #1e1e1e;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: white;
}
.bar #title {
    color: #f0f1e9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.bar #meta {
    color: #5599cc;
}
#empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 25px;
    text-align: center;
    color: white;
}
#empty label {
    padding: 12px 20px;
    border: 1px dashed #4b5948;
    cursor: pointer;
    font-size: 13px;
}
#empty label:hover {
    border-color: #5599cc;
    background: #1f3859;
}
#empty b {
    color: #f0f1e9;
}

#view {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
#view.webtoon-mode {
    align-items: flex-start;
}
.pages {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    transform-origin: center;
}
.pages.rtl {
    flex-direction: row-reverse;
}
.card {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card img {
    max-width: 100%;
    max-height: 100%;
}
.card.text {
    width: 640px;
    max-width: 100%;
    min-height: 420px;
    padding: 35px;
    overflow: auto;
}
.card.text pre {
    white-space: pre-wrap;
    font:
        14px/1.8 Georgia,
        serif;
}
.spread .card {
    width: calc(50% - 2px);
}
.spread .card:first-child {
    justify-content: flex-end;
}
.spread .card:last-child {
    justify-content: flex-start;
}
.spread.rtl .card:first-child {
    justify-content: flex-start;
}
.spread.rtl .card:last-child {
    justify-content: flex-end;
}
.spread {
    gap: 4px;
}
.spread .card:only-child {
    justify-content: center;
}
.webtoon {
    width: 760px;
    max-width: 100%;
    height: auto;
    display: block;
    transform-origin: top;
}
.webtoon .card {
    width: 100%;
    height: auto;
}
.webtoon .card img {
    width: 100%;
    max-height: none;
}

footer {
    grid-area: f;
    height: 32px;
    padding: 8px 12px;
    border-top: 1px solid #1e1e1e;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-group {
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-group.rtl {
    flex-direction: row-reverse;
}
#pos {
    color: white;
    font-size: 11px;
}
.opts {
    flex: 1;
    display: flex;
    gap: 12px;
    justify-content: center;
}
.opts span {
    display: flex;
    border: 1px solid #1e1e1e;
    border-radius: 7px;
}
.opts b {
    padding: 4px 6px;
    color: white;
    font-size: 9px;
    cursor: pointer;
    white-space: nowrap;
    border-radius: 6px;
}
.opts b.on {
    background: #1f3859;
}
#zval {
    color: white;
    font-size: 9px;
    width: 35px;
    text-align: center;
}

#toast {
    position: fixed;
    bottom: 15px;
    left: 50%;
    padding: 10px 13px;
    background: #5599cc;
    color: #111111;
    font-size: 10px;
    transform: translate(-50%, 80px);
    transition: transform 0.2s;
}
#toast.on {
    transform: translate(-50%, 0);
}
#dlg {
    width: 460px;
    max-width: calc(100% - 24px);
    border: 1px solid #1e1e1e;
    padding: 0;
    color: white;
    background: #111111;
}
#dlg::backdrop {
    background: #000b;
}
#dlg > div {
    padding: 0 12px;
}
#dlg h2 {
    margin: 0;
    font:
        24px Georgia,
        serif;
}
.dlghead {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #1e1e1e;
}
#dlglist {
    max-height: 400px;
    overflow: auto;
}
#dlglist button {
    width: 100%;
    padding: 12px 0;
    gap: 8px;
    border-bottom: 1px solid #1e1e1e;
    display: flex;
}
#dlglist button span {
    color: #5599cc;
    font-size: 11px;
}
#dlglist button strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: normal;
    font-size: 11px;
}

@media (max-width: 820px) {
    .app {
        grid-template-columns: 150px 1fr;
    }
    .opts b {
        font-size: 8px;
    }
}
@media (max-width: 620px) {
    .app {
        grid-template: 32px minmax(0, 1fr) 0 / 1fr;
        grid-template-areas: "h" "m" "f";
    }
    .app.has-book {
        grid-template-rows: 32px minmax(0, 1fr) 52px;
    }
    aside {
        display: none;
    }
    .bar {
        padding: 0 8px;
    }
    footer {
        overflow-x: auto;
    }
    .spread {
        width: auto;
        justify-content: flex-start;
    }
    .spread .card {
        width: auto;
    }
}
