:root {
    --bg: #f4efe6;
    --paper: #fffaf2;
    --paper-strong: #fff;
    --ink: #1f2933;
    --muted: #5f6c7b;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --border: #d7c9b6;
    --shadow: 0 20px 50px rgba(61, 43, 16, 0.08);
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Manrope", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.15), transparent 28%),
        linear-gradient(180deg, #f9f3e8 0%, #efe5d4 100%);
    min-height: 100vh;
}

html,
body,
.button,
.input,
.textarea,
.select select,
.content,
.title,
.subtitle,
p,
li,
label,
small {
    color: var(--ink);
}

body.reader-page {
    background: linear-gradient(180deg, #f8efe1 0%, #f3e8d4 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

.page-shell {
    width: min(1180px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.2rem 0 3rem;
}

.reader-shell-page {
    width: 100%;
    max-width: none;
    padding: 0;
}

body.reader-page .site-header,
body.reader-page .flash-stack {
    display: none;
}

.site-header,
.hero-actions,
.section-head,
.history-card-head,
.tag-row,
.result-head,
.result-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-header {
    padding: 1rem 0 2rem;
}

.brand,
h1,
h2 {
    font-family: "Fraunces", serif;
}

.brand {
    font-size: 1.2rem;
    font-weight: 700;
}

.app-navbar {
    background: rgba(255, 250, 242, 0.72);
    border: 1px solid rgba(215, 201, 182, 0.85);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 0.25rem 0.55rem;
    backdrop-filter: blur(12px);
}

.app-navbar .navbar-brand,
.app-navbar .navbar-end {
    align-items: center;
}

.app-navbar .navbar-item,
.app-navbar .navbar-link,
.app-navbar .navbar-burger {
    color: var(--ink);
}

.app-navbar .navbar-item:hover,
.app-navbar .navbar-link:hover {
    background: rgba(15, 118, 110, 0.08);
    color: var(--accent-dark);
}

.app-navbar .navbar-menu {
    background: transparent;
    box-shadow: none;
}

.app-navbar .navbar-burger {
    height: auto;
    width: auto;
    margin-left: auto;
    padding: 0.7rem;
}

.app-navbar .navbar-burger:hover {
    background: rgba(15, 118, 110, 0.08);
}

.app-navbar .navbar-item form {
    margin: 0;
}

.primary-btn,
.ghost-btn,
button {
    border: 0;
    border-radius: 999px;
    padding: 0.9rem 1.3rem;
    font: inherit;
    cursor: pointer;
}

.inline-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
}

.primary-btn {
    background: var(--accent);
    color: white;
}

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

.ghost-btn {
    background: rgba(255, 250, 242, 0.75);
    color: var(--ink);
    border: 1px solid var(--border);
}

.hero,
.dashboard-grid,
.result-grid {
    display: grid;
    gap: 1.5rem;
}

.hero {
    grid-template-columns: minmax(0, 760px);
    align-items: stretch;
    padding: 1.6rem 0 1rem;
}

.hero > div {
    display: grid;
    gap: 1.1rem;
    align-content: start;
}

.sample-card {
    margin-top: 1.5rem;
}

.social-proof {
    margin-top: 1.5rem;
}

.sample-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
}

.testimonial-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.testimonial-card {
    display: grid;
    gap: 1rem;
    padding: 1.1rem;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.48);
}

.testimonial-head {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 118, 110, 0.14);
    color: var(--accent-dark);
    font-weight: 700;
}

.rating-stars {
    margin-top: 0.2rem;
    color: #b7791f;
    letter-spacing: 0.04em;
}

.sample-grid h3 {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

.hero h1,
.dashboard-grid h1,
.result-head h1,
.history-head h1 {
    font-size: clamp(2.2rem, 5vw, 4.2rem);
    line-height: 0.95;
    margin: 0.3rem 0 1rem;
}

#hero-problem {
    min-height: 2.1em;
    margin: 0;
    color: var(--ink);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

#hero-problem.headline-fade {
    opacity: 0.18;
    transform: translateY(6px);
}

.hero-copy,
.panel-note,
label span,
small,
.flash {
    color: var(--muted);
}

.hero-copy {
    max-width: 44rem;
    margin: 0;
    font-size: 1.08rem;
    line-height: 1.7;
    color: var(--ink);
}

.hero-actions {
    align-items: center;
    flex-wrap: wrap;
    padding-top: 0.35rem;
}

