:root {
    font-family:
        InterVariable,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    font-feature-settings:
        "liga" 1,
        "calt" 1;

    /* Light Theme */
    --bg-primary: #f9f9f9;
    --primary: #1b1b1b;
    --secondary: #757575;
    --tertiary: #8e8e8e;
    --border: rgba(0, 0, 0, 0.1);
    --outline: #f1f1f1;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #131313;
        --primary: rgba(255, 255, 255, 0.9);
        --secondary: rgba(255, 255, 255, 0.62);
        --tertiary: rgba(255, 255, 255, 0.44);
        --border: #2a2b2a;
        --outline: #272727;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

button,
input,
optgroup,
select,
textarea {
    font-family: inherit;
}

body {
    font-weight: 400;
    line-height: 1.4;
    color: var(--primary);
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* --- Global Typography --- */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin-top: 0.5em;
    margin-bottom: 0.75em;
    line-height: 1.25;
    font-weight: 700;
    color: var(--primary);
}

h1 {
    font-size: 1.75rem;
}
h2 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0;
}
h3 {
    font-size: 1.25rem;
}

p {
    margin-bottom: 1em;
    user-select: text;
}

ul,
ol {
    margin-bottom: 1em;
    padding-left: 1.5rem;
}

li {
    margin-bottom: 0.25em;
}

hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.container > *:first-child,
.novel-info > *:first-child,
.chapter-content > *:first-child {
    margin-top: 0;
}

/* Header */
.header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
}

.header.static {
    position: relative;
    top: auto;
    background: var(--bg-primary);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.025em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 1rem;
}

/* Search */
.search-bar {
    position: relative;
    flex: 1;
    max-width: 400px;
    margin-left: auto;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    opacity: 0.5;
    z-index: 10;
}

@media (prefers-color-scheme: dark) {
    .search-icon {
        filter: invert(1);
    }
}

.search-bar input {
    width: 100%;
    padding: 0.7rem 1rem 0.65rem 2.75rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--primary);
    outline: none;
    transition: all 0.2s ease;
}

.search-bar input:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px var(--outline);
}

.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 10px 15px -3px rgba(0, 0, 0, 0.1);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1000;
    padding: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--outline) transparent;
}

.search-loading,
.no-results {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.search-result-card {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    align-items: center;
    transition: background-color 0.2s ease;
    border: none;
    margin-bottom: 2px;
}

.search-result-card:hover,
.search-result-card:focus {
    background-color: var(--border);
    outline: none;
}

.search-result-card img {
    width: 48px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: var(--outline);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    image-rendering: auto;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.search-result-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.search-result-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.25rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--primary);
    line-height: 1.2;
}

.search-result-info .author {
    font-size: 0.8rem;
    color: var(--tertiary);
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 600px) {
    .header.search-expanded .header-left {
        display: none;
    }

    .header.search-expanded .search-bar {
        max-width: 100%;
        width: 100%;
        margin-left: 0;
    }

    .header.search-expanded .search-input-wrapper {
        width: 100%;
    }
}

/* Main Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
    flex: 1;
    width: 100%;
}

/* Novels Grid */
.novels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

@media (max-width: 400px) {
    .novels-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
}

.novel-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    position: relative;
}

.novel-card img {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 8px;
    background: var(--bg-primary);
    box-shadow: 0 1px 3px var(--outline);
}

.novel-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.novel-card-info h3 {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.3;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
    color: var(--primary);
}
.novel-card-info .author {
    font-size: 0.8rem;
    color: var(--secondary);
    font-weight: 500;
}

/* Pagination */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    margin: 2.5rem 0;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    border-radius: 8px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    user-select: none;
    line-height: 1;
    padding: 0;
}

.page-link.prev-next {
    font-size: 1.1rem;
}

.page-link.active {
    cursor: default;
    border-color: var(--secondary);
    box-shadow: 0 0 0 1px var(--outline);
}

.page-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    color: var(--secondary);
    font-weight: 700;
    letter-spacing: 1px;
}

@media (max-width: 400px) {
    .pagination {
        gap: 0.25rem;
    }
}

