﻿:root {
    --bg-cream: #fbf6ec;
    --bg-gold: #f2d98d;
    --ink: #2f2230;
    --ink-soft: #5f4a62;
    --rose: #ce5a71;
    --rose-dark: #a13f53;
    --leaf: #2f7a68;
    --card: #fffef9;
    --shadow: 0 16px 35px rgba(47, 34, 48, 0.18);
    --radius: 16px;
    --surface: #ffffff;
    --surface-alt: #f7ecdc;
    --surface-border: #e4d6c1;
    --surface-border-strong: #d8ccb8;
    --muted-surface: #eadfcb;
    --chat-panel-border: #e4d6c1;
    --chat-header-border: #e5d6c1;
    --chat-delete-border: #d9c2c8;
    --chat-delete-bg: linear-gradient(135deg, #fff4f6, #f6e7db);
    --chat-delete-bg-hover: linear-gradient(135deg, #ffeef2, #f1e0d2);
    --chat-delete-fg: #8f5f67;
    --chat-close-border: #d7c7b0;
    --chat-close-bg: linear-gradient(135deg, #fff, #f3e8da);
    --chat-close-bg-hover: linear-gradient(135deg, #fff, #eadfce);
    --chat-input-bg: #fff;
    --chat-input-border: #d8ccb8;
    --chat-history-hold-border: #ccb48e;
    --chat-history-border: #e7d8c4;
    --chat-history-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.42));
    --chat-bubble-border: #e6d8c4;
    --chat-bubble-bg: #fffdf9;
    --chat-bubble-own-bg: linear-gradient(135deg, #ffeef2, #ffe6cf);
    --chat-bubble-own-border: #f0c8cf;
    --chat-bubble-own-fg: var(--ink);
    --chat-bubble-other-bg: linear-gradient(135deg, #fffefb, #f8f1e4);
    --chat-bubble-other-border: #eadcc8;
    --chat-bubble-other-fg: var(--ink);
    --chat-time-fg: var(--ink-soft);
    --chat-compose-input-border: #d7d7d7;
    --chat-compose-input-bg: #fff;
    --chat-compose-emoji-border: #d8ccb8;
    --chat-compose-emoji-bg: #f7ecdc;
    --chat-compose-emoji-bg-hover: #f1e2cc;
    --chat-emoji-border: #d9a5b1;
    --chat-emoji-bg: linear-gradient(135deg, #fff3f6, #ffe3ea);
    --chat-emoji-bg-hover: linear-gradient(135deg, #ffe7ee, #ffd6e2);
    --chat-emoji-fg: var(--rose-dark);
    --chat-emoji-picker-border: #e6d7c2;
    --chat-emoji-option-border: #f0deca;
    --chat-emoji-option-bg: #fffaf2;
    --chat-emoji-option-bg-hover: #fff0d8;
    --chat-send-border: #25685a;
    --chat-send-bg: linear-gradient(135deg, #2f7a68, #43a08a 60%, #63b59f);
    --chat-send-shadow: 0 8px 18px rgba(47, 122, 104, 0.28);
    --chat-send-shadow-hover: 0 10px 22px rgba(47, 122, 104, 0.34);
    --chat-send-focus: rgba(47, 122, 104, 0.45);
    --chat-tick-muted: #9aa1aa;
    --chat-tick-read: #2f80ed;
    --menu-item-hover-bg: #fff3df;
    --menu-item-disabled-bg: #f6efe3;
    --menu-item-disabled-fg: #8e8578;
    --menu-focus-ring: rgba(47, 122, 104, 0.35);
    --theme-option-hover-bg: #fff5e5;
}

body[data-theme='dark'] {
    --bg-cream: #111418;
    --bg-gold: #1d242d;
    --ink: #ffffff;
    --ink-soft: #ffffff;
    --rose: #d16d86;
    --rose-dark: #b64f69;
    --leaf: #56a790;
    --card: #1a2028;
    --shadow: 0 16px 35px rgba(0, 0, 0, 0.38);
    --surface: #202833;
    --surface-alt: #1f2936;
    --surface-border: #344152;
    --surface-border-strong: #3d4f64;
    --muted-surface: #293645;
    --chat-panel-border: #344152;
    --chat-header-border: #344152;
    --chat-delete-border: #3d4f64;
    --chat-delete-bg: linear-gradient(135deg, #2b3643, #23303d);
    --chat-delete-bg-hover: linear-gradient(135deg, #344557, #28384b);
    --chat-delete-fg: #ffffff;
    --chat-close-border: #3d4f64;
    --chat-close-bg: linear-gradient(135deg, #2b3643, #23303d);
    --chat-close-bg-hover: linear-gradient(135deg, #344557, #28384b);
    --chat-input-bg: #202833;
    --chat-input-border: #3d4f64;
    --chat-history-hold-border: #5c6d84;
    --chat-history-border: #344152;
    --chat-history-bg: linear-gradient(180deg, rgba(40, 51, 66, 0.9), rgba(31, 40, 52, 0.88));
    --chat-bubble-border: #4c5f77;
    --chat-bubble-bg: #223041;
    --chat-bubble-own-bg: linear-gradient(135deg, #365074, #2d4565);
    --chat-bubble-own-border: #4f6f98;
    --chat-bubble-own-fg: #ffffff;
    --chat-bubble-other-bg: linear-gradient(135deg, #293a4e, #233144);
    --chat-bubble-other-border: #405875;
    --chat-bubble-other-fg: #ffffff;
    --chat-time-fg: #ffffff;
    --chat-compose-input-border: #3d4f64;
    --chat-compose-input-bg: #202833;
    --chat-compose-emoji-border: #3d4f64;
    --chat-compose-emoji-bg: #293645;
    --chat-compose-emoji-bg-hover: #324255;
    --chat-emoji-border: #4b5f78;
    --chat-emoji-bg: linear-gradient(135deg, #2a3a4f, #233244);
    --chat-emoji-bg-hover: linear-gradient(135deg, #32455d, #293a50);
    --chat-emoji-fg: #ffffff;
    --chat-emoji-picker-border: #344152;
    --chat-emoji-option-border: #3d4f64;
    --chat-emoji-option-bg: #253244;
    --chat-emoji-option-bg-hover: #2f4158;
    --chat-send-border: #4f6f98;
    --chat-send-bg: linear-gradient(135deg, #365074, #2d4565 60%, #456997);
    --chat-send-shadow: 0 8px 18px rgba(61, 95, 137, 0.34);
    --chat-send-shadow-hover: 0 10px 22px rgba(61, 95, 137, 0.42);
    --chat-send-focus: rgba(79, 111, 152, 0.5);
    --chat-tick-muted: #ffffff;
    --chat-tick-read: #ffffff;
    --menu-item-hover-bg: #2f4158;
    --menu-item-disabled-bg: #28384b;
    --menu-item-disabled-fg: #ffffff;
    --menu-focus-ring: rgba(104, 167, 255, 0.45);
    --theme-option-hover-bg: #2f4158;
}

body[data-theme='ebook'] {
    --bg-cream: #f4f4f4;
    --bg-gold: #e8e8e8;
    --ink: #111111;
    --ink-soft: #333333;
    --rose: #2f2f2f;
    --rose-dark: #1f1f1f;
    --leaf: #4a4a4a;
    --card: #ffffff;
    --shadow: 0 16px 35px rgba(17, 17, 17, 0.14);
    --surface: #ffffff;
    --surface-alt: #f0f0f0;
    --surface-border: #d6d6d6;
    --surface-border-strong: #bfbfbf;
    --muted-surface: #e2e2e2;
    --chat-panel-border: #d6d6d6;
    --chat-header-border: #d6d6d6;
    --chat-delete-border: #c3c3c3;
    --chat-delete-bg: linear-gradient(135deg, #f5f5f5, #ececec);
    --chat-delete-bg-hover: linear-gradient(135deg, #efefef, #e2e2e2);
    --chat-delete-fg: #222222;
    --chat-close-border: #c3c3c3;
    --chat-close-bg: linear-gradient(135deg, #ffffff, #f1f1f1);
    --chat-close-bg-hover: linear-gradient(135deg, #f7f7f7, #ebebeb);
    --chat-input-bg: #ffffff;
    --chat-input-border: #c7c7c7;
    --chat-history-hold-border: #a6a6a6;
    --chat-history-border: #d1d1d1;
    --chat-history-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(245, 245, 245, 0.96));
    --chat-bubble-border: #d3d3d3;
    --chat-bubble-bg: #ffffff;
    --chat-bubble-own-bg: linear-gradient(135deg, #f2f2f2, #e9e9e9);
    --chat-bubble-own-border: #cccccc;
    --chat-bubble-own-fg: #111111;
    --chat-bubble-other-bg: linear-gradient(135deg, #ffffff, #f5f5f5);
    --chat-bubble-other-border: #d7d7d7;
    --chat-bubble-other-fg: #111111;
    --chat-time-fg: #333333;
    --chat-compose-input-border: #bfbfbf;
    --chat-compose-input-bg: #ffffff;
    --chat-compose-emoji-border: #c7c7c7;
    --chat-compose-emoji-bg: #f0f0f0;
    --chat-compose-emoji-bg-hover: #e7e7e7;
    --chat-emoji-border: #c7c7c7;
    --chat-emoji-bg: linear-gradient(135deg, #f6f6f6, #ededed);
    --chat-emoji-bg-hover: linear-gradient(135deg, #efefef, #e4e4e4);
    --chat-emoji-fg: #222222;
    --chat-emoji-picker-border: #d4d4d4;
    --chat-emoji-option-border: #d8d8d8;
    --chat-emoji-option-bg: #fafafa;
    --chat-emoji-option-bg-hover: #efefef;
    --chat-send-border: #4a4a4a;
    --chat-send-bg: linear-gradient(135deg, #3a3a3a, #2a2a2a 60%, #1f1f1f);
    --chat-send-shadow: 0 8px 18px rgba(20, 20, 20, 0.24);
    --chat-send-shadow-hover: 0 10px 22px rgba(20, 20, 20, 0.3);
    --chat-send-focus: rgba(64, 64, 64, 0.45);
    --chat-tick-muted: #555555;
    --chat-tick-read: #222222;
    --menu-item-hover-bg: #efefef;
    --menu-item-disabled-bg: #e8e8e8;
    --menu-item-disabled-fg: #444444;
    --menu-focus-ring: rgba(70, 70, 70, 0.35);
    --theme-option-hover-bg: #efefef;
}

body[data-theme='magazine'] {
    --bg-cream: #f4f6fb;
    --bg-gold: #ccd4ef;
    --ink: #1d2230;
    --ink-soft: #4d5570;
    --rose: #f05454;
    --rose-dark: #cf3e3e;
    --leaf: #2d9cdb;
    --card: #ffffff;
    --shadow: 0 16px 35px rgba(29, 34, 48, 0.22);
    --surface: #ffffff;
    --surface-alt: #edf2ff;
    --surface-border: #d7def5;
    --surface-border-strong: #a9bbe8;
    --muted-surface: #e3eafc;
}

body[data-theme='ocean'] {
    --bg-cream: #eaf6fb;
    --bg-gold: #b7dff2;
    --ink: #1f3650;
    --ink-soft: #436483;
    --rose: #2f7eb2;
    --rose-dark: #256591;
    --leaf: #1f9da9;
    --card: #f7fcff;
    --shadow: 0 16px 35px rgba(31, 54, 80, 0.2);
    --surface: #f7fcff;
    --surface-alt: #d9eef9;
    --surface-border: #b6d7e8;
    --surface-border-strong: #97c0d6;
    --muted-surface: #d3eaf5;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Nunito', sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top right, #fff6cf 0%, var(--bg-cream) 40%, #f6e8da 100%);
    transition: background 0.25s ease, color 0.25s ease;
}

body[data-theme='dark'] {
    background: radial-gradient(circle at top right, #202833 0%, var(--bg-cream) 42%, #0c1014 100%);
}

body[data-theme='ebook'] {
    background:
        repeating-linear-gradient(
            0deg,
            #f8f8f8 0px,
            #f8f8f8 28px,
            #ececec 28px,
            #ececec 29px
        );
}

body[data-theme='magazine'] {
    background: linear-gradient(135deg, #f1f4ff 0%, #e9efff 40%, #fff7f8 100%);
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-main {
    width: 100%;
    max-width: 460px;
}

.auth-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.3rem;
}

.auth-subtitle {
    margin-top: -0.35rem;
    color: var(--ink-soft);
}

.auth-label {
    display: block;
    margin: 0.9rem 0 0.35rem;
    font-weight: 700;
}

.auth-input {
    width: 100%;
    border: 1px solid var(--surface-border-strong);
    border-radius: 10px;
    padding: 0.62rem 0.78rem;
    font-size: 1rem;
    background: var(--surface);
    color: var(--ink);
}

.auth-submit {
    width: 100%;
    margin-top: 1rem;
}

.auth-error {
    border: 1px solid #efc2c8;
    background: #fff0f2;
    color: #96394a;
    border-radius: 10px;
    padding: 0.6rem 0.7rem;
}

h1,
h2,
h3 {
    font-family: 'Cinzel', serif;
    margin-top: 0;
}

.hidden {
    display: none !important;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    padding: 0.65rem 1.1rem;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--rose), #dd7a8d);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--rose-dark), #c66378);
}

.btn-secondary {
    color: #fff;
    background: linear-gradient(135deg, var(--leaf), #47a28d);
}

.btn-light {
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--surface-border);
}

.btn-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #dfd7cb;
    color: #6d665d;
}

.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: linear-gradient(150deg, #fff7dd, #ffeff2 50%, #f4f8ff);
    text-align: center;
    padding: 1.25rem;
    z-index: 20;
}

.splash h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 0;
}

.splash p {
    max-width: 560px;
    margin: 0;
    color: var(--ink-soft);
}

.splash.splash-out {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.hidden-until-splash {
    visibility: hidden;
}

.home-main {
    visibility: visible;
    padding: 2rem clamp(1rem, 4vw, 4rem) 2.5rem;
}

.hero {
    background: linear-gradient(120deg, rgba(255, 255, 255, 0.92), rgba(255, 246, 223, 0.9));
    border-radius: var(--radius);
    padding: clamp(1.1rem, 3vw, 2rem);
    box-shadow: var(--shadow);
}

.hero-meta {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: center;
}

.reader-settings {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.reader-settings label {
    font-weight: 700;
}

.reader-settings select {
    border: 1px solid #d8ccb8;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    background: #fff;
    font-weight: 700;
    color: var(--ink);
}

.story-grid {
    margin-top: 1.5rem;
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.story-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.story-card img {
    width: 100%;
    height: 260px;
    object-fit: cover;
    background: #f8f0e5;
}

.story-content {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.story-content .author {
    color: var(--ink-soft);
    margin: 0;
}

.reader-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    align-items: center;
    background: rgba(255, 251, 241, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #eadfcb;
    padding: 0.8rem 1rem;
}

.user-menu {
    position: relative;
}

.user-menu > summary {
    list-style: none;
}

.user-menu > summary::-webkit-details-marker {
    display: none;
}

.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid #f0e2cd;
    border-radius: 999px;
    background: #fff;
    padding: 0.4rem 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.user-menu-trigger svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.user-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.45rem);
    min-width: 190px;
    border-radius: 12px;
    border: 1px solid #f0e2cd;
    background: #fffef9;
    box-shadow: var(--shadow);
    padding: 0.35rem;
    display: grid;
    gap: 0.15rem;
}

.user-menu-item {
    display: block;
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    text-decoration: none;
    color: var(--ink);
    font-weight: 700;
}

.user-menu-button {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 1rem;
}

.user-menu-item:hover {
    background: var(--menu-item-hover-bg);
}

.user-menu-item.disabled {
    color: var(--menu-item-disabled-fg);
    background: var(--menu-item-disabled-bg);
    cursor: default;
}

.user-menu-theme-label {
    display: block;
    margin: 0.35rem 0.55rem 0.15rem;
    color: var(--ink-soft);
    font-weight: 700;
    font-size: 0.8rem;
}

.user-menu-theme-select {
    border: 1px solid #d8ccb8;
    border-radius: 10px;
    background: #fff;
    padding: 0.45rem 0.6rem;
    margin: 0 0.45rem 0.2rem;
    color: var(--ink);
    font-weight: 700;
}

.user-menu-theme-select:focus-visible {
    outline: 2px solid var(--menu-focus-ring);
    outline-offset: 1px;
}

.theme-modal {
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: rgba(17, 20, 24, 0.45);
    display: grid;
    place-items: center;
    padding: 1rem;
}

.theme-modal-card {
    width: min(460px, 100%);
    background: var(--card);
    border: 1px solid #e4d8c4;
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 0.9rem;
}

.theme-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.theme-modal-head h2 {
    margin: 0;
    font-size: 1.2rem;
}

.theme-modal-close {
    border: 1px solid #d8ccb8;
    background: #fff;
    border-radius: 10px;
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.theme-modal-list {
    display: grid;
    gap: 0.45rem;
    margin-top: 0.85rem;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border: 1px solid #eadfcb;
    border-radius: 10px;
    padding: 0.55rem 0.65rem;
    background: #fff;
    cursor: pointer;
    font-weight: 700;
}

.theme-option:hover {
    background: var(--theme-option-hover-bg);
}

.theme-option input[type='radio'] {
    margin: 0;
    accent-color: var(--leaf);
}

.user-menu-label {
    display: block;
    border-bottom: 1px solid #f0e2cd;
    margin-bottom: 0.2rem;
    padding: 0.45rem 0.65rem 0.55rem;
    color: var(--ink-soft);
    font-weight: 700;
    font-size: 0.9rem;
}

.reader-topbar-meta {
    display: flex;
    gap: 1rem;
    font-weight: 700;
    flex-wrap: wrap;
}

.reader-main {
    padding: 1rem;
    max-width: 1100px;
    margin: 0 auto 4.5rem;
}

.chapter-list {
    display: flex;
    gap: 0.6rem;
    overflow-x: auto;
    padding: 0.3rem 0 0.9rem;
}

.chapter-pill {
    white-space: nowrap;
    text-decoration: none;
    color: var(--ink);
    background: #fff;
    border: 1px solid #f1dfcf;
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    font-size: 0.92rem;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
}

.chapter-pill-title {
    font-weight: 700;
}

.chapter-pill-pages {
    font-size: 0.78rem;
    color: var(--ink-soft);
}

.chapter-pill.active {
    background: #ffe8c8;
    border-color: #ebc47d;
}

.book-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(1rem, 3vw, 2rem);
    position: relative;
}

.chapter-meta {
    color: var(--ink-soft);
}

.chapter-text {
    font-size: 1.08rem;
    line-height: 1.8;
}

.page-nav {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.page-nav-btn {
    min-width: 132px;
}

.reader-main.is-page-turning {
    perspective: 1400px;
}

.book-card {
    transform-style: preserve-3d;
    backface-visibility: hidden;
    touch-action: pan-y;
}

.book-card.is-turning-next {
    transform-origin: 100% 100%;
    animation: pageTurnFromBottomRight 1.05s cubic-bezier(0.22, 0.7, 0.2, 1) forwards;
}

.book-card.is-turning-prev {
    transform-origin: 0% 100%;
    animation: pageTurnFromBottomLeft 1.05s cubic-bezier(0.22, 0.7, 0.2, 1) forwards;
}

.book-card.is-flip-source-hidden {
    visibility: hidden;
}

.page-flip-overlay {
    position: fixed;
    z-index: 1400;
    pointer-events: none;
    perspective: 1800px;
}

.page-flip-sheet {
    transform-style: preserve-3d;
    backface-visibility: hidden;
    will-change: transform, opacity, filter;
    overflow: hidden;
    background: var(--card);
}

.turnjs-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(22, 16, 18, 0.2);
    display: grid;
    place-items: center;
    pointer-events: none;
}

.turnjs-stage {
    box-shadow: 0 24px 48px rgba(25, 16, 20, 0.28);
    border-radius: 10px;
    overflow: hidden;
    background: #f9f0e2;
}

.turnjs-book,
.turnjs-sheet {
    width: 100%;
    height: 100%;
}

.turnjs-sheet {
    background: var(--card);
}

.turnjs-sheet-blank {
    background: linear-gradient(135deg, #fff8ec, #f6e8d4);
}

.turnjs-placeholder {
    width: 100%;
    height: 100%;
}

@keyframes pageTurnFromBottomRight {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) translate3d(0, 0, 0);
        opacity: 1;
        filter: brightness(1);
    }
    55% {
        transform: rotateX(6deg) rotateY(-24deg) rotateZ(4deg) translate3d(-20px, -6px, 0);
        opacity: 0.78;
        filter: brightness(0.94);
    }
    100% {
        transform: rotateX(12deg) rotateY(-42deg) rotateZ(8deg) translate3d(-46px, -14px, 0);
        opacity: 0.08;
        filter: brightness(0.82);
    }
}

@keyframes pageTurnFromBottomLeft {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) translate3d(0, 0, 0);
        opacity: 1;
        filter: brightness(1);
    }
    55% {
        transform: rotateX(6deg) rotateY(24deg) rotateZ(-4deg) translate3d(20px, -6px, 0);
        opacity: 0.78;
        filter: brightness(0.94);
    }
    100% {
        transform: rotateX(12deg) rotateY(42deg) rotateZ(-8deg) translate3d(46px, -14px, 0);
        opacity: 0.08;
        filter: brightness(0.82);
    }
}

.page-footer-number {
    margin: 1.25rem 0 0;
    padding-top: 0.7rem;
    border-top: 1px solid #f0e5d6;
    text-align: center;
    font-weight: 700;
    color: var(--ink-soft);
}

.page-footer-hint {
    margin: 1.1rem 0 0;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.92rem;
}

.chat-open-btn {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    border: 0;
    border-radius: 50%;
    width: 54px;
    height: 54px;
    padding: 0;
    background: linear-gradient(120deg, var(--rose), var(--leaf));
    color: #fff;
    box-shadow: var(--shadow);
    cursor: pointer;
    z-index: 15;
}

.chat-open-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.chat-panel {
    position: fixed;
    right: 1rem;
    bottom: 4.6rem;
    width: min(390px, calc(100vw - 2rem));
    background: var(--card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--chat-panel-border);
    overflow: hidden;
    display: none;
    z-index: 15;
    font-family: inherit;
}

.chat-panel.open {
    display: block;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.8rem 0.9rem;
    background: linear-gradient(120deg, var(--bg-cream), var(--bg-gold));
    border-bottom: 1px solid var(--chat-header-border);
}

.chat-header-main h2 {
    margin: 0;
    font-family: 'Cinzel', serif;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}

.chat-title-row {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.chat-unread-count {
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    background: #d94d6d;
    color: #fff;
    box-shadow: 0 4px 10px rgba(217, 77, 109, 0.28);
}

.chat-status-msg {
    margin: 0.2rem 0 0;
    min-height: 1.1rem;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.chat-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.chat-delete-btn {
    border: 1px solid var(--chat-delete-border);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--chat-delete-bg);
    color: var(--chat-delete-fg);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(47, 34, 48, 0.12);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-delete-btn:hover {
    background: var(--chat-delete-bg-hover);
    box-shadow: 0 8px 18px rgba(47, 34, 48, 0.16);
}

.chat-delete-btn:active {
    transform: translateY(1px) scale(0.98);
}

.chat-delete-btn:focus-visible {
    outline: 2px solid rgba(206, 90, 113, 0.35);
    outline-offset: 2px;
}

.chat-close-btn {
    border: 1px solid var(--chat-close-border);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--chat-close-bg);
    color: var(--ink);
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 14px rgba(47, 34, 48, 0.15);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-close-btn:hover {
    background: var(--chat-close-bg-hover);
    box-shadow: 0 8px 18px rgba(47, 34, 48, 0.2);
}

.chat-close-btn:active {
    transform: translateY(1px) scale(0.98);
}

.chat-close-btn:focus-visible {
    outline: 2px solid rgba(206, 90, 113, 0.45);
    outline-offset: 2px;
}

.chat-lock-box,
.chat-unlocked {
    padding: 0.9rem;
    background: var(--card);
}

.chat-inline-form {
    display: flex;
    gap: 0.5rem;
}

.chat-inline-form input {
    flex: 1;
    border: 1px solid var(--chat-input-border);
    border-radius: 10px;
    padding: 0.58rem 0.72rem;
    font-size: 1rem;
    background: var(--chat-input-bg);
    color: var(--ink);
    font-family: inherit;
}

.chat-msg {
    min-height: 1.2rem;
    margin-bottom: 0;
    color: var(--ink-soft);
}

.chat-history-hold {
    user-select: none;
    text-align: center;
    border: 1px dashed var(--chat-history-hold-border);
    border-radius: 10px;
    padding: 0.8rem;
    background: var(--bg-cream);
    cursor: default;
    margin-bottom: 0.7rem;
}

.chat-history {
    border: 1px solid var(--chat-history-border);
    border-radius: 10px;
    max-height: 190px;
    overflow-y: auto;
    padding: 0.55rem;
    margin-bottom: 0.7rem;
    background: var(--chat-history-bg);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.chat-timeout-wrap {
    height: 2px;
    border-radius: 0;
    background: var(--muted-surface);
    overflow: hidden;
    margin-bottom: 0;
    opacity: 0.5;
}

.chat-timeout-bar {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2f80ed, #59b3ff);
    transition: width 0.1s linear;
}

.chat-item {
    display: flex;
    width: 100%;
}

.chat-item-head {
    display: flex;
    align-items: baseline;
    gap: 0.35rem 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}

.chat-item-text {
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.chat-item-own {
    justify-content: flex-end;
}

.chat-item-other {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 82%;
    border-radius: 16px;
    padding: 0.48rem 0.62rem 0.5rem;
    border: 1px solid var(--chat-bubble-border);
    background: var(--chat-bubble-bg);
    box-shadow: 0 4px 12px rgba(47, 34, 48, 0.08);
    position: relative;
}

.chat-item-own .chat-bubble {
    background: var(--chat-bubble-own-bg);
    border-color: var(--chat-bubble-own-border);
    color: var(--chat-bubble-own-fg);
    border-bottom-right-radius: 6px;
}

.chat-item-other .chat-bubble {
    background: var(--chat-bubble-other-bg);
    border-color: var(--chat-bubble-other-border);
    color: var(--chat-bubble-other-fg);
    border-bottom-left-radius: 6px;
}

.chat-item-user {
    font-weight: 700;
    color: inherit;
}

.chat-item-time {
    color: var(--chat-time-fg);
    font-size: 0.76rem;
}

.chat-item-own .chat-item-time {
    color: var(--chat-time-fg);
}

.chat-tick {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-left: auto;
}

.chat-tick-single {
    color: var(--chat-tick-muted);
}

.chat-tick-double {
    color: var(--chat-tick-read);
}

.chat-send-btn {
    border: 1px solid var(--chat-send-border);
    width: 44px;
    min-width: 44px;
    border-radius: 10px;
    background: var(--chat-send-bg);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chat-send-shadow);
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.chat-send-btn:hover {
    filter: brightness(1.05);
    box-shadow: var(--chat-send-shadow-hover);
}

.chat-send-btn:active {
    transform: translateY(1px) scale(0.98);
}

.chat-send-btn:focus-visible {
    outline: 2px solid var(--chat-send-focus);
    outline-offset: 2px;
}

.chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.chat-emoji-btn {
    border: 1px solid var(--chat-emoji-border);
    width: 44px;
    min-width: 44px;
    border-radius: 10px;
    background: var(--chat-emoji-bg);
    color: var(--chat-emoji-fg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(161, 63, 83, 0.18);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-emoji-btn:hover {
    background: var(--chat-emoji-bg-hover);
    box-shadow: 0 8px 16px rgba(161, 63, 83, 0.24);
}

.chat-emoji-btn:active {
    transform: translateY(1px) scale(0.98);
}

.chat-emoji-btn:focus-visible {
    outline: 2px solid rgba(206, 90, 113, 0.45);
    outline-offset: 2px;
}

.chat-emoji-btn span {
    font-size: 1.2rem;
    line-height: 1;
}

.chat-inline-compose {
    align-items: center;
}

.chat-compose {
    position: relative;
    flex: 1;
}

.chat-compose #chatTextInput {
    width: 100%;
    height: 52px;
    border: 1px solid var(--chat-compose-input-border);
    border-radius: 999px;
    background: var(--chat-compose-input-bg);
    color: var(--ink);
    font-size: 1rem;
    font-weight: 600;
    padding: 0 3.35rem 0 1.1rem;
    font-family: inherit;
}

.chat-compose #chatTextInput::placeholder {
    color: var(--ink-soft);
    font-weight: 700;
}

.chat-compose .chat-emoji-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    min-width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--chat-compose-emoji-border);
    background: var(--chat-compose-emoji-bg);
    color: var(--ink-soft);
    box-shadow: none;
}

.chat-compose .chat-emoji-btn:hover {
    background: var(--chat-compose-emoji-bg-hover);
    box-shadow: none;
}

.chat-compose .chat-emoji-btn span {
    font-size: 1.4rem;
}

.chat-emoji-picker {
    margin-top: 0.55rem;
    margin-bottom: 0.7rem;
    padding: 0.5rem;
    border: 1px solid var(--chat-emoji-picker-border);
    border-radius: 10px;
    background: var(--card);
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 0.28rem;
}

.chat-emoji-option {
    border: 1px solid var(--chat-emoji-option-border);
    border-radius: 8px;
    background: var(--chat-emoji-option-bg);
    cursor: pointer;
    padding: 0.2rem;
    line-height: 1;
    font-size: 1rem;
}

.chat-emoji-option:hover {
    background: var(--chat-emoji-option-bg-hover);
}

.chat-emoji {
    width: 16px;
    height: 16px;
    vertical-align: -3px;
}

.butterfly {
    width: min(52vw, 360px);
    height: min(38vw, 260px);
}

.butterfly img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.hero,
.story-card,
.chapter-pill,
.chat-panel,
.chat-history,
.chat-emoji-picker,
.turnjs-stage,
.user-menu-trigger,
.user-menu-panel {
    color: var(--ink);
}

body[data-theme='dark'] .reader-topbar {
    background: rgba(22, 27, 34, 0.94);
    border-bottom-color: #2e3947;
}

body[data-theme='dark'] .hero {
    background: linear-gradient(120deg, rgba(33, 40, 50, 0.95), rgba(26, 33, 42, 0.96));
}

body[data-theme='dark'] .chapter-pill {
    background: #202833;
    border-color: #344152;
}

body[data-theme='dark'] .chapter-pill.active {
    background: #2b3644;
    border-color: #5f748e;
}

body[data-theme='dark'] .user-menu-trigger,
body[data-theme='dark'] .user-menu-panel,
body[data-theme='dark'] .chat-panel,
body[data-theme='dark'] .chat-history,
body[data-theme='dark'] .chat-emoji-picker,
body[data-theme='dark'] .theme-modal-card,
body[data-theme='dark'] .theme-option,
body[data-theme='dark'] .theme-modal-close {
    background: var(--surface);
    border-color: var(--surface-border);
}

body[data-theme='dark'] .chat-header {
    background: linear-gradient(120deg, var(--surface-alt), var(--surface));
}

body[data-theme='dark'] .chat-delete-btn {
    background: var(--chat-delete-bg);
    border-color: var(--chat-delete-border);
    color: var(--chat-delete-fg);
}

body[data-theme='dark'] .chat-item-other .chat-bubble {
    background: var(--chat-bubble-other-bg);
    border-color: var(--chat-bubble-other-border);
    color: var(--chat-bubble-other-fg);
}

body[data-theme='dark'] .chat-item-own .chat-bubble {
    background: var(--chat-bubble-own-bg);
    border-color: var(--chat-bubble-own-border);
    color: var(--chat-bubble-own-fg);
}

body[data-theme='dark'] .chat-item-time,
body[data-theme='dark'] .chat-item-own .chat-item-time {
    color: var(--chat-time-fg);
}

body[data-theme='ebook'] .book-card,
body[data-theme='ebook'] .story-card,
body[data-theme='ebook'] .hero {
    border: 1px solid #d6d6d6;
    box-shadow: 0 8px 16px rgba(17, 17, 17, 0.1);
}

body[data-theme='ebook'] .reader-topbar {
    background: rgba(238, 238, 238, 0.96);
    border-bottom-color: #d2d2d2;
}

body[data-theme='ebook'] .chapter-pill.active {
    background: #e8e8e8;
    border-color: #c8c8c8;
}

body[data-theme='ebook'] .chapter-text {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.9;
}

body[data-theme='magazine'] .hero {
    background: linear-gradient(120deg, #ffffff 0%, #edf2ff 55%, #ffeef1 100%);
    border: 1px solid #d7def5;
}

body[data-theme='magazine'] .story-card,
body[data-theme='magazine'] .book-card {
    border: 1px solid #d7def5;
    border-radius: 8px;
}

body[data-theme='magazine'] .chapter-pill.active {
    background: #eaf0ff;
    border-color: #a9bbe8;
}

@media (max-width: 760px) {
    .reader-topbar {
        flex-direction: row;
        align-items: center;
    }

    .reader-topbar-meta {
        min-width: 0;
    }

    .reader-topbar-meta span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-menu {
        margin-left: auto;
    }

    .chat-panel {
        right: 0.7rem;
        bottom: 4.8rem;
        width: calc(100vw - 1.4rem);
    }
}

.notifications-body {
    min-height: 100vh;
    padding: 1rem;
    background:
        radial-gradient(circle at top left, rgba(255, 245, 213, 0.92), transparent 32%),
        linear-gradient(145deg, #fff8e7 0%, #fdecef 50%, #edf7ff 100%);
}

.notifications-main {
    min-height: calc(100vh - 2rem);
    display: grid;
    place-items: center;
}

.notifications-card {
    width: min(760px, 100%);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(231, 214, 195, 0.9);
    border-radius: 24px;
    box-shadow: 0 22px 50px rgba(47, 34, 48, 0.14);
    padding: clamp(1rem, 3.5vw, 2rem);
    backdrop-filter: blur(12px);
}

.notifications-heading h1 {
    margin-bottom: 0.35rem;
}

.notifications-kicker {
    margin: 0 0 0.45rem;
    color: var(--rose-dark);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.notifications-subtitle {
    margin: 0;
    color: var(--ink-soft);
}

.notifications-filter {
    display: grid;
    gap: 0.55rem;
    margin-top: 1.25rem;
}

.notifications-select {
    width: 100%;
    border: 1px solid var(--surface-border-strong);
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    font-size: 1rem;
    font-weight: 700;
    background: #fff;
    color: var(--ink);
}

.notifications-flash {
    margin: 1rem 0 0;
    border: 1px solid #d3eadf;
    background: #effaf4;
    color: #1e6b4b;
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    font-weight: 700;
}

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

.notification-action {
    margin: 0;
}

.notification-tile {
    width: 100%;
    border: 1px solid #edd9c0;
    border-radius: 22px;
    padding: 1rem;
    background: linear-gradient(135deg, #fffdf8 0%, #fff3e2 100%);
    color: var(--ink);
    box-shadow: 0 12px 28px rgba(47, 34, 48, 0.08);
    display: grid;
    gap: 0.4rem;
    text-align: left;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.notification-tile:hover,
.notification-tile:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(47, 34, 48, 0.12);
    border-color: #dfb873;
}

.notification-type {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    font-weight: 700;
}

.notification-count {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 800;
    line-height: 1;
    color: var(--leaf);
}

.notification-count-red {
    color: #d63f4a;
}

.notification-count-purple {
    color: #7f4dff;
}

.notification-count-pink {
    color: #e44f95;
}

.notification-hint {
    color: var(--ink-soft);
    font-weight: 700;
}

.notifications-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

.notifications-reset-form {
    margin: 0;
}

.notifications-reset-btn {
    color: #fff;
    background: linear-gradient(135deg, #b9475a, #d26473);
}

.notifications-reset-btn:hover {
    background: linear-gradient(135deg, #9f384a, #bf5565);
}

.notifications-details {
    margin-top: 1rem;
    border: 1px solid #eadfcb;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    overflow: hidden;
}

.notifications-details-summary {
    list-style: none;
    cursor: pointer;
    padding: 0.95rem 1rem;
    font-weight: 800;
    color: var(--ink);
    background: linear-gradient(135deg, #fffaf1 0%, #f7ece0 100%);
}

.notifications-details-summary::-webkit-details-marker {
    display: none;
}

.notifications-details-summary::after {
    content: '+';
    float: right;
    font-size: 1.2rem;
    line-height: 1;
}

.notifications-details[open] .notifications-details-summary::after {
    content: '-';
}

.notifications-table-wrap {
    overflow-x: auto;
    padding: 0.4rem 0.75rem 0.75rem;
}

.notifications-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 420px;
}

.notifications-table th,
.notifications-table td {
    padding: 0.75rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid #efe4d4;
}

.notifications-table th {
    font-size: 0.84rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.notifications-table tbody tr:last-child td {
    border-bottom: 0;
}

@media (max-width: 640px) {
    .notifications-body {
        padding: 0.75rem;
    }

    .notifications-main {
        min-height: calc(100vh - 1.5rem);
    }

    .notifications-card {
        border-radius: 20px;
        padding: 1rem;
    }

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

    .notification-tile {
        min-height: 134px;
    }

    .notifications-actions {
        justify-content: stretch;
    }

    .notifications-reset-form,
    .notifications-reset-btn {
        width: 100%;
    }
}
