/*
 * DTI Auto — the look of a baseline 作品紹介 article.
 *
 * Every selector in this file begins with a `dti-auto-` class. Nothing here
 * says `table`, `a`, `img` or `blockquote` on its own, because this stylesheet
 * loads on a page a theme also styles, and a bare element selector would reach
 * content this plugin did not write.
 *
 * The article's markup carries these classes whatever order the operator's
 * template puts them in, so moving [dti:cta] moves its styling with it. There
 * is no rule here that depends on a section being first, last or next to
 * anything else.
 *
 * Colours are stated as tokens on the article's own components rather than
 * inherited from the theme, so the CTA reads as a button on a light theme and a
 * dark one. Everything else stays close to the surrounding text: this is a
 * plugin decorating its own sections, not a plugin restyling a site.
 */

:root {
	--dti-auto-accent: #d81b60;
	--dti-auto-accent-hover: #ad1457;
	--dti-auto-accent-text: #ffffff;
	--dti-auto-rule: rgba( 127, 127, 127, 0.28 );
	--dti-auto-quiet: rgba( 127, 127, 127, 0.09 );
	--dti-auto-radius: 6px;
	--dti-auto-gap: 1.8em;
}

/* ------------------------------------------------------------------ spacing */

/*
 * One rhythm for the whole article, applied to the components themselves. No
 * h2 rule: headings belong to the theme, and a plugin that restyles them
 * changes every article on the site, not only its own.
 */
.dti-auto-featured,
.dti-auto-sample,
.dti-auto-cta,
.dti-auto-gallery,
.dti-auto-facts,
.dti-auto-description,
.dti-auto-tags {
	margin-top: var( --dti-auto-gap );
	margin-bottom: var( --dti-auto-gap );
}

/* ------------------------------------------------------------------ featured */

.dti-auto-featured {
	margin-left: auto;
	margin-right: auto;
	text-align: center;
}

.dti-auto-featured img {
	border-radius: var( --dti-auto-radius );
}

/* --------------------------------------------------------------- sample video */

.dti-auto-sample {
	margin-left: auto;
	margin-right: auto;
}

.dti-auto-sample video {
	display: block;
	border-radius: var( --dti-auto-radius );
	background: #000;
}

/* ------------------------------------------------------------------- the CTA */

/*
 * The one thing on the page a reader is meant to press. Centred, wide enough to
 * be an obvious target and bounded so it does not become a stripe across a
 * desktop; on a narrow screen it takes the full width, which is where a thumb
 * expects it.
 */
.dti-auto-cta {
	text-align: center;
}

/*
 * core/buttons lays its buttons out with flexbox rather than text-align, so the
 * block-native wrapper is centred the way core expects and the width below is
 * what makes it fill the column.
 */
.dti-auto-section--cta .wp-block-buttons,
.dti-auto-section--cta-video .wp-block-buttons,
.dti-auto-section--cta-final .wp-block-buttons {
	justify-content: center;
}

.dti-auto-section--cta .wp-block-button,
.dti-auto-section--cta-video .wp-block-button,
.dti-auto-section--cta-final .wp-block-button {
	width: 100%;
	max-width: 24em;
}

/*
 * Two selectors for one button, for the length of the migration.
 *
 * A legacy article's CTA is `<p class="dti-auto-cta"><a class="dti-auto-cta__link">`.
 * A block-native one is core/buttons, and core decides the inner element's
 * class - the anchor is `wp-block-button__link` and the custom class lands on
 * the wrapper instead. So the block-native anchor is reached through the
 * section it lives in rather than through a class of its own.
 *
 * The legacy selector stays. Eight accepted production drafts are still in the
 * legacy format and must keep looking exactly as they were accepted; dropping
 * it the moment the new one exists would restyle every one of them. It goes
 * when the last article has migrated and not before.
 */
