/*
 * Tate — print: the scroll laid out on paper (enqueued with media="print", after tate.css).
 *
 * On paper there is no band and no inner scroller: .maki becomes an ordinary block, the root is as
 * wide as its content, and the browser breaks it into pages along the block axis, right to left
 * (the first page holds the start of the text). Chromium paginates vertical-rl this way; other
 * browsers may differ.
 *  - hidden: the band (masthead, breadcrumbs, menu, search, dark toggle), the skip link, the admin
 *    bar, the comment form and reply links, the navigation between posts, pages and comments, the
 *    related posts and the button back to the head (both ways to move on screen), the
 *    colophon's widgets and menu (the colophon's line with the site's name stays);
 *  - paper colours whatever the screen scheme;
 *  - lines run the full height of the page; pictures, cards and the boxes (.masu: vertical tables,
 *    horizontal code and embeds) are kept whole on one page, and headings stay with the text that
 *    follows them; a box taller than the paper (a long listing, or a table row of more cells than
 *    fit down the page) is cut at the bottom;
 *  - a link with an absolute URL is followed by that URL, small, in brackets (not a link card's
 *    link: the card shows its URL itself).
 * Generic font families only.
 */

@page {
	margin: 20mm 16mm;
}

/* Paper colours: the dark scheme's tokens are reset too. */
html,
html.dark {
	--kami: #fff;
	--sumi: #000;
	--usuzumi: #444;
	--shu: #b3282d;
	--sen: #999;
	--hikari: #fff;
	color-scheme: light;
}

/* No band on paper, nor the breadcrumbs' strip that widens it (the pictures' caps in tate.css count it). */
body.tate-pan {
	--pan: 0px;
}

html,
body {
	inline-size: auto; /* the page's height */
	block-size: auto;  /* as wide as the content: the pages follow each other to the left */
	overflow: visible;
}

body {
	background: #fff;
	color: #000;
	font-size: 11pt;
	line-height: 1.75;
}

.skip-link,
.obi,
.kensaku,
.kurai-kirikae,
.navigation,
.kanren,
.kanto,
.kiji-peji,
.comment-respond,
.tayori-list .reply,
.edit-link,
.comment-edit-link,
.oku-widgets,
.oku-nav,
#wpadminbar {
	display: none !important;
}

/* The scroll is an ordinary block: every column is printed, none is clipped. */
.maki {
	position: static;
	inset: auto;
	inline-size: auto;
	block-size: auto;
	overflow: visible;
	padding: 0;
	outline: none;
}

.maki-hon {
	padding: 0;
	outline: none;
}

:focus,
:focus-visible {
	outline: none;
}

/* ------------------------------------------------------------------
 * The article: lines as long as the page is high.
 * ------------------------------------------------------------------ */
.kiji-tobira {
	float: none;
}

.kiji-honbun {
	max-inline-size: none;
}

.kiji-honbun p {
	orphans: 2;
	widows: 2;
}

/*
 * A picture is never wider than the page (it cannot be split). Only its block size (width) is capped;
 * the inline size (height) is left as on screen (the height attribute, at most the line's length) and
 * the width follows the attributes' ratio. Setting both to auto would size lazy images with
 * sizes="auto, …" (the UA gives them contain: size) by core's contain-intrinsic-size (3000px 1500px)
 * instead of the picture. If the cap narrows the box, object-fit keeps the proportions.
 */
.kiji-honbun img {
	max-block-size: 80vw;
	object-fit: contain;
}

/*
 * A picture aligned left or right keeps its size on paper. On screen it takes at most half the line,
 * and so do its `sizes` (tate.css, inc/images.php); a printed picture would keep the size its `sizes`
 * gave it on screen, as Chromium does not choose its file again for paper. inc/images.php writes the
 * width it has in a full line into --tate-width (only where it halved the `sizes`; a picture cropped
 * to another ratio in the block editor, by an aspect-ratio in its style, counts that ratio); the
 * height follows the ratio, and the caps above still apply. The theme alone writes this property:
 * inc/images.php takes one an author wrote out of the pictures in the text.
 */
.kiji-honbun img[style*="--tate-width"] {
	block-size: var(--tate-width);
}

/* ------------------------------------------------------------------
 * Breaks: the column after a heading goes with it; pictures, cards and boxes stay whole.
 * ------------------------------------------------------------------ */
h1,
h2,
h3,
h4,
.ichiran-mado {
	break-after: avoid;
}

figure,
.wp-caption,
.gallery-item,
.kiji-e,
.kiji-honbun img,
.fuda,
.linkcard,
.masu,
.kakomi,
.kakomi-chui,
.kakomi-memo,
.is-style-kakomi,
.is-style-kakomi-chui,
.is-style-kakomi-memo,
.wp-block-buttons,
.wp-block-social-links {
	break-inside: avoid;
}

/* The summary of a details goes with what follows it (ADR-62). */
summary {
	break-after: avoid;
}

/*
 * Boxes (vertical tables, horizontal code and embeds) at full length: no inner scrolling on paper.
 * The screen's cap on a horizontal box's width stays, so long code lines wrap; a box that still
 * cannot be that narrow widens (min-content) instead of spilling to the right, over the text before
 * it. Nothing breaks a box along its height: a listing taller than the paper, or a table row of more
 * cells than fit down the page, is cut at the bottom.
 */
.masu {
	min-width: min-content;
	max-height: none;
	overflow: visible;
}

.masu th,
.masu td {
	overflow-wrap: anywhere;
}

.masu pre {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	background: none;
}

/* The code block's <code> sets overflow-wrap: break-word itself (core's block style), which does not
 * count in min-content: without this, the longest unbroken word would set the box's min-content. */
.masu pre *,
.masu code {
	overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------
 * Links: underlined in ink; a link with an absolute URL (http… — the site's own included) is
 * followed by that URL, small. Not the links of a Pz link card (.lkc-link): the card shows its URL
 * (or, for a post of the site, its date), and on a card without pictures (no thumbnail, no site
 * icon) the URL would come as one more column at its left.
 * ------------------------------------------------------------------ */
a {
	color: inherit;
	text-decoration-color: currentColor;
}

/* Buttons and social icons (ADR-62) keep their colours on paper: without its ink, a filled button's
   paper-coloured letters vanish on the white. */
.kiji-honbun :is(.wp-block-button__link, .wp-social-link) {
	-webkit-print-color-adjust: exact;
	print-color-adjust: exact;
}

/* The address of a link in the text follows it; not inside a button or a social icon (a pill as long as the URL). */
.kiji-honbun a[href^="http"]:not(:has(img), .lkc-link, .wp-block-button__link, .wp-block-social-link-anchor)::after {
	content: "（" attr(href) "）";
	font-family: sans-serif;
	font-size: 0.7em;
	word-break: break-all;
}