.hero-panel,
.card {
    background: rgba(255, 250, 242, 0.82);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(215, 201, 182, 0.85);
    border-radius: 28px;
    box-shadow: var(--shadow);
}

.hero-panel,
.card,
.flash {
    padding: 1.4rem;
}

.feature-list,
.history-preview {
    padding-left: 1.2rem;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.76rem;
    color: var(--accent-dark);
    margin: 0 0 0.15rem;
}

.dashboard-grid {
    grid-template-columns: 1.6fr 0.9fr;
}

.shelf-layout {
    align-items: start;
}

.shelf-head {
    align-items: flex-start;
    margin-bottom: 1rem;
}

.reader-form,
.feedback-form,
.option-grid,
.history-list {
    display: grid;
    gap: 1rem;
}

.library-card,
.reader-shell {
    margin-top: 1.5rem;
}

.shelf-primary {
    margin-top: 0;
}

.shelf-callout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1rem 0 1.4rem;
    padding: 1rem 1.1rem;
    border: 1px dashed var(--border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.32);
}

.shelf-callout h2,
.empty-shelf h2 {
    margin: 0.2rem 0 0.35rem;
}

.empty-shelf {
    display: grid;
    gap: 0.35rem;
    padding: 1.4rem 0 0.25rem;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.book-card {
    display: grid;
    gap: 0.85rem;
    padding: 1rem;
    border: 1px solid rgba(215, 201, 182, 0.82);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.4);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.book-card:hover {
    transform: translateY(-2px);
    border-color: rgba(15, 118, 110, 0.28);
    box-shadow: 0 14px 34px rgba(31, 41, 51, 0.08);
}

.book-card h3,
.mini-result-card h3 {
    margin: 0 0 0.35rem;
}

.book-card h3 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}

.book-card-cover {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    background: rgba(15, 118, 110, 0.12);
    color: var(--accent-dark);
    font-family: "Fraunces", serif;
    font-size: 1.1rem;
    font-weight: 700;
}

.book-card-body p {
    margin: 0;
    color: var(--muted);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}

.book-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    color: var(--accent-dark);
    font-size: 0.88rem;
    font-weight: 600;
}

.shelf-sidecard {
    margin-top: 0;
}

.reader-shell {
    display: grid;
    place-items: center;
    min-height: 100dvh;
}

.reader-notes-section {
    width: min(100%, 760px);
    margin-inline: auto;
    margin-top: 1.5rem;
}

.reader-notes-list {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

.reader-note-card {
    display: grid;
    gap: 0.9rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.reader-note-card:first-child {
    padding-top: 0.2rem;
}

.reader-note-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.86rem;
}

.reader-note-selection {
    padding: 0.9rem 1rem;
    border: 1px dashed var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.36);
    white-space: pre-wrap;
}

.reader-note-results {
    display: grid;
    gap: 0.8rem;
}

.reader-note-result {
    padding: 0.95rem 1rem;
    border: 1px solid rgba(215, 201, 182, 0.8);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.5);
}

.reader-note-result h3 {
    margin: 0 0 0.45rem;
}

.reader-note-result p {
    margin: 0;
}

.reader-notes-empty {
    margin-top: 1rem;
}

.reader-stage {
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    gap: 0.45rem;
    width: min(100%, 760px);
    min-height: 100dvh;
    height: 100dvh;
    padding: 0.3rem 0;
    overflow: hidden;
}

.reader-head,
.reader-head-actions,
.reader-sidepanel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.reader-head-actions {
    flex-wrap: wrap;
}

.reader-head {
    align-items: center;
    gap: 0.7rem;
}

.reader-head h1 {
    margin: 0;
    font-size: clamp(1rem, 2.1vw, 1.28rem);
    line-height: 1.1;
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0 0 0.15rem;
}

.reader-meta-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.page-indicator {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    text-align: right;
}

.font-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.18rem 0.24rem;
    border: 1px solid rgba(215, 201, 182, 0.9);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.42);
}

.font-btn {
    padding: 0.38rem 0.62rem;
    min-width: auto;
}

.font-label {
    min-width: 3rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
}

.epub-reader {
    min-height: 0;
    height: auto;
    width: 100%;
    align-self: stretch;
    border: 0;
    border-radius: 18px;
    background: #fffdf9;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.epub-reader:focus {
    outline: 2px solid rgba(15, 118, 110, 0.45);
    outline-offset: 4px;
}

.nav-arrow,
.nav-pill {
    min-width: 0;
    padding: 0.65rem 0.9rem;
}