.dti-auto-cta__link,
.dti-auto-section--cta .wp-block-button__link,
.dti-auto-section--cta-video .wp-block-button__link,
.dti-auto-section--cta-final .wp-block-button__link {
	display: inline-block;
	box-sizing: border-box;
	width: 100%;
	max-width: 24em;
	padding: 0.9em 1.6em;
	border: 0;
	border-radius: var( --dti-auto-radius );
	background: var( --dti-auto-accent );
	color: var( --dti-auto-accent-text );
	font-size: 1.05em;
	font-weight: 700;
	line-height: 1.4;
	text-align: center;
	text-decoration: none;
	transition: background-color 0.15s ease-in-out;
}

.dti-auto-cta__link:hover,
.dti-auto-section--cta .wp-block-button__link:hover,
.dti-auto-section--cta-video .wp-block-button__link:hover,
.dti-auto-section--cta-final .wp-block-button__link:hover {
	background: var( --dti-auto-accent-hover );
	color: var( --dti-auto-accent-text );
	text-decoration: none;
}

/*
 * Focus is a separate state from hover and is stated separately. A keyboard
 * reader gets a ring; a mouse reader gets the darker fill above. Neither is the
 * only way to tell the button is the button - the text and the fill say that on
 * their own.
 */
.dti-auto-cta__link:focus,
.dti-auto-cta__link:focus-visible,
.dti-auto-section--cta .wp-block-button__link:focus,
.dti-auto-section--cta .wp-block-button__link:focus-visible,
.dti-auto-section--cta-video .wp-block-button__link:focus,
.dti-auto-section--cta-video .wp-block-button__link:focus-visible,
.dti-auto-section--cta-final .wp-block-button__link:focus,
.dti-auto-section--cta-final .wp-block-button__link:focus-visible {
	outline: 3px solid var( --dti-auto-accent-hover );
	outline-offset: 2px;
	background: var( --dti-auto-accent-hover );
	color: var( --dti-auto-accent-text );
}

@media ( max-width: 480px ) {
	.dti-auto-cta__link,
	.dti-auto-section--cta .wp-block-button__link,
	.dti-auto-section--cta-video .wp-block-button__link,
	.dti-auto-section--cta-final .wp-block-button__link {
		max-width: none;
		padding: 1em 1.2em;
	}
}

/* -------------------------------------------------------------- work facts */

/*
 * The column shares stay inline, on the colgroup and the cells, because
 * WordPress keeps `width` and removes `table-layout` - measured, not assumed.
 * What lives here is everything that is only about reading it.
 */
.dti-auto-facts table {
	border-collapse: collapse;
}

.dti-auto-facts th,
.dti-auto-facts td {
	padding: 0.6em 0.8em;
	border-top: 1px solid var( --dti-auto-rule );
	/*
	 * Centred across the row rather than pinned to the top. A label is one
	 * short line and its value is often several - 出演者 against a list of
	 * names, タグ against a dozen - and top alignment left the label floating
	 * beside the first line of a tall cell. Middle reads as one row.
	 */
	vertical-align: middle;
	text-align: left;
	line-height: 1.7;
	/* A long tag list wraps. It never asks the page to scroll sideways. */
	word-break: break-word;
	overflow-wrap: break-word;
}

.dti-auto-facts tr:last-child th,
.dti-auto-facts tr:last-child td {
	border-bottom: 1px solid var( --dti-auto-rule );
}

.dti-auto-facts th {
	background: var( --dti-auto-quiet );
	font-weight: 700;
	/*
	 * The label is centred in its own column; the value beside it stays left,
	 * from the shared rule above. Only the label moves, and only horizontally -
	 * the 30/70 share is written inline by the composer and nothing here
	 * touches it.
	 */
	text-align: center;
	/*
	 * The label column is 30% of the table, which is wider than four Japanese
	 * characters need at any screen size this plugin is read on. It is allowed
	 * to wrap rather than forced not to: a label longer than the column is
	 * better wrapped than overflowing.
	 */
	white-space: normal;
}