@media (max-width: 510px) {
    .page-link {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 0.9rem;
        border-radius: 6px;
    }

    .page-link.prev-next {
        font-size: 1rem;
    }

    .page-ellipsis {
        width: 1rem;
        font-size: 0.8rem;
    }

    .mobile-hide {
        display: none;
    }
}

/* Novel Page */
.novel-header {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

@media (min-width: 600px) {
    .novel-header {
        flex-direction: row;
        align-items: start;
        gap: 2rem;
    }
}

/* Cover & Button Container Styles */
.novel-cover-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-self: center;
    width: 140px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

@media (min-width: 600px) {
    .novel-cover-container {
        align-self: flex-start;
        width: 220px;
        margin: 0;
    }
}

.novel-info {
    text-align: center;
    flex: 1;
}

@media (min-width: 600px) {
    .novel-info {
        text-align: left;
    }
}

.novel-info h1 {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
    user-select: text;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    color: var(--secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
}

.badge {
    background: var(--outline);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 8px;
    user-select: text;
}

@media (min-width: 600px) {
    .meta {
        justify-content: flex-start;
    }
}

/* Chapters */
.chapters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
}
@media (prefers-color-scheme: dark) {
    .toggle img {
        filter: invert(1);
    }
}

.chapters-list {
    display: flex;
    flex-direction: column;
}

.chapter-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem 0.5rem;
    background: transparent;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    align-items: baseline;
}

.chapter-item:last-child {
    border-bottom: none;
}

.chapter-item:active {
    opacity: 0.6;
}

.chapter-num {
    font-size: 0.9rem;
    color: var(--tertiary);
    font-weight: 600;
    white-space: nowrap;
}

.chapter-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* Reader */
.chapter-reader h1 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 2rem;
    line-height: 1.3;
    user-select: text;
}
.chapter-content {
    font-size: 1.125rem;
    line-height: 1.8;
    color: var(--primary);
    margin-bottom: 3rem;
}

.chapter-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    border-radius: 8px;
}

.chapter-navigation {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 2rem;
}

.chapter-navigation button {
    width: 100%;
    padding: 1rem;
    background: var(--bg-primary);
    border: var(--border) 1px solid;
    border-radius: 12px;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.95rem;
}

.chapter-navigation button:hover {
    cursor: pointer;
}

.chapter-navigation button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chapter-source {
    margin-top: 1.5rem;
    padding-top: 0.25rem;
    font-size: 0.8rem;
    text-align: center;
    color: var(--tertiary);
    user-select: text;
}

/* Footer */
.footer {
    padding: 3rem 1.25rem 2rem;
    margin-top: auto;
    font-size: 0.9rem;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto 3rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 3rem;
}

.footer-section h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--tertiary);
    margin-bottom: 1.25rem;
    font-weight: 700;
}

.footer-nav {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.footer-nav a {
    color: var(--secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.footer-nav a:hover {
    color: var(--primary);
}

.footer-disclaimer {
    color: var(--secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 0;
    max-width: 400px;
}

.footer-disclaimer a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: opacity 0.2s;
    user-select: text;
}

.footer-disclaimer a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Footer Bottom (Copyright + Status) */
.footer-bottom {
    max-width: 800px;
    margin: 0 auto;
    padding-top: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.copyright {
    color: var(--tertiary);
    font-size: 0.85rem;
    font-weight: 500;
}

/* Native Status Widget */
.status-widget {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    background: var(--bg-primary);
}

.status-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--tertiary);
    position: relative;
}

/* Status States */
.status-widget.operational .status-dot {
    background-color: #10b981; /* Green */
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.2);
}
.status-widget.operational {
    color: #10b981;
}

.status-widget.degraded .status-dot {
    background-color: #f59e0b; /* Orange/Yellow */
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.2);
}
.status-widget.degraded {
    color: #f59e0b;
}

.status-widget.outage .status-dot {
    background-color: #ef4444; /* Red */
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.2);
}
.status-widget.outage {
    color: #ef4444;
}

/* Pulse Animation */
@keyframes pulse-dot {
    0% {
        transform: scale(0.95);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(0.95);
        opacity: 0.7;
    }
}

.status-widget.operational .status-dot {
    animation: pulse-dot 3s infinite ease-in-out;
}