.reader-back,
.reader-first {
    padding: 0.45rem 0.78rem;
    border-radius: 999px;
    background: transparent;
    border: 1px solid rgba(215, 201, 182, 0.9);
    color: var(--muted);
}

.reader-back:hover,
.reader-first:hover {
    background: rgba(255, 255, 255, 0.5);
    color: var(--ink);
}

.nav-arrow {
    flex: 1 1 0;
    font-size: 1.15rem;
    line-height: 1;
}

.selection-flyout {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%);
    width: min(760px, calc(100% - 1.5rem));
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    width: auto;
    z-index: 25;
}

.selection-chip {
    padding: 0.85rem 1.05rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(15, 118, 110, 0.96);
    box-shadow: var(--shadow);
}

.analysis-popover {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.analysis-popover-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(31, 41, 51, 0.34);
    backdrop-filter: blur(5px);
}

.analysis-popover-card {
    position: relative;
    width: min(760px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: auto;
}

.analysis-options {
    display: grid;
    gap: 0.9rem;
    margin-top: 1rem;
}

.analysis-loader {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-top: 1rem;
    color: var(--accent-dark);
}

.popover-preview {
    min-height: auto;
}

body.popover-open {
    overflow: hidden;
}

.selection-preview,
.selection-status,
.reader-status,
.mini-result-card {
    margin-top: 1rem;
}

.selection-preview {
    border: 1px dashed var(--border);
    border-radius: 20px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.35);
    color: var(--ink);
    min-height: 110px;
}

.selection-status {
    color: var(--accent-dark);
    min-height: 1.5rem;
}

.reader-status {
    color: var(--muted);
    display: none;
}

body.reader-page main {
    min-height: 100dvh;
    display: grid;
}

.result-stack {
    display: grid;
    gap: 1rem;
}

.mini-result-card {
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.45);
}

.submit-bar {
    display: flex;
    justify-content: flex-start;
}

.submit-btn {
    min-width: 220px;
}

label,
fieldset {
    display: grid;
    gap: 0.45rem;
}

input[type="text"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--paper-strong);
    border-radius: 18px;
    padding: 1rem;
    font: inherit;
    color: var(--ink);
}

select:disabled {
    opacity: 0.62;
    cursor: not-allowed;
    background: rgba(215, 201, 182, 0.24);
}

textarea {
    resize: vertical;
    min-height: 220px;
}

fieldset {
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem;
}

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

.checkbox-row {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.75rem;
}

.inline-field {
    display: none;
    grid-column: 1 / -1;
}

.inline-field.visible {
    display: grid;
}

.usage-pill,
.tag-row span {
    background: rgba(15, 118, 110, 0.12);
    color: var(--accent-dark);
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    font-size: 0.92rem;
}

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

.full-width {
    grid-column: 1 / -1;
}

.word-table {
    display: grid;
    gap: 0.8rem;
}

.word-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}

.history-list {
    margin-top: 1.5rem;
}

