/*
 * The HiMatcher User's Guide. Set like a printed software manual: serif text in a comfortable
 * measure, section headings hanging in a wide left margin, numbered steps, margin notes and
 * numbered figures. No web fonts, and one small script (guide.js, the chapter navigator): it should read
 * anywhere and print cleanly.
 */
:root {
    --ink: #1d2430;
    --soft: #55606f;
    --faint: #8a93a0;
    --rule: #d9dde3;
    --paper: #fdfcf9;
    --desk: #f1efe9;
    --accent: #23527c;
    --accent-soft: #e8eff6;
    --note: #f6f3e8;
    --caution: #fbeee6;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --sans: "Segoe UI", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
    --margin: 13rem; /* the hanging margin the headings sit in */
}

* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: var(--header-h, 0px); }
body { margin: 0; background: var(--desk); color: var(--ink); font-family: var(--serif); line-height: 1.62; }
a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; height: auto; }

.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0.5rem; top: 0.5rem; }

.draft { margin: 0; padding: 0.45rem 2rem; background: #9a3412; color: #fff; font: 600 0.8rem var(--sans); }
.to-come-link { font-style: italic; }

/* Masthead */
/* The masthead stays at the top as the reader scrolls, a little smaller once away from the top (the script in layout.blade.php). */
.masthead { position: sticky; top: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1.5rem; padding: 0.9rem 2rem; background: var(--ink); color: #fff; font-family: var(--sans); transition: padding 0.2s ease, box-shadow 0.2s ease; }
.masthead.shrunk { padding-top: 0.45rem; padding-bottom: 0.45rem; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
.masthead .brand-name { transition: font-size 0.2s ease; }
.masthead.shrunk .brand-name { font-size: 1rem; }
@media (prefers-reduced-motion: reduce) { .masthead, .masthead .brand-name { transition: none; } }
.brand { color: #fff; text-decoration: none; }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: 0.01em; }
.brand-book { margin-left: 0.5rem; padding-left: 0.6rem; border-left: 1px solid rgba(255, 255, 255, 0.35); font-size: 0.95rem; opacity: 0.9; }
.masthead-links { display: flex; flex-wrap: wrap; gap: 1.25rem; font-size: 0.85rem; }
.masthead-links a { color: #fff; opacity: 0.85; text-decoration: none; }
.masthead-links a:hover { opacity: 1; text-decoration: underline; }
.masthead-links .print { font: inherit; color: #fff; opacity: 0.85; background: none; border: 0; padding: 0; cursor: pointer; }
.masthead-links .print:hover { opacity: 1; text-decoration: underline; }

/* The open book: contents on the left, the page on the right */
.book { display: grid; grid-template-columns: 17.5rem minmax(0, 1fr); max-width: 86rem; margin: 0 auto; }

.contents { font-family: var(--sans); font-size: 0.84rem; line-height: 1.4; padding: 2rem 1.25rem 3rem 2rem; position: sticky; top: var(--header-h, 0px); align-self: start; max-height: calc(100vh - var(--header-h, 0px)); overflow-y: auto; }
.contents summary { font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem; color: var(--soft); cursor: pointer; list-style: none; }
.contents summary::-webkit-details-marker { display: none; }
.contents .part { margin: 1.4rem 0 0.35rem; font-weight: 700; color: var(--ink); }
.contents ol { margin: 0; padding-left: 1.6rem; }
.contents li { padding: 0.2rem 0; color: var(--faint); }
.contents li a { color: var(--soft); text-decoration: none; }
.contents li a:hover { color: var(--accent); text-decoration: underline; }
.contents li.current a { color: var(--ink); font-weight: 700; }
.contents li.current::marker { color: var(--ink); font-weight: 700; }
.contents em, .cover-list em { font-style: normal; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); border: 1px solid var(--rule); border-radius: 3px; padding: 0 0.3rem; margin-left: 0.25rem; white-space: nowrap; }

.page { background: var(--paper); min-height: 100vh; padding: 3.5rem 3.5rem 4rem; border-left: 1px solid var(--rule); box-shadow: -8px 0 24px -18px rgba(0, 0, 0, 0.25); }
.chapter { max-width: 54rem; }

/* Chapter opening */
.chapter-head { padding-left: var(--margin); border-bottom: 3px double var(--ink); padding-bottom: 1.5rem; margin-bottom: 2rem; }
.chapter-number { font-family: var(--sans); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--soft); margin: 0 0 0.6rem; }
h1 { font-family: var(--sans); font-size: 2.3rem; line-height: 1.12; letter-spacing: -0.015em; margin: 0; font-weight: 700; }
.lede { font-size: 1.12rem; color: var(--soft); margin: 1rem 0 0; font-style: italic; }

.learn { margin: 0 0 2.2rem var(--margin); padding: 1rem 1.25rem 1.1rem; background: var(--accent-soft); border-left: 4px solid var(--accent); }
.learn-title { font-family: var(--sans); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; margin: 0 0 0.4rem; color: var(--accent); }
.learn ul { margin: 0; padding-left: 1.2rem; }
.learn li { margin: 0.15rem 0; }

/* Running text: everything sits to the right of the margin; h2 headings hang in it */
.text > * { margin-left: var(--margin); }
.text p, .text ul, .text ol { margin-top: 0; margin-bottom: 0.95rem; }
.text .section-gap { height: 2.4rem; clear: both; margin: 0; }
.text h2 { font-family: var(--sans); font-size: 1.02rem; line-height: 1.3; font-weight: 700; margin: 0; float: left; clear: both; width: calc(var(--margin) - 1.75rem); text-align: right; padding-top: 0.3rem; border-top: 1px solid var(--ink); }
.text h2 + * { margin-top: 0; padding-top: 0.3rem; border-top: 1px solid var(--rule); }
.text h2 + figure, .text h2 + aside, .text h2 + table { border-top: 0; }
.text h3 { font-family: var(--sans); font-size: 0.98rem; margin-top: 1.6rem; margin-bottom: 0.4rem; }
.text strong, .text b { font-family: var(--sans); font-size: 0.93em; font-weight: 700; }
.text code { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 0.86em; background: var(--desk); padding: 0.05em 0.3em; border-radius: 3px; }
.text ul { padding-left: 1.2rem; }
.text li { margin: 0.25rem 0; }

/* Numbered steps, as in a manual: the number stands clear of the text */
.text ol { list-style: none; counter-reset: step; padding-left: 0; }
.text ol > li { counter-increment: step; position: relative; padding-left: 2.4rem; margin: 0.55rem 0; }
.text ol > li::before { content: counter(step); position: absolute; left: 0; top: 0.08rem; width: 1.55rem; height: 1.55rem; border-radius: 50%; background: var(--ink); color: #fff; font: 700 0.8rem/1.55rem var(--sans); text-align: center; }
.text ol > li > p { margin-bottom: 0.4rem; }

/* Tables */
.text table { border-collapse: collapse; font-family: var(--sans); font-size: 0.86rem; line-height: 1.4; width: calc(100% - var(--margin)); margin-bottom: 1.4rem; }
.text th { text-align: left; border-bottom: 2px solid var(--ink); padding: 0.4rem 0.75rem 0.4rem 0; }
.text td { border-bottom: 1px solid var(--rule); padding: 0.45rem 0.75rem 0.45rem 0; vertical-align: top; }

/* Figures reach into the margin so the screens are large enough to read */
.text figure { margin: 1.6rem 0 1.9rem calc(var(--margin) - 9rem); }
.text figure img { display: block; border: 1px solid var(--rule); box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.3); background: #fff; }
.text figcaption { font-family: var(--sans); font-size: 0.8rem; color: var(--soft); margin-top: 0.5rem; padding-left: 9rem; }
.text figcaption b { color: var(--ink); margin-right: 0.35rem; }
.text figure, .text table { clear: both; }

/* A narrow picture stands to one side and the text runs alongside it, rather than leaving the line empty.
   The caption sits under the picture and is no wider than it. */
.text figure.side { float: left; display: table; margin-top: 0.35rem; margin-right: 1.75rem; margin-bottom: 1.1rem; }
.text figure.side figcaption { display: table-caption; caption-side: bottom; padding-left: 0; }
.text figure.side-fitted img { width: 28rem; }
.text h2 + figure.side { clear: left; }
/* Each paragraph, list and note after it stands beside the picture as a box of its own, rather than running under it. */
.text .by-figure { display: flow-root; }

/* Margin notes */
.note { background: var(--note); border-top: 2px solid var(--ink); padding: 0.75rem 1rem 0.2rem; margin-top: 1.2rem; margin-bottom: 1.4rem; font-size: 0.95rem; }
.note-caution { background: var(--caution); border-top-color: #9a3412; }
.note-label { font-family: var(--sans); font-weight: 700; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.1em; margin-right: 0.5rem; }
.note-caution .note-label { color: #9a3412; }
.note p:last-child { margin-bottom: 0.6rem; }

/* Cover page */
.cover-part { border-bottom: 1px solid var(--ink); padding-bottom: 0.2rem; }
.cover-list { list-style: decimal !important; counter-reset: none !important; padding-left: 1.6rem !important; }
.cover-list > li { padding-left: 0.3rem !important; margin: 0.5rem 0 !important; }
.cover-list > li::before { content: none !important; }
.cover-list li.to-come { color: var(--faint); }
.cover-summary { display: block; font-size: 0.92rem; color: var(--soft); }

/* Turning the page */
.turn { display: flex; justify-content: space-between; gap: 1rem; margin: 3.5rem 0 0 var(--margin); padding-top: 1rem; border-top: 3px double var(--ink); font-family: var(--sans); font-size: 0.92rem; }
.turn a { text-decoration: none; font-weight: 700; max-width: 48%; }
.turn a span { display: block; font-weight: 400; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--soft); }
.turn-on { text-align: right; margin-left: auto; }
.updated { margin: 1.5rem 0 0 var(--margin); font-family: var(--sans); font-size: 0.75rem; color: var(--faint); }

.colophon { max-width: 86rem; margin: 0 auto; padding: 1.25rem 2rem 2.5rem; font-family: var(--sans); font-size: 0.75rem; color: var(--soft); }

/* Narrower screens: the margin closes up and the headings come back above the text */
@media (max-width: 1150px) {
    :root { --margin: 0rem; }
    .text h2 { float: none; width: auto; text-align: left; border-top: 2px solid var(--ink); padding-top: 0.5rem; margin-bottom: 0.6rem; font-size: 1.15rem; }
    .text h2 + * { border-top: 0; padding-top: 0; }
    .text figure { margin-left: 0; }
    .text figcaption { padding-left: 0; }
    .text table { width: 100%; }
    /* With the margin closed up there is only room beside the smallest pictures. */
    .text figure.side:not(.side-small) { float: none; display: block; margin: 1.6rem 0 1.9rem; }
    .text figure.side:not(.side-small) figcaption { display: block; }
    .text figure.side-fitted img { width: auto; }
}
@media (max-width: 560px) {
    .text figure.side { float: none; display: block; margin: 1.6rem 0 1.9rem; }
    .text figure.side figcaption { display: block; }
}
@media (max-width: 900px) {
    .book { grid-template-columns: 1fr; }
    .contents { position: static; max-height: none; padding: 1rem 1.25rem; border-bottom: 1px solid var(--rule); }
    .page { padding: 2rem 1.25rem 3rem; border-left: 0; box-shadow: none; }
    h1 { font-size: 1.8rem; }
}

/* On paper */
@media print {
    html { font-size: 11pt; }
    body { background: #fff; }
    .masthead, .contents, .turn, .skip, .colophon, .draft, .chapter-nav { display: none; }
    .book { display: block; max-width: none; }
    .page { padding: 0; border: 0; box-shadow: none; background: #fff; min-height: 0; }
    :root { --margin: 4.2cm; }
    .text figure { margin-left: 0; break-inside: avoid; }
    .text figcaption { padding-left: 0; }
    .text figure.side { max-width: 45%; }
    .text figure img { box-shadow: none; }
    .note, .learn, .text ol > li { break-inside: avoid; }
    .text h2 { break-after: avoid; }
    a { color: inherit; text-decoration: none; }
}

/* The opening list: each line is a link to the section it describes, and a section arrives with a little room above it */
.learn a { color: inherit; text-decoration-color: rgba(35, 82, 124, 0.4); }
.learn a:hover { color: var(--accent); text-decoration-color: currentColor; }
.text h2 { scroll-margin-top: 1.25rem; }

/* The chapter navigator: the chapter's sections in a small box that follows the reader once the opening list has
   scrolled out of sight, fades away when it comes back, and can be dragged anywhere by its handle (guide.js). */
.chapter-nav { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 20; width: 16rem; font-family: var(--sans); font-size: 0.8rem; line-height: 1.35; opacity: 0; visibility: hidden; transform: translateY(0.5rem); transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s; }
.chapter-nav.is-shown { opacity: 1; visibility: visible; transform: none; transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s; }
.chapter-nav.is-dragging { transition: none; }
.chapter-nav-panel { background: var(--paper); border: 1px solid var(--rule); border-left: 4px solid var(--accent); border-radius: 4px; box-shadow: 0 10px 30px -12px rgba(29, 36, 48, 0.35), 0 2px 6px -2px rgba(29, 36, 48, 0.15); overflow: hidden; }
.chapter-nav.is-dragging .chapter-nav-panel { box-shadow: 0 18px 40px -14px rgba(29, 36, 48, 0.45); }
.chapter-nav-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem 0.45rem 0.5rem; background: var(--accent-soft); border-bottom: 1px solid var(--rule); }
.chapter-nav-title { flex: 1; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); }
.chapter-nav-handle { flex: none; display: grid; place-items: center; width: 1.5rem; height: 1.25rem; padding: 0; border: 0; border-radius: 3px; background: none; cursor: grab; touch-action: none; }
.chapter-nav-handle span { display: block; width: 0.6rem; height: 0.9rem; background-image: radial-gradient(circle, var(--faint) 1.1px, transparent 1.4px); background-size: 0.3rem 0.3rem; }
.chapter-nav-handle:hover span, .chapter-nav-handle:focus-visible span { background-image: radial-gradient(circle, var(--accent) 1.1px, transparent 1.4px); }
.chapter-nav-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chapter-nav.is-dragging .chapter-nav-handle { cursor: grabbing; }
.chapter-nav-close { display: none; }
.chapter-nav-sections { list-style: none; margin: 0; padding: 0.35rem 0; max-height: min(60vh, 26rem); overflow-y: auto; }
.chapter-nav-sections li { margin: 0; padding: 0; }
.chapter-nav-sections a { display: block; padding: 0.3rem 0.75rem 0.3rem 0.85rem; color: var(--soft); text-decoration: none; }
.chapter-nav-sections a:hover { color: var(--accent); background: var(--accent-soft); }
.chapter-nav-sections a.current { color: var(--ink); font-weight: 700; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.chapter-nav-top { display: block; padding: 0.5rem 0.75rem 0.55rem 0.85rem; border-top: 1px solid var(--rule); color: var(--accent); text-decoration: none; font-weight: 700; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; }
.chapter-nav-top::before { content: ""; display: inline-block; width: 0.4rem; height: 0.4rem; margin: 0 0.55rem 0 0.1rem; border-left: 2px solid currentColor; border-top: 2px solid currentColor; transform: translateY(0.12rem) rotate(45deg); }
.chapter-nav-top:hover { background: var(--accent-soft); }
.chapter-nav-pill { display: none; }

/* On a phone the navigator folds to a pill at the foot of the screen, and a tap opens the list as a sheet. */
@media (max-width: 700px) {
    .chapter-nav, .chapter-nav.is-placed { left: auto !important; top: auto !important; right: 0.75rem !important; bottom: 0.75rem !important; width: auto; max-width: calc(100vw - 1.5rem); }
    .chapter-nav-pill { display: inline-flex; align-items: center; gap: 0.5rem; max-width: 100%; padding: 0.5rem 0.9rem 0.5rem 0.75rem; border: 1px solid var(--rule); border-left: 4px solid var(--accent); border-radius: 999px; background: var(--paper); color: var(--accent); font: 700 0.68rem/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.08em; box-shadow: 0 8px 24px -10px rgba(29, 36, 48, 0.4); cursor: pointer; }
    .chapter-nav-pill-label { white-space: nowrap; }
    .chapter-nav-pill-now { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .chapter-nav-pill-now:empty { display: none; }
    .chapter-nav-pill-now:not(:empty)::before { content: "· "; }
    .chapter-nav-panel { display: none; position: fixed; left: 0.75rem; right: 0.75rem; bottom: 0.75rem; }
    .chapter-nav.is-open .chapter-nav-panel { display: block; }
    .chapter-nav.is-open .chapter-nav-pill { visibility: hidden; }
    .chapter-nav-handle { display: none; }
    .chapter-nav-close { display: block; position: relative; flex: none; width: 1.5rem; height: 1.5rem; padding: 0; border: 0; background: none; cursor: pointer; }
    .chapter-nav-close::before, .chapter-nav-close::after { content: ""; position: absolute; left: 50%; top: 50%; width: 0.9rem; height: 2px; background: var(--soft); transform: translate(-50%, -50%) rotate(45deg); }
    .chapter-nav-close::after { transform: translate(-50%, -50%) rotate(-45deg); }
    .chapter-nav-sections { max-height: 50vh; }
}

/* For a reader who has asked for less movement: no gliding, no fading */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .chapter-nav, .chapter-nav.is-shown { transition: none; transform: none; }
}
