/* Scriptorium — visual identity shared with hdplus.es (palette, Georgia headings, light/dark theme) */
:root {
	color-scheme: light;
	--bg: #f8f7f4;
	--surface: #fff;
	--ink: #182435;
	--muted: #586170;
	--line: #dededb;
	--gold: #93713e;
	--soft: #f0ebe2;
	--mark: #f3e2b8;
	--shadow: 0 18px 45px rgba(21, 34, 51, .06);
	--serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
	--sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #111923;
	--surface: #1c2733;
	--ink: #f1f1ee;
	--muted: #bac2ca;
	--line: #35414f;
	--gold: #d6b47e;
	--soft: #263441;
	--mark: #5a4a2a;
	--shadow: 0 18px 45px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
	margin: 0;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	font: 17px/1.65 var(--sans);
	background: var(--bg);
	color: var(--ink);
}
main { flex: 1 0 auto; }
a { color: inherit; }
a:hover { color: var(--gold); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
img { max-width: 100%; height: auto; }
.shell { max-width: 1180px; width: calc(100% - 64px); margin: 0 auto; }
.narrow { max-width: 780px; padding: 56px 0 90px; }
.skip { position: absolute; left: 8px; top: -100px; z-index: 100; background: var(--ink); color: var(--bg); padding: 10px; }
.skip:focus { top: 8px; }
.eyebrow { font-size: 15px; text-transform: uppercase; letter-spacing: .18em; color: var(--gold); font-weight: 700; margin: 0; }
.lead { font: 21px/1.55 var(--serif); color: var(--muted); }
.note { color: var(--muted); }
.pre { white-space: pre-wrap; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.head-row { display: flex; align-items: center; gap: 28px; min-height: 88px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; line-height: 1.25; margin-right: auto; text-decoration: none; }
.brand strong { font: 700 28px var(--serif); letter-spacing: .01em; }
.brand span { font-size: 15px; color: var(--muted); margin-top: 3px; }
.main-nav a { text-decoration: none; font-size: 17px; }
.main-nav a.active { color: var(--gold); border-bottom: 2px solid var(--gold); }
.switches { display: flex; align-items: center; gap: 16px; border-left: 1px solid var(--line); padding-left: 18px; flex-wrap: wrap; }
.langs { display: flex; gap: 8px; font-size: 16px; }
.langs a { text-decoration: none; }
.langs a[aria-current] { color: var(--gold); font-weight: 750; }
.theme-toggle { border: 0; background: transparent; font-size: 24px; line-height: 1; padding: 6px; cursor: pointer; }
.account { display: flex; align-items: center; gap: 12px; font-size: 16px; }
.account a { text-decoration: none; }
.user-name { font-weight: 600; }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.orcid-icon { width: 1.15em; height: 1.15em; vertical-align: -.2em; margin-right: .4em; }
.orcid-link { font-weight: 600; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 5px; padding: 12px 18px; min-height: 48px; font-size: 16px; font-weight: 650; text-decoration: none; cursor: pointer; border: 1px solid transparent; }
.btn.primary { background: var(--gold); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #111923; }
.btn.outline { background: var(--surface); border-color: var(--line); }
.btn:hover { filter: brightness(1.05); }

/* Library */
.page-top { padding: 64px 0 36px; border-bottom: 1px solid var(--line); background: linear-gradient(115deg, var(--surface) 45%, var(--soft)); }
.page-top h1 { font: 500 clamp(44px, 5vw, 66px)/1.07 var(--serif); letter-spacing: -.03em; margin: 12px 0; }
.page-top .lead { max-width: 820px; margin: 0; }
.library { padding: 36px 0 90px; }
.search-form { display: grid; grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(150px, 1fr)) auto; gap: 14px; align-items: end; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 15px; font-weight: 650; }
.field input, .field select, .stack-form input, .stack-form textarea {
	width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
.field-actions { flex-direction: row; gap: 10px; }
.result-count { margin: 26px 0 8px; color: var(--muted); }
.doc-list { display: grid; gap: 16px; margin-top: 12px; }
.doc-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 26px 28px; transition: box-shadow .2s; }
.doc-card:hover { box-shadow: var(--shadow); }
.doc-card.pinned { border-left: 4px solid var(--gold); }
.doc-card h2 { font: 500 29px/1.25 var(--serif); margin: 8px 0 4px; }
.doc-card h2 a { text-decoration: none; }
.doc-meta, .reader-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; color: var(--muted); font-size: 16px; margin: 0; }
.pin-mark { color: var(--gold); font-weight: 700; }
.badge { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 20px; padding: 2px 12px; background: var(--bg); }
.doc-subtitle { font: italic 20px/1.4 var(--serif); color: var(--muted); margin: 0 0 8px; }
.doc-abstract { margin: 10px 0 0; }
.snippet { margin: 12px 0 0; padding: 10px 14px; background: var(--soft); border-radius: 6px; font-family: var(--serif); }
mark { background: var(--mark); color: inherit; padding: 0 .1em; }
.keywords { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.keywords li { background: var(--soft); border-radius: 4px; padding: 2px 10px; font-size: 15px; }
.empty { font: 20px var(--serif); color: var(--muted); padding: 40px 0; }

/* Reader */
.reader-layout { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); gap: 56px; padding: 44px 0 90px; align-items: start; }
.reader-layout.no-toc { grid-template-columns: minmax(0, 1fr); max-width: 860px; }
.reader-toc { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 14px 18px; font-size: 16px; }
.reader-toc summary { font: 600 19px var(--serif); cursor: pointer; }
.reader-toc ul { list-style: none; padding-left: 14px; margin: 6px 0; }
.reader-toc nav > ul { padding-left: 0; }
.reader-toc a { text-decoration: none; display: block; padding: 3px 0; line-height: 1.35; }
.reader-toc a.current { color: var(--gold); font-weight: 650; }
.reader { min-width: 0; max-width: 46rem; }
.reader-head { border-bottom: 1px solid var(--line); padding-bottom: 24px; margin-bottom: 30px; }
.reader-head h1 { font: 500 clamp(40px, 4.6vw, 58px)/1.1 var(--serif); letter-spacing: -.02em; margin: 10px 0 8px; }
.reader-subtitle { font: italic 24px/1.35 var(--serif); color: var(--muted); margin: 0 0 14px; }
.reader-author { font-size: 19px; font-weight: 600; margin: 0; }
.reader-affiliation { color: var(--muted); margin: 0 0 14px; }
.reader-body {
	font: 19px/1.7 var(--serif);
	text-align: justify;
	hyphens: auto;
	-webkit-hyphens: auto;
	overflow-wrap: break-word;
}
.reader-body p { margin: 0 0 .85em; }
.reader-body h2, .reader-body h3, .reader-body h4, .reader-body h5, .reader-body h6 {
	font-family: var(--serif); font-weight: 500; text-align: left; hyphens: manual; -webkit-hyphens: manual; line-height: 1.25; scroll-margin-top: 16px;
}
.reader-body .part-label { margin-top: 4.5rem; text-align: center; text-transform: uppercase; letter-spacing: .2em; color: var(--muted); font-family: var(--sans); font-size: 16px; }
.reader-body .part { text-align: center; font-size: 36px; margin: .3rem 0 2.6rem; }
.reader-body .chapter { font-size: 31px; margin-top: 3.6rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.reader-body .sec1 { font-size: 25px; margin-top: 2.4rem; }
.reader-body .sec2 { font-size: 21px; margin-top: 2rem; }
.reader-body .sec3 { font-size: 19px; font-style: italic; margin-top: 1.6rem; }
.reader-body.no-parts .chapter { font-size: 33px; }
.reader-body .centrado { text-align: center; }
.reader-body blockquote { margin: 1.2rem 2rem; color: var(--muted); }
.reader-body .regla { border-left: 4px solid var(--gold); background: var(--soft); padding: .7rem 1.1rem; margin: 1.3rem 0; border-radius: 0 6px 6px 0; }
.reader-body .regla p:last-child { margin-bottom: 0; }
.reader-body .bibliography p { padding-left: 2em; text-indent: -2em; text-align: left; }
.reader-body .figura { text-align: center; }
.reader-body img { cursor: zoom-in; border-radius: 3px; }
.reader-body .titulo-de-tabla-o-figura, .reader-body .caption { font-family: var(--sans); font-weight: 650; font-size: 17px; text-align: left; margin-top: 1.6rem; hyphens: manual; }
.reader-body .nota-de-tabla-o-figura { font-family: var(--sans); font-size: 16px; color: var(--muted); text-align: left; hyphens: manual; }
.reader-body table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-family: var(--sans); font-size: 16px; display: block; overflow-x: auto; }
.reader-body th, .reader-body td { border-bottom: 1px solid var(--line); padding: .4rem .55rem; vertical-align: top; text-align: left; hyphens: manual; }
.reader-body thead th { border-bottom: 2px solid var(--ink); }
.reader-body .texto-de-tabla p { margin: 0; }
.reader-body ul, .reader-body ol { padding-left: 1.6em; }
.reader-body a { color: var(--gold); }
.reader-body sup a, .reader-body .footnote-ref { text-decoration: none; font-family: var(--sans); font-weight: 650; }
.reader-body section.footnotes { border-top: 1px solid var(--line); margin-top: 3.5rem; padding-top: 1rem; font-size: 17px; line-height: 1.55; }
.reader-body section.footnotes hr { display: none; }
.reader-body section.footnotes li { margin-bottom: .7rem; }
.reader-body .footnote-back { text-decoration: none; margin-left: .3em; }
.reader-body math { font-size: 1.05em; }

/* Gate (sign-in required) */
.reader-gate .reader-head { margin-bottom: 18px; }
.gate-box, .download-box, .cite-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 24px 28px; margin-top: 30px; }
.gate-box { border-top: 3px solid var(--gold); }
.gate-box h2, .download-box h2, .cite-box h2, .extras > h2 { font: 500 25px/1.3 var(--serif); margin: 0 0 10px; }
.orcid-button .orcid-icon { margin-right: 0; }

