:root {
    --toolbar: #12383d;
    --toolbar-dark: #0c292d;
    --accent: #f1b33b;
    --accent-dark: #c27c1e;
    --ink: #172225;
    --paper-shadow: 0 10px 30px rgba(18, 34, 36, 0.22);
    --control: rgba(18, 56, 61, 0.94);
    --control-border: rgba(255, 255, 255, 0.14);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        linear-gradient(180deg, #e7f0ed 0, #f6f4ed 220px, #eef2f0 100%);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    overflow-x: hidden;
}

button,
select,
input {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: stretch;
    min-height: 58px;
    background: var(--toolbar);
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}

.icon-button,
.tool-button,
.date-button,
.select-block,
.social-button {
    min-height: 58px;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(0, 0, 0, 0.18);
}

.icon-button,
.tool-button,
.date-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 56px;
    padding: 0 14px;
    background: var(--toolbar);
    color: #fff;
}

.icon-button:hover,
.tool-button:hover,
.date-button:hover {
    background: var(--toolbar-dark);
}

.menu-button {
    width: 78px;
    background: #0f3034;
}

.menu-button span {
    display: block;
    width: 22px;
    height: 3px;
    margin: 3px 0;
    background: #fff;
    border-radius: 99px;
}

.select-block {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 160px;
    background: var(--toolbar);
}

.select-block--edition {
    min-width: 250px;
    background: var(--accent);
    color: #172225;
}

.select-block::after {
    content: "";
    position: absolute;
    right: 16px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid currentColor;
    pointer-events: none;
}

.select-block select,
.page-select select {
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    appearance: none;
    background: transparent;
    color: inherit;
    font-weight: 700;
}

.select-block select {
    padding: 0 48px 0 64px;
}

.date-button {
    position: relative;
    min-width: 218px;
    justify-content: space-between;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    overflow: hidden;
}

.date-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.calendar-icon {
    position: relative;
    width: 25px;
    height: 25px;
    border: 2px solid #fff;
    border-radius: 3px;
}

.calendar-icon::before,
.calendar-icon::after {
    content: "";
    position: absolute;
    background: #fff;
}

.calendar-icon::before {
    left: 3px;
    right: 3px;
    top: 6px;
    height: 2px;
}

.calendar-icon::after {
    left: 6px;
    top: -5px;
    width: 3px;
    height: 8px;
    box-shadow: 9px 0 0 #fff;
}

.toolbar-group,
.share-actions {
    display: flex;
    margin-left: 0;
}

.magnifier {
    position: relative;
    width: 22px;
    height: 22px;
    border: 3px solid #fff;
    border-radius: 50%;
}

.magnifier::before,
.magnifier::after {
    content: "";
    position: absolute;
    background: #fff;
}

.magnifier::before {
    left: 5px;
    right: 5px;
    top: 8px;
    height: 3px;
}

.magnifier.plus::after {
    top: 5px;
    bottom: 5px;
    left: 8px;
    width: 3px;
}

.magnifier::after {
    width: 11px;
    height: 3px;
    right: -10px;
    bottom: -6px;
    transform: rotate(45deg);
}

.fit-icon,
.bookmark-icon,
.clip-icon,
.grid-icon {
    position: relative;
    display: inline-block;
    width: 24px;
    height: 24px;
}

.fit-icon {
    border: 2px solid transparent;
}

.fit-icon::before {
    content: "";
    position: absolute;
    inset: 3px;
    border: 2px solid #fff;
    border-style: dashed;
}

.bookmark-icon {
    background: #fff;
    clip-path: polygon(18% 0, 82% 0, 82% 100%, 50% 75%, 18% 100%);
}

.clip-icon::before,
.clip-icon::after {
    content: "";
    position: absolute;
    border: 2px solid #fff;
    border-radius: 50%;
}

.clip-icon::before {
    width: 9px;
    height: 9px;
    left: 2px;
    top: 3px;
}

.clip-icon::after {
    width: 9px;
    height: 9px;
    right: 2px;
    bottom: 3px;
}

.clip-icon {
    transform: rotate(-25deg);
}

.social-button {
    width: 52px;
    background: var(--toolbar);
    color: #fff;
    font-size: 24px;
    font-weight: 800;
}

.facebook {
    background: #2f5f8f;
    border-radius: 50%;
    align-self: center;
    width: 40px;
    min-height: 40px;
    margin: 0 8px;
    border: 0;
}

.x {
    background: #050505;
    border-radius: 50%;
    align-self: center;
    width: 40px;
    min-height: 40px;
    margin-right: 8px;
    border: 0;
    font-size: 18px;
}

.profile {
    background: var(--accent);
    color: #172225;
    border-radius: 50%;
    align-self: center;
    width: 40px;
    min-height: 40px;
    margin-right: 12px;
    border: 0;
    font-size: 18px;
}

.reader-shell {
    position: relative;
    min-height: calc(100vh - 58px);
    padding: 18px 0 82px;
}

.page-stage {
    width: min(1664px, calc(100vw - 128px));
    margin: 0 auto;
}

.paper-frame {
    position: relative;
    transform-origin: top center;
    transition: transform 160ms ease;
}

