/* Dedicated novel reader.
   Loaded only on novel chapters (see thn_novel_reader_assets in inc/novel.php).

   All reading preferences are driven by data-* attributes and CSS variables set
   on .novelbody by assets/js/novel-reader.js, so switching a setting is a single
   attribute write with no layout thrash and no inline styles to fight. */

.novelbody {
	--novel-size: 18px;
	--novel-leading: 2.5;
	--novel-para: 1.6em;
	/* Surface the reader panel and its toolbar sit on. Themed rather than a
	   hard-coded #181B21 so picking Light or Sepia does not leave a dark slab
	   of panel on a pale page. Dark (the default) is exactly #181B21. */
	--novel-surface: #181B21;
	--novel-width: 46rem;
	--novel-align: left;
	--novel-bg: #14161a;
	--novel-fg: #d7d9dd;
	--novel-muted: #8b9098;
	--novel-panel: #1c1f25;
	--novel-border: rgba(255, 255, 255, .12);
	--novel-accent: #4a9eff;
	--novel-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	/* Control accent for the settings dialog. Deliberately NOT overridden by the
	   reader themes below -- the selected-pill colour should stay recognisable
	   whichever page theme is active, while the dialog's surface still follows
	   --novel-panel so a Light reader does not open a black dialog. */
	--novel-ui: #7c3aed;
}

/* ---- themes ---- */
.novelbody[data-theme="sepia"] {
	--novel-bg: #f4ecd8;
	--novel-fg: #4a3f2f;
	--novel-muted: #8a7a63;
	--novel-panel: #ebe0c7;
	--novel-border: rgba(0, 0, 0, .14);
	--novel-accent: #9a6a3a;
	--novel-surface: #fbf5e6;
}

.novelbody[data-theme="light"] {
	--novel-bg: #ffffff;
	--novel-fg: #23262b;
	--novel-muted: #6b7280;
	--novel-panel: #f3f4f6;
	--novel-border: rgba(0, 0, 0, .12);
	--novel-accent: #2563eb;
	--novel-surface: #ffffff;
}

.novelbody[data-theme="black"] {
	--novel-bg: #000000;
	--novel-fg: #c8cbd0;
	--novel-muted: #7a7f87;
	--novel-panel: #101114;
	--novel-border: rgba(255, 255, 255, .1);
	--novel-accent: #4a9eff;
	--novel-surface: #0b0c0e;
}

/* ---- typeface ---- */
.novelbody[data-font="serif"] {
	--novel-font: Georgia, "Iowan Old Style", "Times New Roman", serif;
}

/* A screen-optimised reading face: taller x-height and looser fitting than a
   print serif, which is what "Reader" means in an e-reader. */
.novelbody[data-font="reader"] {
	--novel-font: Literata, Charter, "Bookerly", "Iowan Old Style", Palatino, serif;
}

/* ---- leading / width / alignment ---- */
.novelbody[data-leading="tight"] {
	--novel-leading: 1.5;
}

.novelbody[data-leading="normal"] {
	--novel-leading: 1.75;
}

.novelbody[data-leading="loose"] {
	--novel-leading: 2.1;
}

/* Widened so the default ("Comfortable") is the 65rem panel asked for, while
   the Reading width control still works -- hard-coding 65rem on .postarea would
   have pinned the panel and made that setting do nothing. */
.novelbody[data-width="narrow"] {
	--novel-width: 48rem;
}

.novelbody[data-width="medium"] {
	--novel-width: 65rem;
}

.novelbody[data-width="wide"] {
	--novel-width: 80rem;
}

.novelbody[data-width="full"] {
	--novel-width: 100%;
}

.novelbody[data-align="justify"] {
	--novel-align: justify;
}

/* ---- paragraph spacing ---- */
/* Scaled up from .55/1.1/1.8: the old "normal" still read as a wall of text on
   chapters that are one line per paragraph, which is most of them. */
.novelbody[data-para="tight"] {
	--novel-para: .9em;
}

.novelbody[data-para="normal"] {
	--novel-para: 1.6em;
}

.novelbody[data-para="loose"] {
	--novel-para: 2.4em;
}

/* ---- shell ---- */
.novelbody {
	background: var(--novel-bg);
	color: var(--novel-fg);
	padding: 0 1.25rem 3rem;
	transition: background .2s ease, color .2s ease;
}

.novelbody .postarea {
	max-width: var(--novel-width);
	margin: 0 auto;
	transition: max-width .2s ease;
}

/* Reading progress bar. */
.novel-progress {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: 3px;
	background: transparent;
	z-index: 9999;
	pointer-events: none;
}

