/* ==========================================================================
   MageMinion (Tech Digest theme) — mobile app UI (≤ 768px): bottom tab bar,
   action bar, tutorial progress, swipeable TIL archive.
   Enqueued with media="(max-width: 768px)" (inc/setup.php). The @media
   wrapper is kept so the same file is safe inside the block editor, where
   it is added through add_editor_style().
   ========================================================================== */

@media (max-width: 768px) {
	body.td-theme {
		padding-bottom: calc(84px + env(safe-area-inset-bottom));
	}

	/* Single posts also carry the floating action bar (64px tall, 96px above
	   the viewport bottom): keep the footer clear of it. */
	body.td-theme.single-post {
		padding-bottom: calc(176px + env(safe-area-inset-bottom));
	}

	/* Phones navigate with the tab bar: hide Blocksy's hamburger (the trigger <a> itself carries
	   data-id="trigger"). Tablets at 769-999 px keep it, as the tab bar is phone-only. */
	.ct-header [data-id="trigger"] {
		display: none;
	}

	/* The header search button (added for tablets in 1.4.21) is hidden on phones: the tab bar has Search.
	   Scoped to the header; the tab bar item is outside .ct-header. */
	body.td-theme .ct-header [data-id="search"].ct-header-search {
		display: none;
	}

	/* Header Subscribe pill (same Blocksy button as desktop, in the mobile header): about 36px tall,
	   with a transparent 44px tap area. */
	body.td-theme .ct-header .ct-header-cta .ct-button {
		position: relative;
		min-height: 36px;
		padding: 5px 14px;
		font-size: 14px;
		box-shadow: 2px 2px 0 var(--td-ink);
	}

	body.td-theme .ct-header .ct-header-cta .ct-button::after {
		content: "";
		position: absolute;
		inset: -6px -4px;
	}

	/* About: experience card stacks title, date pill, company. */
	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-sticker:has(> .td-pill:first-child + h3) {
		grid-template-columns: auto minmax(0, 1fr);
		row-gap: 10px;
	}

	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-sticker:has(> .td-pill:first-child + h3) > h3 {
		grid-column: 1 / -1;
	}

	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-sticker:has(> .td-pill:first-child + h3) > .td-pill {
		grid-column: 1;
		grid-row: 2;
	}

	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-sticker:has(> .td-pill:first-child + h3) > :not(.td-pill, h3) {
		grid-column: 1 / -1;
	}

	/* About: "Let's talk" buttons stack under the copy. */
	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-violet:not(.td-newsletter):has(> h2 + p + .wp-block-buttons) {
		grid-template-columns: minmax(0, 1fr);
		row-gap: 16px;
	}

	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-violet:not(.td-newsletter):has(> h2 + p + .wp-block-buttons) > .wp-block-buttons {
		grid-column: 1;
		grid-row: auto;
		justify-content: flex-start;
	}

	:is(body.td-theme, .editor-styles-wrapper) .is-style-td-violet:not(.td-newsletter):has(> h2 + p + .wp-block-buttons) .wp-block-button__link {
		font-size: 14px;
		padding-inline: 12px;
		overflow-wrap: anywhere;
	}

	/* The floating action bar has its own back-to-top; hide Blocksy's button on phones. */
	body.td-theme .ct-back-to-top {
		display: none;
	}

	.td-tabbar {
		display: flex;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 60;
		background: var(--td-paper);
		border-top: var(--td-border);
		padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
	}

	/* Tab items are <a> links, plus a <button> for Search: the :is() form outranks
	   Blocksy's link colour / underline and the button resets neutralise UA styles. */
	body.td-theme :is(a, button).td-tabbar__item {
		flex: 1;
		min-width: 0;
		min-height: 52px;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 4px;
		margin: 0;
		padding: 0;
		border: 0;
		background: none;
		font-family: inherit;
		cursor: pointer;
		color: var(--td-ink);
		text-decoration: none;
		font-size: var(--td-text-xs);
		font-weight: 600;
	}

	/* The Search tab carries Blocksy's .ct-header-search (opens #search-modal);
	   keep Blocksy's svg fill / label colour rules off it so it matches the other tabs. */
	body.td-theme .td-tabbar__item.ct-header-search svg,
	body.td-theme .td-tabbar__item.ct-header-search:hover svg {
		fill: none;
	}

	.td-tabbar__icon {
		width: 56px;
		height: 32px;
		border-radius: var(--td-radius-pill);
		border: 2px solid transparent;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
	}

	body.td-theme :is(a, button).td-tabbar__item.is-active {
		font-weight: 700;
	}

	.td-tabbar__item.is-active .td-tabbar__icon {
		background: var(--td-lime);
		border-color: var(--td-ink);
	}

	/* Floating post action bar */
	.td-actionbar {
		display: flex;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		bottom: calc(96px + env(safe-area-inset-bottom));
		z-index: 55;
		gap: 6px;
		padding: 6px;
		background: var(--td-paper);
		border: var(--td-border);
		border-radius: var(--td-radius-pill);
		box-shadow: var(--td-shadow-sm);
	}

	/* Hidden until scrolled past 400 px and scrolling up (techdigest.js adds html.td-ab-js and .is-visible).
	   visibility flips after the fade so a hidden bar can't take focus; without JS the bar stays visible. */
	html.td-ab-js .td-actionbar {
		opacity: 0;
		visibility: hidden;
		pointer-events: none;
		transform: translate(-50%, 12px);
		transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
	}

	html.td-ab-js .td-actionbar.is-visible {
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
		transform: translateX(-50%);
		transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
	}

	@media (prefers-reduced-motion: reduce) {
		html.td-ab-js .td-actionbar,
		html.td-ab-js .td-actionbar.is-visible {
			transform: translateX(-50%);
			transition: opacity 0.01s linear, visibility 0s linear 0.01s;
		}

		html.td-ab-js .td-actionbar.is-visible {
			transition: opacity 0.01s linear, visibility 0s;
		}
	}

	.td-actionbar__btn {
		width: 48px;
		height: 48px;
		border-radius: var(--td-radius-pill);
		border: 0;
		background: transparent;
		color: var(--td-ink);
		display: flex;
		align-items: center;
		justify-content: center;
		font: inherit;
		font-weight: 700;
		font-size: var(--td-text-md);
		cursor: pointer;
	}

	.td-actionbar__btn--lime {
		background: var(--td-lime);
		border: var(--td-border);
	}

	body.td-text-lg .entry-content {
		font-size: 1.15em;
	}

	body.td-text-xl .entry-content {
		font-size: 1.3em;
	}

	/* Tutorial: sticky "Step x of y" strip */
	.td-layout-tutorial .td-step-progress {
		display: flex;
		position: sticky;
		/* Same offset Blocksy uses for its own sticky sidebars. --header-sticky-height
		   is only set when a sticky header row is enabled; otherwise this is 0. */
		top: calc(var(--admin-bar, 0px) + var(--theme-frame-size, 0px) + var(--header-sticky-height, 0px) * var(--sticky-shrink, 100) / 100);
		z-index: 20;
		align-items: center;
		gap: 12px;
		/* Full bleed: Blocksy fixes the width (--theme-block-width), so widen to the
		   viewport and pull back by half the difference. !important kept (1/1): core's
		   constrained layout sets margin-inline:auto !important on children. */
		width: 100vw;
		max-width: none;
		margin: 0 calc(50% - 50vw) 16px !important;
		padding: 10px 16px;
		background: var(--td-ground);
		border-bottom: var(--td-border);
		font-size: var(--td-text-sm);
		font-weight: 700;
	}

	.td-step-progress__bar {
		flex: 1;
		height: 10px;
		border-radius: var(--td-radius-pill);
		border: var(--td-border);
		background: var(--td-paper);
		overflow: hidden;
	}

	.td-step-progress__bar span {
		display: block;
		height: 100%;
		width: 0;
		background: var(--td-lime);
		transition: width 0.25s ease;
	}

	/* Step cards sit close to the screen edge on phones: smaller shadow so
	   it keeps clear of the viewport edge. */
	.is-style-td-step {
		--td-card-shadow: var(--td-shadow-sm);
	}

	.is-style-td-step::before {
		font-size: 64px;
	}

	/* Swipeable TIL archive. body.td-theme.td-til-archive outranks Blocksy's
	   grid on .entries without !important. */
	body.td-theme.td-til-archive .entries {
		display: flex;
		flex-wrap: nowrap;
		gap: 14px;
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		padding: 40px 16px 20px;
		margin-inline: -16px;
		grid-template-columns: none;
	}

	.td-til-archive .entries .entry-card {
		flex: 0 0 86%;
		scroll-snap-align: center;
		border-style: dashed;
	}

	/* Zine type scales down for phones */
	body.td-theme :is(.is-style-td-zine, .is-style-td-zine-violet),
	.editor-styles-wrapper :is(.is-style-td-zine, .is-style-td-zine-violet) {
		-webkit-text-stroke-width: 2px;
		text-shadow: var(--td-shadow-sm);
	}

	body.td-theme .td-cards .wp-block-post-template.is-layout-grid,
	.editor-styles-wrapper .td-cards .wp-block-post-template.is-layout-grid {
		grid-template-columns: 1fr;
	}
}

