:root {
    color-scheme: light;
    --ink: #17243d;
    --ink-soft: #52627e;
    --ink-faint: #73829d;
    --blue: #2467dd;
    --blue-deep: #1352c2;
    --line: rgba(255, 255, 255, 0.82);
    --glass: rgba(255, 255, 255, 0.43);
    --glass-bright: rgba(255, 255, 255, 0.68);
    --glass-shadow: 0 16px 42px rgba(47, 69, 116, 0.11), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    color: var(--ink);
    background: linear-gradient(155deg, #e7f0ff 0%, #f3f5fd 48%, #f8f1eb 100%);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body::before,
body::after {
    position: fixed;
    z-index: 0;
    width: 80vw;
    height: 58vh;
    border-radius: 50%;
    content: "";
    pointer-events: none;
    filter: blur(44px);
}

body::before {
    top: -20vh;
    left: -22vw;
    background: radial-gradient(ellipse, rgba(118, 176, 255, 0.42), transparent 69%);
}

body::after {
    right: -24vw;
    bottom: -24vh;
    background: radial-gradient(ellipse, rgba(255, 185, 142, 0.37), transparent 68%);
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 3px solid rgba(36, 103, 221, 0.48);
    outline-offset: 3px;
}

.icon-library {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.icon {
    display: inline-block;
    width: 19px;
    height: 19px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

.container {
    position: relative;
    z-index: 1;
    width: min(100%, 760px);
    min-height: 100vh;
    margin: 0 auto;
    padding: calc(max(28px, env(safe-area-inset-top)) + 20px) 20px calc(154px + env(safe-area-inset-bottom));
}

.container.blurred {
    filter: blur(7px);
    pointer-events: none;
    user-select: none;
}

.eyebrow {
    display: block;
    color: var(--blue-deep);
    font-size: 11px;
    font-weight: 760;
    letter-spacing: 0.16em;
    line-height: 1.4;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
}

.header-copy { min-width: 0; }

h1 {
    margin: 8px 0 7px;
    font-size: clamp(38px, 7vw, 48px);
    font-weight: 780;
    letter-spacing: -0.055em;
    line-height: 1.03;
}

.title-dot { color: var(--blue); }

.library-summary {
    margin: 0;
    color: var(--ink-soft);
    font-size: 14px;
    line-height: 1.45;
}

.logout,
#search-close,
.notes-back {
    flex: none;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.45);
    color: var(--ink-soft);
    box-shadow: 0 5px 18px rgba(58, 79, 121, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    cursor: pointer;
    font-size: 13px;
    font-weight: 650;
}

.logout { margin-top: 8px; padding: 10px 14px; }
.logout:hover, #search-close:hover, .notes-back:hover { background: rgba(255, 255, 255, 0.7); }

.segmented {
    position: relative;
    display: flex;
    width: min(100%, 400px);
    margin: 0 0 27px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.68);
    border-radius: 20px;
    background: rgba(227, 236, 250, 0.52);
    box-shadow: inset 0 1px 3px rgba(59, 83, 129, 0.07), 0 8px 24px rgba(59, 83, 129, 0.06);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.seg-thumb {
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 5px;
    width: calc(50% - 5px);
    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: 15px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(246, 250, 255, 0.74));
    box-shadow: 0 5px 15px rgba(44, 78, 143, 0.14), inset 0 1px 0 #fff;
    transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
    pointer-events: none;
}

.segmented.right .seg-thumb { transform: translateX(100%); }

.segmented button {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 9px;
    border: 0;
    border-radius: 15px;
    background: transparent;
    color: var(--blue-deep);
    cursor: pointer;
    font-size: 14px;
    font-weight: 690;
    transition: color 200ms ease;
}

.segmented button.inactive { color: var(--ink-faint); }
.segmented .icon { width: 18px; height: 18px; }

.view.hidden, .error.hidden, .login-overlay.hidden, .search-results.hidden,
#library-screen.hidden, .notes-screen.hidden { display: none; }

.empty-state {
    position: relative;
    display: flex;
    min-height: 365px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 34px 24px 40px;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.29) 72%, rgba(244, 249, 255, 0.46));
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(30px) saturate(170%);
    -webkit-backdrop-filter: blur(30px) saturate(170%);
    text-align: center;
}

.empty-state::before,
.card::before,
.login-card::before {
    position: absolute;
    top: 0;
    right: 14%;
    left: 14%;
    height: 1px;
    background: linear-gradient(90deg, transparent, #fff, transparent);
    content: "";
    pointer-events: none;
}

.empty-art {
    position: relative;
    display: grid;
    width: 116px;
    height: 116px;
    margin-bottom: 22px;
    place-items: center;
}

.empty-art-glow {
    position: absolute;
    inset: 0;
    border-radius: 36px;
    background: radial-gradient(circle at 24% 20%, rgba(255, 255, 255, 0.95), rgba(174, 205, 255, 0.66) 54%, rgba(178, 173, 255, 0.4));
    box-shadow: 0 20px 36px rgba(60, 110, 199, 0.18), inset 0 1px 1px #fff;
    transform: rotate(-8deg);
}

.empty-art-mark {
    position: relative;
    display: grid;
    width: 72px;
    height: 72px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.86);
    border-radius: 23px;
    background: rgba(255, 255, 255, 0.48);
    box-shadow: inset 0 1px 0 #fff, 0 10px 25px rgba(51, 91, 161, 0.11);
    color: var(--blue-deep);
    transform: rotate(6deg);
}

.empty-art-mark .icon { width: 38px; height: 38px; stroke-width: 1.45; }

.empty-state h2 {
    margin: 0 0 8px;
    font-size: clamp(21px, 5vw, 26px);
    font-weight: 740;
    letter-spacing: -0.035em;
}

.empty-state p {
    max-width: 330px;
    margin: 0 0 22px;
    color: var(--ink-soft);
    font-size: 14px;
    line-height: 1.55;
}

.card {
    position: relative;
    display: flex;
    gap: 16px;
    overflow: hidden;
    margin-bottom: 12px;
    padding: 17px;
    border: 1px solid var(--line);
    border-radius: 25px;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.73), rgba(255, 255, 255, 0.37) 74%, rgba(246, 250, 255, 0.48));
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(26px) saturate(175%);
    -webkit-backdrop-filter: blur(26px) saturate(175%);
}