.paper-frame img {
    display: block;
    width: 100%;
    min-width: 820px;
    background: #fff;
    border: 8px solid #fff;
    border-radius: 4px;
    box-shadow: var(--paper-shadow);
    user-select: none;
}

.clip-mode .paper-frame img {
    cursor: crosshair;
}

.clip-box {
    position: absolute;
    z-index: 8;
    border: 2px solid var(--accent);
    background: rgba(241, 179, 59, 0.18);
    box-shadow: 0 0 0 9999px rgba(9, 22, 24, 0.18);
    pointer-events: none;
}

.empty-reader {
    display: grid;
    place-items: center;
    gap: 14px;
    min-height: 420px;
    background: #fff;
    box-shadow: var(--paper-shadow);
}

.empty-reader h1 {
    margin: 0;
    font-size: 28px;
}

.upload-form button,
.upload-heading a {
    color: #fff;
    background: var(--accent);
    border-radius: 5px;
    font-weight: 700;
    text-decoration: none;
}

.side-nav {
    position: fixed;
    top: 50%;
    z-index: 12;
    width: 50px;
    height: 82px;
    display: grid;
    place-items: center;
    background: rgba(18, 56, 61, 0.7);
    transform: translateY(-50%);
}

.side-nav:hover {
    background: rgba(18, 56, 61, 0.9);
}

.side-nav--prev {
    left: 0;
    border-radius: 0 10px 10px 0;
}

.side-nav--next {
    right: 0;
    border-radius: 10px 0 0 10px;
}

.side-nav span {
    width: 24px;
    height: 24px;
    border-top: 5px solid #fff;
    border-left: 5px solid #fff;
}

.side-nav--prev span {
    transform: rotate(-45deg);
}

.side-nav--next span {
    transform: rotate(135deg);
}

.bottom-pager {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 16;
    display: flex;
    align-items: stretch;
    height: 52px;
    overflow: hidden;
    background: var(--control);
    border-radius: 8px;
    box-shadow: 0 12px 24px rgba(13, 34, 38, 0.24);
    transform: translateX(-50%);
}

.bottom-pager button,
.page-select {
    color: #fff;
    background: transparent;
    border-right: 1px solid var(--control-border);
}

.pager-command {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    min-width: 198px;
}