/* Home topic row: label + chips on one line; the chips scroll sideways and snap. */
@media (max-width: 768px) {
	body.td-theme .td-home-topics {
		flex-wrap: nowrap;
		margin-block: 16px 24px;
	}

	body.td-theme .td-home-topics .td-topics {
		flex: 1 1 auto;
		min-width: 0;
		flex-wrap: nowrap;
		overflow-x: auto;
		scroll-snap-type: x proximity;
		scrollbar-width: none;
		padding-block: 2px 4px;
	}

	/* Right-edge fade cue: the row scrolls. JS adds .is-at-end when scrolled to the end; without JS the fade stays. */
	body.td-theme .td-home-topics .td-topics:not(.is-at-end) {
		-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
		mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
	}

	body.td-theme .td-home-topics .td-topics::-webkit-scrollbar {
		display: none;
	}

	body.td-theme .td-home-topics .td-topics li {
		flex: none;
		scroll-snap-align: start;
	}
}

/* Home first frame: the band stacks, image above the title. */
@media (max-width: 768px) {
	body.td-theme .td-band {
		padding: 24px 16px;
		min-height: 0;
	}

	body.td-theme .td-band .td-band-cols {
		flex-direction: column-reverse;
		gap: 24px;
	}

	/* 200px keeps the "Featured" chip and the title above the tab bar on the first screen (360x780 and up). */
	.td-band .wp-block-post-featured-image img {
		height: 200px;
	}

	/* Elliptical radii keep the desktop arch proportions at 200px tall (a 240px circular radius would make a pure dome). */
	.td-band .wp-block-post-featured-image {
		--td-card-radius: 50% 50% 28px 28px / 60% 60% 28px 28px;
	}

	/* Title size comes from the generic zine h2 rule (36px on phones); a font-size here would never apply. */
	.td-band .wp-block-post-title {
		margin-bottom: 14px;
	}

	body.td-theme .td-band a.wp-block-read-more.td-band-btn {
		display: block;
		text-align: center;
		width: 100%;
		box-sizing: border-box;
	}
}