.flash-stack {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.flash {
    border-radius: 16px;
    background: rgba(255, 250, 242, 0.84);
    border: 1px solid var(--border);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.flash-dismiss {
    opacity: 0;
    transform: translateY(-8px);
}

.flash-error {
    color: var(--danger);
}

.warning {
    color: var(--danger);
}

.loader-overlay {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    padding: 1.5rem;
    background: rgba(31, 41, 51, 0.28);
    backdrop-filter: blur(6px);
    z-index: 20;
}

.loader-overlay.active {
    display: grid;
}

.loader-card {
    width: min(520px, 100%);
    background: rgba(255, 250, 242, 0.96);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 1.6rem;
    box-shadow: var(--shadow);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid rgba(15, 118, 110, 0.18);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
    margin-bottom: 1rem;
}

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

@media (max-width: 900px) {
    .hero,
    .dashboard-grid,
    .result-grid,
    .option-grid,
    .sample-grid,
    .testimonial-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        padding-top: 1.4rem;
    }

    .hero > div {
        gap: 0.9rem;
    }

    .hero-copy {
        font-size: 1rem;
        line-height: 1.65;
    }

    .site-header,
    .section-head,
    .result-head,
    .history-card-head,
    .result-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .app-navbar {
        padding: 0.2rem 0.35rem;
    }

    .app-navbar .navbar-menu {
        padding-top: 0.35rem;
    }

    .app-navbar .navbar-end {
        align-items: flex-end;
        margin-left: auto;
    }

    .app-navbar .navbar-item {
        width: 100%;
        justify-content: flex-end;
        text-align: right;
    }

    .app-navbar .navbar-item form,
    .app-navbar .navbar-item .ghost-btn,
    .app-navbar .navbar-item .primary-btn {
        width: 100%;
    }

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

    .page-shell {
        width: min(100% - 1rem, 1180px);
        padding-top: 0.4rem;
        padding-bottom: 4rem;
    }

    .card,
    .flash {
        padding: 1.1rem;
        border-radius: 22px;
    }

    .submit-bar {
        position: sticky;
        bottom: 0.75rem;
        padding-top: 0.4rem;
        background: linear-gradient(180deg, rgba(249, 243, 232, 0), rgba(249, 243, 232, 0.95) 40%);
    }

    .submit-btn,
    .result-actions .ghost-btn {
        width: 100%;
        justify-content: center;
    }

    .book-card,
    .reader-head,
    .reader-sidepanel-head,
    .reader-head-actions,
    .book-meta {
        align-items: flex-start;
        flex-direction: column;
    }

    .reader-meta {
        align-items: center;
        flex-direction: row;
        gap: 0.45rem;
        padding: 0;
    }

    .reader-meta-left {
        gap: 0.45rem;
        flex-wrap: wrap;
    }

    .reader-meta .ghost-btn {
        flex: 0 0 auto;
        padding: 0.45rem 0.75rem;
        font-size: 0.92rem;
    }

    .shelf-callout {
        flex-direction: column;
        align-items: stretch;
    }

    .selection-flyout {
        bottom: 1rem;
    }

    .selection-flyout .primary-btn {
        width: 100%;
    }

    .epub-reader {
        min-height: 0;
        height: auto;
        border-radius: 14px;
        border-color: rgba(215, 201, 182, 0.45);
        background: #fff;
    }

    .reader-shell {
        margin-top: 0;
        min-height: 100dvh;
    }

    .reader-note-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .reader-stage {
        width: min(100%, 680px);
        min-height: 100dvh;
        height: 100dvh;
        gap: 0.4rem;
        padding: 0.2rem 0.35rem calc(0.35rem + env(safe-area-inset-bottom));
        border-radius: 0;
        background: transparent;
        overflow: hidden;
    }

    .reader-head {
        gap: 0.45rem;
        align-items: center;
        flex-direction: row;
    }

    .reader-head h1 {
        font-size: 0.95rem;
        line-height: 1.08;
    }

    .reader-status {
        margin-top: 0.2rem;
        font-size: 0.88rem;
    }

    .page-indicator {
        font-size: 0.76rem;
        line-height: 1.25;
    }

    .reader-back,
    .reader-first {
        padding: 0.38rem 0.68rem;
        font-size: 0.82rem;
    }

    .font-controls {
        padding: 0.12rem 0.16rem;
    }

    .font-btn {
        padding: 0.32rem 0.52rem;
        font-size: 0.8rem;
    }

    .font-label {
        min-width: 2.7rem;
        font-size: 0.74rem;
    }
}

@media (max-width: 640px) {
    .page-shell {
        width: calc(100% - 0.5rem);
        padding-top: 0.25rem;
        padding-bottom: 3rem;
    }

    .site-header {
        padding: 0.35rem;
        gap: 0.5rem;
    }

    .brand {
        font-size: 1.05rem;
    }

    .card,
    .flash {
        padding: 0.95rem;
        border-radius: 18px;
    }

    .hero,
    .dashboard-grid,
    .result-grid {
        gap: 1rem;
    }

    .hero h1,
    .dashboard-grid h1,
    .result-head h1,
    .history-head h1 {
        font-size: clamp(1.8rem, 8vw, 2.45rem);
        line-height: 0.98;
        margin: 0.15rem 0 0.75rem;
    }

    .hero-copy {
        font-size: 0.95rem;
        line-height: 1.55;
    }

    .section-head {
        gap: 0.7rem;
    }

    .shelf-head {
        margin-bottom: 0.85rem;
    }

    .book-card {
        gap: 0.75rem;
        padding: 0.8rem 0;
    }

    .book-meta {
        width: 100%;
        gap: 0.55rem;
    }

    .book-meta .ghost-btn {
        width: 100%;
        justify-content: center;
    }

    .shelf-callout {
        margin: 0.75rem 0 1rem;
        padding: 0.9rem;
        gap: 0.75rem;
        border-radius: 18px;
    }

    .feature-list,
    .history-preview {
        padding-left: 1rem;
    }
}