/*
 * The 30/70 share, for block-native articles only.
 *
 * A legacy article carries the share inline, twice - on a colgroup and on every
 * th - and the comment above says why. A block-native article cannot: core/table
 * registers no colgroup and no per-cell width, so both declarations are stripped
 * the first time the post is opened in the editor. Measured against the shipped
 * block.json, not assumed.
 *
 * So the share moves here, and the thing that makes it hold moves with it. The
 * reason it had to be written twice was that safecss_filter_attr strips inline
 * `table-layout: fixed`, leaving the widths without the layout mode that honours
 * them. core/table states fixed layout as the `has-fixed-layout` class instead,
 * which kses keeps. One declaration, and the mode it needs actually survives.
 *
 * The cost, stated plainly: a legacy article keeps its 30/70 even if this
 * stylesheet never loads, and a block-native one does not - it falls back to the
 * equal columns `has-fixed-layout` gives. Correct rather than broken, but it is
 * a real change to the "markup carries its own structural widths" property.
 *
 * WHY THE SELECTOR IS THIS LONG
 *
 * Because a short one lost. The first version of this rule was
 * `.dti-auto-section--work-info th`, specificity (0,1,1), and on production it
 * was outranked by the active theme's own first-cell rule:
 *
 *   .wp-block-table > table tr > :first-child:not(.-no1)   (0,3,2)
 *       width: var( --swl-cell1-width, auto );
 *
 * The variable is undefined, so the width resolved to `auto`, and `auto` under
 * `has-fixed-layout` means equal columns. Phase 6C measured the migrated
 * article at 49.9/49.9 on both desktop and mobile, against 30.0/69.9 for a
 * legacy article on the same page - legacy wins there because its widths sit on
 * a `<col>`, which no cell rule can outrank.
 *
 * This is written at (0,4,2) out of classes this plugin owns and the block
 * contract guarantees: the section group, the table block's own class, and the
 * facts class the composer puts on the figure. It beats the measured rule, and
 * it would beat any other theme rule of that shape, without naming a theme,
 * without borrowing a theme's custom property, and without !important.
 *
 * Both columns are stated rather than only the first. A rule that only pins
 * 30% leaves the second column to whatever the theme says about it, and the
 * point of this block is that the split is ours.
 *
 * Deliberately NOT keyed on `th`: the first cell is a `th` today because the
 * composer writes one, and this rule is about which column a cell is in.
 */
.dti-auto-section--work-info .wp-block-table.dti-auto-facts > table tr > :first-child {
	/*
	 * Border-box, and this is the half of the rule that makes the share real.
	 *
	 * The legacy table carried its 30% on a `<col>`, and a column width is a
	 * border-box width - padding lives inside it. A `width` on the cell is not:
	 * with the default content-box it means 30% of the table PLUS whatever
	 * padding the theme adds, which on Twenty Twenty-Five measured 35.6% rather
	 * than 30%. Measured in a browser on the migrated article, not assumed.
	 *
	 * core/table registers no colgroup, so the column route is gone and the
	 * cell has to be told to behave like one.
	 */
	box-sizing: border-box;
	width: 30%;
}

.dti-auto-section--work-info .wp-block-table.dti-auto-facts > table tr > :nth-child( 2 ) {
	box-sizing: border-box;
	width: 70%;
}