.grid-icon {
    width: 22px;
    height: 22px;
    background:
        linear-gradient(#fff 0 0) left top / 9px 9px no-repeat,
        linear-gradient(#fff 0 0) right top / 9px 9px no-repeat,
        linear-gradient(#fff 0 0) left bottom / 9px 9px no-repeat,
        linear-gradient(#fff 0 0) right bottom / 9px 9px no-repeat;
}

.pager-icon {
    width: 52px;
    position: relative;
}

.pager-icon::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 13px;
    height: 13px;
    border-left: 4px solid #fff;
    border-bottom: 4px solid #fff;
    transform: translate(-35%, -50%) rotate(45deg);
}

.pager-icon:first-of-type::after,
.pager-icon--last::after {
    content: "";
    position: absolute;
    top: 17px;
    bottom: 17px;
    width: 4px;
    background: #fff;
}

.pager-icon:first-of-type::after {
    left: 16px;
}

.pager-icon--next::before,
.pager-icon--last::before {
    transform: translate(-65%, -50%) rotate(225deg);
}

.pager-icon--last::after {
    right: 16px;
}

.page-select {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 144px;
    padding: 0 12px;
}

.page-select select {
    width: 46px;
    color: #fff;
    font-weight: 700;
}

.page-select option,
.select-block option {
    color: #202326;
}

.pages-drawer {
    position: fixed;
    inset: 56px 0 0 auto;
    z-index: 24;
    width: min(440px, 100vw);
    padding: 20px;
    background: #fff;
    box-shadow: -6px 0 20px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.drawer-header h2 {
    margin: 0;
    font-size: 22px;
}

.drawer-header .icon-button {
    min-height: 38px;
    min-width: 38px;
    padding: 0;
    background: #333a3e;
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.thumbnail {
    padding: 8px;
    background: #f3f4f5;
    border: 2px solid transparent;
    border-radius: 6px;
    text-align: left;
}

.thumbnail.is-active {
    border-color: var(--accent);
}

.thumbnail img {
    width: 100%;
    height: 128px;
    object-fit: cover;
    object-position: top;
    background: #fff;
}

.thumbnail span {
    display: block;
    padding-top: 8px;
    font-weight: 700;
}

.upload-page {
    min-height: 100vh;
    background:
        linear-gradient(90deg, rgba(18, 56, 61, 0.08), transparent 32%),
        #eef1f4;
}

.utility-drawer {
    position: fixed;
    inset: 58px auto 0 0;
    z-index: 24;
    width: min(360px, 100vw);
    padding: 20px;
    background: #fbfaf5;
    box-shadow: 6px 0 20px rgba(0, 0, 0, 0.18);
    overflow-y: auto;
}

.edition-summary {
    margin: 0 0 22px;
}

.edition-summary div {
    padding: 12px 0;
    border-bottom: 1px solid #d9ddd8;
}

.edition-summary dt {
    color: #5c6b6d;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.edition-summary dd {
    margin: 4px 0 0;
    font-weight: 800;
}

.bookmark-list h3 {
    margin: 0 0 10px;
    font-size: 18px;
}

.bookmark-list p,
.bookmark-list button {
    margin: 0 0 8px;
}

.bookmark-list button {
    width: 100%;
    min-height: 38px;
    color: #fff;
    background: var(--toolbar);
    border-radius: 5px;
}

.reader-toast {
    position: fixed;
    right: 18px;
    bottom: 92px;
    z-index: 40;
    max-width: min(340px, calc(100vw - 36px));
    padding: 12px 14px;
    color: #fff;
    background: #12383d;
    border-left: 4px solid var(--accent);
    border-radius: 6px;
    box-shadow: 0 12px 28px rgba(13, 34, 38, 0.28);
    font-weight: 700;
}

.is-active-tool {
    background: var(--accent-dark);
}

.upload-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

.upload-panel {
    width: min(560px, 100%);
    padding: 26px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 12px 34px rgba(21, 28, 34, 0.18);
}

.upload-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.upload-heading h1 {
    margin: 0;
    font-size: 28px;
}

.upload-heading a {
    flex: 0 0 auto;
    padding: 10px 12px;
    background: #30363a;
}

.upload-form {
    display: grid;
    gap: 18px;
}

.upload-form label {
    display: grid;
    gap: 7px;
    color: #30363a;
    font-weight: 700;
}

.upload-form input {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid #c9cfd4;
    border-radius: 5px;
    color: #202326;
    background: #fff;
}

.upload-form input[type="file"] {
    padding: 10px;
}

.upload-form button {
    min-height: 48px;
    padding: 0 18px;
    font-size: 16px;
}

.errorlist,
.form-errors {
    margin: 0;
    padding: 0;
    color: #bd121b;
    list-style: none;
    font-weight: 700;
}

.message-list {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: #e9f7ef;
    border-left: 4px solid #3b7f6f;
    color: #1c4f42;
    font-weight: 700;
}

.message-list p {
    margin: 0;
}

@media (max-width: 1100px) {
    .reader-toolbar {
        overflow-x: auto;
    }

    .menu-button {
        width: 62px;
        flex: 0 0 62px;
    }

    .select-block--edition {
        min-width: 210px;
    }

    .date-button {
        min-width: 190px;
    }

    .page-stage {
        width: calc(100vw - 34px);
        overflow-x: auto;
    }

    .paper-frame img {
        min-width: 760px;
    }
}

@media (max-width: 720px) {
    body {
        overflow-x: hidden;
    }

    .reader-toolbar {
        display: grid;
        grid-template-columns: 52px minmax(0, 1.15fr) minmax(0, 0.85fr);
        grid-auto-rows: 52px;
        align-items: stretch;
        min-height: 104px;
        overflow: visible;
    }

    .reader-shell {
        min-height: calc(100vh - 104px);
        padding: 12px 0 88px;
    }

    .icon-button,
    .tool-button,
    .date-button,
    .select-block,
    .social-button {
        min-height: 52px;
    }

    .menu-button {
        order: 1;
        width: 52px;
        min-width: 52px;
    }

    .select-block {
        min-width: 0;
    }

    .select-block--edition {
        order: 2;
        min-width: 0;
    }

    .select-block select {
        padding: 0 34px 0 14px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .reader-toolbar > .select-block:not(.select-block--edition) {
        order: 3;
    }

    .date-button {
        order: 4;
        grid-column: 1 / 2;
        min-width: 52px;
        width: 52px;
        padding: 0;
        font-size: 16px;
    }

    .date-button span:first-child {
        display: none;
    }

    .calendar-icon {
        width: 22px;
        height: 22px;
    }

    .toolbar-group {
        order: 5;
        grid-column: 2 / 4;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .toolbar-group .icon-button,
    .toolbar-group .tool-button {
        min-width: 0;
        width: 100%;
        padding: 0;
    }

    .tool-button span:last-child,
    .share-actions {
        display: none;
    }

    .page-stage {
        width: 100vw;
        padding: 0 10px;
        overflow-x: auto;
    }

    .paper-frame {
        width: 100%;
        margin: 0 auto;
    }

    .paper-frame img {
        width: 100%;
        min-width: 0;
        border-width: 5px;
    }

    .side-nav {
        top: auto;
        bottom: 92px;
        width: 38px;
        height: 58px;
    }

    .bottom-pager {
        width: calc(100vw - 16px);
        height: 58px;
        bottom: 12px;
    }

    .pager-command {
        min-width: 50px;
        padding: 0 14px;
    }

    .pager-command span:last-child {
        display: none;
    }

    .page-select {
        flex: 1;
        justify-content: center;
        min-width: 118px;
        padding: 0 8px;
        font-size: 14px;
    }

    .pager-icon {
        width: 46px;
        flex: 0 0 46px;
    }

    .pages-drawer {
        inset: 104px 0 0 auto;
        width: 100vw;
    }

    .utility-drawer {
        inset: 104px auto 0 0;
        width: 100vw;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