.cover {
    width: 76px;
    height: 108px;
    flex: none;
    border-radius: 13px;
    background: linear-gradient(145deg, #9bc4ff, #c0b9f5);
    box-shadow: 0 10px 20px rgba(45, 64, 109, 0.19), 0 0 0 1px rgba(255, 255, 255, 0.65);
    object-fit: cover;
}

.cover-placeholder {
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.88);
}

.cover-placeholder .icon { width: 34px; height: 34px; stroke-width: 1.3; }

.card-body { flex: 1; min-width: 0; padding-top: 1px; }
.title { margin-bottom: 4px; font-size: 16px; font-weight: 710; letter-spacing: -0.018em; line-height: 1.28; overflow-wrap: anywhere; }
.meta { color: var(--ink-soft); font-size: 13px; line-height: 1.42; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }

.btn {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid rgba(255, 255, 255, 0.66);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.5);
    color: var(--ink);
    cursor: pointer;
    font-size: 13px;
    font-weight: 670;
    line-height: 1.2;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86), 0 4px 10px rgba(50, 70, 116, 0.06);
    transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.btn-primary {
    border-color: rgba(82, 148, 249, 0.56);
    background: linear-gradient(155deg, #4b98ff 0%, #2674e8 56%, #155bcf 100%);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42), 0 7px 16px rgba(35, 104, 214, 0.25);
}
.btn-primary:hover { background: linear-gradient(155deg, #58a1ff, #216ee1 70%, #1555c7); }
.btn-secondary { background: rgba(255, 255, 255, 0.55); color: var(--ink); }
.btn-secondary:hover { background: rgba(255, 255, 255, 0.82); }
.btn-danger { background: rgba(249, 231, 230, 0.6); color: #b34b51; }
.btn-icon { width: 40px; padding: 8px; }
.btn-block { width: 100%; min-height: 48px; font-size: 15px; }
.empty-action { padding: 11px 16px; border-radius: 14px; }

.stars { display: flex; align-items: center; gap: 3px; margin: 9px 0 0; }
.star {
    padding: 0 1px;
    border: 0;
    background: none;
    color: rgba(68, 89, 129, 0.25);
    cursor: pointer;
    font-size: 21px;
    line-height: 1.1;
    transition: color 160ms ease, transform 160ms ease;
}
.star:hover { transform: scale(1.13); }
.star.filled { color: #eea53f; text-shadow: 0 2px 9px rgba(238, 165, 63, 0.24); }
.rating-text { margin-left: 7px; color: var(--ink-faint); font-size: 12px; }

/* A read book's notes open as a full page within the library. */
body.notes-open .searchdock { display: none; }
.notes-screen { padding-bottom: 18px; }
.notes-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 43px;
    margin-bottom: 28px;
    padding: 9px 15px;
    color: var(--blue-deep);
}
.notes-back .icon { width: 18px; height: 18px; }
.notes-book-head,
.notes-editor {
    border: 1px solid var(--line);
    border-radius: 28px;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.77), rgba(255, 255, 255, 0.4) 80%, rgba(243, 248, 255, 0.57));
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(26px) saturate(175%);
    -webkit-backdrop-filter: blur(26px) saturate(175%);
}
.notes-book-head {
    display: flex;
    align-items: flex-start;
    gap: 22px;
    margin-bottom: 18px;
    padding: 24px;
}
.notes-cover {
    width: 112px;
    height: 160px;
    flex: none;
    border-radius: 15px;
    background: linear-gradient(145deg, #9bc4ff, #c0b9f5);
    box-shadow: 0 12px 24px rgba(45, 64, 109, 0.19), 0 0 0 1px rgba(255, 255, 255, 0.65);
    object-fit: cover;
}
.notes-book-copy { min-width: 0; padding-top: 4px; }
.notes-book-copy h1 {
    margin: 10px 0 7px;
    font-size: clamp(23px, 5.5vw, 34px);
    line-height: 1.12;
    overflow-wrap: anywhere;
}
.notes-book-copy .meta { margin: 0; font-size: 14px; }
.notes-book-copy .stars { margin-top: 17px; }
.notes-book-copy .star { font-size: 26px; }
.notes-editor { padding: 26px; }
.notes-editor-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.notes-editor h2 { margin: 5px 0 0; font-size: 26px; letter-spacing: -0.04em; }
.notes-save-status { color: var(--ink-soft); font-size: 12px; text-align: right; }
.notes-label { display: block; margin-bottom: 10px; color: var(--ink-soft); font-size: 14px; }
#notes-text {
    display: block;
    width: 100%;
    min-height: 280px;
    resize: vertical;
    padding: 18px;
    border: 1px solid rgba(169, 189, 220, 0.55);
    border-radius: 19px;
    background: rgba(255, 255, 255, 0.63);
    color: var(--ink);
    box-shadow: inset 0 1px 3px rgba(42, 65, 111, 0.06);
    font-size: 16px;
    line-height: 1.55;
}
#notes-text::placeholder { color: #8996ac; }
.notes-save { margin-top: 14px; padding: 12px 20px; }

.error {
    margin: 0 0 16px;
    padding: 12px 15px;
    border: 1px solid rgba(236, 105, 101, 0.27);
    border-radius: 15px;
    background: rgba(255, 237, 235, 0.76);
    color: #a8363c;
    font-size: 13px;
    line-height: 1.45;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* The dock floats above the library; the full search view expands from it. */
.searchdock {
    position: fixed;
    right: 0;
    bottom: var(--visual-viewport-bottom, 0px);
    left: 0;
    z-index: 50;
    display: flex;
    max-width: 760px;
    flex-direction: column;
    margin: 0 auto;
    padding: 0 18px calc(15px + env(safe-area-inset-bottom));
    pointer-events: none;
}

.searchdock > * { pointer-events: auto; }

.searchdock.keyboard-open { padding-bottom: 8px; }

.dock-fade {
    position: absolute;
    right: 0;
    bottom: 100%;
    left: 0;
    height: 100px;
    background: linear-gradient(to top, rgba(239, 243, 250, 0.86), transparent);
    pointer-events: none;
}

.search {
    display: flex;
    min-height: 65px;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 7px 8px 7px 19px;
    border: 1px solid rgba(255, 255, 255, 0.88);
    border-radius: 24px;
    background: linear-gradient(130deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.57));
    box-shadow: 0 14px 38px rgba(45, 68, 115, 0.2), inset 0 1px 0 #fff;
    backdrop-filter: blur(30px) saturate(175%);
    -webkit-backdrop-filter: blur(30px) saturate(175%);
}

.search-leading { width: 21px; height: 21px; color: #687b9c; }
.search input {
    width: 100%;
    min-width: 0;
    flex: 1;
    padding: 8px 0;
    border: 0;
    outline: 0;
    background: none;
    color: var(--ink);
    font-size: 16px;
}
.search input::placeholder { color: #8090aa; }
.search input:focus-visible { outline: 0; }
.search:focus-within { box-shadow: 0 14px 38px rgba(45, 68, 115, 0.2), 0 0 0 3px rgba(36, 103, 221, 0.23), inset 0 1px 0 #fff; }
.search button {
    display: grid;
    width: 49px;
    height: 49px;
    flex: none;
    place-items: center;
    border: 1px solid rgba(110, 164, 246, 0.75);
    border-radius: 18px;
    background: linear-gradient(155deg, #4d9dff, #1f69dd 75%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.48), 0 7px 15px rgba(33, 104, 221, 0.29);
    color: white;
    cursor: pointer;
    transition: transform 160ms ease;
}
.search button:active { transform: scale(0.94); }
.search button .icon { width: 21px; height: 21px; stroke-width: 2.3; }

.search-results { display: none; }
body.search-open { overflow: hidden; }

.searchdock.search-open {
    top: var(--visual-viewport-top, 0px);
    bottom: var(--visual-viewport-bottom, 0px);
    z-index: 90;
    width: 100%;
    max-width: none;
    padding: 0;
    background:
        radial-gradient(ellipse at 10% 0%, rgba(166, 202, 255, 0.54), transparent 48%),
        radial-gradient(ellipse at 100% 100%, rgba(255, 205, 170, 0.34), transparent 46%),
        linear-gradient(150deg, #edf4ff, #f6f7fc 55%, #f9f3ef);
    pointer-events: auto;
}

.searchdock.search-open .dock-fade { display: none; }
.searchdock.search-open .search-results {
    display: flex;
    width: min(100%, 980px);
    min-height: 0;
    flex: 1;
    flex-direction: column;
    align-self: center;
    padding: calc(max(26px, env(safe-area-inset-top)) + 20px) 20px 0;
    outline: none;
}
.searchdock.search-open .search-results.hidden { display: none; }

.search-header {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}
.search-heading { min-width: 0; }
.search-heading h2 {
    margin: 6px 0 0;
    font-size: clamp(23px, 5vw, 32px);
    font-weight: 750;
    letter-spacing: -0.045em;
    line-height: 1.13;
    overflow-wrap: anywhere;
}
#search-close { padding: 11px 18px; color: var(--blue-deep); font-size: 14px; }
#search-list {
    display: grid;
    min-height: 0;
    flex: 1;
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    align-content: start;
    gap: 2px;
    overflow-y: auto;
    padding: 1px 1px 18px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(97, 122, 160, 0.32) transparent;
}
#search-list .card { margin-bottom: 12px; }
.searchdock.search-open .search {
    width: calc(100% - 36px);
    max-width: 720px;
    flex: none;
    align-self: center;
    margin: 7px 0 calc(15px + env(safe-area-inset-bottom));
}
.searchdock.search-open.keyboard-open .search { margin-bottom: 8px; }

.empty { padding: 58px 20px; color: var(--ink-soft); text-align: center; font-size: 14px; line-height: 1.6; }

.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(230, 237, 250, 0.54);
    backdrop-filter: blur(26px) saturate(140%);
    -webkit-backdrop-filter: blur(26px) saturate(140%);
}
.login-card {
    position: relative;
    width: min(100%, 400px);
    overflow: hidden;
    padding: 34px;
    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: 30px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.57));
    box-shadow: 0 28px 70px rgba(45, 65, 113, 0.2), inset 0 1px 0 #fff;
    backdrop-filter: blur(32px) saturate(170%);
    -webkit-backdrop-filter: blur(32px) saturate(170%);
}
.brand-mark {
    display: grid;
    width: 54px;
    height: 54px;
    margin-bottom: 24px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 17px;
    background: linear-gradient(145deg, #eaf4ff, #c6dcff);
    box-shadow: 0 10px 22px rgba(46, 104, 208, 0.16), inset 0 1px 0 #fff;
    color: var(--blue-deep);
}
.brand-mark .icon { width: 27px; height: 27px; }
.login-card h2 { margin: 7px 0 8px; font-size: 29px; font-weight: 760; letter-spacing: -0.045em; line-height: 1.1; }
.login-card p { margin: 0 0 23px; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }
.login-error { margin-bottom: 16px; color: #a8363c; font-size: 13px; }
.login-error.hidden { display: none; }

@media (min-width: 850px) {
    .searchdock.search-open .search-results { padding-right: 28px; padding-left: 28px; }
    #search-list { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 14px; }
}

@media (max-width: 420px) {
    .container { padding-right: 18px; padding-left: 18px; }
    .page-header { gap: 8px; }
    .logout { padding: 9px 11px; font-size: 12px; }
    .card { gap: 14px; padding: 14px; border-radius: 23px; }
    .cover { width: 72px; height: 104px; }
    .notes-book-head { gap: 15px; padding: 18px; }
    .notes-cover { width: 88px; height: 126px; }
    .notes-editor { padding: 20px; }
    .searchdock.search-open .search-results { padding-right: 18px; padding-left: 18px; }
}

@media (prefers-reduced-transparency: reduce) {
    .empty-state, .card, .search, .login-card, .segmented, .logout, #search-close,
    .notes-back, .notes-book-head, .notes-editor {
        background: #f9fbff;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .login-overlay { background: #edf3fc; backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