.novel-progress-bar {
	display: block;
	height: 100%;
	width: 0;
	background: var(--novel-accent, #4a9eff);
}

/* ---- header ---- */
/* Plain block, not flex: the settings button used to sit alongside the title
   and needed space-between. It now lives in .novel-toolbar under the chapter
   select, so the head only holds the series link and title and simply centres. */
.novel-head {
	padding: 2rem 0 1rem;
	text-align: center;
}

.novel-series-link a {
	color: var(--novel-muted);
	font-size: .875rem;
	text-decoration: none;
}

.novel-series-link a:hover {
	color: var(--novel-accent);
}

.novelbody .entry-title {
	margin: .35rem 0 0;
	font-size: 1.6rem;
	line-height: 1.3;
	color: var(--novel-fg);
}

/* Sits under the chapter select / prev-next row, and forms the top of the
   reader panel -- same surface as .novel-reader below it so the two read as
   one continuous card. */
.novel-toolbar {
	display: flex;
	justify-content: center;
	margin: 0;
	padding-top: 1.5rem;
	background: var(--novel-surface);
	border-radius: 10px 10px 0 0;
}

.novel-settings-toggle {
	display: inline-flex;
	align-items: center;
	gap: .5rem;
	padding: .55rem .9rem;
	border: 1px solid var(--novel-border);
	border-radius: 6px;
	background: var(--novel-panel);
	color: var(--novel-fg);
	font: inherit;
	font-size: .8125rem;
	cursor: pointer;
	white-space: nowrap;
}

.novel-settings-toggle:hover {
	border-color: var(--novel-accent);
}

/* ---- settings modal ---- */
.novel-modal {
	position: fixed;
	inset: 0;
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.25rem;
}

.novel-modal[hidden] {
	display: none;
}

.novel-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .6);
	backdrop-filter: blur(2px);
}

.novel-modal-box {
	position: relative;
	width: 100%;
	/* Narrow on purpose: a single column of pill groups reads as a settings
	   sheet, whereas a wide box spreads them into unrelated-looking columns. */
	max-width: 24rem;
	max-height: 88vh;
	overflow-y: auto;
	border: 1px solid var(--novel-border);
	border-radius: 14px;
	background: var(--novel-panel);
	color: var(--novel-fg);
	box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}

.novel-modal-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.35rem 1.35rem .35rem;
}

.novel-modal-titles h2 {
	margin: 0;
	font-size: 1.25rem;
	font-weight: 700;
	line-height: 1.25;
	color: var(--novel-fg);
}

.novel-modal-titles p {
	margin: .3rem 0 0;
	font-size: .8125rem;
	line-height: 1.45;
	color: var(--novel-muted);
}

.novel-modal-close {
	flex: 0 0 auto;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: var(--novel-muted);
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.novel-modal-close:hover {
	color: var(--novel-fg);
}

/* Single column so each group's pills stay visually tied to their own label. */
.novel-settings {
	display: block;
	padding: 1rem 1.35rem .25rem;
}

.novel-setting {
	margin: 0 0 1.15rem;
}

.novel-setting label {
	display: block;
	margin: 0 0 .55rem;
	font-size: .6875rem;
	font-weight: 700;
	letter-spacing: .07em;
	text-transform: uppercase;
	color: var(--novel-muted);
}

.novel-opts {
	display: flex;
	gap: .5rem;
	flex-wrap: wrap;
}

.novel-opts button,
.novel-step {
	padding: .5rem 1rem;
	border: 1px solid var(--novel-border);
	border-radius: 999px;
	background: transparent;
	color: var(--novel-fg);
	font: inherit;
	font-size: .8125rem;
	font-weight: 600;
	cursor: pointer;
	transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.novel-opts button:hover,
.novel-step:hover {
	border-color: var(--novel-ui);
}

.novel-opts button[aria-pressed="true"] {
	border-color: var(--novel-ui);
	background: var(--novel-ui);
	color: #fff;
}

.novel-range {
	display: flex;
	align-items: center;
	gap: .5rem;
}

.novel-step {
	width: 2.5rem;
	padding: .5rem 0;
	text-align: center;
	font-size: 1rem;
}

.novel-range-val {
	min-width: 4ch;
	text-align: center;
	font-size: .875rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--novel-fg);
}

/* ---- footer actions ---- */
.novel-modal-foot {
	display: flex;
	flex-direction: column;
	gap: .625rem;
	padding: .75rem 1.35rem 1.35rem;
}

.novel-done,
.novel-reset {
	width: 100%;
	padding: .75rem 1rem;
	border-radius: 10px;
	font: inherit;
	font-size: .9375rem;
	font-weight: 600;
	cursor: pointer;
	transition: filter .15s ease, border-color .15s ease;
}

.novel-done {
	border: 0;
	background: var(--novel-ui);
	color: #fff;
}

.novel-done:hover {
	filter: brightness(1.1);
}

.novel-reset {
	border: 1px solid var(--novel-border);
	background: transparent;
	color: var(--novel-fg);
}

.novel-reset:hover {
	border-color: var(--novel-ui);
}

/* ---- the prose itself ---- */
.novelbody .novel-shell {
	background: transparent;
	padding: 0;
}

/* Overrides the theme's .novel-reader rule (style.css), which hard-codes
   padding: 5rem 7rem and color: wheat -- both wrong once the reader is themed
   and width-constrained here. */
.novelbody .novel-reader,
.novelbody #readerarea.novel-reader {
	max-width: 100%;
	margin: 0;
	/* Bottom padding is mine, not in the supplied CSS: with padding:0 the last
	   paragraph sits flush against the panel edge. Top spacing comes from
	   .novel-toolbar above. */
	padding: 1.5rem 3% 2.5rem;
	text-align: var(--novel-align);
	font-family: var(--novel-font);
	font-size: var(--novel-size);
	line-height: var(--novel-leading);
	color: var(--novel-fg);
	background: var(--novel-surface);
	border-radius: 0 0 10px 10px;
}

