:root {
    color-scheme: dark;
    --orange: #f57c20;
    --dark: #414042;
    --toolbar-height: 68px;
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background: #262628;
    color: #fff;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.toolbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 10;
    min-height: var(--toolbar-height);
    padding: 10px 16px;
    display: grid;
    grid-template-columns: auto minmax(120px, 1fr) auto;
    align-items: center;
    gap: 16px;
    background: rgba(65, 64, 66, .98);
    border-bottom: 2px solid var(--orange);
    box-shadow: 0 3px 20px rgba(0, 0, 0, .35);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: white;
    text-decoration: none;
    font-weight: 800;
    letter-spacing: .08em;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: white;
    background: var(--orange);
    font-style: italic;
}

h1 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: #fff;
    font-size: 16px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

button, .download, .page-control {
    min-height: 40px;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 9px;
    color: #fff;
    background: rgba(255, 255, 255, .08);
    font: inherit;
}

button, .download { padding: 8px 12px; cursor: pointer; }
button:hover, button:focus-visible, button.active { background: var(--orange); border-color: var(--orange); }
button:disabled { cursor: default; opacity: .35; }
.download { background: var(--orange); border-color: var(--orange); font-weight: 700; text-decoration: none; }
.download:hover, .download:focus-visible { background: #dd6814; }

.page-control {
    padding: 3px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#page-number {
    width: 52px;
    padding: 5px;
    border: 0;
    border-radius: 5px;
    color: #fff;
    background: rgba(0, 0, 0, .25);
    font: inherit;
    text-align: center;
}

#zoom-value { min-width: 54px; text-align: center; font-size: 13px; }

#viewer {
    position: fixed;
    inset: var(--toolbar-height) 0 0;
    overflow: auto;
    padding: 24px;
    text-align: center;
    overscroll-behavior: contain;
}

#pdf-canvas {
    display: block;
    margin: 0 auto 24px;
    background: #fff;
    box-shadow: 0 8px 35px rgba(0, 0, 0, .5);
}

.message {
    width: min(480px, calc(100% - 32px));
    margin: 16vh auto 0;
    padding: 28px;
    border-radius: 16px;
    background: var(--dark);
    box-shadow: 0 10px 35px rgba(0, 0, 0, .35);
}

.message[hidden], #pdf-canvas[hidden] { display: none; }
.message h2 { margin-top: 0; }
.message a { color: #fff; font-weight: 700; }
.error { border: 1px solid var(--orange); }

.spinner {
    width: 44px;
    height: 44px;
    display: inline-block;
    border: 4px solid rgba(255, 255, 255, .25);
    border-top-color: var(--orange);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.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;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
    :root { --toolbar-height: 122px; }
    .toolbar { grid-template-columns: auto 1fr; gap: 8px 12px; }
    h1 { text-align: right; }
    .controls { grid-column: 1 / -1; justify-content: center; }
}

@media (max-width: 620px) {
    :root { --toolbar-height: 154px; }
    .toolbar { padding: max(8px, env(safe-area-inset-top)) 8px 8px; }
    .brand-text, #zoom-value { display: none; }
    h1 { font-size: 14px; }
    .controls { flex-wrap: wrap; gap: 5px; }
    button, .download { min-height: 38px; padding: 7px 10px; }
    #fit-width { display: none; }
    #viewer { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 1.8s; }
}