/* Home option B on phones: card stacks (16:9 cover on top), then the list, then Latest. */
@media (max-width: 768px) {
	body.td-theme .td-home-top {
		margin-top: 12px;
	}

	.td-home-top .td-home-top-cols {
		gap: 16px;
	}

	.td-feature-card {
		grid-template-columns: 1fr;
	}

	.td-feature-img {
		order: -1;
		border-left: 0;
		border-bottom: var(--td-border);
	}

	.td-feature-img img {
		height: auto;
		min-height: 0;
		aspect-ratio: 16 / 9;
		object-position: 50% 50%;
	}

	.td-feature-text {
		padding: 16px 18px 18px;
	}

	body.td-theme .td-feature h2.wp-block-post-title.is-style-td-zine {
		font-size: 30px;
	}

	.td-feature .wp-block-post-excerpt__excerpt {
		font-size: 15px;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	body.td-theme .td-feature a.wp-block-read-more.td-band-btn {
		display: block;
		width: 100%;
		box-sizing: border-box;
		text-align: center;
	}

	body.td-theme .td-rail.td-term {
		height: auto;
	}

	.td-term__cmd,
	.td-term__who,
	.td-term__end {
		padding-inline: 14px;
		font-size: 12px;
	}

	.td-term .wp-block-query {
		padding-inline: 14px;
	}

	/* 44px tap rows; two-line titles at most. */
	.td-term .td-rail-item {
		min-height: 44px;
	}

	body.td-theme .td-term .td-rail-title a {
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}
}

/* Contact page: core already stacks the columns below 782px (heading, intro and link cards, then the form card); just tighten the gap. */
@media (max-width: 768px) {
	.td-contact.wp-block-columns {
		gap: 32px;
	}

	body.td-theme .wp-block-group.td-link-card,
	.editor-styles-wrapper .wp-block-group.td-link-card {
		padding-right: 52px;
	}

	body.td-theme .td-contact-title mark {
		margin-inline-start: 0.2em;
	}

	/* The Credly URL breaks only at its <wbr> (item 7), so the value keeps the 14px body size. */
	.td-link-card__value {
		font-size: 14px;
	}

	.td-link-card__value a::after {
		padding-right: 20px;
		font-size: 24px;
	}
}

/* Bottom sheets: "More" (tab bar) and the tutorial steps list. Native <dialog>, opened with showModal(). */
@media (max-width: 768px) {
	.td-sheet {
		position: fixed;
		inset: auto 0 0 0;
		width: 100%;
		max-width: none;
		max-height: 85vh;
		margin: 0;
		padding: 0;
		border: 0;
		border-top: var(--td-border);
		border-radius: var(--td-radius-lg) var(--td-radius-lg) 0 0;
		background: var(--td-ground);
		color: var(--td-ink);
		overflow: auto;
		overscroll-behavior: contain;
	}

	.td-sheet::backdrop {
		background: rgba(17, 17, 17, 0.45);
	}

	html:has(.td-sheet[open]) {
		overflow: hidden;
	}

	.td-sheet__inner {
		padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
	}

	.td-sheet__grab {
		width: 40px;
		height: 5px;
		border-radius: 9px;
		background: rgba(17, 17, 17, 0.3);
		margin: 0 auto 10px;
	}

	.td-sheet__head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: 12px;
		margin-bottom: 12px;
	}

	body.td-theme .td-sheet__title {
		font-family: var(--td-display);
		font-style: italic;
		font-weight: 900;
		text-transform: uppercase;
		font-size: 22px;
		line-height: 1.05;
		margin: 0;
	}

	.td-sheet__close {
		flex: none;
		width: 44px;
		height: 44px;
		display: grid;
		place-items: center;
		padding: 0;
		border: var(--td-border);
		border-radius: var(--td-radius-sm);
		background: var(--td-paper);
		color: var(--td-ink);
		cursor: pointer;
	}

	body.td-theme :is(.td-sheet__link, .td-steps__link) {
		display: flex;
		align-items: center;
		gap: 10px;
		min-height: 48px;
		box-sizing: border-box;
		padding: 10px 14px;
		margin-bottom: 8px;
		background: var(--td-paper);
		border: var(--td-border);
		border-radius: var(--td-radius-md);
		box-shadow: 2px 2px 0 var(--td-ink);
		color: var(--td-ink);
		text-decoration: none;
		font-weight: 600;
	}

	.td-sheet__link {
		justify-content: space-between;
	}

	body.td-theme .td-sheet__link.is-lime {
		background: var(--td-lime);
	}

	.td-sheet__hint {
		font-family: var(--td-mono);
		font-size: 11px;
		font-weight: 500;
		color: var(--td-muted);
	}

	/* Chips wrap in the sheet (on Home they scroll sideways). */
	.td-sheet .td-sheet__topics {
		display: flex;
		flex-wrap: wrap;
		gap: 6px;
		overflow: visible;
		list-style: none;
		padding: 0;
		margin: 2px 0 12px;
	}

	.td-sheet .td-sheet__topics li {
		margin: 0;
	}

	@media (prefers-reduced-motion: no-preference) {
		.td-sheet[open] {
			animation: td-sheet-up 0.2s ease-out;
		}

		@keyframes td-sheet-up {
			from {
				transform: translateY(24px);
				opacity: 0.6;
			}
		}
	}

	/* Tutorial "Step x of y" strip: a tap anywhere opens the steps sheet (the button's ::after covers the strip). */
	.td-step-progress__btn {
		flex: none;
		display: inline-flex;
		align-items: center;
		gap: 2px;
		min-height: 32px;
		margin: 0;
		padding: 4px 8px 4px 12px;
		border: var(--td-border);
		border-radius: var(--td-radius-pill);
		background: var(--td-paper);
		color: var(--td-ink);
		font: inherit;
		font-size: var(--td-text-xs);
		font-weight: 700;
		cursor: pointer;
	}

	.td-step-progress__btn svg {
		width: 16px;
		height: 16px;
	}

	.td-step-progress__btn::after {
		content: "";
		position: absolute;
		inset: 0;
	}

	.td-step-progress__btn:focus-visible {
		outline: 3px solid var(--td-violet);
		outline-offset: 2px;
	}

	/* Plain #td-step-N links land below the sticky header and strip (about 64 + 49px); the steps sheet measures it exactly in JS. */
	.entry-content .is-style-td-step {
		scroll-margin-top: 124px;
	}

	.td-steps__list {
		list-style: none;
		margin: 0;
		padding: 0;
	}

	.td-steps__list li {
		margin: 0;
	}

	.td-steps__n {
		flex: none;
		width: 26px;
		height: 26px;
		display: grid;
		place-items: center;
		border: var(--td-border);
		border-radius: 50%;
		font-family: var(--td-mono);
		font-size: 12px;
		font-weight: 700;
	}

	.td-steps__link.is-done .td-steps__n {
		background: var(--td-ink);
		color: var(--td-lime);
	}

	body.td-theme .td-steps__link.is-current {
		background: var(--td-lime);
	}

	/* Episode cards cloned from the plugin's series nav; 2 columns here (the plugin stacks them below 640px). */
	.td-sheet .td-sheet__episodes {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 8px;
		margin-top: 12px;
	}
}