.dti-auto-facts td a {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

/* ----------------------------------------------------------------- the tags */

.dti-auto-tags {
	line-height: 1.9;
}

.dti-auto-tags a {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

/* --------------------------------------------------- the official description */

/*
 * This block is somebody else's writing and is meant to look like it. A rule
 * down the side, a quiet ground and room to breathe - enough that a reader can
 * see where the provider's words start and stop, and not so much that it
 * becomes the loudest thing on the page.
 */
.dti-auto-description {
	margin-left: 0;
	margin-right: 0;
	padding: 1em 1.2em;
	border-left: 4px solid var( --dti-auto-accent );
	border-radius: 0 var( --dti-auto-radius ) var( --dti-auto-radius ) 0;
	background: var( --dti-auto-quiet );
	font-style: normal;
	line-height: 1.9;
}

.dti-auto-description p {
	margin: 0;
}

.dti-auto-description cite {
	display: block;
	margin-top: 0.8em;
	font-size: 0.85em;
	font-style: normal;
	opacity: 0.75;
}

.dti-auto-description cite::before {
	content: "— ";
}

/* --------------------------------------------------------------- the gallery */

/*
 * Three across on a desktop, two on a tablet, two on a phone. `auto-fill` with
 * a minimum would do most of this on its own, but the counts below are the ones
 * measured in a browser at 1200, 768 and 390 - a sample picture is worth seeing,
 * and four to a row on a phone is not seeing it.
 *
 * WHY TWO SELECTORS
 *
 * Because the element holding the figures is not the same element in both
 * formats, and a grid only lays out its own children.
 *
 *   legacy        div.dti-auto-gallery > figure ×5
 *   block-native  div.wp-block-group.dti-auto-gallery
 *                   > div.wp-block-group__inner-container > figure ×5
 *
 * That inner div is WordPress's, not ours. core's wp_restore_group_inner_container()
 * puts it back inside every core/group when the active theme ships no
 * theme.json - its own comment says it is "to avoid breaking styles relying on
 * that div". On a site whose theme has no theme.json it is always there.
 *
 * So the block-native gallery had one grid item, not five: the inner container
 * sat in column one and the five figures stacked inside it. Measured on
 * production at 812px wide - three columns of 264px computed, two of them
 * empty, five rows of one. The CSS was doing exactly what it said; it was
 * pointed at the wrong element.
 *
 * Both get the grid, and the inner container spans the outer one so no width is
 * lost to those empty columns. Legacy matches only the first selector and is
 * untouched.
 */
.dti-auto-gallery,
.dti-auto-gallery > .wp-block-group__inner-container {
	display: grid;
	grid-template-columns: repeat( 3, 1fr );
	gap: 10px;
}

/*
 * The whole width, not one column of it.
 *
 * `1 / -1` spans every track including the gaps between them, so the inner grid
 * gets exactly the outer's content width. The outer keeps its columns and never
 * shows a gap, because a single spanning item leaves nothing to put between -
 * the 10px a reader sees is the inner grid's, once.
 */
.dti-auto-gallery > .wp-block-group__inner-container {
	grid-column: 1 / -1;
}

.dti-auto-gallery__item {
	margin: 0;
}

.dti-auto-gallery__item a {
	display: block;
	line-height: 0;
	border-radius: var( --dti-auto-radius );
	overflow: hidden;
}

.dti-auto-gallery__item img {
	display: block;
	width: 100%;
	height: auto;
	cursor: zoom-in;
	transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
}

.dti-auto-gallery__item a:hover img {
	opacity: 0.85;
}

.dti-auto-gallery__item a:focus,
.dti-auto-gallery__item a:focus-visible {
	outline: 3px solid var( --dti-auto-accent );
	outline-offset: 2px;
}

/*
 * Measured, not guessed. At a 390px viewport this theme gives the article a
 * 315px column, so a 30% label cell is about 94px; four Japanese characters at
 * the body size plus 0.8em of padding on each side did not fit, and
 * シリーズ wrapped. The share stays at 30% - it is an accepted contract - and
 * the padding and the label size give way instead.
 */
@media ( max-width: 600px ) {
	.dti-auto-facts th,
	.dti-auto-facts td {
		padding: 0.55em 0.5em;
	}

	.dti-auto-facts th {
		font-size: 0.92em;
	}
}

@media ( max-width: 900px ) {
	.dti-auto-gallery,
	.dti-auto-gallery > .wp-block-group__inner-container {
		grid-template-columns: repeat( 2, 1fr );
	}
}

@media ( max-width: 400px ) {
	/*
	 * Both, so the gap a reader sees changes. The outer's gap is never drawn -
	 * its single item spans every track - so stating it on the outer alone
	 * would change nothing at all in block-native markup.
	 */
	.dti-auto-gallery,
	.dti-auto-gallery > .wp-block-group__inner-container {
		gap: 8px;
	}
}

/* -------------------------------------------------------------- the lightbox */

/*
 * Built by assets/js/article-gallery.js, and only when a reader actually opens
 * a picture. An article nobody clicks, or a page where the script did not run,
 * has none of these nodes - and the gallery still works, because every picture
 * is an anchor to the approved image.
 *
 * Class names are DTI-prefixed for the usual reason and one extra: a SWELL site
 * may already have a lightbox plugin, and two things called `.lightbox` on one
 * page is a bug nobody can see coming.
 */
.dti-auto-lightbox {
	position: fixed;
	z-index: 100000;
	inset: 0;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	/*
	 * Room around the panel so it never touches the edge of the screen. This is
	 * what makes it read as a panel on the page rather than as the page.
	 */
	padding: 3vmin;
	box-sizing: border-box;
}

.dti-auto-lightbox[hidden] {
	display: none;
}

/*
 * The backdrop stays the full viewport - that part was always right, and it is
 * what a reader clicks to dismiss. What changed is everything in front of it.
 */
.dti-auto-lightbox__backdrop {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba( 0, 0, 0, 0.75 );
}

/*
 * A centred panel, not a full-screen image.
 *
 * The picture used to be sized against the viewport and the close button pinned
 * to the corner of the screen, which put the one control a reader wants as far
 * from the thing they are looking at as the display allows. A bounded panel
 * fixes both at once: the image has a frame, and the frame has a corner for the
 * button to sit in.
 *
 * The width is a `max-width` on purpose - the panel shrinks to the picture it is
 * showing rather than always being 1100px of white around a small image - and it
 * is stated in viewport units with a ceiling so it can never widen a phone.
 */
.dti-auto-lightbox__dialog {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	max-width: min( 84vw, 1100px );
	max-height: 90vh;
	padding: 10px;
	border-radius: var( --dti-auto-radius );
	background: #fff;
	box-shadow: 0 10px 40px rgba( 0, 0, 0, 0.45 );
}

.dti-auto-lightbox__image {
	display: block;
	max-width: 100%;
	max-height: 82vh;
	width: auto;
	height: auto;
	border-radius: 2px;
	/* Fits. Never cropped, never stretched. */
	object-fit: contain;
}

/*
 * On the panel, not on the viewport.
 *
 * It overlaps the upper-right corner slightly so it reads as belonging to the
 * panel and never sits on top of the middle of the picture. The 44px box is the
 * tap target and is the one pixel width in this stylesheet, named as such by the
 * styling census: it cannot widen a page because it is inside a fixed-position
 * modal rather than in the document flow.
 */
.dti-auto-lightbox__close {
	position: absolute;
	z-index: 1;
	top: -14px;
	right: -14px;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 2px solid #fff;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.78 );
	color: #fff;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
}

.dti-auto-lightbox__close:hover {
	background: rgba( 0, 0, 0, 0.92 );
}

.dti-auto-lightbox__close:focus,
.dti-auto-lightbox__close:focus-visible {
	outline: 3px solid var( --dti-auto-accent );
	outline-offset: 2px;
}

/*
 * Narrow screens. The panel takes nearly the whole width but keeps its margin,
 * and the button moves inside the corner rather than outside it, so it cannot be
 * clipped by the edge of the display.
 */
@media ( max-width: 600px ) {
	.dti-auto-lightbox {
		padding: 10px;
	}

	.dti-auto-lightbox__dialog {
		max-width: 100%;
		max-height: 92vh;
		padding: 6px;
	}

	.dti-auto-lightbox__image {
		max-height: 78vh;
	}

	.dti-auto-lightbox__close {
		top: 2px;
		right: 2px;
	}
}

/*
 * The scroll lock. A DTI-prefixed class rather than a bare `body {}` rule, put
 * on both the document element and the body because which of the two actually
 * scrolls is the theme's decision. Both are removed on close, along with the
 * inline overflow the script remembered for each.
 */
.dti-auto-lightbox-open {
	overflow: hidden;
}