.novelbody .novel-reader p {
	margin: 0 0 var(--novel-para);
	text-align: inherit;
	/* Stops justified text from opening rivers on narrow screens. */
	hyphens: auto;
}

.novelbody .novel-reader p:last-child {
	margin-bottom: 0;
}

/* Chapters pasted or uploaded with single newlines come out of wpautop as one
   <p> full of <br>, not as separate paragraphs -- and a bare <br> takes no
   margin, which is why those chapters render as a solid wall of lines while
   properly paragraphed ones look fine. Promoting the <br> to a block lets it
   carry the same spacing, so both markup styles read identically. */
.novelbody .novel-reader br {
	display: block;
	content: "";
	margin-bottom: var(--novel-para);
}

.novelbody .novel-reader img {
	max-width: 100%;
	height: auto;
	margin: 1.5em auto;
	display: block;
}

.novelbody .novel-reader hr {
	margin: 2.5em auto;
	width: 40%;
	border: 0;
	border-top: 1px solid var(--novel-border);
}

.novelbody .novel-reader h2,
.novelbody .novel-reader h3 {
	margin: 2em 0 .75em;
	line-height: 1.3;
	color: var(--novel-fg);
}

.novelbody .novel-reader blockquote {
	margin: 1.5em 0;
	padding: .25em 0 .25em 1.25em;
	border-left: 3px solid var(--novel-border);
	color: var(--novel-muted);
	font-style: italic;
}

/* ---- navigation ---- */
.novelbody .novel-nav {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: .75rem;
	margin: 1.75rem 0;
	padding: 1rem 0;
	border-top: 1px solid var(--novel-border);
	border-bottom: 1px solid var(--novel-border);
	flex-wrap: wrap;
}

/* Chapter label between the Prev/Next controls. Sits in the middle on desktop
   and drops to its own centred line once the nav wraps on narrow screens. */
.novelbody .novel-nav-title {
	flex: 1 1 auto;
	min-width: 0;
	text-align: center;
	font-size: .9375rem;
	font-weight: 600;
	color: var(--novel-fg);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.novelbody .novel-nav select {
	max-width: 100%;
	padding: .45rem .6rem;
	border: 1px solid var(--novel-border);
	border-radius: 5px;
	background: var(--novel-panel);
	color: var(--novel-fg);
	font: inherit;
	font-size: .8125rem;
}

.novelbody .chaptertags {
	margin-top: 2rem;
	color: var(--novel-muted);
	font-size: .8125rem;
	line-height: 1.6;
}

.novelbody .kln {
	margin: 1rem 0;
}

@media (max-width: 680px) {
	.novelbody {
		padding: 0 1rem 2rem;
	}

	.novelbody .entry-title {
		font-size: 1.3rem;
	}

	.novel-head {
		padding: 1.25rem 0 .75rem;
	}

	/* The old flex-basis override here is gone: .novel-head is a plain centred
	   block at every width now, so the title needs no mobile special case. */

	.novel-settings {
		padding: 1rem;
	}

	.novel-toolbar {
		margin-bottom: 1.25rem;
	}

	.novel-modal {
		padding: 0;
		align-items: flex-end;
	}

	.novel-modal-box {
		max-width: 100%;
		max-height: 90vh;
		border-radius: 12px 12px 0 0;
	}

	/* Force the label onto its own centred line above the buttons. */
	.novelbody .novel-nav-title {
		flex: 1 0 100%;
		order: -1;
		margin-bottom: .5rem;
	}
}

/* Someone who prefers reduced motion gets no width/colour transitions. */
@media (prefers-reduced-motion: reduce) {

	.novelbody,
	.novelbody .postarea {
		transition: none;
	}
}