:root {
    color-scheme: light;
    --page: #f4f6fb;
    --surface: rgb(255 255 255 / 94%);
    --surface-solid: #ffffff;
    --border: #e0e6f0;
    --text: #182238;
    --muted: #67748a;
    --primary: #4666d8;
    --primary-soft: #eef1ff;
    --primary-ring: rgb(70 102 216 / 30%);
    --shadow: 0 16px 42px rgb(34 52 85 / 10%);
    --ease: 180ms cubic-bezier(.2, .8, .2, 1);
}

html[data-theme='dark'] {
    color-scheme: dark;
    --page: #0d1320;
    --surface: rgb(21 29 45 / 94%);
    --surface-solid: #151d2d;
    --border: #2b3951;
    --text: #edf3ff;
    --muted: #aab7cb;
    --primary: #93a8ff;
    --primary-soft: #202b57;
    --primary-ring: rgb(147 168 255 / 34%);
    --shadow: 0 20px 48px rgb(0 0 0 / 27%);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-width: 320px;
    min-height: 100%;
    margin: 0;
}

body {
    color: var(--text);
    background:
        radial-gradient(50rem 30rem at 15% -18%, color-mix(in srgb, var(--primary) 13%, transparent), transparent 70%),
        var(--page);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
}

svg {
    display: block;
}

.grammar-reader {
    width: min(100%, 1500px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 18px 24px 36px;
}

.reader-toolbar {
    position: sticky;
    z-index: 1;
    top: 12px;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(0, 2fr) minmax(150px, 1fr);
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 8px 22px rgb(34 52 85 / 7%);
    backdrop-filter: blur(14px);
}

.reader-back {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: 6px;
    min-height: 36px;
    padding: 0 9px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 750;
    text-decoration: none;
    transition: color var(--ease), background-color var(--ease);
}

.reader-back:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

.reader-back:focus-visible,
.reader-control:focus-visible,
.page-field input:focus-visible,
.pdf-stage:focus-visible {
    outline: 3px solid var(--primary-ring);
    outline-offset: 3px;
}

.reader-back svg,
.reader-control svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.9;
}

.reader-title-group {
    min-width: 0;
    text-align: center;
}

.reader-title-group p {
    margin: 0 0 1px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.reader-title-group h1 {
    overflow: hidden;
    margin: 0;
    color: var(--text);
    font-size: 0.93rem;
    letter-spacing: -0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.reader-control {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--primary);
    background: var(--surface-solid);
    cursor: pointer;
    transition: border-color var(--ease), background-color var(--ease), transform var(--ease);
}

.reader-control:hover:not(:disabled) {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
    background: var(--primary-soft);
}

.reader-control:active:not(:disabled) {
    transform: translateY(1px);
}

.reader-control:disabled {
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.page-field input {
    width: 48px;
    min-height: 36px;
    padding: 0 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface-solid);
    font-size: 0.84rem;
    font-weight: 750;
    text-align: center;
}

.page-field input:disabled {
    color: var(--muted);
    opacity: 0.65;
}

.page-count {
    min-width: 42px;
    color: var(--muted);
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.reader-status {
    min-height: 1.5em;
    margin: 15px 0 10px;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
}

.pdf-stage {
    display: grid;
    min-height: calc(100vh - 138px);
    place-items: start center;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface-solid) 42%, transparent);
}

#pdf-canvas {
    max-width: 100%;
    height: auto;
    background: #ffffff;
    box-shadow: var(--shadow);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    clip-path: inset(50%);
}

@media (max-width: 720px) {
    .grammar-reader {
        padding: 10px 10px 24px;
    }

    .reader-toolbar {
        grid-template-columns: 1fr auto;
        gap: 8px 12px;
        border-radius: 15px;
    }

    .reader-title-group {
        order: 3;
        grid-column: 1 / -1;
        padding: 2px 4px 5px;
        text-align: left;
    }

    .reader-controls {
        justify-self: end;
    }

    .pdf-stage {
        min-height: calc(100vh - 164px);
        padding: 8px;
        border-radius: 15px;
    }
}

@media (max-width: 410px) {
    .reader-back span {
        display: none;
    }

    .reader-back {
        padding: 0 6px;
    }

    .reader-toolbar {
        padding: 8px;
    }
}
