:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --panel: #ffffff;
    --text: #14202e;
    --muted: #5f6d7c;
    --line: #d9e0e8;
    --primary: #1f7a7a;
    --primary-dark: #155f61;
    --secondary: #8f4f2a;
    --accent: #d66a3f;
    --success-bg: #e7f6ee;
    --success-text: #17633a;
    --error-bg: #fde9e7;
    --error-text: #9b2f24;
    --shadow: 0 16px 40px rgba(20, 32, 46, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 16px clamp(18px, 4vw, 48px);
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--text);
    color: #fff;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: var(--muted);
    font-size: 13px;
}

.topnav,
.logout-form {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topnav a:not(.button) {
    color: var(--muted);
    text-decoration: none;
    font-weight: 700;
}

.page {
    width: min(1180px, calc(100% - 36px));
    margin: 0 auto;
    padding: 34px 0 64px;
}

.hero,
.page-heading,
.reader-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.hero {
    min-height: 220px;
    align-items: center;
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(31, 122, 122, 0.12), transparent 48%),
        linear-gradient(315deg, rgba(214, 106, 63, 0.14), transparent 44%),
        #fff;
    box-shadow: var(--shadow);
}

.hero h1,
.page-heading h1,
.reader-heading h1 {
    margin: 0;
    max-width: 780px;
    font-size: clamp(32px, 5vw, 58px);
    line-height: 1.02;
    letter-spacing: 0;
}

.reader-heading h1 {
    font-size: clamp(28px, 4vw, 46px);
}

.hero p,
.reader-heading p {
    max-width: 660px;
    color: var(--muted);
    font-size: 18px;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button.primary {
    background: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.secondary {
    background: var(--secondary);
    color: #fff;
}

.button.ghost {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.button.full {
    width: 100%;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

.install-button[hidden] {
    display: none;
}

.notice {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.notice.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.notice.error {
    background: var(--error-bg);
    color: var(--error-text);
}

.search-panel {
    margin: 0 0 22px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.search-form {
    display: grid;
    gap: 8px;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: center;
}

.result-summary {
    margin: 0 0 14px;
    color: var(--muted);
    font-weight: 800;
}

.auth-card,
.panel,
.empty-state {
    max-width: 560px;
    margin: 52px auto;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.panel {
    max-width: none;
    margin: 0;
}

.panel.narrow {
    max-width: 720px;
    margin: 0;
}

.auth-card h1,
.empty-state h2,
.panel h2,
.side-panel h2 {
    margin-top: 0;
}

.auth-card p,
.empty-state p,
.help,
.muted,
.info-box p {
    color: var(--muted);
}

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

label {
    display: grid;
    gap: 7px;
    font-weight: 800;
}

input,
textarea,
select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: 3px solid rgba(31, 122, 122, 0.22);
    border-color: var(--primary);
}

.help {
    font-size: 13px;
    font-weight: 400;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.document-tile a {
    display: grid;
    min-height: 240px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
    text-decoration: none;
}

.document-tile a:hover {
    border-color: rgba(31, 122, 122, 0.5);
    transform: translateY(-2px);
}

.document-tile h2 {
    margin: 16px 0 8px;
    font-size: 22px;
    line-height: 1.18;
}

.document-tile p {
    margin: 0;
    color: var(--muted);
}

.tile-topline,
.tile-meta,
.meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.tile-meta {
    align-self: end;
    justify-content: space-between;
    margin-top: 18px;
}

.file-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 8px;
    background: #eef6f6;
    color: var(--primary-dark);
}

.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--primary-dark);
    font-weight: 800;
    text-decoration: none;
}

.reader-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}

.pdf-panel,
.side-panel,
.tts-box,
.info-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.pdf-panel {
    min-height: 720px;
    overflow: hidden;
}

.pdf-frame {
    width: 100%;
    height: 720px;
    border: 0;
}

.side-panel {
    display: grid;
    gap: 0;
    overflow: hidden;
}

.tts-box,
.info-box {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 20px;
}

.tts-box {
    border-bottom: 1px solid var(--line);
}

.tts-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 16px 0;
}

.compact-label {
    margin-top: 14px;
    font-size: 14px;
}

.text-panel {
    margin-top: 18px;
}

.document-text {
    max-height: 520px;
    overflow: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    color: #243244;
    white-space: pre-wrap;
    word-break: break-word;
    font: 15px/1.6 Consolas, Monaco, monospace;
}

.empty-text {
    color: var(--muted);
}

code {
    padding: 2px 5px;
    border-radius: 6px;
    background: #eef2f6;
}

@media (max-width: 860px) {
    .topbar,
    .topnav,
    .hero,
    .page-heading,
    .reader-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .topnav,
    .logout-form {
        width: 100%;
    }

    .topnav .button,
    .logout-form .button {
        width: 100%;
    }

    .hero {
        min-height: 0;
        padding: 24px;
    }

    .reader-grid {
        grid-template-columns: 1fr;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    .pdf-panel,
    .pdf-frame {
        min-height: 520px;
        height: 520px;
    }
}

@media (max-width: 520px) {
    .page {
        width: min(100% - 24px, 1180px);
        padding-top: 22px;
    }

    .auth-card,
    .panel,
    .empty-state {
        padding: 20px;
    }

    .hero h1,
    .page-heading h1,
    .reader-heading h1 {
        font-size: 30px;
    }

    .tts-controls {
        grid-template-columns: 1fr;
    }
}