@media (max-width: 500px) {
    .footer {
        padding: 2rem 1.25rem;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
        margin-bottom: 2rem;
    }
}

/* Modals */
.error,
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--secondary);
    font-weight: 500;
}
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-content {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
}
.modal-content h3 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 1rem;
}
.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1.5rem;
}
.modal-actions button {
    padding: 0.875rem;
    border-radius: 10px;
    font-weight: 600;
    border: 1px solid var(--border);
}
.btn-back {
    background: var(--bg-primary);
    color: var(--primary);
}
.btn-confirm {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
}

/* Age Checkbox */
.age-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--secondary);
    cursor: pointer;
}

.age-checkbox-label input {
    appearance: none;
    -webkit-appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.age-checkbox-label input:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.age-checkbox-label input:checked::after {
    content: "";
    width: 6px;
    height: 10px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

/* Scroll bar */
html {
    scrollbar-width: thin;
    scrollbar-color: var(--outline) var(--bg-primary);
}
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background-color: var(--outline);
    border-radius: 20px;
    border: 3px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover {
    background-color: var(--tertiary);
}

/* Description Toggle */
.description-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
}

.description {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--secondary);
    text-align: left;
    transition: max-height 0.3s ease;
    user-select: text;
}

.description.collapsed {
    max-height: 140px;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}

.read-more-toggle {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-top: 0.25rem;
    display: block;
}

.read-more-toggle:hover {
    text-decoration: underline;
}

/* Action Buttons (Start/Continue) */
.action-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    transition:
        transform 0.1s,
        opacity 0.2s;
    margin-top: 1rem;
    color: white !important;
}

.action-btn:active {
    transform: scale(0.98);
}

.btn-start {
    background-color: #2563eb;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-continue {
    background-color: #f97316;
    box-shadow: 0 4px 6px -1px rgba(249, 115, 22, 0.2);
}

/* Responsive Button Placement */
.desktop-actions {
    display: none;
}
.mobile-actions {
    display: block;
}

@media (min-width: 600px) {
    .desktop-actions {
        display: block;
    }
    .mobile-actions {
        display: none;
    }
}

/* --- Ambient Glow Effect --- */
.poster-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: 8px;
}

.poster-wrapper::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background-image: var(--bg-url);
    background-size: cover;
    background-position: center;
    filter: blur(15px) saturate(180%);
    opacity: 0.5;
    transform: translateY(8px) scale(0.9);
    border-radius: 12px;
    transition: opacity 0.3s;
}

@media (prefers-color-scheme: dark) {
    .poster-wrapper::before {
        opacity: 0.6;
    }
}

.poster-wrapper img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    background: var(--bg-primary);
}

/* --- Error Pages --- */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    text-align: center;
    min-height: 50vh;
}

.error-code {
    font-size: 6rem;
    font-weight: 800;
    line-height: 1;
    color: var(--tertiary);
    opacity: 0.3;
    margin-bottom: 1rem;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.error-message {
    color: var(--secondary);
    margin-bottom: 2rem;
    max-width: 400px;
}

.btn-home {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary);
    color: var(--bg-primary);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: opacity 0.2s;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
}

.btn-home:hover {
    opacity: 0.9;
}

/* Hyphens */
.description,
.chapter-content {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

@supports (hyphenate-limit-chars: 9 4 4) {
    .chapter-content,
    .description {
        hyphens: auto;
        -webkit-hyphens: auto;
        -ms-hyphens: auto;
        hyphenate-limit-chars: 9 4 4;
    }
}

@supports (-webkit-hyphenate-limit-before: 4) and
    (-webkit-hyphenate-limit-after: 4) {
    .chapter-content,
    .description {
        hyphens: auto;
        -webkit-hyphens: auto;
        -ms-hyphens: auto;
        -webkit-hyphenate-limit-before: 4;
        -webkit-hyphenate-limit-after: 4;
    }
}

@supports (not (hyphenate-limit-chars: 9 4 4)) and
    (not (-webkit-hyphenate-limit-before: 4)) and
    (not (-webkit-hyphenate-limit-after: 4)) {
    .chapter-content,
    .description {
        hyphens: none;
        -webkit-hyphens: none;
        -ms-hyphens: none;
    }
}
