/* Edit Fiction Title UI */
.fiction-title {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.edit-title-btn {
    background: none;
    border: none;
    color: var(--link-color);
    cursor: pointer;
    padding: 0 0.2em;
    margin-left: 0.5em;
    opacity: 0;
    transition: color 0.2s, opacity 0.2s;
    outline: none;
    display: flex;
    align-items: center;
}
.fiction-title:hover .edit-title-btn,
.edit-title-btn:focus {
    opacity: 1;
}
.edit-title-btn svg {
    display: block;
    stroke: var(--link-color);
    width: 1.1em;
    height: 1.1em;
    pointer-events: none;
}
.edit-title-btn:hover svg {
    stroke: #0056b3;
}
.edit-title-input {
    font-size: 1em;
    padding: 2px 6px;
    border: 1px solid var(--link-color);
    border-radius: 4px;
    margin-left: 0.5em;
}
.edit-title-input.input-error {
    border-color: #d9534f;
    background: #fff0f0;
    color: #b30000;
}
.save-title-btn, .cancel-title-btn {
    font-size: 0.95em;
    margin-left: 0.5em;
    padding: 2px 10px;
    border-radius: 4px;
    border: 1px solid var(--link-color);
    background: var(--bg-color);
    color: var(--link-color);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.save-title-btn:hover, .cancel-title-btn:hover {
    background: var(--link-color);
    color: #fff;
}
/* Make side menu links unclickable and unfocusable when menu is hidden */
#side-menu:not(.open) .side-menu-link,
#side-menu:not(.open) .side-theme-toggle,
#side-menu:not(.open) .font-selector {
    pointer-events: none;
    user-select: none;
    color: var(--disabled-color, #aaa);
}

#side-menu.open .side-menu-link,
#side-menu.open .side-theme-toggle,
#side-menu.open .font-selector {
    pointer-events: auto;
    user-select: auto;
    color: inherit;
}
.side-menu-font-li {
    padding-left: 1.5em;
    padding-right: 1.5em;
}
.font-selector {
    font-size: 1em;
    border-radius: 4px;
    border: 1px solid var(--text-color);
    background: var(--bg-color);
    color: var(--text-color);
    margin-bottom: 0.5em;
}

/* Font classes for chapter content */
html.font-serif .chapter-content, html.font-serif .chapter-title,
body.font-serif .chapter-content, body.font-serif .chapter-title,
.chapter-content.font-serif, .chapter-title.font-serif {
    font-family: 'Georgia', 'Times New Roman', Times, serif;
}
html.font-sans-serif .chapter-content, html.font-sans-serif .chapter-title,
body.font-sans-serif .chapter-content, body.font-sans-serif .chapter-title,
.chapter-content.font-sans-serif, .chapter-title.font-sans-serif {
    font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
}
html.font-monospace .chapter-content, html.font-monospace .chapter-title,
body.font-monospace .chapter-content, body.font-monospace .chapter-title,
.chapter-content.font-monospace, .chapter-title.font-monospace {
    font-family: 'Fira Mono', 'Consolas', 'Courier New', monospace;
}
:root {
    --bg-color: #e8e8e8;
    --text-color: #333;
    --link-color: #007BFF;
    --container-text: #444;
    /* Safe area insets for devices with notches/rounded corners */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --viewport-height: 100vh;
}

/* Define dark mode variables */
html.dark-mode {
    --bg-color: #151515;
    --text-color: #e0e0e0;
    /* --link-color: #bb86fc; */
    --container-text: #c0c0c0;
}

/* Apply base styles using variables */
@supports (height: 100dvh) {
    :root {
        --viewport-height: 100dvh;
    }
}

html {
    margin: 0;
    padding: 0;
    min-height: var(--viewport-height);
    min-height: -webkit-fill-available;
    background-color: var(--bg-color);
    overflow-x: hidden;
    /* Critical for Android fullscreen - extend into system UI areas */
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: max(20px, var(--safe-area-inset-top)) max(20px, var(--safe-area-inset-right)) max(20px, var(--safe-area-inset-bottom)) max(20px, var(--safe-area-inset-left));
    min-height: var(--viewport-height);
    min-height: -webkit-fill-available;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

h1 {
    color: var(--text-color);
}

form {
    margin-bottom: 20px;
}

#message {
    margin-top: 10px;
    font-weight: bold;
}

ul {
    list-style-type: none;
    padding: 0;
}

li {
    margin: 5px 0;
}

li a {
    color: var(--link-color);
}

li a:hover {
    text-decoration: underline;
}

/* Styles for containers using variables */
.chapters-container, .chapter-container {
    max-width: 800px;
    margin: 20px auto; /* Added top/bottom margin */
    padding: 20px;
    background-color: var(--bg-color);
    border-radius: 8px;
    box-shadow: 0 4px 6px var(--shadow-color);
    color: var(--container-text);
}

.chapters-title, .chapter-title {
    font-size: 2em;
    margin-bottom: 20px;
    text-align: center;
    color: var(--text-color); /* Use main text color */
}

.chapters-list {
    list-style-type: none;
    padding: 0;
}

.chapters-list li {
    margin: 10px 0;
}

.chapters-list a {
    text-decoration: none;
    color: var(--link-color);
    font-weight: bold;
}

.chapters-list a:hover {
    text-decoration: underline;
}

.chapter-content {
    font-size: 1.2em;
    line-height: 1.6;
    color: var(--container-text);
}

.navigation {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
}

a {
    text-decoration: none;
    color: var(--link-color);
}

.navigation {
    font-weight: bold;
}

.navigation a:hover {
    text-decoration: underline;
}

/* Theme toggle button styles using variables */
.theme-toggle-button {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--text-color);
    border-radius: 5px;
    cursor: pointer;
    z-index: 1000;
}

/* Side Menu Styles */
.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: -webkit-fill-available;
    width: 250px;
    background: var(--bg-color);
    color: var(--text-color);
    box-shadow: 2px 0 8px var(--shadow-color);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
}
.side-menu.open {
    transform: translateX(0);
}
.side-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1em;
    border-bottom: 1px solid var(--shadow-color);
    font-weight: bold;
    font-size: 1.2em;
}
.close-menu-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-color);
}
.side-menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
}
.side-menu-list li {
    border-bottom: 1px solid var(--shadow-color);
}
.side-menu-list a, .side-theme-toggle {
    display: block;
    padding: 1em;
    color: var(--text-color);
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-size: 1em;
    cursor: pointer;
}
.side-menu-list a:hover, .side-theme-toggle:hover {
    background: var(--bg-color);
}

/* Overlay Styles */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
    background: rgba(0,0,0,0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1500;
}
.menu-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* Hamburger Button Styles */
/* Hamburger menu button removed: menu is swipe-only on mobile */
@media (max-width: 900px) {
    .theme-toggle-button {
        top: 10px;
        right: 10px;
    }
}