/* Extras */
.extras { margin-top: 56px; padding-top: 26px; border-top: 2px solid var(--gold); }
.extra { margin: 0 0 32px; }
.extra h3 { font: 500 21px var(--serif); margin: 0 0 10px; }
.extra figcaption { color: var(--muted); margin-top: 8px; font-size: 16px; }
.extra-image img { cursor: zoom-in; border: 1px solid var(--line); border-radius: 4px; }
.extra audio, .extra video { width: 100%; }
.video-frame { position: relative; aspect-ratio: 16 / 9; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 6px; }
.app-frame { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }

/* Forms and messages */
.message-page h1, .form-page h1, .admin h1 { font: 500 clamp(36px, 4vw, 50px)/1.15 var(--serif); margin: 10px 0 16px; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.stack-form label { display: grid; gap: 6px; font-weight: 650; }
.stack-form label.check { display: flex; gap: 10px; align-items: start; font-weight: 400; }
.stack-form .check input { width: 22px; height: 22px; min-height: 0; margin-top: 3px; accent-color: var(--gold); }
.hint { margin: -8px 0 0; color: var(--muted); }
.identity { display: flex; align-items: center; background: var(--soft); padding: 12px 16px; border-radius: 6px; margin: 0; }
.form-errors { border-left: 4px solid #b3412e; background: var(--soft); padding: 10px 18px; border-radius: 0 6px 6px 0; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 24px 0; }
.details dt { font-weight: 650; }
.details dd { margin: 0; }
.decide-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* Administration */
.admin { padding: 48px 0 90px; }
.admin h2 { font: 500 27px var(--serif); margin: 40px 0 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.admin table { border-collapse: collapse; width: 100%; font-size: 16px; }
.admin th, .admin td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.admin .num { text-align: right; }

/* Image viewer */
.viewer { border: 0; padding: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; background: rgba(10, 14, 20, .94); color: #fff; }
.viewer::backdrop { background: rgba(10, 14, 20, .94); }
.viewer-stage { position: absolute; inset: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
.viewer-stage img { max-width: 92vw; max-height: 88vh; transform-origin: center; user-select: none; -webkit-user-drag: none; }
.viewer-tools { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; z-index: 2; }
.viewer-tools button { min-width: 48px; min-height: 48px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .35); background: rgba(0, 0, 0, .45); color: #fff; font-size: 20px; cursor: pointer; }
.viewer-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 20px; background: rgba(0, 0, 0, .55); font-size: 17px; text-align: center; }

/* Footer: always at the bottom (body is a flex column) */
.site-footer { background: var(--surface); border-top: 1px solid var(--line); padding: 40px 0 20px; }
.foot-grid { display: grid; grid-template-columns: 1.2fr 1.7fr .6fr; gap: 25px; align-items: start; }
.foot-brand { font: 24px var(--serif); text-decoration: none; }
.foot-grid p, .copyright { color: var(--muted); font-size: 15px; }
.foot-links { display: flex; flex-wrap: wrap; gap: 10px 22px; font-size: 16px; }
.foot-links a, .foot-external a { text-decoration: none; }
.foot-external { display: flex; flex-direction: column; gap: 7px; font-size: 16px; }
.copyright { border-top: 1px solid var(--line); margin-top: 30px; padding-top: 16px; }

@media (max-width: 980px) {
	.search-form { grid-template-columns: 1fr 1fr; }
	.field-q, .field-actions { grid-column: 1 / -1; }
	.reader-layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
	.reader-toc { position: static; max-height: none; }
	.foot-grid { grid-template-columns: 1fr 1fr; }
	.foot-external { grid-column: 1 / -1; flex-direction: row; gap: 20px; }
}
@media (max-width: 690px) {
	.shell { width: calc(100% - 34px); }
	.head-row { gap: 12px; padding: 12px 0; }
	.switches { border-left: 0; padding-left: 0; width: 100%; justify-content: space-between; }
	.search-form { grid-template-columns: 1fr; }
	.doc-card { padding: 20px; }
	.reader-body { font-size: 18px; text-align: left; }
	.reader-body .part { font-size: 30px; }
	.reader-body .chapter { font-size: 27px; }
	.foot-grid { grid-template-columns: 1fr; }
	.details { grid-template-columns: 1fr; }
}
@media print {
	.site-header, .site-footer, .reader-toc, .download-box, .extras { display: none; }
	.reader-layout { display: block; }
	body { background: #fff; color: #000; }
}
@media (prefers-reduced-motion: reduce) {
	html { scroll-behavior: auto; }
	* { transition: none !important; }
}
